mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Parse ICE servers with pion/ice library function
This commit is contained in:
parent
b443e99417
commit
a6a18c1a9b
2 changed files with 19 additions and 5 deletions
|
@ -195,15 +195,20 @@ func TestICEServerParser(t *testing.T) {
|
|||
1,
|
||||
},
|
||||
{
|
||||
[]string{"stun:stun.l.google.com:19302", "stun.ekiga.net"},
|
||||
[][]string{[]string{"stun:stun.l.google.com:19302"}, []string{"stun.ekiga.net"}},
|
||||
[]string{"stun:stun.l.google.com", "stuns:stun.ekiga.net"},
|
||||
[][]string{[]string{"stun:stun.l.google.com:3478"}, []string{"stuns:stun.ekiga.net:5349"}},
|
||||
2,
|
||||
},
|
||||
{
|
||||
[]string{"stun:stun.l.google.com:19302", "stun.ekiga.net"},
|
||||
[][]string{[]string{"stun:stun.l.google.com:19302"}, []string{"stun.ekiga.net"}},
|
||||
[]string{"stuns:stun.l.google.com:19302", "turn:relay.metered.ca:80"},
|
||||
[][]string{[]string{"stuns:stun.l.google.com:19302"}, []string{"turn:relay.metered.ca:80?transport=udp"}},
|
||||
2,
|
||||
},
|
||||
{
|
||||
[]string{"stun:stun1.l.google.com:19302", "stun.ekiga.net", "stun:stun.example.com:1234/path?query", "https://example.com"},
|
||||
[][]string{[]string{"stun:stun1.l.google.com:19302"}},
|
||||
1,
|
||||
},
|
||||
} {
|
||||
servers := parseIceServers(test.input)
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ import (
|
|||
"git.torproject.org/pluggable-transports/snowflake.git/v2/common/event"
|
||||
"git.torproject.org/pluggable-transports/snowflake.git/v2/common/nat"
|
||||
"git.torproject.org/pluggable-transports/snowflake.git/v2/common/turbotunnel"
|
||||
"github.com/pion/ice/v2"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"github.com/xtaci/kcp-go/v5"
|
||||
"github.com/xtaci/smux"
|
||||
|
@ -269,8 +270,16 @@ func parseIceServers(addresses []string) []webrtc.ICEServer {
|
|||
}
|
||||
for _, url := range addresses {
|
||||
url = strings.TrimSpace(url)
|
||||
|
||||
// add default port, other sanity checks
|
||||
parsedURL, err := ice.ParseURL(url)
|
||||
if err != nil {
|
||||
log.Printf("Warning: Parsing ICE server %v resulted in error: %v, skipping", url, err)
|
||||
continue
|
||||
}
|
||||
|
||||
servers = append(servers, webrtc.ICEServer{
|
||||
URLs: []string{url},
|
||||
URLs: []string{parsedURL.String()},
|
||||
})
|
||||
}
|
||||
return servers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue