diff --git a/gold/link/listen.go b/gold/link/listen.go index 2adc5e8..4b80757 100644 --- a/gold/link/listen.go +++ b/gold/link/listen.go @@ -2,11 +2,9 @@ package link import ( "bytes" - "errors" "io" "net" "net/netip" - "os" "runtime" "strconv" "sync" @@ -50,19 +48,11 @@ func (m *Me) listenudp() (conn *net.UDPConn, err error) { } logrus.Debugln("[listen] lock index", i) lbf := listenbuff[i*65536 : (i+1)*65536] - err = conn.SetDeadline(time.Now().Add(time.Second)) - if err != nil { - logrus.Warnln("[listen] set ddl err:", err) - } - READ: n, addr, err := conn.ReadFromUDP(lbf) if m.loop == nil { logrus.Warnln("[listen] quit listening") return } - if errors.Is(err, os.ErrDeadlineExceeded) { - goto READ - } if err != nil { logrus.Warnln("[listen] read from udp err, reconnect:", err) conn, err = net.ListenUDP("udp", net.UDPAddrFromAddrPort(netip.MustParseAddrPort(m.udpep.String()))) diff --git a/gold/link/me.go b/gold/link/me.go index 86dd7aa..a3bad7e 100644 --- a/gold/link/me.go +++ b/gold/link/me.go @@ -86,9 +86,13 @@ func NewMe(cfg *MyConfig) (m Me) { cache: ttl.NewCache[string, *Link](time.Minute), } m.router.SetDefault(nil) + _, localp, err := net.SplitHostPort(m.EndPoint().String()) + if err != nil { + panic(err) + } m.loop = m.AddPeer(&PeerConfig{ PeerIP: m.me.String(), - EndPoint: "127.0.0.1:56789", + EndPoint: "127.0.0.1:" + localp, AllowedIPs: []string{cfg.MyIPwithMask}, NoPipe: cfg.NIC != nil, MTU: cfg.MTU,