mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
refactor: separate some Negotiate
logic
As per https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/merge_requests/392#note_3096760 in preparation for further changes to `Negotiate`.
This commit is contained in:
parent
75e73ce397
commit
f6767061e4
1 changed files with 23 additions and 11 deletions
|
@ -127,20 +127,13 @@ func newBrokerChannelFromConfig(config ClientConfig) (*BrokerChannel, error) {
|
|||
func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
|
||||
*webrtc.SessionDescription, error,
|
||||
) {
|
||||
offerSDP, err := util.SerializeSessionDescription(offer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Encode the client poll request.
|
||||
bc.lock.Lock()
|
||||
req := &messages.ClientPollRequest{
|
||||
Offer: offerSDP,
|
||||
NAT: bc.natType,
|
||||
Fingerprint: bc.BridgeFingerprint,
|
||||
}
|
||||
encReq, err := req.EncodeClientPollRequest()
|
||||
natType := bc.natType
|
||||
bridgeFingerprint := bc.BridgeFingerprint
|
||||
bc.lock.Unlock()
|
||||
|
||||
encReq, err := preparePollRequest(offer, natType, bridgeFingerprint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -163,6 +156,25 @@ func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
|
|||
return util.DeserializeSessionDescription(resp.Answer)
|
||||
}
|
||||
|
||||
// Pure function
|
||||
func preparePollRequest(
|
||||
offer *webrtc.SessionDescription,
|
||||
natType string,
|
||||
bridgeFingerprint string,
|
||||
) (encReq []byte, err error) {
|
||||
offerSDP, err := util.SerializeSessionDescription(offer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req := &messages.ClientPollRequest{
|
||||
Offer: offerSDP,
|
||||
NAT: natType,
|
||||
Fingerprint: bridgeFingerprint,
|
||||
}
|
||||
encReq, err = req.EncodeClientPollRequest()
|
||||
return
|
||||
}
|
||||
|
||||
// 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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue