1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-07-01 16:10:24 +08:00

feat: split udp protocol to folder p2p

This commit is contained in:
源文雨
2024-07-14 22:26:44 +09:00
parent 4a8e848673
commit 32af3ce142
16 changed files with 180 additions and 49 deletions

View File

@@ -2,12 +2,12 @@ package link
import (
"encoding/json"
"net"
"time"
"github.com/sirupsen/logrus"
"github.com/fumiama/WireGold/gold/head"
"github.com/fumiama/WireGold/gold/p2p"
"github.com/fumiama/WireGold/helper"
)
@@ -44,11 +44,11 @@ func (l *Link) onNotify(packet []byte) {
// ---- 遍历 Notify注册对方的 endpoint 到
// ---- connections注意使用读写锁connmapmu
for peer, ep := range notify {
addr, err := net.ResolveUDPAddr("udp", ep)
addr, err := p2p.NewEndPoint(ep[0], ep[1])
if err == nil {
p, ok := l.me.IsInPeer(peer)
if ok {
if p.endpoint.String() != ep {
if !p.endpoint.Euqal(addr) {
p.endpoint = addr
logrus.Infoln("[nat] notify set ep of peer", peer, "to", ep)
}
@@ -80,7 +80,10 @@ func (l *Link) onQuery(packet []byte) {
for _, p := range peers {
lnk, ok := l.me.IsInPeer(p)
if ok {
notify[p] = lnk.endpoint.String()
notify[p] = [2]string{
lnk.endpoint.Network(),
lnk.endpoint.String(),
}
}
}
if len(notify) > 0 {