mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-07 08:50:25 +08:00
fix
This commit is contained in:
@@ -79,7 +79,14 @@ func (l *Link) Write(p *head.Packet) (n int, err error) {
|
||||
d, err = p.Marshal(l.me.me.String(), l.peerip.String())
|
||||
logrus.Debugln("[link] write data", string(d))
|
||||
if err == nil {
|
||||
n, err = l.me.myconn.WriteToUDP(d, l.me.router.NextHop(l.peerip.String()+"/32").endpoint)
|
||||
peerlink := l.me.router.NextHop(l.peerip.String() + "/32")
|
||||
if peerlink != nil {
|
||||
peerep := peerlink.endpoint
|
||||
logrus.Infoln("[link] write data from ep", l.me.myconn.LocalAddr(), "to", peerep)
|
||||
n, err = l.me.myconn.WriteToUDP(d, peerep)
|
||||
} else {
|
||||
logrus.Warnln("[link] drop packet: nil peerlink")
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ func (m *Me) AddPeer(peerip string, pubicKey *[32]byte, endPoint string, allowed
|
||||
if err == nil {
|
||||
l.allowedips = append(l.allowedips, cidr)
|
||||
l.me.router.SetItem(cidr, l)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
14
main.go
14
main.go
@@ -129,6 +129,20 @@ func main() {
|
||||
|
||||
nic := lower.NewNIC(c.IP, c.SubNet)
|
||||
me := link.NewMe(&key, c.IP+"/32", c.EndPoint, true)
|
||||
|
||||
for _, peer := range c.Peers {
|
||||
var peerkey [32]byte
|
||||
k, err := base14.UTF82utf16be(helper.StringToBytes(peer.PublicKey + suffix32))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
n := copy(peerkey[:], base14.Decode(k))
|
||||
if n != 32 {
|
||||
panic("peer public key length is not 32")
|
||||
}
|
||||
me.AddPeer(peer.IP, &peerkey, peer.EndPoint, peer.AllowedIPs, peer.KeepAliveSeconds, peer.AllowTrans, true)
|
||||
}
|
||||
|
||||
nic.Up()
|
||||
defer func() {
|
||||
nic.Stop()
|
||||
|
||||
Reference in New Issue
Block a user