From 6384643109c36480ff6a82c6248e9f6a7ca6294b Mon Sep 17 00:00:00 2001 From: WofWca Date: Mon, 16 Dec 2024 01:44:48 +0400 Subject: [PATCH] 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. --- proxy/lib/snowflake.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/proxy/lib/snowflake.go b/proxy/lib/snowflake.go index 796fd13..18a321a 100644 --- a/proxy/lib/snowflake.go +++ b/proxy/lib/snowflake.go @@ -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)