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 nat_status = None if not arguments.disable_stun_check: print "Checking NAT Status..." nat_status = network_util.get_NAT_status() 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: p = multiprocessing.Process(target=node_starter, args=(ob_ctxs,)) p.start()
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 nat_status = None if not arguments.disable_stun_check: print "Checking NAT Status..." nat_status = network_util.get_NAT_status() 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: p = multiprocessing.Process(target=node_starter, args=(ob_ctxs,)) p.start()
def valid_peer_uri(self, uri): try: [self_protocol, self_addr, self_port] = network_util.uri_parts(self.uri) [other_protocol, other_addr, other_port] = network_util.uri_parts(uri) except RuntimeError: return False if not network_util.is_valid_protocol(other_protocol) or not network_util.is_valid_port(other_port): return False if network_util.is_private_ip_address(self_addr): if not network_util.is_private_ip_address(other_addr): self.log.warning(("Trying to connect to external " "network with a private ip address.")) else: if network_util.is_private_ip_address(other_addr): return False return True
def valid_peer_uri(self, uri): try: [_, self_addr, _] = network_util.uri_parts(self.uri) [other_protocol, other_addr, other_port] = \ network_util.uri_parts(uri) except RuntimeError: return False if not network_util.is_valid_protocol(other_protocol) \ or not network_util.is_valid_port(other_port): return False if network_util.is_private_ip_address(self_addr): if not network_util.is_private_ip_address(other_addr): self.log.warning(('Trying to connect to external ' 'network with a private ip address.')) else: if network_util.is_private_ip_address(other_addr): return False return True
def test_is_private_ip_address(self): self.assertTrue(network_util.is_private_ip_address('localhost')) self.assertTrue(network_util.is_private_ip_address('127.0.0.1')) self.assertTrue(network_util.is_private_ip_address('192.168.1.1')) self.assertTrue(network_util.is_private_ip_address('172.16.1.1')) self.assertTrue(network_util.is_private_ip_address('10.1.1.1')) self.assertFalse(network_util.is_private_ip_address('8.8.8.8'))