def test_get_peer_url(self):
     self.assertEqual(network_util.get_peer_url('8.8.8.8', 1234),
                      'tcp://8.8.8.8:1234')
     self.assertEqual(
         network_util.get_peer_url('8.8.8.8', 1234, protocol='udp'),
         'udp://8.8.8.8:1234')
     self.assertEqual(network_util.get_peer_url('2a00::', 1234),
                      'tcp://[2a00::]:1234')
     self.assertEqual(
         network_util.get_peer_url('2a00::', 1234, protocol='udp'),
         'udp://[2a00::]:1234')
     self.assertEqual(network_util.get_peer_url('www.openbazaar.com', 1234),
                      'tcp://www.openbazaar.com:1234')
Example #2
0
    def __init__(self, ob_ctx, db_connection):

        self.ob_ctx = ob_ctx
        self.loop = ioloop.IOLoop.current()
        self.log = logging.getLogger(
            '[%s] %s' % (ob_ctx.market_id, self.__class__.__name__)
        )
        requests_log = logging.getLogger("requests")
        requests_log.setLevel(logging.WARNING)

        self.db_connection = db_connection

        self.bitmessage_api = None
        if (ob_ctx.bm_user, ob_ctx.bm_pass, ob_ctx.bm_port) != (None, None, -1):
            if not self._connect_to_bitmessage():
                self.log.info('Bitmessage not installed or started')

        self.market_id = ob_ctx.market_id
        self.nick_mapping = {}
        self.uri = network_util.get_peer_url(ob_ctx.server_ip, ob_ctx.server_port)
        self.hostname = ob_ctx.server_ip
        self.nickname = ""
        self.avatar_url = ""
        self.dev_mode = ob_ctx.dev_mode
        self.seed_mode = ob_ctx.seed_mode
        self.mediation_mode = {}
        self.guid = ""
        self.sin = ""

        self._connections = {}
        self._punches = {}

        self.all_messages = (
            'hello',
            'hello_response',
            'goodbye',
            'findNode',
            'findNodeResponse',
            'store',
            'mediate',
            'register',
            'punch',
            MSG_PING_ID,
            MSG_PONG_ID,
            'get_nat_type',
            'nat_type',
            'relay_msg'
        )

        self._setup_settings()
        ob_ctx.market_id = self.market_id
        self.dht = DHT(self, self.market_id, self.settings, self.db_connection)
        TransportLayer.__init__(self, ob_ctx, self.guid, self.nickname, self.avatar_url)
        self.start_listener()

        self.ip_checker_caller = None
        if ob_ctx.enable_ip_checker and not ob_ctx.seed_mode and not ob_ctx.dev_mode:
            self.start_ip_address_checker()
Example #3
0
 def test_get_peer_url(self):
     self.assertEqual(
         network_util.get_peer_url('8.8.8.8', 1234),
         'tcp://8.8.8.8:1234'
     )
     self.assertEqual(
         network_util.get_peer_url('8.8.8.8', 1234, protocol='udp'),
         'udp://8.8.8.8:1234'
     )
     self.assertEqual(
         network_util.get_peer_url('2a00::', 1234),
         'tcp://[2a00::]:1234'
     )
     self.assertEqual(
         network_util.get_peer_url('2a00::', 1234, protocol='udp'),
         'udp://[2a00::]:1234'
     )
     self.assertEqual(
         network_util.get_peer_url('www.openbazaar.com', 1234),
         'tcp://www.openbazaar.com:1234'
     )
Example #4
0
    def __init__(self, ob_ctx, db_connection):

        self.ob_ctx = ob_ctx
        self.loop = ioloop.IOLoop.current()
        self.log = logging.getLogger(
            '[%s] %s' % (ob_ctx.market_id, self.__class__.__name__))
        requests_log = logging.getLogger("requests")
        requests_log.setLevel(logging.WARNING)

        self.db_connection = db_connection

        self.bitmessage_api = None
        if (ob_ctx.bm_user, ob_ctx.bm_pass, ob_ctx.bm_port) != (None, None,
                                                                -1):
            if not self._connect_to_bitmessage():
                self.log.info('Bitmessage not installed or started')

        self.market_id = ob_ctx.market_id
        self.nick_mapping = {}
        self.uri = network_util.get_peer_url(ob_ctx.server_ip,
                                             ob_ctx.server_port)
        self.hostname = ob_ctx.server_ip
        self.nickname = ""
        self.avatar_url = ""
        self.dev_mode = ob_ctx.dev_mode
        self.seed_mode = ob_ctx.seed_mode
        self.mediation_mode = {}
        self.guid = ""
        self.sin = ""

        self._connections = {}
        self._punches = {}

        self.all_messages = ('hello', 'hello_response', 'goodbye', 'findNode',
                             'findNodeResponse', 'store', 'mediate',
                             'register', 'punch', MSG_PING_ID, MSG_PONG_ID,
                             'get_nat_type', 'nat_type', 'relay_msg')

        self._setup_settings()
        ob_ctx.market_id = self.market_id
        self.dht = DHT(self, self.market_id, self.settings, self.db_connection)
        TransportLayer.__init__(self, ob_ctx, self.guid, self.nickname,
                                self.avatar_url)
        self.start_listener()

        self.ip_checker_caller = None
        if ob_ctx.enable_ip_checker and not ob_ctx.seed_mode and not ob_ctx.dev_mode:
            self.start_ip_address_checker()
Example #5
0
    def __init__(self, ob_ctx, guid, nickname=None, avatar_url=None):
        self.peers = {}
        self.callbacks = defaultdict(list)
        self.timeouts = []
        self.port = ob_ctx.server_port
        self.hostname = ob_ctx.server_ip
        self.nat_type = ob_ctx.nat_status['nat_type']
        self.guid = guid
        self.market_id = ob_ctx.market_id
        self.nickname = nickname
        self.avatar_url = avatar_url
        self.handler = None
        self.uri = network_util.get_peer_url(self.hostname, self.port)
        self.listener = None

        self.mediate_peers = []

        self.log = logging.getLogger(
            '[%s] %s' % (ob_ctx.market_id, self.__class__.__name__))
Example #6
0
    def __init__(self, ob_ctx, guid, nickname=None, avatar_url=None):
        self.peers = {}
        self.callbacks = defaultdict(list)
        self.timeouts = []
        self.port = ob_ctx.server_port
        self.hostname = ob_ctx.server_ip
        self.nat_type = ob_ctx.nat_status['nat_type']
        self.guid = guid
        self.market_id = ob_ctx.market_id
        self.nickname = nickname
        self.avatar_url = avatar_url
        self.handler = None
        self.uri = network_util.get_peer_url(self.hostname, self.port)
        self.listener = None

        self.mediate_peers = []

        self.log = logging.getLogger(
            '[%s] %s' % (ob_ctx.market_id, self.__class__.__name__)
        )