1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-28 06:40:26 +08:00

优化代码结构,router增加ttl

This commit is contained in:
源文雨
2022-04-15 15:41:09 +08:00
parent dcaff382bf
commit 826c89c678
9 changed files with 152 additions and 70 deletions

View File

@@ -65,7 +65,7 @@ func (wg *WG) Stop() {
_ = wg.me.Close()
}
func (wg *WG) init(srcport, destport, mtu uint16) {
func (wg *WG) init(srcport, dstport, mtu uint16) {
cidrsmap := make(map[string]bool, 32)
_, mysubnet, err := net.ParseCIDR(wg.c.SubNet)
if err != nil {
@@ -89,13 +89,15 @@ func (wg *WG) init(srcport, destport, mtu uint16) {
i++
}
wg.me = link.NewMe(
&wg.key,
wg.c.IP+"/32",
wg.c.EndPoint,
lower.NewNIC(wg.c.IP, wg.c.SubNet, fmt.Sprintf("%d", mtu), cidrs...),
srcport, destport, mtu,
)
wg.me = link.NewMe(&link.MyConfig{
MyIPwithMask: wg.c.IP + "/32",
MyEndpoint: wg.c.EndPoint,
PrivateKey: &wg.key,
NIC: lower.NewNIC(wg.c.IP, wg.c.SubNet, fmt.Sprintf("%d", mtu), cidrs...),
SrcPort: srcport,
DstPort: dstport,
MTU: mtu,
})
for _, peer := range wg.c.Peers {
var peerkey [32]byte
@@ -107,6 +109,16 @@ func (wg *WG) init(srcport, destport, mtu uint16) {
if n != 32 {
panic("peer public key length is not 32")
}
wg.me.AddPeer(peer.IP, &peerkey, peer.EndPoint, peer.AllowedIPs, peer.QueryList, peer.KeepAliveSeconds, peer.QuerySeconds, peer.AllowTrans, true)
wg.me.AddPeer(&link.PeerConfig{
PeerIP: peer.IP,
EndPoint: peer.EndPoint,
AllowedIPs: peer.AllowedIPs,
Querys: peer.QueryList,
PubicKey: &peerkey,
KeepAliveDur: peer.KeepAliveSeconds,
QueryTick: peer.QuerySeconds,
AllowTrans: peer.AllowTrans,
NoPipe: true,
})
}
}