From fb52c291465867352b2d22ea64e411ed2e7356a6 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Fri, 8 Sep 2017 09:06:47 +0100 Subject: [PATCH] svc/connect.in: Add a method for finding a named PingPeer. Organization: Straylight/Edgeware From: Mark Wooding And use it in `cmd_kick' to avoid the need for a linear search through the peers list. --- svc/connect.in | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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')) -- [mdw]