From: Mark Wooding Date: Fri, 8 Sep 2017 08:06:47 +0000 (+0100) Subject: svc/connect.in: Add a method for finding a named PingPeer. X-Git-Tag: 1.5.0~120 X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/commitdiff_plain/fb52c291465867352b2d22ea64e411ed2e7356a6 svc/connect.in: Add a method for finding a named PingPeer. And use it in `cmd_kick' to avoid the need for a linear search through the peers list. --- diff --git a/svc/connect.in b/svc/connect.in index feb79ea8..917366d1 100644 --- a/svc/connect.in +++ b/svc/connect.in @@ -586,6 +586,10 @@ class Pinger (T.Coroutine): """ return me._peers.keys() + def find(me, name): + """Return the PingPeer with the given name.""" + return me._peers[name] + ###-------------------------------------------------------------------------- ### New connections. @@ -712,8 +716,8 @@ def cmd_kick(name): """ kick NAME: Force a new connection attempt for the NAMEd peer. """ - if name not in pinger.adopted(): - raise T.TripeJobError('peer-not-adopted', name) + try: pp = pinger.find(name) + except KeyError: raise T.TripeJobError('peer-not-adopted', name) try: peer = Peer(name) except KeyError: raise T.TripeJobError('unknown-peer', name) T.spawn(run_connect, peer, peer.get('connect'))