Skip to content

Commit

Permalink
udpnat2: Add timeout check
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Nov 26, 2024
1 parent 30e9d91 commit a8f5bf4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions common/udpnat2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type Metrics struct {
}

func New(handler N.UDPConnectionHandlerEx, prepare PrepareFunc, timeout time.Duration, shared bool) *Service {
if timeout == 0 {
panic("invalid timeout")
}
var cache freelru.Cache[netip.AddrPort, *natConn]
if !shared {
cache = common.Must1(freelru.New[netip.AddrPort, *natConn](1024, maphash.NewHasher[netip.AddrPort]().Hash32))
Expand Down Expand Up @@ -80,11 +83,10 @@ func (s *Service) Start() error {
return nil
}

func (s *Service) Close() error {
func (s *Service) Close() {
s.closeOnce.Do(func() {
close(s.doneChan)
})
return nil
}

func (s *Service) NewPacket(bufferSlices [][]byte, source M.Socksaddr, destination M.Socksaddr, userData any) {
Expand Down

0 comments on commit a8f5bf4

Please sign in to comment.