1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-05 07:50:24 +08:00

fix transfer

This commit is contained in:
fumiama
2021-12-30 17:36:28 +08:00
parent 6c50fa477d
commit b7ffc3996d
2 changed files with 8 additions and 7 deletions

View File

@@ -88,11 +88,11 @@ func (l *Link) Write(p *head.Packet, istransfer bool) (n int, err error) {
}
logrus.Debugln("[link] write", len(d), "bytes data")
if err == nil {
peerlink := l.me.router.NextHop(l.peerip.String())
peerlink := l.me.router.NextHop(p.Dst.String())
if peerlink != nil {
peerep := peerlink.endpoint
if peerep == nil {
return 0, errors.New("[link] nil endpoint of " + l.peerip.String())
return 0, errors.New("[link] nil endpoint of " + p.Dst.String())
}
logrus.Infoln("[link] write data from ep", l.me.myconn.LocalAddr(), "to", peerep)
n, err = l.me.myconn.WriteToUDP(d, peerep)

View File

@@ -40,11 +40,11 @@ func (r *Router) SetDefault(l *Link) {
}
// NextHop 得到前往 ip 的下一跳的 link
func (r *Router) NextHop(ip string) *Link {
func (r *Router) NextHop(ip string) (l *Link) {
ipb := net.ParseIP(ip)
if ipb == nil {
logrus.Errorln("[router] nil ip")
return nil
return
}
// TODO: 遍历 r.table得到正确的下一跳
@@ -54,14 +54,15 @@ func (r *Router) NextHop(ip string) *Link {
for _, c := range r.list {
if c.Contains(ipb) {
logrus.Infoln("[router] get nexthop to", ipb, "-->", c)
return r.table[c.String()]
l = r.table[c.String()]
logrus.Infoln("[router] get nexthop to", ipb, "-->", c, "link", l)
return l
}
}
logrus.Errorln("[router] cannot find nexthop for ip:", ipb)
return nil
return
}
// SetItem 添加一条表项