1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-27 14:20:27 +08:00

init complete

This commit is contained in:
fumiama
2021-10-25 01:01:22 +08:00
parent d9138df3cd
commit e29d5b2f48
9 changed files with 115 additions and 38 deletions

View File

@@ -6,7 +6,7 @@ import (
"github.com/fumiama/WireGold/gold/head"
)
func AddPeer(peerip string, pubicKey [32]byte, endPoint string, keepAlive int64) (l *Link) {
func AddPeer(peerip string, pubicKey [32]byte, endPoint string, allowedIPs []string, keepAlive int64) (l *Link) {
peerip = net.ParseIP(peerip).String()
var ok bool
l, ok = IsInPeer(peerip)
@@ -27,6 +27,15 @@ func AddPeer(peerip string, pubicKey [32]byte, endPoint string, keepAlive int64)
l.EndPoint = endPoint
l.endpoint = e
}
if allowedIPs != nil {
l.allowedips = make([]*net.IPNet, len(allowedIPs))
for _, ipnet := range allowedIPs {
_, cidr, err := net.ParseCIDR(ipnet)
if err != nil {
l.allowedips = append(l.allowedips, cidr)
}
}
}
connmapmu.Lock()
connections[peerip] = l
connmapmu.Unlock()