[mnet-devel] patch: remove bsddb from mesgen.py
Zooko O'Whielacronx
zooko at zooko.com
Tue Apr 6 17:36:13 BST 2004
This removes bsddb from mesgen.py and replaces it with no persistence!
The downside is that when a remote peer restarts, then the next time you try to
talk to them your message will fail. If you connected with them via TCP, then
you will realize what happened and generate a new shared secret. If you sent
to them via Relay then I think you will not be able to talk to them again until
the next time your node restarts.
I know how to fix this, but I'm posting this patch now so that MMIM can use it
to get up and running with no bsddb.
--Z
-------------- next part --------------
? cdiff.patch
? cup.log
? setup.py-keepgoing
? mnetlib/admin/AdminServerHandlers.pyo
? mnetlib/admin/__init__.pyo
? mnetlib/metatrackerserver/MetaTracker.pyo
? mnetlib/metatrackerserver/__init__.pyo
Index: egtp/CryptoCommsHandler.py
===================================================================
RCS file: /cvsroot/mnet/mnet_new/egtp/CryptoCommsHandler.py,v
retrieving revision 1.15
diff -p -u -r1.15 CryptoCommsHandler.py
--- egtp/CryptoCommsHandler.py 4 Dec 2003 12:03:37 -0000 1.15
+++ egtp/CryptoCommsHandler.py 6 Apr 2004 14:48:56 -0000
@@ -140,7 +140,19 @@ class CryptoCommsHandler:
counterparty_pub_key, cleartext = self._mesgen.parse(msg)
except mesgen.Error, e:
if isinstance(e, mesgen.SessionInvalidated):
- debugprint("%s.inmsg_handler(msg: %s, lowerstrategy: %s, strategy_id_for_debug: %s) got exceptions: %s\n", args=(self, msg, lowerstrategy, strategy_id_for_debug, e,), v=3, vs="crypto")
+ debugprint("%s.inmsg_handler(lowerstrategy: %s, strategy_id_for_debug: %s) got SessionInvalidated exception. Probably the remote peer has been restarted and next time we talk to him we will offer a new shared secret via public key encryption.\n", args=(self, lowerstrategy, strategy_id_for_debug,), v=6, vs="crypto")
+ return
+
+ if isinstance(e, mesgen.UnknownSession):
+ debugprint("%s.inmsg_handler(lowerstrategy: %s, strategy_id_for_debug: %s) got UnknownSession exception. Probably we have been restarted and the next time the remote peer talks to us he will offer a new shared secret via public key encryption.\n", args=(self, lowerstrategy, strategy_id_for_debug,), v=6, vs="crypto")
+ # if it is an UnknownSession error, attempt to send a note back down the lowerstrategy if it happens to be a two way connection
+ if lowerstrategy and isinstance(lowerstrategy, CommStrat.TCP) and lowerstrategy.asyncsock:
+ # XXX if all CommStrats are updated in the future to have a send() method, just use it if the CommStrat has a "twowaycomms" flag?
+ debugprint("sending an 'invalidate session' note back on the TCP connection\n", v=1, vs="CryptoCommsHandler")
+ # send e.invalidate_session_msg back out this TCP Connection
+ lowerstrategy.asyncsock.send(e.invalidate_session_msg)
+ else:
+ debugprint("message did not come via a two way CommStrat, cannot send an 'invalidate session'\n", v=3, vs="CryptoCommsHandler")
return
if lowerstrategy:
@@ -160,16 +172,6 @@ class CryptoCommsHandler:
else:
debugprint("WARNING: a message arrived with suggested strategy_id_for_debug %s that couldn't be decrypted. Perhaps it was cleartext, or garbled. The message was %s. The error was: %s\n", args=(strategy_id_for_debug, msg, e), v=1, vs="crypto")
- # if it is an UnknownSession error, attempt to send a note back down the lowerstrategy if it happens to be a two way connection
- if isinstance(e, mesgen.UnknownSession) and lowerstrategy:
- # XXX if all CommStrats are updated in the future to have a send() method, just use it if the CommStrat has a "twowaycomms" flag?
- if isinstance(lowerstrategy, CommStrat.TCP) and lowerstrategy.asyncsock:
- debugprint("sending an 'invalidate session' note back on the TCP connection\n", v=1, vs="CryptoCommsHandler")
- # send e.invalidate_session_msg back out this TCP Connection
- lowerstrategy.asyncsock.send(e.invalidate_session_msg)
- else:
- debugprint("message did not come via a two way CommStrat, cannot send an 'invalidate session'\n", v=3, vs="CryptoCommsHandler")
-
return # drop it on the floor
counterparty_id = idlib.make_id(counterparty_pub_key)
Index: egtp/MojoTransaction.py
===================================================================
RCS file: /cvsroot/mnet/mnet_new/egtp/MojoTransaction.py,v
retrieving revision 1.38
diff -p -u -r1.38 MojoTransaction.py
--- egtp/MojoTransaction.py 16 Jan 2004 23:53:31 -0000 1.38
+++ egtp/MojoTransaction.py 6 Apr 2004 14:48:56 -0000
@@ -172,7 +172,7 @@ class MojoTransactionManager:
broker, the contents of the query message, and optionally a callback
function that will be called when the transaction completes or fails.
"""
- def __init__(self, lookupman, discoveryman, datadir, pt=None, announced_service_dicts=[], handler_funcs={}, serialized=None, ip_bind=None, listen_port=None, recoverdb=True, pickyport=False, dontbind=False, neverpoll=False, keyID=None, allow_send_metainfo=True, allownonrouteableip=False, clientversion=None, kbps_in=None, kbps_out=None, announce_ip=None):
+ def __init__(self, lookupman, discoveryman, datadir, pt=None, announced_service_dicts=[], handler_funcs={}, serialized=None, ip_bind=None, listen_port=None, pickyport=False, dontbind=False, neverpoll=False, keyID=None, allow_send_metainfo=True, allownonrouteableip=False, clientversion=None, kbps_in=None, kbps_out=None, announce_ip=None):
"""
@param lookupman: an object which implements the ILookupManager
interface; MojoTransaction uses the lookupman to get fresh EGTP
@@ -237,7 +237,7 @@ class MojoTransactionManager:
ready = False
if keyID:
try:
- self._mesgen = mesgen.MessageMaker(dir=os.path.join(dbparentdir, keyID), recoverdb=recoverdb)
+ self._mesgen = mesgen.MessageMaker(dir=os.path.join(dbparentdir, keyID))
ready = True
except:
# We sometimes get exceptions here because of corrupted db.
@@ -249,7 +249,7 @@ class MojoTransactionManager:
pass
if not ready:
- self._mesgen = mesgen.create_MessageMaker(dbparentdir=dbparentdir, recoverdb=recoverdb)
+ self._mesgen = mesgen.create_MessageMaker(dbparentdir=dbparentdir)
self.keyID = self._mesgen.get_id()
self._dbdir=os.path.join(dbparentdir, idlib.to_mojosixbit(self._mesgen.get_id()))
@@ -276,7 +276,7 @@ class MojoTransactionManager:
self._listenermanager = ListenerManager.ListenerManager(cryptol=self._ch, tcpl=tcpch, relayl=RelayListener.RelayListener(self, discoveryman=self._discoveryman, neverpoll=neverpoll), mtm=self, allownonrouteableip=allownonrouteableip)
- self._keeper=counterparties.CounterpartyObjectKeeper(dbparentdir=self._datadir, local_id=self.get_id(), recoverdb=True)
+ self._keeper=counterparties.CounterpartyObjectKeeper(dbparentdir=self._datadir, local_id=self.get_id())
# this is used to prevent >1 update from occurring at the same time
self.__handler_funcs_and_services_dicts_update_lock=threading.Lock()
Index: egtp/mesgen.py
===================================================================
RCS file: /cvsroot/mnet/mnet_new/egtp/mesgen.py,v
retrieving revision 1.20
diff -p -u -r1.20 mesgen.py
--- egtp/mesgen.py 4 Nov 2003 23:10:25 -0000 1.20
+++ egtp/mesgen.py 6 Apr 2004 14:48:56 -0000
@@ -1,4 +1,5 @@
# Copyright (c) 2001 HiveCache
+# Copyright (c) 2004 Bryce "Zooko" Wilcox-O'Hearn
# This file is licensed under the
# GNU Lesser General Public License v2.1.
# See the file COPYING or visit http://www.gnu.org/ for details.
@@ -11,12 +12,6 @@ from cPickle import dumps, loads
import exceptions, threading, traceback, os, sys, time, types, xdrlib
from xdrlib import Packer, Unpacker
-try:
- from bsddb3 import db, dbobj
- db.DB_AUTO_COMMIT = 0
-except:
- from bsddb import db, dbobj
-
from pyutil.assertutil import _assert, precondition, postcondition
from pyutil.debugprint import debugprint, debugstream
from pyutil import Cache, fileutil
@@ -83,8 +78,7 @@ class SessionKeeper:
This is for holding things (external resources) that SK needs to
finalize after SK is killed. (post-mortem finalization)
"""
- def __init__(self, db_env, session_map, counterparty_map):
- self.db_env = db_env
+ def __init__(self, session_map, counterparty_map):
self.session_map = session_map
self.counterparty_map = counterparty_map
@@ -92,25 +86,15 @@ class SessionKeeper:
try:
debugprint("%s.__del__()\n", args=(self,))
if self.session_map is not None:
- self.session_map.close()
self.session_map = None
if self.counterparty_map is not None:
- self.counterparty_map.close()
self.counterparty_map = None
- if self.db_env is not None:
- #debugprint("%s.__del__(): self.db_env.nosyncerror_txn_checkpoint(0)\n", args=(self,))
- self.db_env.nosyncerror_txn_checkpoint(0)
- #debugprint("%s.__del__(): self.db_env.close()\n", args=(self,))
- self.db_env.close()
- #debugprint("%s.__del__(): self.db_env = None\n", args=(self,))
- self.db_env = None
- #debugprint("%s.__del__(): done\n", args=(self,))
except:
(etype, evalue, realtb) = sys.exc_info()
debugprint("WARNING: got exception in SessionKeeper.ExtRes.__del__(). ignoring.\n")
traceback.print_exc(file=debugstream)
- def __init__(self, dbparentdir=None, dir=None, serialized = None, maxitems = 1000, recoverdb=True):
+ def __init__(self, dbparentdir=None, dir=None, serialized = None, maxitems = 1000):
"""
You can pass either dir or dbparentdir, but not both. You pass `dbparentdir' if you
don't know the id of the key (either because the key is being created or because it is
@@ -175,35 +159,13 @@ class SessionKeeper:
# CryptoCommsHandler accessing it from the DoQ thread.
self.lock = threading.Lock()
- db_env = CleanLogDbEnv()
- db_env.set_lk_detect(db.DB_LOCK_DEFAULT)
- if recoverdb:
- recoverflag = db.DB_RECOVER
- else:
- recoverflag = 0
-
- privateflag = db.DB_PRIVATE
-
- try:
- db_env.open(self._dbdir, db.DB_CREATE | db.DB_INIT_MPOOL | db.DB_INIT_LOCK | db.DB_INIT_LOG | db.DB_INIT_TXN | privateflag | recoverflag)
- except db.DBError, dbe:
- debugprint('Failed to open the database environment the first time, reason: %s\nTrying again...\n', args=(dbe,), vs='mesgen', v=2)
- try:
- db_env.open(self._dbdir, db.DB_CREATE | db.DB_INIT_MPOOL | db.DB_INIT_LOCK | db.DB_INIT_LOG | db.DB_INIT_TXN | privateflag | recoverflag | db.DB_RECOVER)
- except db.DBError, dbe:
- debugprint('Failed to open the database environment the second time, reason: %s\nTrying again...\n', args=(dbe,), vs='mesgen', v=2)
- # XXX DOUBLE CHOCOLATEY HACK sometimes trying *again* after one open *without* DB_RECOVER works.
- db_env.open(self._dbdir, db.DB_CREATE | db.DB_INIT_MPOOL | db.DB_INIT_LOCK | db.DB_INIT_LOG | db.DB_INIT_TXN | privateflag | recoverflag & (~db.DB_RECOVER))
-
self.__key = keyMV
# maps id_in to counterparty id
- session_map = dbobj.DB(db_env)
- session_map.open('session_map', db.DB_BTREE, db.DB_CREATE | db.DB_AUTO_COMMIT)
+ session_map = {}
# maps counterparty id to [session_id_in, session_id_out, symmetric_key, header, full pk]
# (XXX session_id_in in counterparty_map is never used, that's what session_map is for)
- counterparty_map = dbobj.DB(db_env)
- counterparty_map.open('counterparty_map', db.DB_BTREE, db.DB_CREATE | db.DB_AUTO_COMMIT)
- self.extres = SessionKeeper.ExtRes(db_env, session_map, counterparty_map)
+ counterparty_map = {}
+ self.extres = SessionKeeper.ExtRes(session_map, counterparty_map)
# maps header ids to content of headers for memoization
self.__cached_headers = Cache.LRUCache(maxsize=maxitems)
@@ -250,22 +212,14 @@ class SessionKeeper:
counterparty_id = idlib.canonicalize(counterparty_id, 'broker')
- self.extres.db_env.nosyncerror_txn_checkpoint(MINS_BETWEEN_DB_CHECKPOINTS)
- trans = self.extres.db_env.txn_begin()
- try:
- # maps counterparty id to [session_id_in, session_id_out, symmetric_key, header, full pk]
- session_id_in, session_id_out, symmetric_key, _header, full_key = loads(self.extres.counterparty_map.get(counterparty_id, flags=db.DB_RMW, txn=trans))[:5]
+ # maps counterparty id to [session_id_in, session_id_out, symmetric_key, header, full pk]
+ session_id_in, session_id_out, symmetric_key, _header, full_key = loads(self.extres.counterparty_map.get(counterparty_id))[:5]
- # remove the header (to signify our acknowledgement of their session acceptance)
- assert len(symmetric_key) == SIZE_OF_SYMMETRIC_KEYS
- assert keyutil.publicRSAKeyIsSane(full_key)
- assert keyutil.publicKeyForCommunicationSecurityIsWellFormed(full_key)
- self.extres.counterparty_map.put(counterparty_id, dumps([session_id_in, session_id_out, symmetric_key, None, full_key], 1), txn=trans)
- trans.commit()
- trans = None
- finally:
- if trans is not None:
- trans.abort()
+ # remove the header (to signify our acknowledgement of their session acceptance)
+ assert len(symmetric_key) == SIZE_OF_SYMMETRIC_KEYS
+ assert keyutil.publicRSAKeyIsSane(full_key)
+ assert keyutil.publicKeyForCommunicationSecurityIsWellFormed(full_key)
+ self.extres.counterparty_map[counterparty_id] = dumps([session_id_in, session_id_out, symmetric_key, None, full_key], 1)
def parse_header(self, header):
self.lock.acquire()
@@ -347,40 +301,32 @@ class SessionKeeper:
if thingie != summary:
raise Error, 'bad signature: %s != %s' % (`thingie`, `summary`)
- self.extres.db_env.nosyncerror_txn_checkpoint(MINS_BETWEEN_DB_CHECKPOINTS)
- trans = self.extres.db_env.txn_begin()
- try:
- # store session info if it's a new one
- if self.extres.counterparty_map.get(full_key_id, flags=db.DB_RMW, txn=trans) is None :
- if self.extres.session_map.get(id_in, flags=db.DB_RMW, txn=trans) is not None :
- raise Error, 'a session with the specified incoming id already exists'
- assert len(symmetric_key) == SIZE_OF_SYMMETRIC_KEYS
- self.extres.session_map.put(id_in, full_key, txn=trans)
- self.extres.counterparty_map.put(full_key_id, dumps([id_in, id_out, symmetric_key, None, full_key], 1), txn=trans)
- else:
- # Hmm.. We already had a session for this counterparty.
- # this means that most likely we both tried to send each other messages to establish a session
- # at the same time or at different times but one message got lost; usually due to the other
- # counterparty being offline at the time or having just switched relay servers.
- #
- # TODO implement this:
- # Accept and store this key and use it in the future. Keep the current key available
- # as well incase they get the session establishing message we sent them and switch to
- # using the session that we setup ourselves.
- # What this would do:
- # prevent the current situation of always sending the header to/from counterparties
- # where initiating session establishing messages have crossed. This is good because
- # full header messages are a bit larger and require two PKops on the receiver if the
- # header is not currently in its in memory parsed headers cache.
- pass
- result = (full_key, symmetric_key)
- self.__cached_headers[hash] = result
- trans.commit()
- trans = None
- return result
- finally:
- if trans is not None:
- trans.abort()
+ # store session info if it's a new one
+ if self.extres.counterparty_map.get(full_key_id) is None :
+ if self.extres.session_map.get(id_in) is not None :
+ raise Error, 'a session with the specified incoming id already exists'
+ assert len(symmetric_key) == SIZE_OF_SYMMETRIC_KEYS
+ self.extres.session_map[id_in] = full_key
+ self.extres.counterparty_map[full_key_id] = dumps([id_in, id_out, symmetric_key, None, full_key], 1)
+ else:
+ # Hmm.. We already had a session for this counterparty.
+ # this means that most likely we both tried to send each other messages to establish a session
+ # at the same time or at different times but one message got lost; usually due to the other
+ # counterparty being offline at the time or having just switched relay servers.
+ #
+ # TODO implement this:
+ # Accept and store this key and use it in the future. Keep the current key available
+ # as well incase they get the session establishing message we sent them and switch to
+ # using the session that we setup ourselves.
+ # What this would do:
+ # prevent the current situation of always sending the header to/from counterparties
+ # where initiating session establishing messages have crossed. This is good because
+ # full header messages are a bit larger and require two PKops on the receiver if the
+ # header is not currently in its in memory parsed headers cache.
+ pass
+ result = (full_key, symmetric_key)
+ self.__cached_headers[hash] = result
+ return result
except (modval.Error, tripledescbc.Error, xdrlib.Error, EOFError), le:
debugprint("got error in mesgen.__parse_header(): %s", args=(le,), v=4, vs="debug")
raise Error, le
@@ -389,20 +335,14 @@ class SessionKeeper:
"""
@idempotent
"""
- trans = self.extres.db_env.txn_begin()
- try:
- if self.extres.counterparty_map.has_key(idlib.make_id(full_key, 'key'), trans):
- return
+ if self.extres.counterparty_map.has_key(idlib.make_id(full_key, 'key')):
+ return
- return self.__store_key(full_key, txn=trans)
- finally:
- if trans:
- trans.commit()
+ return self.__store_key(full_key)
- def __store_key(self, full_key, txn):
- self.extres.db_env.nosyncerror_txn_checkpoint(MINS_BETWEEN_DB_CHECKPOINTS)
+ def __store_key(self, full_key):
key_id = sha(full_key).digest()
- if self.extres.counterparty_map.get(key_id, flags=db.DB_RMW, txn=txn) is not None :
+ if self.extres.counterparty_map.get(key_id) is not None :
return
id_in_rep = randsource.get(SIZE_OF_UNIQS)
id_in = _mix_counterparties(self.__my_public_key_id, key_id, id_in_rep)
@@ -445,10 +385,10 @@ class SessionKeeper:
p.pack_string(encrypted)
header = p.get_buffer()
- self.extres.counterparty_map.put(key_id, dumps([id_in, id_out, symmetric_key, header, full_key], 1), txn=txn)
+ self.extres.counterparty_map[key_id] = dumps([id_in, id_out, symmetric_key, header, full_key], 1)
_assert(idlib.is_id(id_in), "internal consistency", id_in)
- self.extres.session_map.put(id_in, full_key, txn=txn)
+ self.extres.session_map[id_in] = full_key
def get_connect_info(self, counterparty_id):
self.lock.acquire()
@@ -469,13 +409,7 @@ class SessionKeeper:
counterparty_id = idlib.canonicalize(counterparty_id, 'broker')
- self.extres.db_env.nosyncerror_txn_checkpoint(MINS_BETWEEN_DB_CHECKPOINTS)
- trans = self.extres.db_env.txn_begin()
- try:
- infopickle = self.extres.counterparty_map.get(counterparty_id, txn=trans)
- finally:
- if trans:
- trans.commit()
+ infopickle = self.extres.counterparty_map.get(counterparty_id)
if infopickle is None:
raise NoCounterpartyInfo, 'no counterparty information stored'
@@ -489,36 +423,24 @@ class SessionKeeper:
return {'header': header, 'symmetric_key': symmetric_key}
def get_session_info(self, id_in):
- self.lock.acquire()
- try:
- return self.__get_session_info(id_in)
- finally:
- self.lock.release()
+ return self.__get_session_info(id_in)
def __get_session_info(self, id_in):
"""
Returns (counterparty_pub_key_sexp, symmetric_key, want ack) throws Error
"""
precondition(idlib.is_id(id_in), "id_in is required to be an id.", id_in)
- self.extres.db_env.nosyncerror_txn_checkpoint(MINS_BETWEEN_DB_CHECKPOINTS)
- trans = self.extres.db_env.txn_begin()
- try:
- counterparty_pub_key_sexp = self.extres.session_map.get(id_in, txn=trans)
- if counterparty_pub_key_sexp is None:
- raise UnknownSession(id_in, self.get_id())
- counterparty_id = idlib.make_id(counterparty_pub_key_sexp, 'broker')
- try:
- thingie = self.extres.counterparty_map.get(counterparty_id, txn=trans)
- symmetric_key, header = loads(thingie)[2:4]
- except TypeError, le:
- # well, we did know about the session, but our counterparty database somehow didn't have an entry
- raise UnknownSession(id_in, self.get_id(), humanreadable.hr(le))
- return (counterparty_pub_key_sexp, symmetric_key, header is not None)
- trans.commit()
- trans = None
- finally:
- if trans is not None:
- trans.abort()
+ counterparty_pub_key_sexp = self.extres.session_map.get(id_in)
+ if counterparty_pub_key_sexp is None:
+ raise UnknownSession(id_in, self.get_id())
+ counterparty_id = idlib.make_id(counterparty_pub_key_sexp, 'broker')
+ try:
+ thingie = self.extres.counterparty_map.get(counterparty_id)
+ symmetric_key, header = loads(thingie)[2:4]
+ except TypeError, le:
+ # well, we did know about the session, but our counterparty database somehow didn't have an entry
+ raise UnknownSession(id_in, self.get_id(), humanreadable.hr(le))
+ return (counterparty_pub_key_sexp, symmetric_key, header is not None)
def invalidate_session(self, bad_session_id_out, counterparty_id):
self.lock.acquire()
@@ -532,41 +454,33 @@ class SessionKeeper:
Removes an outgoing session id from our database if counterparty_id matches the public key id
associated with this session id. Raises Error if bad_session_id_out is not associated with counterparty_id.
"""
- self.extres.db_env.nosyncerror_txn_checkpoint(MINS_BETWEEN_DB_CHECKPOINTS)
- trans = self.extres.db_env.txn_begin()
+ # maps counterparty id to [session_id_in, session_id_out, symmetric_key, header, full pk]
try:
- # maps counterparty id to [session_id_in, session_id_out, symmetric_key, header, full pk]
- try:
- stored_session_id_out = loads(self.extres.counterparty_map.get(counterparty_id, (None,None,None,None), txn=trans))[1]
- except:
- stored_session_id_out = None
- debugprint("__invalidate_session for unverified cid %s, bad_session_id_out %s, stored_session_id_out %s\n", args=(counterparty_id, bad_session_id_out, stored_session_id_out), v=4, vs='mesgen')
- if idlib.equal(stored_session_id_out, bad_session_id_out):
- self.extres.counterparty_map.delete(counterparty_id, txn=trans)
- else:
- raise Error, "someone asked us to invalidate session_id_out %s, but they claimed that that session was with counterparty %s, but we do not have a that session id as our session id for that counterparty. Not invalidating; we probably connected to broker that is now using a different key from the one we know for the CommStrat" % (`bad_session_id_out`, base32.b2a(counterparty_id))
- # TODO this should be its own class of error, if caught it is -reasonable- (though not absolute in
- # in the rare case of someone malicious hijacking/inserting data into the TCP stream) to assume
- # that any of the messages you just sent down this TCP connection were undecryptable and should
- # be fast failed at this point. [even in the malicious case above, its just becomes a convoluted
- # "denial of service" from you to the given counterparty that there are -much- easier ways to
- # accomplish without sniffing and hijacking connections] -greg 2001-06-04
- trans.commit()
- trans = None
- finally:
- if trans is not None:
- trans.abort()
+ stored_session_id_out = loads(self.extres.counterparty_map.get(counterparty_id, (None,None,None,None)))[1]
+ except:
+ stored_session_id_out = None
+ debugprint("__invalidate_session for unverified cid %s, bad_session_id_out %s, stored_session_id_out %s\n", args=(counterparty_id, bad_session_id_out, stored_session_id_out), v=4, vs='mesgen')
+ if idlib.equal(stored_session_id_out, bad_session_id_out):
+ del self.extres.counterparty_map[counterparty_id]
+ else:
+ raise Error, "someone asked us to invalidate session_id_out %s, but they claimed that that session was with counterparty %s, but we do not have a that session id as our session id for that counterparty. Not invalidating; we probably connected to broker that is now using a different key from the one we know for the CommStrat" % (`bad_session_id_out`, base32.b2a(counterparty_id))
+ # TODO this should be its own class of error, if caught it is -reasonable- (though not absolute in
+ # in the rare case of someone malicious hijacking/inserting data into the TCP stream) to assume
+ # that any of the messages you just sent down this TCP connection were undecryptable and should
+ # be fast failed at this point. [even in the malicious case above, its just becomes a convoluted
+ # "denial of service" from you to the given counterparty that there are -much- easier ways to
+ # accomplish without sniffing and hijacking connections] -greg 2001-06-04
-def create_MessageMaker(dbparentdir, recoverdb=True):
- return MessageMaker(dbparentdir=dbparentdir, dir=None, recoverdb=recoverdb)
+def create_MessageMaker(dbparentdir):
+ return MessageMaker(dbparentdir=dbparentdir, dir=None)
-def load_MessageMaker(dir, recoverdb=True):
- return MessageMaker(dbparentdir=None, dir=dir, recoverdb=recoverdb)
+def load_MessageMaker(dir):
+ return MessageMaker(dbparentdir=None, dir=dir)
class MessageMaker:
- def __init__(self, dbparentdir=None, dir=None, serialized=None, recoverdb=True):
+ def __init__(self, dbparentdir=None, dir=None, serialized=None):
"""
You can pass either dir or dbparentdir, but not both. You pass `dbparentdir' if you
don't know the id of the key (either because the key is being created or because it is
@@ -591,14 +505,14 @@ class MessageMaker:
assert ((dbparentdir is not None) and (dir is None)) or ((dbparentdir is None) and (dir is not None)), "precondition: Exactly one of (dbparentdir, dir) must be not None." + " -- " + "dbparentdir: %s, dir: %s" % (hr(dbparentdir), hr(dir))
if dir:
- self._session_keeper = SessionKeeper(dbparentdir=None, dir=dir, recoverdb=recoverdb)
+ self._session_keeper = SessionKeeper(dbparentdir=None, dir=dir)
else:
if serialized:
mmdict = mencode.mdecode(serialized)
skserialized = mmdict['session keeper']
- self._session_keeper = SessionKeeper(dbparentdir=dbparentdir, dir=None, serialized=skserialized, recoverdb=recoverdb)
+ self._session_keeper = SessionKeeper(dbparentdir=dbparentdir, dir=None, serialized=skserialized)
else:
- self._session_keeper = SessionKeeper(dbparentdir=dbparentdir, dir=None, recoverdb=recoverdb)
+ self._session_keeper = SessionKeeper(dbparentdir=dbparentdir, dir=None)
def get_public_key(self):
return self._session_keeper.get_public_key()
More information about the Mnet-devel
mailing list