Skip to content

Commit

Permalink
Issue #37: Client-side workarounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Perry committed Mar 27, 2019
1 parent d4c9b9e commit c9622d5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/vanguards/bandguards.py
Expand Up @@ -251,6 +251,17 @@ def circ_event(self, event):
self.circs[event.id].dropped_cells_allowed = 1
else:
self.circs[event.id].dropped_cells_allowed = 0
# Workaround for Tor bug #29927 (see also
# https://github.com/mikeperry-tor/vanguards/issues/37).
# Class 4: Mysterious client-side cases of dropped cells
# and protocol errors.
elif event.purpose == "HS_CLIENT_REND" or event.purpose == "GENERAL":
self.circs[event.id].dropped_cells_allowed = 1
elif event.purpose == "HS_CLIENT_INTRO":
if event.hs_state == "HSCI_DONE":
self.circs[event.id].dropped_cells_allowed = 1
else:
self.circs[event.id].dropped_cells_allowed = 0

# Consider all BUILT circs that have a specific HS purpose
# to be "in_use".
Expand Down Expand Up @@ -324,15 +335,26 @@ def circ_minor_event(self, event):
if event.old_purpose == "HS_CLIENT_INTRO" \
and event.old_hs_state != "HSCI_DONE":
self.circs[event.id].dropped_cells_allowed = 1

# Workaround for Tor bug #29700 (see also
# https://github.com/mikeperry-tor/vanguards/issues/37).
# Class 3: Service rend circs can sometimes fail ntor handshake on extend
if event.purpose == "HS_SERVICE_REND":
elif event.purpose == "HS_SERVICE_REND":
if event.hs_state == "HSSR_CONNECTING":
self.circs[event.id].dropped_cells_allowed = 1
else:
self.circs[event.id].dropped_cells_allowed = 0
# Workaround for Tor bug #29927 (see also
# https://github.com/mikeperry-tor/vanguards/issues/37).
# Class 4: Mysterious client-side cases of dropped cells
# and protocol errors.
elif event.purpose == "HS_CLIENT_REND":
self.circs[event.id].dropped_cells_allowed = 1
elif event.purpose == "HS_CLIENT_INTRO":
if event.hs_state == "HSCI_DONE":
self.circs[event.id].dropped_cells_allowed = 1
else:
self.circs[event.id].dropped_cells_allowed = 0


plog("DEBUG", event.raw_content())

Expand Down Expand Up @@ -464,6 +486,11 @@ def check_circuit_limits(self, circ):
+"(in state %s %s; old state %s %s).", circ.circ_id,
str(circ.purpose), str(circ.hs_state),
str(circ.old_purpose), str(circ.old_hs_state))
else:
plog("INFO", "Tor bug #29927: Got a dropped cell on circ %s "\
+"(in state %s %s; old state %s %s).", circ.circ_id,
str(circ.purpose), str(circ.hs_state),
str(circ.old_purpose), str(circ.old_hs_state))

if CIRC_MAX_MEGABYTES > 0 and \
circ.total_bytes() > CIRC_MAX_MEGABYTES*_BYTES_PER_MB:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_bandguards.py
Expand Up @@ -278,6 +278,8 @@ def test_bwstats():
"HS_CLIENT_REND",
"PATH_BIAS_TESTING"))
check_dropped_bytes(state, controller, circ_id, 0, 1)
assert controller.closed_circ == None
check_dropped_bytes(state, controller, circ_id, 0, 1)
assert controller.closed_circ == str(circ_id)

# Test that no dropped cells are allowed on not-built circ.
Expand All @@ -301,6 +303,8 @@ def test_bwstats():
controller.closed_circ = None
state.circ_event(built_general_circ(circ_id))
check_dropped_bytes(state, controller, circ_id, 1000, 1)
assert controller.closed_circ == None
check_dropped_bytes(state, controller, circ_id, 1000, 1)
assert controller.closed_circ == str(circ_id)

# Test that with #25573, no dropped cell is allowed
Expand All @@ -317,6 +321,8 @@ def test_bwstats():
state.tor_has_25573 = True
state.circ_event(built_general_circ(circ_id))
check_dropped_bytes(state, controller, circ_id, 1000, 1)
assert controller.closed_circ == None
check_dropped_bytes(state, controller, circ_id, 1000, 1)
assert controller.closed_circ == str(circ_id)


Expand Down

0 comments on commit c9622d5

Please sign in to comment.