From: Brian Warner Date: Sat, 2 Dec 2006 23:26:26 +0000 (-0700) Subject: standardize on keeping nodeids (and all other SHA1-derived values as binary everywher... X-Git-Tag: tahoe_v0.1.0-0-UNSTABLE~497 X-Git-Url: https://git.rkrishnan.org/running.html?a=commitdiff_plain;h=08d9c492588386f8e2ecbb3a93277dc97b1175b8;p=tahoe-lafs%2Ftahoe-lafs.git standardize on keeping nodeids (and all other SHA1-derived values as binary everywhere, only doing idlib.b2a() when interacting with a human or the filesystem --- diff --git a/allmydata/client.py b/allmydata/client.py index 9b8ed7ea..7ad41053 100644 --- a/allmydata/client.py +++ b/allmydata/client.py @@ -16,6 +16,7 @@ from twisted.internet.base import BlockingResolver reactor.installResolver(BlockingResolver()) from allmydata.storageserver import StorageServer +from allmydata.util import idlib class Client(service.MultiService, Referenceable): implements(RIClient) @@ -32,7 +33,7 @@ class Client(service.MultiService, Referenceable): f = open(self.CERTFILE, "wb") f.write(self.tub.getCertData()) f.close() - self.nodeid = self.tub.tubID + self.nodeid = idlib.a2b(self.tub.tubID) self.tub.setServiceParent(self) self.queen = None # self.queen is either None or a RemoteReference self.all_peers = set() @@ -90,21 +91,21 @@ class Client(service.MultiService, Referenceable): for nodeid, pburl in new_peers: if nodeid == self.nodeid: continue - log.msg("adding peer %s" % nodeid) + log.msg("adding peer %s" % idlib.b2a(nodeid)) if nodeid in self.all_peers: log.msg("weird, I already had an entry for them") self.all_peers.add(nodeid) if nodeid not in self.connections: d = self.tub.getReference(pburl) def _got_reference(ref): - log.msg("connected to %s" % nodeid) + log.msg("connected to %s" % idlib.b2a(nodeid)) if nodeid in self.all_peers: self.connections[nodeid] = ref d.addCallback(_got_reference) def remote_lost_peers(self, lost_peers): for nodeid in lost_peers: - log.msg("lost peer %s" % nodeid) + log.msg("lost peer %s" % idlib.b2a(nodeid)) if nodeid in self.all_peers: self.all_peers.remove(nodeid) else: diff --git a/allmydata/interfaces.py b/allmydata/interfaces.py index 0bacbd43..dd45a28a 100644 --- a/allmydata/interfaces.py +++ b/allmydata/interfaces.py @@ -2,9 +2,9 @@ from foolscap.schema import StringConstraint, ListOf, TupleOf, Any, Nothing from foolscap import RemoteInterface -Nodeid = StringConstraint(20) # base32 encoded 20-byte SHA1 hash -PBURL = StringConstraint() -Tubid = StringConstraint() +Nodeid = StringConstraint(20) # binary format 20-byte SHA1 hash +PBURL = StringConstraint(150) +Verifierid = StringConstraint(20) ShareData = StringConstraint(20000) # these three are here because Foolscap does not yet support the kind of # restriction I really want to apply to these. @@ -25,8 +25,8 @@ class RIClient(RemoteInterface): return Nothing() class RIStorageServer(RemoteInterface): - def allocate_bucket(verifierid=Nodeid, bucket_num=int, size=int, - leaser=Tubid): + def allocate_bucket(verifierid=Verifierid, bucket_num=int, size=int, + leaser=Nodeid): return RIBucketWriter_ diff --git a/allmydata/queen.py b/allmydata/queen.py index 0934b489..0a75a930 100644 --- a/allmydata/queen.py +++ b/allmydata/queen.py @@ -5,6 +5,7 @@ from twisted.application import service from twisted.python import log import os.path from allmydata.util.iputil import get_local_ip_for +from allmydata.util import idlib from zope.interface import implements from allmydata.interfaces import RIQueenRoster @@ -17,7 +18,7 @@ class Roster(service.MultiService, Referenceable): self.connections = {} def remote_hello(self, nodeid, node, pburl): - log.msg("contact from %s" % nodeid) + log.msg("contact from %s" % idlib.b2a(nodeid)) eventually(self._educate_the_new_peer, node) eventually(self._announce_new_peer, nodeid, pburl) self.phonebook[nodeid] = pburl @@ -33,7 +34,7 @@ class Roster(service.MultiService, Referenceable): new_peers=[(new_nodeid, new_node_pburl)]) def _lost_node(self, nodeid): - log.msg("lost contact with %s" % nodeid) + log.msg("lost contact with %s" % idlib.b2a(nodeid)) del self.phonebook[nodeid] del self.connections[nodeid] eventually(self._announce_lost_peer, nodeid) diff --git a/allmydata/upload.py b/allmydata/upload.py index ae659c03..b6dc4de0 100644 --- a/allmydata/upload.py +++ b/allmydata/upload.py @@ -1,6 +1,7 @@ from twisted.python import failure from twisted.internet import defer +from allmydata.util import idlib class NotEnoughPeersError(Exception): pass @@ -64,7 +65,7 @@ class Uploader: d = self._peer.get_remote_service(peerid, "storageserver") def _got_peer(service): bucket_num = len(self.landlords) - if self.debug: print "asking %s" % peerid + if self.debug: print "asking %s" % idlib.b2a(peerid) d2 = service.callRemote("allocate_bucket", verifierid=self._verifierid, bucket_num=bucket_num, @@ -72,7 +73,7 @@ class Uploader: leaser=self._peer.nodeid) def _allocate_response(bucket): if self.debug: - print " peerid %s will grant us a lease" % peerid + print " peerid %s will grant us a lease" % idlib.b2a(peerid) self.landlords.append( (peerid, bucket_num, bucket) ) self.goodness_points += 1 if self.goodness_points >= self.target_goodness: @@ -83,7 +84,7 @@ class Uploader: return d2 d.addCallback(_got_peer) def _done_with_peer(res): - if self.debug: print "done with peer %s:" % peerid + if self.debug: print "done with peer %s:" % idlib.b2a(peerid) if isinstance(res, failure.Failure): if res.check(HaveAllPeersError): if self.debug: print " all done"