Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#13447 closed enhancement (fixed)

Don't build introduction circuits until we know we can build circuits

Reported by: akwizgran Owned by:
Priority: Medium Milestone: Tor: 0.2.6.x-final
Component: Core Tor/Tor Version:
Severity: Keywords: tor-hs
Cc: arma Actual Points:
Parent ID: Points:
Reviewer: Sponsor: SponsorR

Description

When the network is disabled and re-enabled via DisableNetwork, Tor will try to build new introduction circuits as soon as the network is re-enabled. The circuits will fail and Tor will wait for five minutes (INTRO_CIRC_RETRY_PERIOD) before trying again.

This patch sets can_complete_circuit to 0 when the network is disabled, and doesn't try to build intro circuits while can_complete_circuit is 0, so when the network is re-enabled Tor will wait for a circuit to be successfully built before trying to build intro circuits.

This should improve the performance of hidden services that use DisableNetwork to respond to connectivity changes, such as services running on mobile devices.

Child Tickets

Attachments (1)

git.diff (1.0 KB) - added by akwizgran 5 years ago.

Download all attachments as: .zip

Change History (9)

Changed 5 years ago by akwizgran

Attachment: git.diff added

comment:1 Changed 5 years ago by nickm

Milestone: Tor: 0.2.6.x-final
Status: newneeds_review

comment:2 Changed 5 years ago by nickm

Hi! Can you say a little about what you've done to test this?

comment:3 Changed 5 years ago by akwizgran

Hi, I've tested this on two ARM-based Android devices - each device publishes a hidden service and connects to the service published by the other device. The controller sets DisableNetwork 1 in response to losing internet connectivity and DisableNetwork 0 when connectivity is restored.

By adding some log statements to rendservice.c (not included in the final patch) I could see that the devices were trying to build intro circuits as soon as DisableNetwork was set to 0. This coincided with trying to open the first OR connection, so the circuits failed, up to the limit of 10 attempts (MAX_INTRO_CIRCS_PER_PERIOD) at which point no further attempts were made for 5 minutes (INTRO_CIRC_RETRY_PERIOD). After 5 minutes the next round of intro circuits succeeded. With this patch the first round is deferred until the guard connection has come up, so the first round succeeds.

I haven't tested this patch on a relay yet.

comment:4 Changed 5 years ago by akwizgran

Oh, it's probably worth mentioning that can_complete_circuit is set to 0 under other circumstances (when the clock appears to jump), so there shouldn't be any code that's surprised by it changing from 1 to 0.

comment:5 Changed 5 years ago by nickm

Cc: arma added

Adding arma as a cc here because he has a very good grasp of this code, and this is a pretty simple patch.

comment:6 Changed 5 years ago by arma

Keywords: SponsorR added

comment:7 Changed 5 years ago by nickm

Resolution: fixed
Status: needs_reviewclosed

Merged after reviewing with David G.

comment:8 Changed 4 years ago by dgoulet

Keywords: SponsorR removed
Sponsor: SponsorR
Note: See TracTickets for help on using tickets.