fix(proxy): send answer even if ICE gathering is not complete

Otherwise the connection is guaranteed to fail, even though
we actually might have gathered enough to make a successful
connection.

Closes https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40230

This is the standalone proxy counterpart of https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake-webext/-/merge_requests/55
This commit is contained in:
WofWca 2024-09-07 17:32:35 +04:00 committed by Shelikhoo
parent 2bbd4d0643
commit 7f9fea5797
No known key found for this signature in database
GPG key ID: 4C9764E9FE80A3DC

View file

@ -50,6 +50,8 @@ import (
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/task"
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/util"
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/websocketconn"
snowflakeClient "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/client/lib"
)
const (
@ -529,8 +531,15 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(
return nil, err
}
// Wait for ICE candidate gathering to complete
<-done
// Wait for ICE candidate gathering to complete,
// or for whatever we managed to gather before the client times out.
// See https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40230
select {
case <-done:
case <-time.After(snowflakeClient.DataChannelTimeout / 2):
log.Print("ICE gathering is not yet complete, but let's send the answer" +
" before the client times out")
}
if !strings.Contains(pc.LocalDescription().SDP, "\na=candidate:") {
return nil, fmt.Errorf("SDP answer contains no candidate")