[mnet-devel] patch: partially merged libdb work
Zooko O'Whielacronx
zooko at zooko.com
Thu Oct 30 22:50:16 GMT 2003
This patch shows how to use part of Arno's libdb4-usage-patch while
maintaining some fixes in where we pass transactions.
I'm not cvs committing it because (a) I can't test right now and (b) I took
*out* DB_AUTO_COMMIT from Arno's patch.
DB_AUTO_COMMIT is not used for mesgen.py, and I don't *think* it is used for
counterparties.py, but it might be used for contentdb.py. Anyway, I don't
know if DB_AUTO_COMMIT works with libdb3?
Anyway, I thought maybe Arno would like to see this patch while I am busy with
Other Stuff from now until Mnet Hack Day (Sunday).
This patch is against HEAD v0.6.2.251-STABLE.
--Z
--- GNUmakefile 30 Oct 2003 20:23:57 -0000 1.248
+++ GNUmakefile 30 Oct 2003 22:49:57 -0000
@@ -21,7 +21,7 @@
# For the binarytar target to create the tarball structure:
WORKTMPDIR=/tmp/mnettars
-VERSTR="0.6.2.251-STABLE"
+VERSTR="0.6.2.252-STABLE"
PKGNAME=Mnet
# GNU make is required to build this, change this or pass MAKE=gmake
cvs server: Diffing MacOSX
cvs server: Diffing artwork
cvs server: Diffing client
cvs server: Diffing client/blockshare
cvs server: Diffing client/blockshare/Python
cvs server: Diffing client/localhost
--- client/localhost/Broker.py 30 Oct 2003 03:42:52 -0000 1.75
+++ client/localhost/Broker.py 30 Oct 2003 22:49:59 -0000
@@ -36,7 +36,14 @@
import pyutilversion
import dictutil
-import bsddb3
+try:
+ import bsddb
+ bsddbversion = `bsddb._bsddb.version()`
+ pybsddbversion = bsddb.__version__
+except:
+ import bsddb3
+ bsddbversion = `bsddb3._db.version()`
+ pybsddbversion = bsddb3.__version__
# UNHARDCODE ME
@@ -274,8 +281,8 @@
debugprint("broker version: %s\n" % BrokerVersion.versionobj.verbose_string())
debugprint("python version: %s\n" % sys.version)
debugprint("Crypto++ version: %s\n" % CRYPTOPP_VERSION_STR)
- debugprint("Berkeley DB version: %s\n" % `bsddb3._db.version()`)
- debugprint("PyBSDDB version: %s\n" % bsddb3.__version__)
+ debugprint("Berkeley DB version: %s\n" % bsddbversion)
+ debugprint("PyBSDDB version: %s\n" % pybsddbversion)
# Parse the commandline args:
debugprint('Parsing commandline arguments.\n', vs='Broker', v=0)
--- common/BrokerVersion.py 30 Oct 2003 20:23:57 -0000 1.332
+++ common/BrokerVersion.py 30 Oct 2003 22:49:59 -0000
@@ -24,7 +24,7 @@
major = 0 # this will go to `1' when it is ready for widespread public use !?
minor = 6 # release number
micro = 2 # bugfix release number
-nano = 251 # everytime a developer changes anything that anyone might care about, he bumps this one
+nano = 252 # everytime a developer changes anything that anyone might care about, he bumps this one
flag = "STABLE"
versiontup = (major, minor, micro, nano,)
--- common/CleanLogDb.py 30 Oct 2003 02:09:22 -0000 1.3
+++ common/CleanLogDb.py 30 Oct 2003 22:49:59 -0000
@@ -1,6 +1,10 @@
## Subclass of DB that cleans up it's log files periodically
-from bsddb3 import db, dbobj
+try:
+ from bsddb import db, dbobj
+except:
+ from bsddb3 import db, dbobj
+
import debug
import re
import os
@@ -43,11 +47,11 @@
try:
val = apply(self.txn_checkpoint, _args, _kwargs)
- except RuntimeWarning, e:
+ except:
# try again, this is a non-fatal intermittent error
try:
val = apply(self.txn_checkpoint, _args, _kwargs)
- except db.DBError, e:
+ except (db.DBInvalidArgError, db.DBError), e:
debug.mojolog.write("ignoring db.DBError %s during txn_checkpoint\n", args=(e,), v=3, vs="CleanLogDb")
return val
--- common/FileVerifier.py 30 Oct 2003 02:09:22 -0000 1.19
+++ common/FileVerifier.py 30 Oct 2003 22:49:59 -0000
@@ -27,7 +27,11 @@
import humread # This import statement is required to make unique 160-bit ids get printed out as human-readable base32-encoded ids, even though we don't actually *reference* humread anywhere in this file. Sorry for the weirdness. --Zooko 2002-07-23
# Mnet modules
-from bsddb3 import dbtables, db
+try:
+
+ from bsddb import dbtables, db
+except:
+ from bsddb3 import dbtables, db
import contentlib
import idlib
import mojosixbit
--- common/Purse.py 30 Oct 2003 02:09:22 -0000 1.5
+++ common/Purse.py 30 Oct 2003 22:50:00 -0000
@@ -25,7 +25,10 @@
### our modules
import MojoToken
-from bsddb3 import db, dbobj
+try:
+ from bsddb import db, dbobj
+except:
+ from bsddb3 import db, dbobj
import canon
import debug
# HACK: this is needed to allow unpickling of Tokens created using the old "Token" modulename instead of "MojoToken"
--- common/counterparties.py 30 Oct 2003 02:09:22 -0000 1.17
+++ common/counterparties.py 30 Oct 2003 22:50:01 -0000
@@ -13,7 +13,7 @@
# us, their reputation for coming through with their deals in our eyes,
# etc.
#
-__cvsid = '$Id: counterparties.py,v 1.17 2003/10/30 02:09:22 zooko Exp $'
+__cvsid = '$Id: counterparties.py,v 1.15 2003/10/26 19:05:43 zooko Exp $'
# Python standard library modules
@@ -37,7 +37,10 @@
true = 1
false = None
import MojoToken
-from bsddb3 import db, dbobj
+try:
+ from bsddb import db, dbobj
+except:
+ from bsddb3 import db, dbobj
import confutils
from confutils import confman
import debug
@@ -345,7 +348,7 @@
newval = dumps(self.vals)
try:
- self.keeper.extres.balances_db.put(self._counterparty_id, newval, txn=self.trans)
+ self.keeper.extres.balances_db.put(self._counterparty_id, newval, txn=self.trans)
except db.DBError, le:
debug.mojolog.write("Got error from counterparties db trying to save. Ignoring. counterparty_id: %s, vals: %s, le: %s\n", args=(self._counterparty_id, self.vals, le,), v=0, vs="warning")
--- common/localblockstore.py 30 Oct 2003 02:09:22 -0000 1.20
+++ common/localblockstore.py 30 Oct 2003 22:50:03 -0000
@@ -7,7 +7,7 @@
#
# This module implements our local disk based block storage.
#
-__cvsid = '$Id: localblockstore.py,v 1.20 2003/10/30 02:09:22 zooko Exp $'
+__cvsid = '$Id: localblockstore.py,v 1.18 2003/02/14 22:46:43 zooko Exp $'
# UNHARDCODE ME
@@ -51,7 +51,10 @@
true = 1
false = 0
import MetaTrackerLib
-from bsddb3 import db, dbobj
+try:
+ from bsddb import db, dbobj
+except:
+ from bsddb3 import db, dbobj
import confutils
from confutils import confman
import debug
@@ -284,7 +287,7 @@
self._totalbytesusedlock.acquire()
try:
try:
- totalbytes = pickle.loads(self.index_db.get('total bytes used', txn=txn))
+ totalbytes = pickle.loads(self.index_db.get('total bytes used'), txn=txn)
except (TypeError, PickleError,), le:
debug.mojolog.write("%s.__update_space_totals(%s): encountered error in pickle.loads(). Setting totalbytes to 0. le: %s\n", args=(self, delta, le,), vs="debug")
totalbytes = 0
--- common/mesgen.py 30 Oct 2003 20:23:57 -0000 1.8
+++ common/mesgen.py 30 Oct 2003 22:50:04 -0000
@@ -13,7 +13,10 @@
import tripledescbc
from sha import sha
import traceback
-from bsddb3 import db, dbobj
+try:
+ from bsddb import db, dbobj
+except:
+ from bsddb3 import db, dbobj
from cPickle import dumps, loads
import threading
import traceback
@@ -193,11 +196,11 @@
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_THREAD )
+ session_map.open('session_map', db.DB_BTREE, db.DB_CREATE | db.DB_THREAD)
# 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_THREAD )
+ counterparty_map.open('counterparty_map', db.DB_BTREE, db.DB_CREATE | db.DB_THREAD)
self.extres = SessionKeeper.ExtRes(db_env, session_map, counterparty_map)
# maps header ids to content of headers for memoization
self.__cached_headers = Cache.LRUCacheLocked(maxitems)
@@ -460,7 +463,7 @@
"""
Returns either: {'header': ..., 'symmetric_key': ...} {'session_id_out': ..., 'symmetric_key': ...}
- Generates new connection info if there is none
+ Generates new connection info if there is None
@precondition `counterparty_id' must be of the right form for an id.: idlib.is_sloppy_id(counterparty_id): "counterparty_id: %s" % hr(counterparty_id)
"""
@@ -523,22 +526,29 @@
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.
"""
- # maps counterparty id to [session_id_in, session_id_out, symmetric_key, header, full pk]
+ trans = self.extres.db_env.txn_begin()
try:
- stored_session_id_out = loads(self.extres.counterparty_map.get(counterparty_id, (None,None,None,None)))[1]
- except:
- stored_session_id_out = None
- debug.mojolog.write("__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)
- 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`, idlib.to_ascii(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
+ # 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
+ debug.mojolog.write("__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`, idlib.to_ascii(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()
def create_MessageMaker(dbparentdir, recoverdb=true):
--- server/merchant/contentdb.py 30 Oct 2003 02:09:22 -0000 1.13
+++ server/merchant/contentdb.py 30 Oct 2003 22:50:05 -0000
@@ -8,7 +8,7 @@
#
# This module implements Mnet content tracking support.
#
-__cvsid = '$Id: contentdb.py,v 1.13 2003/10/30 02:09:22 zooko Exp $'
+__cvsid = '$Id: contentdb.py,v 1.11 2003/02/16 00:44:41 arnowa Exp $'
# Python standard library modules
from cStringIO import StringIO
@@ -20,7 +20,10 @@
# Mnet modules
from MojoXML import * # this also imports the saxlib+saxexts for us
-from bsddb3 import dbtables, db
+try:
+ from bsddb import dbtables, db
+except:
+ from bsddb3 import dbtables, db
from confutils import confman
import contentlib
from contentlib import ContentTrackerError, ContentDBError, ContentXMLError, ContentTypeError
@@ -57,7 +60,7 @@
# sometimes it raises a DB_INCOMPLETE "sync didn't finish"
# but works the next time you try and open the DBEnv().
try:
- self.db = dbtables.bsdTableDB(name, dbpath, create=1, recover=1, dbflags=db.DB_PRIVATE)
+ self.db = dbtables.bsdTableDB(name, dbpath, create=1, recover=1)
except (dbtables.TableDBError, db.DBError), e:
raise ContentDBError, e
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
_______________________________________________
mnet-devel mailing list
mnet-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mnet-devel
More information about the Mnet-devel
mailing list