File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -54,3 +54,5 @@ require (
5454 gopkg.in/ini.v1 v1.67.0 // indirect
5555 gopkg.in/yaml.v3 v3.0.1 // indirect
5656)
57+
58+ replace github.com/packetcap/go-pcap v0.0.0-20250723190045-d00b185f30b7 => github.com/tjjh89017/go-pcap v0.0.0-20250806125406-94a3a3dd1d4f
Original file line number Diff line number Diff line change @@ -50,8 +50,6 @@ github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721 h1:RlZweED6sbSArvlE9
5050github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721 /go.mod h1:Ickgr2WtCLZ2MDGd4Gr0geeCH5HybhRJbonOgQpvSxc =
5151github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY =
5252github.com/mitchellh/mapstructure v1.5.0 /go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo =
53- github.com/packetcap/go-pcap v0.0.0-20250723190045-d00b185f30b7 h1:MfXxQU9tEe3zmyLVVwE8gJwQVtsG2aqzBkFNz0N6eAo =
54- github.com/packetcap/go-pcap v0.0.0-20250723190045-d00b185f30b7 /go.mod h1:1jryUz9E2ndKwZBNHzVhLMzS3WHO0fOKydYi9XWWu9w =
5553github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M =
5654github.com/pelletier/go-toml/v2 v2.2.3 /go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc =
5755github.com/pion/dtls/v2 v2.2.7 /go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s =
@@ -105,6 +103,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
105103github.com/stretchr/testify v1.10.0 /go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY =
106104github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8 =
107105github.com/subosito/gotenv v1.6.0 /go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU =
106+ github.com/tjjh89017/go-pcap v0.0.0-20250806125406-94a3a3dd1d4f h1:Dg6gfsPyrEJpVpxo4K8C3i/WfG/b4D5symd64FuB+e4 =
107+ github.com/tjjh89017/go-pcap v0.0.0-20250806125406-94a3a3dd1d4f /go.mod h1:1jryUz9E2ndKwZBNHzVhLMzS3WHO0fOKydYi9XWWu9w =
108108github.com/wlynxg/anet v0.0.3 /go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA =
109109github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU =
110110github.com/wlynxg/anet v0.0.5 /go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA =
Original file line number Diff line number Diff line change @@ -135,28 +135,30 @@ func (s *Stun) Start(ctx context.Context) {
135135 logger .Info ().Msgf ("starting to listen stun response on %d interfaces" , len (s .handles ))
136136 s .once .Do (func () {
137137 // Start a goroutine for each interface handle
138+ s .waitGroup .Add (len (s .handles ))
138139 for _ , ih := range s .handles {
140+ logger .Debug ().Msgf ("start handle for interface: %s" , ih .name )
139141 go func (handle interfaceHandle ) {
140- s .waitGroup .Add (1 )
141142 defer func () {
142143 handle .handle .Close ()
143144 logger .Debug ().Msgf ("closed handle for interface: %s" , handle .name )
144145 s .waitGroup .Done ()
145146 }()
147+ timeout := time .After (time .Duration (StunTimeout ) * time .Second )
146148 for {
147149 select {
148150 case <- ctx .Done ():
149151 return
150- case <- time . After ( time . Duration ( StunTimeout ) * time . Second ) :
152+ case <- timeout :
151153 return
152154 default :
153155 var (
154156 buf []byte
155157 err error
156158 )
157- buf , _ , err = handle .handle .ReadPacketData ( )
159+ buf , _ , err = handle .handle .ReadPacketDataWithTimeout ( time . Duration ( StunTimeout ) * time . Second )
158160 if err != nil {
159- logger .Debug ().Msgf ("fail to read packet data from %s, err %v" , handle .name , err )
161+ logger .Trace ().Msgf ("fail to read packet data from %s, err %v" , handle .name , err )
160162 continue
161163 }
162164 // decode STUN
Original file line number Diff line number Diff line change @@ -54,11 +54,12 @@ func (s *Stun) Stop() error {
5454func (s * Stun ) Start (ctx context.Context ) {
5555 s .once .Do (func () {
5656 go func () {
57+ timeout := time .After (time .Duration (StunTimeout + 5 ) * time .Second )
5758 for {
5859 select {
5960 case <- ctx .Done ():
6061 return
61- case <- time . After ( time . Duration ( StunTimeout + 5 ) * time . Second ) :
62+ case <- timeout :
6263 return
6364 default :
6465 buf := make ([]byte , PacketSize )
You can’t perform that action at this time.
0 commit comments