From: Claudio-Daniel Freire <claudio-daniel.freire@inria.fr> Date: Thu, 25 Aug 2011 15:40:49 +0000 (+0200) Subject: UDP TunChannel handshake X-Git-Tag: nepi-3.0.0~267 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=c249af3aaf258fd5b95d862727d6fe297295653a;p=nepi.git UDP TunChannel handshake --- diff --git a/src/nepi/util/tunchannel.py b/src/nepi/util/tunchannel.py index 49f0e6c5..ee914fee 100644 --- a/src/nepi/util/tunchannel.py +++ b/src/nepi/util/tunchannel.py @@ -506,4 +506,33 @@ def tun_fwd(tun, remote, with_pi, ether_mode, cipher_key, udp, TERMINATE, stderr #print >>sys.stderr, "rr:%d\twr:%d\trt:%d\twt:%d" % (rr,wr,rt,wt) +def udp_handshake(TERMINATE, rsock): + endme = False + def keepalive(): + while not endme and not TERMINATE: + try: + rsock.send('') + except: + pass + time.sleep(1) + try: + rsock.send('') + except: + pass + keepalive_thread = threading.Thread(target=keepalive) + keepalive_thread.start() + retrydelay = 1.0 + for i in xrange(30): + if TERMINATE: + raise OSError, "Killed" + try: + heartbeat = rsock.recv(10) + break + except: + time.sleep(min(30.0,retrydelay)) + retrydelay *= 1.1 + else: + heartbeat = rsock.recv(10) + endme = True + keepalive_thread.join()