private void discover_upnp() { upnp = new xbs_upnp(); upnp.upnp_startDiscovery(); int count = 0; while (!upnp.isUPnPavailable() && count < (80)) { Thread.Sleep(250); count++; } if (upnp.isUPnPavailable()) { external_ip = upnp.upnp_getPublicIP(); } }
private void start_engine() { if (option_upnp) { discover_upnp(); } LibPcapLiveDevice pdev = loadCaptureDevice(option_capture_device); if (pdev == null) { xbs_messages.addInfoMessage("!! ERROR - could not load capture device with name \"" + option_capture_device + "\"", xbs_message_sender.GENERAL, xbs_message_type.FATAL_ERROR); close_app(-2); } NAT = new xbs_nat(); node_list = new xbs_node_list(); node_list.notify_on_new_node = false; if (option_local_port == 0) { option_local_port = xbs_udp_listener.standard_port; } GatewayIPAddressInformationCollection local_gateways = xbs_console_app.getGatewaysForBindIP(option_local_ip); try { udp_listener = new xbs_udp_listener(option_local_ip, option_local_port, node_list); } catch (Exception e) { xbs_messages.addInfoMessage("!! ERROR opening UDP port " + option_local_port, xbs_message_sender.GENERAL, xbs_message_type.FATAL_ERROR); xbs_messages.addInfoMessage(e.Message, xbs_message_sender.GENERAL); close_app(-7); } try { if (option_upnp && upnp.isUPnPavailable()) { external_ip = upnp.upnp_getPublicIP(); upnp.upnp_create_mapping(Mono.Nat.Protocol.Udp, udp_listener.udp_socket_port, udp_listener.udp_socket_port); } } catch (Exception) { xbs_messages.addInfoMessage("!! UPnP port mapping failed", xbs_message_sender.GENERAL, xbs_message_type.ERROR); } if (external_ip == null) { external_ip = xbs_upnp.getExternalIPAddressFromWebsite(); } IPAddress local_node_ip = (external_ip == null) ? option_local_ip : external_ip; node_list.local_node = new xbs_node(local_node_ip, udp_listener.udp_socket_port); if (option_nickname != null) { node_list.local_node.nickname = option_nickname; } sniffer = new xbs_sniffer(pdev, false, null, false, node_list, NAT, local_gateways, true); sniffer.start_capture(); if (ExceptionMessage.ABORTING) { close_app(-10); } if (option_cloudserver == null) { option_cloudserver = xbs_cloudlist.DEFAULT_CLOUDLIST_SERVER; } if (option_cloudname != null) { if (option_password == null) { option_password = ""; } if (option_cloudname.Length >= xbs_cloudlist.MIN_CLOUDNAME_LENGTH) { try { cloudlist.JoinOrCreateCloud(option_cloudserver, option_cloudname, option_maxnodes.ToString(), option_password, node_list.local_node.ip_public, node_list.local_node.port_public, node_list.local_node.nickname, xbs_upnp.isPortReachable, xbs_settings.xbslink_version); } catch (Exception e) { xbs_messages.addInfoMessage("!! ERROR connecting to cloud " + option_cloudname, xbs_message_sender.GENERAL, xbs_message_type.ERROR); xbs_messages.addInfoMessage(e.Message, xbs_message_sender.GENERAL, xbs_message_type.ERROR); } } else { xbs_messages.addInfoMessage("!! ERROR - cloudname is too short. " + xbs_cloudlist.MIN_CLOUDNAME_LENGTH + " chars minimum", xbs_message_sender.GENERAL, xbs_message_type.ERROR); close_app(-12); } } main_engine_loop(); }
private void discover_upnp() { upnp = new xbs_upnp(); upnp.upnp_startDiscovery(); int count = 0; while (!upnp.isUPnPavailable() && count < (80)) { Thread.Sleep(250); count++; } if (upnp.isUPnPavailable()) external_ip = upnp.upnp_getPublicIP(); }