Example #1
0
    def test(self):
        private_client1 = m.MsgFactory(PYMDHT_VERSION, tc.CLIENT_ID,
                                       'private1')
        private_server1 = m.MsgFactory(PYMDHT_VERSION, tc.SERVER_ID,
                                       'private1')
        private_client2 = m.MsgFactory(PYMDHT_VERSION, tc.CLIENT_ID,
                                       'private2')
        private_server2 = m.MsgFactory(PYMDHT_VERSION, tc.SERVER_ID,
                                       'private2')
        # Sender doesn't use private flag
        ping_public = clients_msg_f.outgoing_ping_query(tc.SERVER_NODE)
        bencoded_public = ping_public.stamp(tc.TID)
        # Sender uses private flag PRIVATE1
        ping_private1 = private_client1.outgoing_ping_query(tc.SERVER_NODE)
        bencoded_private1 = ping_private1.stamp(tc.TID)
        # Sender uses private flag PRIVATE2
        ping_private2 = private_client2.outgoing_ping_query(tc.SERVER_NODE)
        bencoded_private2 = ping_private2.stamp(tc.TID)

        # Receiver in the public DHT accepts messages (ignores private flag)
        m.private_dht_name = None
        servers_msg_f.incoming_msg(Datagram(bencoded_public, tc.CLIENT_ADDR))
        private_server1.incoming_msg(
            Datagram(bencoded_private1, tc.CLIENT_ADDR))
        private_server2.incoming_msg(
            Datagram(bencoded_private2, tc.CLIENT_ADDR))

        # Receiver in the private DHT accepts ONLY messages from the
        # private DHT it belongs to
        assert_raises(m.MsgError, private_server1.incoming_msg,
                      Datagram(bencoded_public, tc.CLIENT_ADDR))
        private_server1.incoming_msg(
            Datagram(bencoded_private1, tc.CLIENT_ADDR))
        assert_raises(m.MsgError, private_server1.incoming_msg,
                      Datagram(bencoded_private2, tc.CLIENT_ADDR))
Example #2
0
    def __init__(self, version_label, my_node, conf_path, routing_m_mod,
                 lookup_m_mod, experimental_m_mod, private_dht_name,
                 bootstrap_mode):
        self.bootstrapper = bootstrap.OverlayBootstrapper(conf_path)
        my_addr = my_node.addr
        self._my_id = my_node.id  # id indicated by user
        if not self._my_id:
            self._my_id = self._my_id = identifier.RandomId()  # random id
        self._my_node = Node(my_addr, self._my_id, version=version_label)
        self.msg_f = message.MsgFactory(version_label, self._my_id,
                                        private_dht_name)
        self._querier = Querier()
        self._routing_m = routing_m_mod.RoutingManager(self._my_node,
                                                       self.msg_f,
                                                       self.bootstrapper)

        self._responder = responder.Responder(self._my_id, self._routing_m,
                                              self.msg_f, bootstrap_mode)
        self._tracker = self._responder._tracker

        self._lookup_m = lookup_m_mod.LookupManager(self._my_id, self.msg_f,
                                                    self.bootstrapper)
        self._experimental_m = experimental_m_mod.ExperimentalManager(
            self._my_node.id, self.msg_f)

        current_ts = time.time()
        self._next_maintenance_ts = current_ts
        self._next_timeout_ts = current_ts
        self._next_main_loop_call_ts = current_ts
        self._cached_lookups = []
Example #3
0
    def setup(self):
        time.mock_mode()

        self.controller = controller.Controller(PYMDHT_VERSION, tc.CLIENT_NODE,
                                                'test_logs/state.dat',
                                                routing_m_mod, lookup_m_mod,
                                                exp_m_mod, None)
        self.my_id = self.controller._my_id
        self.querier2 = querier.Querier()  #self.my_id)
        self.servers_msg_f = message.MsgFactory(PYMDHT_VERSION, tc.SERVER_ID)
    def __init__(self, version_label,
                 my_node, state_filename,
                 routing_m_mod, lookup_m_mod,
                 experimental_m_mod,
                 private_dht_name,
                 bootstrap_mode):

        if size_estimation:
            self._size_estimation_file = open('size_estimation.dat', 'w')


        self.state_filename = state_filename
        saved_id, saved_bootstrap_nodes = state.load(self.state_filename)
        my_addr = my_node.addr
        self._my_id = my_node.id # id indicated by user
        if not self._my_id:
            self._my_id = saved_id # id loaded from file
        if not self._my_id:
            self._my_id = self._my_id = identifier.RandomId() # random id
        self._my_node = Node(my_addr, self._my_id, version=version_label)
        self.msg_f = message.MsgFactory(version_label, self._my_id,
                                        private_dht_name)
        self._querier = Querier()
        self._routing_m = routing_m_mod.RoutingManager(
            self._my_node, saved_bootstrap_nodes, self.msg_f)

        self._responder = responder.Responder(self._my_id, self._routing_m,
                                              self.msg_f, bootstrap_mode)
        self._tracker = self._responder._tracker

        self._lookup_m = lookup_m_mod.LookupManager(self._my_id, self.msg_f)
        self._experimental_m = experimental_m_mod.ExperimentalManager(
            self._my_node.id, self.msg_f)

        current_ts = time.time()
        self._next_save_state_ts = current_ts + SAVE_STATE_DELAY
        self._next_maintenance_ts = current_ts
        self._next_timeout_ts = current_ts
        self._next_main_loop_call_ts = current_ts
        self._pending_lookups = []
        self._cached_lookups = {}
Example #5
0
logging_conf.testing_setup(__name__)
logger = logging.getLogger('dht')

import random
if random.random() > .8:
    RUN_CPU_INTENSIVE_TESTS = True
    print >> sys.stderr, '>>>>>>>>> Running cpu intensive tests in test_querier'
else:
    RUN_CPU_INTENSIVE_TESTS = False

TIMEOUT_DELAY = 3
LOOKUP_OBJ = 1

PYMDHT_VERSION = (11, 2, 3)

clients_msg_f = message.MsgFactory(PYMDHT_VERSION, tc.CLIENT_ID)
servers_msg_f = message.MsgFactory(PYMDHT_VERSION, tc.SERVER_ID)


class TestQuerier:
    def setup(self):
        time.mock_mode()
        self.querier = Querier()  #tc.CLIENT_ID)

    def test_generate_tids(self):
        #TODO: move to message
        if RUN_CPU_INTENSIVE_TESTS:
            num_tids = pow(2, 16) + 2  #CPU intensive
        else:
            num_tids = 1000
        for i in xrange(num_tids):
Example #6
0
    RUN_CPU_INTENSIVE_TESTS = True
    print >> sys.stderr, '>>>>>>>>> Running cpu intensive tests in test_querier'
else:
    RUN_CPU_INTENSIVE_TESTS = False

TIMEOUT_DELAY = 3
LOOKUP_OBJ = 1

PYMDHT_VERSION = (11, 2, 3)
VERSION_LABEL = ''.join([
    'NS',
    chr((PYMDHT_VERSION[0] - 11) * 24 + PYMDHT_VERSION[1]),
    chr(PYMDHT_VERSION[2])
])

clients_msg_f = message.MsgFactory(VERSION_LABEL, tc.CLIENT_ID)
servers_msg_f = message.MsgFactory(VERSION_LABEL, tc.SERVER_ID)


class TestQuerier:
    def setup(self):
        time.mock_mode()
        self.querier = Querier()  #tc.CLIENT_ID)

    def test_generate_tids(self):
        #TODO: move to message
        if RUN_CPU_INTENSIVE_TESTS:
            num_tids = pow(2, 16) + 2  #CPU intensive
        else:
            num_tids = 1000
        for i in xrange(num_tids):
Example #7
0
import node
import logging, logging_conf

import test_const as tc
import bencode
import message as m
from message import Datagram
import message_tools as mt

logging_conf.testing_setup(__name__)
logger = logging.getLogger('dht')

PYMDHT_VERSION = (11, 2, 3)

clients_msg_f = m.MsgFactory(PYMDHT_VERSION, tc.CLIENT_ID, None)
servers_msg_f = m.MsgFactory(PYMDHT_VERSION, tc.SERVER_ID, None)


def _test_matching_tid():
    # TODO
    # It _only_ matches the first byte)
    ok_(m.matching_tid('aaa', 'aaa'))
    ok_(m.matching_tid('axa', 'a1a'))
    ok_(m.matching_tid('aQWEREWTWETWTWETWETEWT', 'a'))
    ok_(not m.matching_tid('a', 'b'))
    ok_(not m.matching_tid('aZZ', 'bZZ'))


class TestMsgExchanges:
    def test_msg_exhanges(self):
Example #8
0
import bencode
import message as m
from message import Datagram
import message_tools as mt

logging_conf.testing_setup(__name__)
logger = logging.getLogger('dht')

PYMDHT_VERSION = (11, 2, 3)
VERSION_LABEL = ''.join([
    'NS',
    chr((PYMDHT_VERSION[0] - 11) * 24 + PYMDHT_VERSION[1]),
    chr(PYMDHT_VERSION[2])
])

clients_msg_f = m.MsgFactory(VERSION_LABEL, tc.CLIENT_ID, None)
servers_msg_f = m.MsgFactory(VERSION_LABEL, tc.SERVER_ID, None)


def _test_matching_tid():
    # TODO
    # It _only_ matches the first byte)
    ok_(m.matching_tid('aaa', 'aaa'))
    ok_(m.matching_tid('axa', 'a1a'))
    ok_(m.matching_tid('aQWEREWTWETWTWETWETEWT', 'a'))
    ok_(not m.matching_tid('a', 'b'))
    ok_(not m.matching_tid('aZZ', 'bZZ'))


class TestMsgExchanges:
    def test_msg_exhanges(self):