chiark / gitweb /
svc/watch.in: Fix startup scan to initialize unwatched connections.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 23 Apr 2012 16:49:30 +0000 (17:49 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 23 Apr 2012 17:38:43 +0000 (18:38 +0100)
There's no point defining connection parameters for a peer unless
something's going to act on them, and that something is watch(8).  On
startup (the `--startup' switch), we're meant to notice existing peers
(probably established by connect(8)) and ensure that they're set up
properly.  This initial pass over the peer list is done by
Pinger.rescan, which /usually/ is interested only in watched peers that
need pinging.  It therefore ignores unwatched peers, with the result
that pre-existing unwatched peers are left unconfigured.  Subsequent
peers are detected through the notification mechanism and processed by
the addpeers function which works correctly.

Now, if startup is set, Pinger.rescan tracks all peers and invokes
addpeer on them.

The code relies on the fact that a startup scan is done only once, when
the peer list is empty.  Otherwise it'll reconfigure existing peers,
which is probably a mistake.

svc/watch.in

index 97a12bfd60ccad2d2f3773d68d6ba4551fd7cc1b..140f1fcee51821c2ea5e672ea1c9f89fe8a6e280 100644 (file)
@@ -527,6 +527,7 @@ class Pinger (T.Coroutine):
     """
     if T._debug: print '# rescan peers'
     correct = {}
+    start = {}
     for peer in S.list():
       try:
         info = peerinfo(peer)
@@ -534,14 +535,17 @@ class Pinger (T.Coroutine):
         continue
       if boolean(info, 'watch', False):
         if T._debug: print '# interesting peer %s' % peer
-        correct[peer] = info
+        correct[peer] = start[peer] = info
+      elif startup:
+        if T._debug: print '# peer %s ready for adoption' % peer
+        start[peer] = info
     for peer, obj in me._peers.items():
       if peer in correct:
         obj.update(correct[peer])
       else:
         if T._debug: print '# peer %s vanished' % peer
         del me._peers[peer]
-    for peer, info in correct.iteritems():
+    for peer, info in start.iteritems():
       if peer not in me._peers:
         if startup:
           if T._debug: print '# setting up peer %s' % peer