fix(proxy): improve NAT test reliability

This is a hack, and I'm not entirely sure how it works,
but it appears to work, at least somewhat.
See https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40419#note_3141855.
This commit is contained in:
WofWca 2024-12-16 01:44:48 +04:00 committed by Shelikhoo
parent e345c3bac9
commit 6384643109
No known key found for this signature in database
GPG key ID: 4C9764E9FE80A3DC

View file

@ -592,7 +592,19 @@ func (sf *SnowflakeProxy) makeNewPeerConnection(
})
dc.OnClose(func() {
log.Println("WebRTC: DataChannel.OnClose")
dc.Close()
go func() {
// A hack to make NAT testing more reliable and not mis-identify
// as "restricted".
// See https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40419#note_3141855.
// Instead we should just `dc.Close()` without waiting
// and without a goroutine.
// (or, perhaps, `dc.Close()` is not needed at all
// in the OnClose callback?)
<-time.After(5 * time.Second)
log.Print("NAT check: WebRTC: dc.Close()")
dc.Close()
}()
})
offer, err := pc.CreateOffer(nil)