mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
Update Snowflake client library documentation
Follow best practices for documenting the exported pieces of the Snowflake client library.
This commit is contained in:
parent
99887cd05d
commit
638ec6c222
8 changed files with 83 additions and 50 deletions
|
@ -1,10 +1,5 @@
|
|||
// WebRTC rendezvous requires the exchange of SessionDescriptions between
|
||||
// peers in order to establish a PeerConnection.
|
||||
//
|
||||
// This file contains the one method currently available to Snowflake:
|
||||
//
|
||||
// - Domain-fronted HTTP signaling. The Broker automatically exchange offers
|
||||
// and answers between this client and some remote WebRTC proxy.
|
||||
|
||||
package lib
|
||||
|
||||
|
@ -22,7 +17,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
BrokerErrorUnexpected string = "Unexpected error, no answer."
|
||||
brokerErrorUnexpected string = "Unexpected error, no answer."
|
||||
readLimit = 100000 //Maximum number of bytes to be read from an HTTP response
|
||||
)
|
||||
|
||||
|
@ -55,7 +50,7 @@ func createBrokerTransport() http.RoundTripper {
|
|||
return transport
|
||||
}
|
||||
|
||||
// Construct a new BrokerChannel, where:
|
||||
// NewBrokerChannel construct a new BrokerChannel, where:
|
||||
// |broker| is the full URL of the facilitating program which assigns proxies
|
||||
// to clients, and |front| is the option fronting domain.
|
||||
func NewBrokerChannel(broker, ampCache, front string, keepLocalAddresses bool) (*BrokerChannel, error) {
|
||||
|
@ -85,10 +80,8 @@ func NewBrokerChannel(broker, ampCache, front string, keepLocalAddresses bool) (
|
|||
}, nil
|
||||
}
|
||||
|
||||
// Roundtrip HTTP POST using WebRTC SessionDescriptions.
|
||||
//
|
||||
// Send an SDP offer to the broker, which assigns a proxy and responds
|
||||
// with an SDP answer from a designated remote WebRTC peer.
|
||||
// Negotiate uses a RendezvousMethod to send the client's WebRTC SDP offer
|
||||
// and receive a snowflake proxy WebRTC SDP answer in return.
|
||||
func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
|
||||
*webrtc.SessionDescription, error) {
|
||||
// Ideally, we could specify an `RTCIceTransportPolicy` that would handle
|
||||
|
@ -135,6 +128,7 @@ func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
|
|||
return util.DeserializeSessionDescription(resp.Answer)
|
||||
}
|
||||
|
||||
// SetNATType sets the NAT type of the client so we can send it to the WebRTC broker.
|
||||
func (bc *BrokerChannel) SetNATType(NATType string) {
|
||||
bc.lock.Lock()
|
||||
bc.natType = NATType
|
||||
|
@ -142,13 +136,14 @@ func (bc *BrokerChannel) SetNATType(NATType string) {
|
|||
log.Printf("NAT Type: %s", NATType)
|
||||
}
|
||||
|
||||
// Implements the |Tongue| interface to catch snowflakes, using BrokerChannel.
|
||||
// WebRTCDialer implements the |Tongue| interface to catch snowflakes, using BrokerChannel.
|
||||
type WebRTCDialer struct {
|
||||
*BrokerChannel
|
||||
webrtcConfig *webrtc.Configuration
|
||||
max int
|
||||
}
|
||||
|
||||
// NewWebRTCDialer constructs a new WebRTCDialer.
|
||||
func NewWebRTCDialer(broker *BrokerChannel, iceServers []webrtc.ICEServer, max int) *WebRTCDialer {
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: iceServers,
|
||||
|
@ -161,14 +156,14 @@ func NewWebRTCDialer(broker *BrokerChannel, iceServers []webrtc.ICEServer, max i
|
|||
}
|
||||
}
|
||||
|
||||
// Initialize a WebRTC Connection by signaling through the broker.
|
||||
// Catch initializes a WebRTC Connection by signaling through the BrokerChannel.
|
||||
func (w WebRTCDialer) Catch() (*WebRTCPeer, error) {
|
||||
// TODO: [#25591] Fetch ICE server information from Broker.
|
||||
// TODO: [#25596] Consider TURN servers here too.
|
||||
return NewWebRTCPeer(w.webrtcConfig, w.BrokerChannel)
|
||||
}
|
||||
|
||||
// Returns the maximum number of snowflakes to collect
|
||||
// GetMax returns the maximum number of snowflakes to collect.
|
||||
func (w WebRTCDialer) GetMax() int {
|
||||
return w.max
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue