[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[minion-cvs] More code to try to isolate memory leaks
Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv27610/lib/mixminion
Modified Files:
test.py benchmark.py
Log Message:
More code to try to isolate memory leaks
Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -d -r1.97 -r1.98
--- test.py 28 Mar 2003 15:36:22 -0000 1.97
+++ test.py 10 Apr 2003 03:03:16 -0000 1.98
@@ -2890,7 +2890,7 @@
else:
return _ml.TLSContext_new()
-def _getMMTPServer():
+def _getMMTPServer(minimal=0):
"""Helper function: create a new MMTP server with a listener connection
Return a tuple of AsyncServer, ListenerConnection, list of received
messages, and keyid."""
@@ -2908,6 +2908,15 @@
receiveMessage)
con.junkCallback = junkCallback
return con
+ def conFactoryMin(sock, context=_getTLSContext(1)):
+ tls = context.sock(sock, serverMode=1)
+ sock.setblocking(0)
+ con = mixminion.server.MMTPServer.MMTPServerConnection(sock,tls,
+ lambda m:None)
+ con.junkCallback = lambda:None
+ return con
+ if minimal:
+ conFactory = conFactoryMin
listener = mixminion.server.MMTPServer.ListenConnection("127.0.0.1",
TEST_PORT, 5, conFactory)
listener.register(server)
Index: benchmark.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/benchmark.py,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- benchmark.py 20 Feb 2003 16:50:42 -0000 1.31
+++ benchmark.py 10 Apr 2003 03:03:16 -0000 1.32
@@ -16,8 +16,10 @@
import os
import stat
import cPickle
+import threading
from time import time
+
import mixminion._minionlib as _ml
from mixminion.BuildMessage import _buildHeader, buildForwardMessage, \
compressData, uncompressData, _encodePayload, decodePayload
@@ -26,7 +28,7 @@
from mixminion.Crypto import *
from mixminion.Crypto import OAEP_PARAMETER
from mixminion.Crypto import _add_oaep_padding, _check_oaep_padding
-from mixminion.Packet import SMTP_TYPE, CompressedDataTooLong
+from mixminion.Packet import SMTP_TYPE, CompressedDataTooLong, IPV4Info
from mixminion.ServerInfo import ServerInfo
from mixminion.server.HashLog import HashLog
from mixminion.server.PacketHandler import PacketHandler
@@ -652,6 +654,7 @@
keytxt="a"*16
key = _ml.aes_key(keytxt)
while 1:
+ _ml.aes_key(keytxt)
_ml.sha1(s20k)
_ml.aes_ctr128_crypt(key,s20k,0)
_ml.aes_ctr128_crypt(key,s20k,2000)
@@ -690,18 +693,140 @@
p = pk_generate(512)
n,e = p.get_public_key()
+ f = open("/dev/null", 'w')
while 1:
- if 1:
+ if 0:
p = pk_generate(512)
+ if 1:
pk_decrypt(pk_encrypt(s20,p),p)
for public in (0,1):
x = p.encode_key(public)
_ml.rsa_decode_key(x,public)
p.get_public_key()
_ml.rsa_make_public_key(n,e)
+ p.get_modulus_bytes()
+ p.get_exponent()
+ if 1:
+ p.PEM_write_key(f, 1)
+ p.PEM_write_key(f, 0)
+ p.PEM_write_key(f, 0, "Z")
+ if 1:
+ x = p.crypt("A"*64, 1, 1)
+ p.crypt(x, 0, 0)
+
+def testLeaks3():
+ print "Trying to leak (certgen)"
+ p = pk_generate(512)
+ p2 = pk_generate(512)
+ fn = mix_mktemp()
+ while 1:
+ _ml.generate_cert(fn, p, p2, "A", "B", 100, 10000)
+
+def testLeaks4():
+ print "Trying to leak (SSL)"
+
+ p = pk_generate(512)
+ p2 = pk_generate(512)
+ fn = mix_mktemp()
+ dh = mix_mktemp()
+ _ml.generate_cert(fn, p, p2, "A", "B", 100, 10000)
+ dh_fname = os.environ.get("MM_TEST_DHPARAMS", None)
+ if dh_fname and os.path.exists(dh_fname):
+ dh = dh_fname
+ elif dh_fname:
+ _ml.generate_dh_parameters(dh_fname, 1, 512)
+ dh = dh_fname
+ else:
+ _ml.generate_dh_parameters(dh, 1, 512)
+ print "OK"
+ context = _ml.TLSContext_new(fn, p, dh)
+ while 1:
+ if 1:
+ context = _ml.TLSContext_new(fn, p, dh)
+ s1 = context.sock(0, 0)
+ s2 = context.sock(0, 1)
+
+def testLeaks5():
+ from mixminion.test import _getMMTPServer
+ server, listener, messagesIn, keyid = _getMMTPServer(1)
+ #t = threading.Thread(None, testLeaks5_send,
+ # args=(keyid,))
+ #t.start()
+
+ while 1:
+ server.process(0.5)
+ #if messagesIn:
+ # print "Connections"
+ del messagesIn[:]
+ #t.join()
+
+def testLeaks5_send():
+ from mixminion.test import TEST_PORT
+ import mixminion.MMTPClient
+ routing = IPV4Info("127.0.0.1", TEST_PORT, None)
+
+ msg = "X" * 32 * 1024
+ n = 0
+ while 1:
+ mixminion.MMTPClient.sendMessages(routing, [])
+ n += 1
+ print n, "sent"
+
+def testLeaks6():
+ import socket
+ p = pk_generate(512)
+ p2 = pk_generate(512)
+ fn = mix_mktemp()
+ dh = mix_mktemp()
+ _ml.generate_cert(fn, p, p2, "A", "B", 100, 10000)
+ dh_fname = os.environ.get("MM_TEST_DHPARAMS", None)
+ if dh_fname and os.path.exists(dh_fname):
+ dh = dh_fname
+ elif dh_fname:
+ _ml.generate_dh_parameters(dh_fname, 1, 512)
+ dh = dh_fname
+ else:
+ _ml.generate_dh_parameters(dh, 1, 512)
+ print "OK"
+ context = _ml.TLSContext_new(fn, p)#XXXX, dh)
+
+ listenSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ listenSock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ listenSock.bind(("127.0.0.1", 48999))
+ listenSock.listen(5)
+ while 1:
+ con, address = listenSock.accept()
+ tls = context.sock(con, serverMode=1)
+ tls.accept()
+ while 1:
+ r = tls.read(50)
+ if r == 0:
+ break
+ while 1:
+ r = tls.shutdown()
+ if r == 1:
+ break
+ con.close()
+
+def testLeaks6_2():
+ import socket
+ context = _ml.TLSContext_new()
+ m = "X"*99*1024
+ while 1:
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sock.connect(("127.0.0.1", 48999))
+ tls = context.sock(sock)
+ tls.connect()
+ tls.write(m)
+ while 1:
+ r = tls.shutdown()
+ if r: break
+ tls.shutdown()
+ sock.close()
#----------------------------------------------------------------------
+
def timeAll(name, args):
cryptoTiming()
buildMessageTiming()
@@ -713,3 +838,6 @@
timeEfficiency()
#import profile
#profile.run("import mixminion.benchmark; mixminion.benchmark.directoryTiming()")
+
+def timeAll(name,args):
+ testLeaks6_2()