mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-22 03:20:30 +08:00
fix route
This commit is contained in:
@@ -33,6 +33,8 @@ type Me struct {
|
||||
myconn *net.UDPConn
|
||||
// 不分目的 link 的接收队列
|
||||
pipe chan *head.Packet
|
||||
// 本机路由表
|
||||
router *Router
|
||||
}
|
||||
|
||||
// NewMe 设置本机参数
|
||||
@@ -57,6 +59,11 @@ func NewMe(privateKey *[32]byte, myipwithmask string, myEndpoint string, nopipei
|
||||
if nopipeinlink {
|
||||
m.pipe = make(chan *head.Packet, 32)
|
||||
}
|
||||
m.router = &Router{
|
||||
list: make([]*net.IPNet, 1, 16),
|
||||
table: make(map[string]*Link, 16),
|
||||
}
|
||||
m.router.SetDefault(nil)
|
||||
m.loop = m.AddPeer(m.me.String(), nil, "127.0.0.1:56789", []string{myipwithmask}, 0, false, nopipeinlink)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -38,8 +38,6 @@ type Link struct {
|
||||
key *[32]byte
|
||||
// 本机信息
|
||||
me *Me
|
||||
// 本连接路由表
|
||||
router *Router
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -90,7 +88,7 @@ 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.router.NextHop(l.peerip.String())
|
||||
peerlink := l.me.router.NextHop(l.peerip.String())
|
||||
if peerlink != nil {
|
||||
peerep := peerlink.endpoint
|
||||
if peerep == nil {
|
||||
|
||||
@@ -23,12 +23,7 @@ func (m *Me) AddPeer(peerip string, pubicKey *[32]byte, endPoint string, allowed
|
||||
peerip: net.ParseIP(peerip),
|
||||
allowtrans: allowTrans,
|
||||
me: m,
|
||||
router: &Router{
|
||||
list: make([]*net.IPNet, 1, 16),
|
||||
table: make(map[string]*Link, 16),
|
||||
},
|
||||
}
|
||||
l.router.SetDefault(l)
|
||||
|
||||
if !nopipe {
|
||||
l.pipe = make(chan *head.Packet, 32)
|
||||
@@ -54,12 +49,12 @@ func (m *Me) AddPeer(peerip string, pubicKey *[32]byte, endPoint string, allowed
|
||||
_, cidr, err := net.ParseCIDR(ipnet)
|
||||
if err == nil {
|
||||
l.allowedips = append(l.allowedips, cidr)
|
||||
l.router.SetItem(cidr, l)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
l.me.router.SetItem(&net.IPNet{IP: l.peerip, Mask: net.IPMask(net.IPv4bcast)}, l)
|
||||
l.me.connmapmu.Lock()
|
||||
l.me.connections[peerip] = l
|
||||
l.me.connmapmu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user