def __repr__(self): return "<%s: %s>" % (self.__class__.__name__, self.value) class NullRem(Rem): """The equivalent of None for the REM""" def __add__(self, b): return b def __radd__(self, b): return b serializable.register(NullRem) class DeadRem(Rem): """A route with this rem is dead""" def __add__(self, b): return self serializable.register(DeadRem) class Rtt(Rem): """Round Trip Time"""
raise NotImplementedError def __repr__(self): return '<%s: %s>' % (self.__class__.__name__, self.value) class NullRem(Rem): """The equivalent of None for the REM""" def __add__(self, b): return b def __radd__(self, b): return b serializable.register(NullRem) class DeadRem(Rem): """A route with this rem is dead""" def __add__(self, b): return self serializable.register(DeadRem) class Rtt(Rem): """Round Trip Time""" def __init__(self, value,
class ParticipantNode(object): def __init__( self, lvl=None, id=None, # these are mandatory for Map.__init__() participant=False): self.participant = participant def _pack(self): return (0, 0, self.participant) serializable.register(ParticipantNode) class MapP2P(Map): """Map of the participant nodes""" def __init__(self, levels, gsize, me, pid): """levels, gsize, me: the same of Map pid: P2P id of the service associated to this map """ Map.__init__(self, levels, gsize, ParticipantNode, me) self.pid = pid def participate(self):
return getattr(self.rsa, name) def verify(self, msg, signature): try: return self.rsa.verify(msg, signature) except RSAError: return False def __repr__(self): return self.rsa.as_pem() def _pack(self): return (self.rsa.as_pem(), ) serializable.register(PublicKey) class KeyPair(): def __init__(self, keys_path=settings.KEY_PAIR_DIR): if os.path.exists(keys_path) and os.path.getsize(keys_path) > 0: self.bio = openfile(keys_path, 'rb') self.rsa = load_key_bio(self.bio, callback=do_nothing) else: self.bio = openfile(keys_path, 'ab+') self.rsa = self.generate() self.rsa.save_key_bio(self.bio, callback=do_nothing) self.rsa.save_pub_key_bio(self.bio) self.bio.reset() def generate(self, keysize=1024, rsa_pub_exponent=65537):
from ntk.lib.rpc import FakeRmt, RPCDispatcher, CallerInfo class P2PError(Exception): '''Generic P2P Error''' class ParticipantNode(object): def __init__(self, lvl=None, id=None, # these are mandatory for Map.__init__() participant=False): self.participant = participant def _pack(self): return (0, 0, self.participant) serializable.register(ParticipantNode) class MapP2P(Map): """Map of the participant nodes""" def __init__(self, levels, gsize, me, pid): """levels, gsize, me: the same of Map pid: P2P id of the service associated to this map """ Map.__init__(self, levels, gsize, ParticipantNode, me) self.pid = pid def participate(self):
def __getattr__(self, name): return getattr(self.rsa, name) def verify(self, msg, signature): try: return self.rsa.verify(msg, signature) except RSAError: return False def __repr__(self): return self.rsa.as_pem() def _pack(self): return (self.rsa.as_pem(),) serializable.register(PublicKey) class KeyPair(): def __init__(self, keys_path=settings.KEY_PAIR_DIR): if os.path.exists(keys_path) and os.path.getsize(keys_path) > 0: self.bio = openfile(keys_path, 'rb') self.rsa = load_key_bio(self.bio, callback=do_nothing) else: self.bio = openfile(keys_path, 'ab+') self.rsa = self.generate() self.rsa.save_key_bio(self.bio, callback=do_nothing) self.rsa.save_pub_key_bio(self.bio) self.bio.reset() def generate(self, keysize=1024, rsa_pub_exponent=65537):