mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Merge remote-tracking branch 'gitlab/mr/102'
This commit is contained in:
commit
56063efbba
2 changed files with 45 additions and 7 deletions
|
@ -114,6 +114,9 @@ type SnowflakeProxy struct {
|
||||||
KeepLocalAddresses bool
|
KeepLocalAddresses bool
|
||||||
// RelayURL is the URL of the Snowflake server that all traffic will be relayed to
|
// RelayURL is the URL of the Snowflake server that all traffic will be relayed to
|
||||||
RelayURL string
|
RelayURL string
|
||||||
|
// Ephemeral*Port limits the pool of ports that ICE UDP connections can allocate from
|
||||||
|
EphemeralMinPort uint16
|
||||||
|
EphemeralMaxPort uint16
|
||||||
// RelayDomainNamePattern is the pattern specify allowed domain name for relay
|
// RelayDomainNamePattern is the pattern specify allowed domain name for relay
|
||||||
// If the pattern starts with ^ then an exact match is required.
|
// If the pattern starts with ^ then an exact match is required.
|
||||||
// The rest of pattern is the suffix of domain name.
|
// The rest of pattern is the suffix of domain name.
|
||||||
|
@ -347,6 +350,18 @@ func (d dataChannelHandlerWithRelayURL) datachannelHandler(conn *webRTCConn, rem
|
||||||
d.sf.datachannelHandler(conn, remoteAddr, d.RelayURL)
|
d.sf.datachannelHandler(conn, remoteAddr, d.RelayURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sf *SnowflakeProxy) makeWebRTCAPI() *webrtc.API {
|
||||||
|
settingsEngine := webrtc.SettingEngine{}
|
||||||
|
|
||||||
|
if sf.EphemeralMinPort != 0 && sf.EphemeralMaxPort != 0 {
|
||||||
|
settingsEngine.SetEphemeralUDPPortRange(sf.EphemeralMinPort, sf.EphemeralMaxPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
settingsEngine.SetICEMulticastDNSMode(ice.MulticastDNSModeDisabled)
|
||||||
|
|
||||||
|
return webrtc.NewAPI(webrtc.WithSettingEngine(settingsEngine))
|
||||||
|
}
|
||||||
|
|
||||||
// Create a PeerConnection from an SDP offer. Blocks until the gathering of ICE
|
// Create a PeerConnection from an SDP offer. Blocks until the gathering of ICE
|
||||||
// candidates is complete and the answer is available in LocalDescription.
|
// candidates is complete and the answer is available in LocalDescription.
|
||||||
// Installs an OnDataChannel callback that creates a webRTCConn and passes it to
|
// Installs an OnDataChannel callback that creates a webRTCConn and passes it to
|
||||||
|
@ -356,9 +371,7 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(sdp *webrtc.SessionDescrip
|
||||||
dataChan chan struct{},
|
dataChan chan struct{},
|
||||||
handler func(conn *webRTCConn, remoteAddr net.Addr)) (*webrtc.PeerConnection, error) {
|
handler func(conn *webRTCConn, remoteAddr net.Addr)) (*webrtc.PeerConnection, error) {
|
||||||
|
|
||||||
s := webrtc.SettingEngine{}
|
api := sf.makeWebRTCAPI()
|
||||||
s.SetICEMulticastDNSMode(ice.MulticastDNSModeDisabled)
|
|
||||||
api := webrtc.NewAPI(webrtc.WithSettingEngine(s))
|
|
||||||
pc, err := api.NewPeerConnection(config)
|
pc, err := api.NewPeerConnection(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("accept: NewPeerConnection: %s", err)
|
return nil, fmt.Errorf("accept: NewPeerConnection: %s", err)
|
||||||
|
@ -446,9 +459,7 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(sdp *webrtc.SessionDescrip
|
||||||
func (sf *SnowflakeProxy) makeNewPeerConnection(config webrtc.Configuration,
|
func (sf *SnowflakeProxy) makeNewPeerConnection(config webrtc.Configuration,
|
||||||
dataChan chan struct{}) (*webrtc.PeerConnection, error) {
|
dataChan chan struct{}) (*webrtc.PeerConnection, error) {
|
||||||
|
|
||||||
s := webrtc.SettingEngine{}
|
api := sf.makeWebRTCAPI()
|
||||||
s.SetICEMulticastDNSMode(ice.MulticastDNSModeDisabled)
|
|
||||||
api := webrtc.NewAPI(webrtc.WithSettingEngine(s))
|
|
||||||
pc, err := api.NewPeerConnection(config)
|
pc, err := api.NewPeerConnection(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("accept: NewPeerConnection: %s", err)
|
return nil, fmt.Errorf("accept: NewPeerConnection: %s", err)
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"git.torproject.org/pluggable-transports/snowflake.git/v2/common/event"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.torproject.org/pluggable-transports/snowflake.git/v2/common/event"
|
||||||
"git.torproject.org/pluggable-transports/snowflake.git/v2/common/safelog"
|
"git.torproject.org/pluggable-transports/snowflake.git/v2/common/safelog"
|
||||||
sf "git.torproject.org/pluggable-transports/snowflake.git/v2/proxy/lib"
|
sf "git.torproject.org/pluggable-transports/snowflake.git/v2/proxy/lib"
|
||||||
)
|
)
|
||||||
|
@ -28,6 +32,27 @@ func main() {
|
||||||
SummaryInterval := flag.Duration("summary-interval", time.Hour,
|
SummaryInterval := flag.Duration("summary-interval", time.Hour,
|
||||||
"the time interval to output summary, 0s disables summaries. Valid time units are \"s\", \"m\", \"h\". ")
|
"the time interval to output summary, 0s disables summaries. Valid time units are \"s\", \"m\", \"h\". ")
|
||||||
verboseLogging := flag.Bool("verbose", false, "increase log verbosity")
|
verboseLogging := flag.Bool("verbose", false, "increase log verbosity")
|
||||||
|
var ephemeralPortsRange []uint16 = []uint16{0, 0}
|
||||||
|
flag.Func("ephemeral-ports-range", "ICE UDP ephemeral ports range (format: \"[min]:[max]\")", func(s string) error {
|
||||||
|
ephemeralPortsRangeParts := strings.Split(s, ":")
|
||||||
|
if len(ephemeralPortsRangeParts) == 2 {
|
||||||
|
ephemeralMinPort, err := strconv.ParseUint(ephemeralPortsRangeParts[0], 10, 16)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ephemeralMaxPort, err := strconv.ParseUint(ephemeralPortsRangeParts[1], 10, 16)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ephemeralPortsRange = []uint16{uint16(ephemeralMinPort), uint16(ephemeralMaxPort)}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors.New(fmt.Sprintf("Bad range port format: %v", s))
|
||||||
|
})
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -39,6 +64,8 @@ func main() {
|
||||||
BrokerURL: *rawBrokerURL,
|
BrokerURL: *rawBrokerURL,
|
||||||
KeepLocalAddresses: *keepLocalAddresses,
|
KeepLocalAddresses: *keepLocalAddresses,
|
||||||
RelayURL: *relayURL,
|
RelayURL: *relayURL,
|
||||||
|
EphemeralMinPort: ephemeralPortsRange[0],
|
||||||
|
EphemeralMaxPort: ephemeralPortsRange[1],
|
||||||
|
|
||||||
NATTypeMeasurementInterval: *NATTypeMeasurementInterval,
|
NATTypeMeasurementInterval: *NATTypeMeasurementInterval,
|
||||||
EventDispatcher: eventLogger,
|
EventDispatcher: eventLogger,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue