From: Mark Wooding Date: Mon, 23 Apr 2012 16:49:30 +0000 (+0100) Subject: svc/watch.in: Fix startup scan to initialize unwatched connections. X-Git-Tag: 1.0.0pre11~17 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/commitdiff_plain/97bbf88a16b0c79af6dca6ec426a24781f2cfd7e svc/watch.in: Fix startup scan to initialize unwatched connections. 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. --- diff --git a/svc/watch.in b/svc/watch.in index 97a12bfd..140f1fce 100644 --- a/svc/watch.in +++ b/svc/watch.in @@ -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