Add package functions to define and set the rendezvous method

Add exported functions to the snowflake client library to allow calling
programs to define and set their own custom broker rendezvous methods.
This commit is contained in:
Cecylia Bocovich 2021-09-09 12:54:31 -04:00
parent 624750d5a8
commit 99887cd05d
5 changed files with 71 additions and 14 deletions

View file

@ -26,21 +26,20 @@ const (
readLimit = 100000 //Maximum number of bytes to be read from an HTTP response
)
// rendezvousMethod represents a way of communicating with the broker: sending
// RendezvousMethod represents a way of communicating with the broker: sending
// an encoded client poll request (SDP offer) and receiving an encoded client
// poll response (SDP answer) in return. rendezvousMethod is used by
// poll response (SDP answer) in return. RendezvousMethod is used by
// BrokerChannel, which is in charge of encoding and decoding, and all other
// tasks that are independent of the rendezvous method.
type rendezvousMethod interface {
type RendezvousMethod interface {
Exchange([]byte) ([]byte, error)
}
// BrokerChannel contains a rendezvousMethod, as well as data that is not
// specific to any rendezvousMethod. BrokerChannel has the responsibility of
// encoding and decoding SDP offers and answers; rendezvousMethod is responsible
// for the exchange of encoded information.
// BrokerChannel uses a RendezvousMethod to communicate with the Snowflake broker.
// The BrokerChannel is responsible for encoding and decoding SDP offers and answers;
// RendezvousMethod is responsible for the exchange of encoded information.
type BrokerChannel struct {
rendezvous rendezvousMethod
Rendezvous RendezvousMethod
keepLocalAddresses bool
natType string
lock sync.Mutex
@ -68,7 +67,7 @@ func NewBrokerChannel(broker, ampCache, front string, keepLocalAddresses bool) (
log.Println("Domain fronting using:", front)
}
var rendezvous rendezvousMethod
var rendezvous RendezvousMethod
var err error
if ampCache != "" {
rendezvous, err = newAMPCacheRendezvous(broker, ampCache, front, createBrokerTransport())
@ -80,7 +79,7 @@ func NewBrokerChannel(broker, ampCache, front string, keepLocalAddresses bool) (
}
return &BrokerChannel{
rendezvous: rendezvous,
Rendezvous: rendezvous,
keepLocalAddresses: keepLocalAddresses,
natType: nat.NATUnknown,
}, nil
@ -118,8 +117,8 @@ func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
return nil, err
}
// Do the exchange using our rendezvousMethod.
encResp, err := bc.rendezvous.Exchange(encReq)
// Do the exchange using our RendezvousMethod.
encResp, err := bc.Rendezvous.Exchange(encReq)
if err != nil {
return nil, err
}

View file

@ -11,7 +11,7 @@ import (
"git.torproject.org/pluggable-transports/snowflake.git/common/amp"
)
// ampCacheRendezvous is a rendezvousMethod that communicates with the
// ampCacheRendezvous is a RendezvousMethod that communicates with the
// .../amp/client route of the broker, optionally over an AMP cache proxy, and
// with optional domain fronting.
type ampCacheRendezvous struct {

View file

@ -10,7 +10,7 @@ import (
"net/url"
)
// httpRendezvous is a rendezvousMethod that communicates with the .../client
// httpRendezvous is a RendezvousMethod that communicates with the .../client
// route of the broker over HTTP or HTTPS, with optional domain fronting.
type httpRendezvous struct {
brokerURL *url.URL

View file

@ -132,6 +132,10 @@ func (t *Transport) Dial() (net.Conn, error) {
return &SnowflakeConn{Stream: stream, sess: sess, pconn: pconn, snowflakes: snowflakes}, nil
}
func (t *Transport) SetRendezvousMethod(r RendezvousMethod) {
t.dialer.Rendezvous = r
}
type SnowflakeConn struct {
*smux.Stream
sess *smux.Session