chiark / gitweb /
Add notion of `ephemeral' associations and a goodbye protocol.
[tripe] / py / tripe.py.in
index ac616ae82acb748efba11046f3c0a82c55bbec17..0126dc586991c1357f71e0679b85c3c34cba0b72 100644 (file)
@@ -9,19 +9,18 @@
 ###
 ### 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/>.
 
 """
 This module provides classes and functions for connecting to a running tripe
@@ -110,7 +109,7 @@ import os as OS
 
 try:
   if OS.getenv('TRIPE_FORCE_RMCR') is not None:
-    raise ImportError
+    raise ImportError()
   from py.magic import greenlet as _Coroutine
 except ImportError:
   from rmcr import Coroutine as _Coroutine
@@ -330,8 +329,10 @@ class SelIOWatcher (object):
     Wait for something interesting to happen, and issue events.
 
     That is, basically, do one iteration of a main select loop, processing
-    all of the events, and then return.  This isn't needed for
-    `TripeCommandDispatcher', but `runservices' wants it.
+    all of the events, and then return.  This is used in the method
+    `TripeCommandDispatcher.mainloop', but that's mostly for the benefit of
+    `runservices'; if your I/O watcher has a different main loop, you can
+    drive it yourself.
     """
     M.select()
 
@@ -507,7 +508,7 @@ class TripeCommandIterator (object):
     """
     me.dcr = Coroutine.getcurrent().parent
     if me.dcr is None:
-      raise ValueError, 'must invoke from coroutine'
+      raise ValueError('must invoke from coroutine')
     me.filter = filter or (lambda x: x)
     if bg:
       words = [words[0], '-background', dispatcher.bgtag()] + list(words[1:])
@@ -531,17 +532,17 @@ class TripeCommandIterator (object):
     if code == 'INFO':
       return me.filter(rest)
     elif code == 'OK':
-      raise StopIteration
+      raise StopIteration()
     elif code == 'CONNERR':
       if rest is None:
-        raise TripeConnectionError, 'connection terminated by user'
+        raise TripeConnectionError('connection terminated by user')
       else:
         raise rest
     elif code == 'FAIL':
       raise TripeError(*rest)
     else:
-      raise TripeInternalError \
-            ('unexpected tripe response %r' % ([code] + rest))
+      raise TripeInternalError('unexpected tripe response %r' %
+                               ([code] + rest))
 
 ### Simple utility functions for the TripeCommandIterator convenience
 ### methods.
@@ -837,7 +838,8 @@ class TripeCommandDispatcher (TripeConnection):
                               *['ADD'] +
                               _kwopts(kw, ['tunnel', 'keepalive',
                                            'key', 'priv', 'cork',
-                                           'mobile']) +
+                                           'mobile', 'knock',
+                                           'ephemeral']) +
                               [peer] +
                               list(addr)))
   def addr(me, peer):
@@ -851,7 +853,7 @@ class TripeCommandDispatcher (TripeConnection):
     return _simple(me.command('DAEMON'))
   def eping(me, peer, **kw):
     return _oneline(me.command(bg = True,
-                               *['PING'] +
+                               *['EPING'] +
                                _kwopts(kw, ['timeout']) +
                                [peer]))
   def forcekx(me, peer):
@@ -1171,7 +1173,7 @@ class TripeServiceCommand (object):
     """
     if (me.min is not None and len(args) < me.min) or \
        (me.max is not None and len(args) > me.max):
-      raise TripeSyntaxError
+      raise TripeSyntaxError()
     me.func(*args)
 
 class TripeServiceJob (Coroutine):
@@ -1382,12 +1384,12 @@ class OptParse (object):
     if len(me.args) == 0 or \
        len(me.args[0]) < 2 or \
        not me.args[0].startswith('-'):
-      raise StopIteration
+      raise StopIteration()
     opt = me.args.pop(0)
     if opt == '--':
-      raise StopIteration
+      raise StopIteration()
     if opt not in me.allowed:
-      raise TripeSyntaxError
+      raise TripeSyntaxError()
     return opt
 
   def arg(me):
@@ -1397,7 +1399,7 @@ class OptParse (object):
     If none is available, raise `TripeSyntaxError'.
     """
     if len(me.args) == 0:
-      raise TripeSyntaxError
+      raise TripeSyntaxError()
     return me.args.pop(0)
 
   def rest(me, min = None, max = None):
@@ -1409,7 +1411,7 @@ class OptParse (object):
     """
     if (min is not None and len(me.args) < min) or \
        (max is not None and len(me.args) > max):
-      raise TripeSyntaxError
+      raise TripeSyntaxError()
     return me.args
 
 ###----- That's all, folks --------------------------------------------------