chiark / gitweb /
svc/connect.in (cmd_kick): Don't assume there's a `connect' command.
[tripe] / svc / connect.in
index 8abe108ac375b1cb0ba9fe2526cdb3f1b3f6da89..3e9fa0a0b707009871b8c8e75a07b3c1f560b444 100644 (file)
 ###
 ### This file is part of Trivial IP Encryption (TrIPE).
 ###
-### TrIPE is free software; you can redistribute it and/or modify
-### it under the terms of the GNU General Public License as published by
-### the Free Software Foundation; either version 2 of the License, or
-### (at your option) any later version.
+### TrIPE is free software: you can redistribute it and/or modify it under
+### the terms of the GNU General Public License as published by the Free
+### Software Foundation; either version 3 of the License, or (at your
+### option) any later version.
 ###
-### TrIPE is distributed in the hope that it will be useful,
-### but WITHOUT ANY WARRANTY; without even the implied warranty of
-### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-### GNU General Public License for more details.
+### TrIPE is distributed in the hope that it will be useful, but WITHOUT
+### ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+### FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+### for more details.
 ###
 ### You should have received a copy of the GNU General Public License
-### along with TrIPE; if not, write to the Free Software Foundation,
-### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+### along with TrIPE.  If not, see <https://www.gnu.org/licenses/>.
 
 VERSION = '@VERSION@'
 
@@ -529,7 +528,8 @@ class Pinger (T.Coroutine):
 
   def kill(me, peername):
     """Remove PEER from the peers being watched by the Pinger."""
-    del me._peers[peername]
+    try: del me._peers[peername]
+    except KeyError: pass
     return me
 
   def rescan(me, startup):
@@ -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,11 +716,13 @@ 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(connect, peer)
+  conn = peer.get('connect', None)
+  if conn: T.spawn(run_connect, peer, peer.get('connect'))
+  else: T.spawn(lambda p: S.forcekx(p.name), peer)
 
 def cmd_adopted():
   """