mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-23 03:50:32 +08:00
fix transfer
This commit is contained in:
@@ -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")
|
logrus.Debugln("[link] write", len(d), "bytes data")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
peerlink := l.me.router.NextHop(l.peerip.String())
|
peerlink := l.me.router.NextHop(p.Dst.String())
|
||||||
if peerlink != nil {
|
if peerlink != nil {
|
||||||
peerep := peerlink.endpoint
|
peerep := peerlink.endpoint
|
||||||
if peerep == nil {
|
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)
|
logrus.Infoln("[link] write data from ep", l.me.myconn.LocalAddr(), "to", peerep)
|
||||||
n, err = l.me.myconn.WriteToUDP(d, peerep)
|
n, err = l.me.myconn.WriteToUDP(d, peerep)
|
||||||
|
|||||||
@@ -40,11 +40,11 @@ func (r *Router) SetDefault(l *Link) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NextHop 得到前往 ip 的下一跳的 link
|
// NextHop 得到前往 ip 的下一跳的 link
|
||||||
func (r *Router) NextHop(ip string) *Link {
|
func (r *Router) NextHop(ip string) (l *Link) {
|
||||||
ipb := net.ParseIP(ip)
|
ipb := net.ParseIP(ip)
|
||||||
if ipb == nil {
|
if ipb == nil {
|
||||||
logrus.Errorln("[router] nil ip")
|
logrus.Errorln("[router] nil ip")
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 遍历 r.table,得到正确的下一跳
|
// TODO: 遍历 r.table,得到正确的下一跳
|
||||||
@@ -54,14 +54,15 @@ func (r *Router) NextHop(ip string) *Link {
|
|||||||
|
|
||||||
for _, c := range r.list {
|
for _, c := range r.list {
|
||||||
if c.Contains(ipb) {
|
if c.Contains(ipb) {
|
||||||
logrus.Infoln("[router] get nexthop to", ipb, "-->", c)
|
l = r.table[c.String()]
|
||||||
return 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)
|
logrus.Errorln("[router] cannot find nexthop for ip:", ipb)
|
||||||
|
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetItem 添加一条表项
|
// SetItem 添加一条表项
|
||||||
|
|||||||
Reference in New Issue
Block a user