Пример #1
0
    def test_get_nat_status(self, method_mock):
        stun_response = ('Symmetric NAT', '123.45.67.89', '12345')
        method_mock.return_value = stun_response

        keys = ('nat_type', 'external_ip', 'external_port')
        dict_response = {key: value for key, value in zip(keys, stun_response)}

        self.assertEqual(dict_response, network_util.get_nat_status())
        method_mock.assert_called_once_with(source_port=0, stun_host=None, stun_port=19302)
Пример #2
0
    def test_get_nat_status(self, method_mock):
        stun_response = ('Symmetric NAT', '123.45.67.89', '12345')
        method_mock.return_value = stun_response

        keys = ('nat_type', 'external_ip', 'external_port')
        dict_response = {key: value for key, value in zip(keys, stun_response)}

        self.assertEqual(dict_response, network_util.get_nat_status())
        method_mock.assert_called_once_with(source_port=0,
                                            stun_host=None,
                                            stun_port=19302)
Пример #3
0
def start(arguments):
    defaults = OpenBazaarContext.get_defaults()
    network_util.set_stun_servers()

    # Turn off checks that don't make sense in development mode
    if arguments.dev_mode:
        print "DEVELOPMENT MODE! (Disable STUN check and UPnP mappings)"
        arguments.disable_stun_check = True
        arguments.disable_upnp = True

    # Try to get NAT escape UDP port
    if not arguments.dev_mode:
        nat_status = network_util.get_nat_status()
    else:
        nat_status = {
            'nat_type': 'Restric NAT'
        }

    if not arguments.disable_stun_check:
        print "Checking NAT Status..."
        if nat_status.get('nat_type') == 'Blocked':
            print "openbazaar: Could not start. The network you are on currently blocks usage",
            print "of OpenBazaar."
            print "(We currently do not support usage on completely closed networks.)"
            sys.exit(1)
    elif not arguments.dev_mode and network_util.is_private_ip_address(arguments.server_ip):
        print "openbazaar: Could not start. The given/default server IP address",
        print arguments.server_ip, "is not a public ip address."
        print "(Try './openbazaar help' and read about the '--server-ip', '-i' options)"
        sys.exit(1)

    ob_ctxs = create_openbazaar_contexts(arguments, nat_status)

    for ob_ctx in ob_ctxs:
        ensure_database_setup(ob_ctx, defaults)

    if hasattr(sys, 'frozen'):
        start_node(ob_ctxs[0])
    else:
        process = multiprocessing.Process(target=node_starter,
                                          args=(ob_ctxs,))
        process.start()
Пример #4
0
def start(arguments):
    defaults = OpenBazaarContext.get_defaults()
    network_util.set_stun_servers()

    # Turn off checks that don't make sense in development mode
    if arguments.dev_mode:
        print "DEVELOPMENT MODE! (Disable STUN check and UPnP mappings)"
        arguments.disable_stun_check = True
        arguments.disable_upnp = True

    # Try to get NAT escape UDP port
    if not arguments.dev_mode:
        nat_status = network_util.get_nat_status()
    else:
        nat_status = {'nat_type': 'Restric NAT'}

    if not arguments.disable_stun_check:
        print "Checking NAT Status..."
        if nat_status.get('nat_type') == 'Blocked':
            print "openbazaar: Could not start. The network you are on currently blocks usage",
            print "of OpenBazaar."
            print "(We currently do not support usage on completely closed networks.)"
            sys.exit(1)
    elif not arguments.dev_mode and network_util.is_private_ip_address(
            arguments.server_ip):
        print "openbazaar: Could not start. The given/default server IP address",
        print arguments.server_ip, "is not a public ip address."
        print "(Try './openbazaar help' and read about the '--server-ip', '-i' options)"
        sys.exit(1)

    ob_ctxs = create_openbazaar_contexts(arguments, nat_status)

    for ob_ctx in ob_ctxs:
        ensure_database_setup(ob_ctx, defaults)

    if hasattr(sys, 'frozen'):
        start_node(ob_ctxs[0])
    else:
        process = multiprocessing.Process(target=node_starter,
                                          args=(ob_ctxs, ))
        process.start()