Search in sources :

Example 1 with UPnPMapping

use of com.biglybt.plugin.upnp.UPnPMapping in project BiglyBT by BiglySoftware.

the class NetworkAdminProtocolImpl method test.

@Override
public InetAddress test(NetworkAdminNetworkInterfaceAddress address, boolean upnp_map, NetworkAdminProgressListener listener) throws NetworkAdminException {
    InetAddress bind_ip = address == null ? null : address.getAddress();
    NetworkAdminProtocolTester tester;
    if (type == PT_HTTP) {
        tester = new NetworkAdminHTTPTester(core, listener);
    } else if (type == PT_TCP) {
        tester = new NetworkAdminTCPTester(core, listener);
    } else {
        tester = new NetworkAdminUDPTester(core, listener);
    }
    InetAddress res;
    if (port <= 0) {
        res = tester.testOutbound(bind_ip, 0);
    } else {
        UPnPMapping new_mapping = null;
        if (upnp_map) {
            PluginInterface pi_upnp = core.getPluginManager().getPluginInterfaceByClass(UPnPPlugin.class);
            if (pi_upnp != null) {
                UPnPPlugin upnp = (UPnPPlugin) pi_upnp.getPlugin();
                UPnPMapping mapping = upnp.getMapping(type != PT_UDP, port);
                if (mapping == null) {
                    new_mapping = mapping = upnp.addMapping("NAT Tester", type != PT_UDP, port, true);
                    try {
                        Thread.sleep(500);
                    } catch (Throwable e) {
                    }
                }
            }
        }
        try {
            res = tester.testInbound(bind_ip, port);
        } finally {
            if (new_mapping != null) {
                new_mapping.destroy();
            }
        }
    }
    return (res);
}
Also used : UPnPPlugin(com.biglybt.plugin.upnp.UPnPPlugin) PluginInterface(com.biglybt.pif.PluginInterface) UPnPMapping(com.biglybt.plugin.upnp.UPnPMapping) InetAddress(java.net.InetAddress)

Example 2 with UPnPMapping

use of com.biglybt.plugin.upnp.UPnPMapping in project BiglyBT by BiglySoftware.

the class DeviceInternetGatewayImpl method getRequiredMappings.

protected Set<mapping> getRequiredMappings() {
    Set<mapping> res = new TreeSet<>();
    UPnPMapping[] required_mappings = current_mappings;
    if (required_mappings != null) {
        for (UPnPMapping mapping : required_mappings) {
            if (mapping.isEnabled()) {
                res.add(new mapping(mapping));
            }
        }
    }
    return (res);
}
Also used : TreeSet(java.util.TreeSet) UPnPMapping(com.biglybt.plugin.upnp.UPnPMapping)

Aggregations

UPnPMapping (com.biglybt.plugin.upnp.UPnPMapping)2 PluginInterface (com.biglybt.pif.PluginInterface)1 UPnPPlugin (com.biglybt.plugin.upnp.UPnPPlugin)1 InetAddress (java.net.InetAddress)1 TreeSet (java.util.TreeSet)1