8 from nepi.util import tunchannel
10 remote = open("/dev/zero","r+b")
11 tun = open("/dev/zero","r+b")
13 def rwrite(remote, packet, remote_fd = remote.fileno(), os_write=os.write, len=len):
16 return os_write(remote_fd, packet)
18 def rread(remote, maxlen, remote_fd = remote.fileno(), os_read=os.read):
20 rv = os_read(remote_fd, maxlen)
24 def test(cipher, passphrase):
28 TERMINATE.append(None)
29 t = threading.Thread(target=stopme)
31 tunchannel.tun_fwd(tun, remote, True, True, passphrase, True, TERMINATE, None, tunkqueue=500,
32 rwrite = rwrite, rread = rread, cipher=cipher)
34 # Swallow exceptions on decryption
35 def decrypt(packet, crypter, super=tunchannel.decrypt):
37 return super(packet, crypter)
40 tunchannel.decrypt = decrypt
42 for cipher in (None, 'AES', 'Blowfish', 'DES', 'DES3'):
46 passphrase = 'Abracadabra'
48 cProfile.runctx('test(%r,%r)' % (cipher, passphrase),globals(),locals(),'tunchannel.%s.profile' % (cipher,))
50 print "Profile (%s):" % ( cipher, )
51 pstats.Stats('tunchannel.%s.profile' % cipher).strip_dirs().sort_stats('time').print_stats()
53 print "Bandwidth (%s): %.4fMb/s" % ( cipher, bytes / 200.0 * 8 / 2**20, )