mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
improvement: use SetIPFilter
for local addrs
Closes https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40271. Supersedes https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/merge_requests/417. This simplifies the code and (probably) removes the need for `StripLocalAddresses`, although makes us more dependent on Pion. Signed-off-by: Cecylia Bocovich <cohosh@torproject.org>
This commit is contained in:
parent
43799819a1
commit
ae5bd52821
6 changed files with 56 additions and 32 deletions
|
@ -14,6 +14,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
@ -54,6 +55,17 @@ func makePeerConnectionFromOffer(stunURL string, sdp *webrtc.SessionDescription,
|
|||
dataChanOpen chan struct{}, dataChanClosed chan struct{}, iceGatheringTimeout time.Duration) (*webrtc.PeerConnection, error) {
|
||||
|
||||
settingsEngine := webrtc.SettingEngine{}
|
||||
|
||||
settingsEngine.SetIPFilter(func(ip net.IP) (keep bool) {
|
||||
// `IsLoopback()` and `IsUnspecified` are likely not neded here,
|
||||
// but let's keep them just in case.
|
||||
// FYI there is similar code in other files in this project.
|
||||
keep = !util.IsLocal(ip) && !ip.IsLoopback() && !ip.IsUnspecified()
|
||||
return
|
||||
})
|
||||
// FYI this is `false` by default anyway as of pion/webrtc@4
|
||||
settingsEngine.SetIncludeLoopbackCandidate(false)
|
||||
|
||||
// Use the SetNet setting https://pkg.go.dev/github.com/pion/webrtc/v3#SettingEngine.SetNet
|
||||
// to functionally revert a new change in pion by silently ignoring
|
||||
// when net.Interfaces() fails, rather than throwing an error
|
||||
|
@ -168,11 +180,7 @@ func probeHandler(stunURL string, w http.ResponseWriter, r *http.Request) {
|
|||
// Otherwise it must be closed below, wherever `closePcOnReturn` is set to `false`.
|
||||
}()
|
||||
|
||||
sdp = &webrtc.SessionDescription{
|
||||
Type: pc.LocalDescription().Type,
|
||||
SDP: util.StripLocalAddresses(pc.LocalDescription().SDP),
|
||||
}
|
||||
answer, err := util.SerializeSessionDescription(sdp)
|
||||
answer, err := util.SerializeSessionDescription(pc.LocalDescription())
|
||||
if err != nil {
|
||||
log.Printf("Error making WebRTC connection: %s", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue