chiark / gitweb /
svc/connect.in: Add a method for finding a named PingPeer.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 8 Sep 2017 08:06:47 +0000 (09:06 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 14 Jun 2018 09:34:25 +0000 (10:34 +0100)
And use it in `cmd_kick' to avoid the need for a linear search through
the peers list.

svc/connect.in

index feb79ea8ef005e155b67037cc02d090592331c6d..917366d15eb0b86553311c798072ede0133fee5e 100644 (file)
@@ -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'))