Skip to content

Commit

Permalink
fix(loop): local loopback
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Jul 11, 2024
1 parent ed19a5a commit 02ad99a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 0 additions & 10 deletions gold/link/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package link

import (
"bytes"
"errors"
"io"
"net"
"net/netip"
"os"
"runtime"
"strconv"
"sync"
Expand Down Expand Up @@ -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())))
Expand Down
6 changes: 5 additions & 1 deletion gold/link/me.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 02ad99a

Please sign in to comment.