Example #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"
        ])

        # logger
        overlaylogpostfix = "dp" + str(port) + ".log"
        self._logger = OverlayLogger.getInstance(overlaylogpostfix, statedir)
        self._candidates_status = {}
        callback.register(self._candidate_logger, priority=-128)

        # 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, priority=-128)
Example #2
0
    def __init__(self, callback, working_directory):
        super(TrackerDispersy, self).__init__(callback, working_directory)

        # get my_member, the key pair that we will use when we join a new community
        keypair = read_keypair(os.path.join(working_directory, u"ec.pem"))
        self._my_member = MyMember(ec_to_public_bin(keypair), ec_to_private_bin(keypair))

        # cleanup communities from memory periodically
        callback.register(self._periodically_cleanup_communities)
Example #3
0
    def setup(self):
        """
        We either need to join the community or semi-create one.
        """
        # we will use the below member identifier to create messages for our test.  the private key
        # can be found on disk, but will not be submitted to SVN for obvious reasons
        assert "hardcoded_member" in self._kargs, ("give --script-args hardcoded_member=A|B|C", self._kargs)
        assert self._kargs["hardcoded_member"] in SimpleDispersyTestCommunity.hardcoded_member_public_keys, "give --script-args hardcoded_member=A|B|C"

        member_name = self._kargs["hardcoded_member"]
        hardcoded_public_key = SimpleDispersyTestCommunity.hardcoded_member_public_keys[member_name]
        hardcoded_mid = sha1(hardcoded_public_key).digest()

        try:
            dprint("load_hardcoded_community")
            self._community = SimpleDispersyTestCommunity.load_hardcoded_community()

        except ValueError, e:
            dprint("failed to load; joining instead [", e, "]")
            # COPIED FROM dispersy/community.py:create_community.  IF ANYTHING CHANGES THERE IT
            # NEEDS TO BE REFLECTED HERE ASWELL

            # obtain the hardcoded_private_key for my_member from disk
            pem = open(expanduser("~/simpledispersytest_ec_private_key_%s" % member_name), "r").read()
            ec = ec_from_private_pem(pem)
            private_key = ec_to_private_bin(ec)
            my_member = MyMember(hardcoded_public_key, private_key)

            # obtain the master_private_key for the master_member from disk
            pem = open(expanduser("~/simpledispersytest_ec_master_private_key"), "r").read()
            ec = ec_from_private_pem(pem)
            master_private_key = ec_to_private_bin(ec)

            # insert entries in the dispersy database to join the community
            with self._dispersy_database as database:
                database.execute(u"INSERT INTO community (user, classification, cid, public_key) VALUES(?, ?, ?, ?)", (my_member.database_id, SimpleDispersyTestCommunity.get_classification(), buffer(SimpleDispersyTestCommunity.hardcoded_cid), buffer(SimpleDispersyTestCommunity.hardcoded_master_public_key)))
                database_id = self._dispersy_database.last_insert_rowid
                database.execute(u"INSERT INTO user (mid, public_key) VALUES(?, ?)", (buffer(SimpleDispersyTestCommunity.hardcoded_cid), buffer(SimpleDispersyTestCommunity.hardcoded_master_public_key)))
                database.execute(u"INSERT INTO key (public_key, private_key) VALUES(?, ?)", (buffer(SimpleDispersyTestCommunity.hardcoded_master_public_key), buffer(master_private_key)))
                database.execute(u"INSERT INTO candidate (community, host, port, incoming_time, outgoing_time) SELECT ?, host, port, incoming_time, outgoing_time FROM candidate WHERE community = 0", (database_id,))

            self._community = SimpleDispersyTestCommunity.load_community(SimpleDispersyTestCommunity.hardcoded_cid, SimpleDispersyTestCommunity.hardcoded_master_public_key)
Example #4
0
    def setup(self):
        """
        We either need to join the community or semi-create one.
        """
        # we will use the below member identifier to create messages for our test.  the private key
        # can be found on disk, but will not be submitted to SVN for obvious reasons
        hardcoded_mid = "6bc9e18b346d9f879a90bbf51a495f3cb8b32957".decode("HEX")
        hardcoded_public_key = "3052301006072a8648ce3d020106052b8104001a033e000400d1f668eb495c76f6a899a46017e8c6ad57c90e85d84fa1524fe7a0e76f0183a3d290a63e80ae14060acc1d1e606f451811bab3f77c8dd318689695".decode("HEX")

        try:
            dprint("load_hardcoded_community")
            self._community = SimpleDispersyTestCommunity.load_hardcoded_community()

        except ValueError, e:
            dprint("failed to load; joining instead [", e, "]")
            # COPIED FROM dispersy/community.py:create_community.  IF ANYTHING CHANGES THERE IT
            # NEEDS TO BE REFLECTED HERE ASWELL

            # obtain the hardcoded_private_key for my_member from disk
            pem = open(expanduser("~/simpledispersytest_ec_private_key"), "r").read()
            ec = ec_from_private_pem(pem)
            private_key = ec_to_private_bin(ec)
            my_member = MyMember(hardcoded_public_key, private_key)

            # obtain the master_private_key for the master_member from disk
            pem = open(expanduser("~/simpledispersytest_ec_master_private_key"), "r").read()
            ec = ec_from_private_pem(pem)
            master_private_key = ec_to_private_bin(ec)

            # insert entries in the dispersy database to join the community
            with self._dispersy_database as execute:
                execute(u"INSERT INTO community (user, classification, cid, public_key) VALUES(?, ?, ?, ?)", (my_member.database_id, SimpleDispersyTestCommunity.get_classification(), buffer(SimpleDispersyTestCommunity.hardcoded_cid), buffer(SimpleDispersyTestCommunity.hardcoded_master_public_key)))
                database_id = self._dispersy_database.last_insert_rowid
                execute(u"INSERT INTO user (mid, public_key) VALUES(?, ?)", (buffer(SimpleDispersyTestCommunity.hardcoded_cid), buffer(SimpleDispersyTestCommunity.hardcoded_master_public_key)))
                execute(u"INSERT INTO key (public_key, private_key) VALUES(?, ?)", (buffer(SimpleDispersyTestCommunity.hardcoded_master_public_key), buffer(master_private_key)))
                execute(u"INSERT INTO candidate (community, host, port, incoming_time, outgoing_time) SELECT ?, host, port, incoming_time, outgoing_time FROM candidate WHERE community = 0", (database_id,))

            self._community = SimpleDispersyTestCommunity.load_community(SimpleDispersyTestCommunity.hardcoded_cid, SimpleDispersyTestCommunity.hardcoded_master_public_key)
    def __init__(self, callback, statedir, port):
        assert isinstance(port, int)
        assert 0 <= port
        super(TrackerDispersy, self).__init__(callback, statedir)

        # logger
        overlaylogpostfix = "dp" + str(port) + ".log"
        self._logger = OverlayLogger.getInstance(overlaylogpostfix, statedir)

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

        callback.register(self._unload_communities, priority=-128)
    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"])

        # logger
        overlaylogpostfix = "dp" + str(port) + ".log"
        self._logger = OverlayLogger.getInstance(overlaylogpostfix, statedir)
        self._candidates_status = {}
        callback.register(self._candidate_logger, priority=-128)

        # 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, priority=-128)
Example #7
0
    def run(self):
        ec = ec_generate_key(u"low")
        self._my_member = Member.get_instance(ec_to_public_bin(ec), ec_to_private_bin(ec), sync_with_database=True)

        self.caller(self.test_incoming_channel)
        self.caller(self.test_outgoing_channel)
# The list is in the following format:
#
# <peername> <ip> <port> <public key> <private key>
#
# The public and private keys come from an eleptic curve
# key, generated during runtime for each peer
#
# Use ./barter-ec-generator.py --help for help on the parameters
#
from Tribler.Core.dispersy.crypto import ec_generate_key, ec_to_public_bin, ec_to_private_bin

if __name__ == "__main__":
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option("--total-peers", help="Total number of peers to generate ip:port and key combinations. Default 50", type=int, default=50)
    parser.add_option("--port-start", help="Port number to start assigning from. Default 12000", default=12000)
    parser.add_option("-o", help="Output file. Default \"../peers/peer-keys\"", default="../peers/peer-keys")
    options, _ = parser.parse_args()

    with open(options.o, 'wb') as nodefp:
        for i in xrange(0, options.total_peers):
            rsa = ec_generate_key(u"low")
            nodefp.write("%(id)s %(ip)s %(port)d %(public_key)s %(private_key)s\n" % \
                          {'id': i+1, #'peer-%05d' % i,
                           'ip': '0.0.0.0',
                           'port': options.port_start + i,
                           'public_key': ec_to_public_bin(rsa).encode("HEX"),
                           'private_key': ec_to_private_bin(rsa).encode("HEX")
                           }
                          )
Example #9
0
    def run(self):
        ec = ec_generate_key(u"low")
        self._my_member = Member.get_instance(ec_to_public_bin(ec), ec_to_private_bin(ec))
        self._community = None

        self.caller(self.scenario)
    def __init__(self, rawserver, statedir):
        super(TrackerDispersy, self).__init__(rawserver, statedir)

        # get my_member, the key pair that we will use when we join a new community
        keypair = read_keypair(os.path.join(statedir, u"ec.pem"))
        self._my_member = MyMember(ec_to_public_bin(keypair), ec_to_private_bin(keypair))