Ejemplo n.º 1
0
    def __init__(self, callback, statedir, port):
        assert isinstance(port, int)
        assert 0 <= port
        super(TrackerDispersy, self).__init__(callback, statedir)

        # non-autoload nodes
        self._non_autoload = set()
        self._non_autoload.update(host for host, _ in self._bootstrap_candidates.iterkeys())
        # leaseweb machines, some are running boosters, they never unload a community
        self._non_autoload.update(["95.211.105.65", "95.211.105.67", "95.211.105.69", "95.211.105.71", "95.211.105.73", "95.211.105.75", "95.211.105.77", "95.211.105.79", "95.211.105.81", "85.17.81.36"])

        # generate a new my-member
        ec = ec_generate_key(u"very-low")
        self._my_member = Member(ec_to_public_bin(ec), ec_to_private_bin(ec))

        callback.register(self._unload_communities)
        callback.register(self._bandwidth_statistics)
Ejemplo n.º 2
0
    def init_my_member(self, bits=None, sync_with_database=None, candidate=True, identity=True):
        assert bits is None, "The parameter bits is deprecated and must be None"
        assert sync_with_database is None, "The parameter sync_with_database is deprecated and must be None"

        ec = ec_generate_key(u"low")
        self._my_member = DebugOnlyMember.get_instance(ec_to_public_bin(ec), ec_to_private_bin(ec), sync_with_database=False)

        if identity:
            # update identity information
            assert self._socket, "Socket needs to be set to candidate"
            assert self._community, "Community needs to be set to candidate"
            message = self.create_dispersy_identity_message(2)
            self.give_message(message)

        if candidate:
            # update candidate information
            assert self._socket, "Socket needs to be set to candidate"
            assert self._community, "Community needs to be set to candidate"
            message = self.create_dispersy_introduction_request_message(self._community.my_candidate, self.lan_address, self.wan_address, False, u"unknown", None, 1, 1)
            self.give_message(message)
Ejemplo n.º 3
0
    def init_my_member(self, bits=None, sync_with_database=None, candidate=True, identity=True):
        assert bits is None, "The parameter bits is depricated and must be None"
        assert sync_with_database is None, "The parameter sync_with_database is depricated and must be None"

        ec = ec_generate_key(u"low")
        self._my_member = DebugPrivateMember.get_instance(ec_to_public_bin(ec), ec_to_private_bin(ec), sync_with_database=False)

        if identity:
            # update identity information
            assert self._socket, "Socket needs to be set to candidate"
            assert self._community, "Community needs to be set to candidate"
            source_address = self._socket.getsockname()
            message = self.create_dispersy_identity_message(source_address, 2)
            self.give_message(message)

        if candidate:
            # update candidate information
            assert self._socket, "Socket needs to be set to candidate"
            assert self._community, "Community needs to be set to candidate"
            source_address = self._socket.getsockname()
            destination_address = self._community._dispersy.socket.get_address()
            message = self.create_dispersy_candidate_request_message(source_address, destination_address, self._community.get_conversion().version, [], 1)
            self.give_message(message)
Ejemplo n.º 4
0
        Sign DATA using our private key.  Returns the signature.
        """
        assert not self._private_key is None
        return ec_sign(self._ec, sha1(data[offset:length or len(data)]).digest())

class MasterMember(Member):
    pass

class ElevatedMasterMember(MasterMember, PrivateMember):
    pass

class MyMember(PrivateMember):
    pass

if __debug__:
    if __name__ == "__main__":
        from crypto import ec_generate_key, ec_to_public_bin, ec_to_private_bin

        ec = ec_generate_key(u"low")
        public_key = ec_to_public_bin(ec)
        private_key = ec_to_private_bin(ec)
        public_member = Member(public_key, sync_with_database=False)
        private_member = PrivateMember(public_key, private_key, sync_with_database=False)

        data = "Hello World! " * 1000
        sig = private_member.sign(data)
        digest = sha1(data).digest()
        dprint(sig.encode("HEX"))
        assert public_member.verify(data, sig)
        assert private_member.verify(data, sig)