From f9e261d939412e279a7bc34fc631e923230c153a Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@allmydata.com>
Date: Mon, 31 Mar 2008 15:28:45 -0700
Subject: [PATCH] introducer.py: accelerate reconnection after being offline.
 Closes #374.

When we establish any new connection, reset the delays on all the other
Reconnectors. This will trigger a new batch of connection attempts. The idea
is to detect when we (the client) have been offline for a while, and to
connect to all servers when we get back online. By accelerating the timers
inside the Reconnectors, we try to avoid spending a long time in a
partially-connected state (which increases the chances of causing problems
with mutable files, by not updating all the shares that we ought to).
---
 src/allmydata/introducer.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/allmydata/introducer.py b/src/allmydata/introducer.py
index 4968d997..6b55a406 100644
--- a/src/allmydata/introducer.py
+++ b/src/allmydata/introducer.py
@@ -169,6 +169,8 @@ class RemoteServiceConnector:
         self.remote_host = None
         self._ic.remove_connection(self._nodeid, self.service_name, rref)
 
+    def reset(self):
+        self._reconnector.reset()
 
 
 class IntroducerClient(service.Service, Referenceable):
@@ -305,6 +307,15 @@ class IntroducerClient(service.Service, Referenceable):
     def add_connection(self, nodeid, service_name, rref):
         self._connections.add( (nodeid, service_name, rref) )
         self.counter += 1
+        # when one connection is established, reset the timers on all others,
+        # to trigger a reconnection attempt in one second. This is intended
+        # to accelerate server connections when we've been offline for a
+        # while. The goal is to avoid hanging out for a long time with
+        # connections to only a subset of the servers, which would increase
+        # the chances that we'll put shares in weird places (and not update
+        # existing shares of mutable files). See #374 for more details.
+        for rsc in self._connectors.values():
+            rsc.reset()
 
     def remove_connection(self, nodeid, service_name, rref):
         self._connections.discard( (nodeid, service_name, rref) )
-- 
2.45.2