From 02ad99abb29efcf330c3266f85d472a72246a9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Thu, 11 Jul 2024 23:36:09 +0900 Subject: [PATCH] fix(loop): local loopback --- gold/link/listen.go | 10 ---------- gold/link/me.go | 6 +++++- 2 files changed, 5 insertions(+), 11 deletions(-) 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,