q.get()
potwatch('connect', peer, q)
+def disconnect(peer, disconn = None):
+ """
+ Start the job of disconnecting from a passive PEER.
+
+ The DISCONN string is a shell command which will disconnect from the peer.
+ """
+ if disconn is None:
+ try:
+ conn = peerinfo(peer)['disconnect']
+ except KeyError:
+ return
+ q = T.Queue()
+ cmd = Command(['disconnect', peer], q, 'disconnect',
+ ['/bin/sh', '-c', disconn], None)
+ potwatch('disconnect', peer, q)
+
_pingseq = 0
class PingPeer (object):
"""
env[prefix + r_bad.sub('_', k.upper())] = v
r_bad = RX.compile(r'[\W_]+')
-def envvars(info):
+def envvars(peer, info):
"""
- Translate the database INFO dictionary for a peer into a dictionary of
+ Translate the database INFO dictionary for a PEER into a dictionary of
environment variables with plausible upper-case names and a P_ prefix.
Also collect the crypto information into A_ variables.
"""
env = {}
encode_envvars(env, 'P_', info)
- encode_envvars(env, 'A_', S.algs())
+ encode_envvars(env, 'A_', S.algs(peer))
return env
def ifupdown(what, peer, info, *args):
c = Command([what, peer], q, what,
M.split(info[what], quotep = True)[0] +
[peer] + list(args),
- envvars(info))
+ envvars(peer, info))
potwatch(what, peer, q)
def addpeer(info, peer, ifname, *addr):
pinger.kill(peer)
except KeyError:
pass
+ if 'disconnect' in info:
+ T.Coroutine(disconnect, name = 'disconnect %s' % peer) \
+ .switch(peer, info['disconnect'])
if 'ifdown' in info:
T.Coroutine(ifupdown, name = 'ifdown %s' % peer) \
.switch('ifdown', peer, info)