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