Skip to content

Commit

Permalink
Exclude tactics parameters from non-CheckTactics proxy announce requests
Browse files Browse the repository at this point in the history
  • Loading branch information
rod-hynes committed Nov 1, 2024
1 parent d0cb905 commit 149259b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion psiphon/common/inproxy/inproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func runTestInproxy(doMustUpgrade bool) error {
return brokerClient, nil
},

GetBaseAPIParameters: func() (common.APIParameters, string, error) {
GetBaseAPIParameters: func(bool) (common.APIParameters, string, error) {
return baseAPIParameters, tacticsNetworkID, nil
},

Expand Down
17 changes: 10 additions & 7 deletions psiphon/common/inproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ type ProxyConfig struct {
// application and build version information. GetBaseAPIParameters also
// returns the network ID, corresponding to the parameters, to be used in
// tactics logic; the network ID is not sent to the broker.
GetBaseAPIParameters func() (common.APIParameters, string, error)
GetBaseAPIParameters func(includeTacticsParameters bool) (
common.APIParameters, string, error)

// MakeWebRTCDialCoordinator provides a WebRTCDialCoordinator which
// specifies WebRTC-related dial parameters, including selected STUN
Expand Down Expand Up @@ -567,6 +568,10 @@ func (p *Proxy) proxyOneClient(

brokerCoordinator := brokerClient.GetBrokerDialCoordinator()

// Only the first worker, which has signalAnnounceDone configured, checks
// for tactics.
checkTactics := signalAnnounceDone != nil

// Get the base Psiphon API parameters and additional proxy metrics,
// including performance information, which is sent to the broker in the
// proxy announcment.
Expand All @@ -578,7 +583,7 @@ func (p *Proxy) proxyOneClient(
// with the original network ID.

metrics, tacticsNetworkID, err := p.getMetrics(
brokerCoordinator, webRTCCoordinator)
checkTactics, brokerCoordinator, webRTCCoordinator)
if err != nil {
return backOff, errors.Trace(err)
}
Expand Down Expand Up @@ -624,10 +629,6 @@ func (p *Proxy) proxyOneClient(
}
p.nextAnnounceMutex.Unlock()

// Only the first worker, which has signalAnnounceDone configured, checks
// for tactics.
checkTactics := signalAnnounceDone != nil

// A proxy ID is implicitly sent with requests; it's the proxy's session
// public key.
//
Expand Down Expand Up @@ -983,13 +984,15 @@ func (p *Proxy) proxyOneClient(
}

func (p *Proxy) getMetrics(
includeTacticsParameters bool,
brokerCoordinator BrokerDialCoordinator,
webRTCCoordinator WebRTCDialCoordinator) (*ProxyMetrics, string, error) {

// tacticsNetworkID records the exact network ID that corresponds to the
// tactics tag sent in the base parameters, and is used when applying any
// new tactics returned by the broker.
baseParams, tacticsNetworkID, err := p.config.GetBaseAPIParameters()
baseParams, tacticsNetworkID, err := p.config.GetBaseAPIParameters(
includeTacticsParameters)
if err != nil {
return nil, "", errors.Trace(err)
}
Expand Down
12 changes: 7 additions & 5 deletions psiphon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3109,7 +3109,7 @@ func (controller *Controller) inproxyGetProxyBrokerClient() (*inproxy.BrokerClie
return brokerClient, nil
}

func (controller *Controller) inproxyGetProxyAPIParameters() (
func (controller *Controller) inproxyGetProxyAPIParameters(includeTacticsParameters bool) (
common.APIParameters, string, error) {

// TODO: include broker fronting dial parameters to be logged by the
Expand All @@ -3130,10 +3130,12 @@ func (controller *Controller) inproxyGetProxyAPIParameters() (

networkID := controller.config.GetNetworkID()

err := tactics.SetTacticsAPIParameters(
GetTacticsStorer(controller.config), networkID, params)
if err != nil {
return nil, "", errors.Trace(err)
if includeTacticsParameters {
err := tactics.SetTacticsAPIParameters(
GetTacticsStorer(controller.config), networkID, params)
if err != nil {
return nil, "", errors.Trace(err)
}
}

return params, networkID, nil
Expand Down

0 comments on commit 149259b

Please sign in to comment.