mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Filter out non stun: server addresses in ParseIceServers
This commit is contained in:
parent
66269c07d8
commit
990fcb4127
2 changed files with 21 additions and 17 deletions
|
@ -190,22 +190,13 @@ func TestICEServerParser(t *testing.T) {
|
||||||
length int
|
length int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
[]string{"stun:stun.l.google.com:19302"},
|
[]string{"stun:stun.l.google.com:19302", "stun:stun.ekiga.net"},
|
||||||
[][]string{[]string{"stun:stun.l.google.com:19302"}},
|
[][]string{[]string{"stun:stun.l.google.com:19302"}, []string{"stun:stun.ekiga.net:3478"}},
|
||||||
1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
[]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,
|
2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
[]string{"stuns:stun.l.google.com:19302", "turn:relay.metered.ca:80"},
|
[]string{"stun:stun1.l.google.com:19302", "stun.ekiga.net", "stun:stun.example.com:1234/path?query",
|
||||||
[][]string{[]string{"stuns:stun.l.google.com:19302"}, []string{"turn:relay.metered.ca:80?transport=udp"}},
|
"https://example.com", "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"}},
|
[][]string{[]string{"stun:stun1.l.google.com:19302"}},
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
|
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -268,13 +269,25 @@ func parseIceServers(addresses []string) []webrtc.ICEServer {
|
||||||
if len(addresses) == 0 {
|
if len(addresses) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, url := range addresses {
|
for _, address := range addresses {
|
||||||
url = strings.TrimSpace(url)
|
address = strings.TrimSpace(address)
|
||||||
|
|
||||||
|
// ice.ParseURL recognizes many types of ICE servers,
|
||||||
|
// but we only support stun over UDP currently
|
||||||
|
u, err := url.Parse(address)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: Parsing ICE server %v resulted in error: %v, skipping", address, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if u.Scheme != "stun" {
|
||||||
|
log.Printf("Warning: Only stun: (STUN over UDP) servers are supported currently, skipping %v", address)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// add default port, other sanity checks
|
// add default port, other sanity checks
|
||||||
parsedURL, err := ice.ParseURL(url)
|
parsedURL, err := ice.ParseURL(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Warning: Parsing ICE server %v resulted in error: %v, skipping", url, err)
|
log.Printf("Warning: Parsing ICE server %v resulted in error: %v, skipping", address, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue