Search in sources :

Example 1 with ForwardPortStatus

use of org.freenetproject.ForwardPortStatus in project i2p.i2p by i2p.

the class UPnP method deviceRemoved.

/**
 *  DeviceChangeListener
 */
public void deviceRemoved(Device dev) {
    String udn = dev.getUDN();
    if (_log.shouldLog(Log.WARN))
        _log.warn("UP&P device removed : " + dev.getFriendlyName() + " UDN: " + udn);
    ForwardPortCallback fpc = null;
    Map<ForwardPort, ForwardPortStatus> removeMap = null;
    synchronized (lock) {
        if (udn != null)
            _otherUDNs.remove(udn);
        else
            _otherUDNs.remove("???");
        if (_router == null)
            return;
        // I2P this wasn't working
        // if(_router.equals(dev)) {
        String type = dev.getDeviceType();
        if ((ROUTER_DEVICE.equals(type) || ROUTER_DEVICE_2.equals(type)) && dev.isRootDevice() && stringEquals(_router.getFriendlyName(), dev.getFriendlyName()) && stringEquals(_router.getUDN(), udn)) {
            if (_log.shouldLog(Log.WARN))
                _log.warn("UP&P IGD device removed : " + dev.getFriendlyName());
            // TODO promote an IGD from _otherUDNs ??
            // For now, just clear the others so they can be promoted later
            // after a rescan.
            _otherUDNs.clear();
            _router = null;
            _service = null;
            _eventVars.clear();
            _serviceLacksAPM = false;
            if (!portsForwarded.isEmpty()) {
                fpc = forwardCallback;
                removeMap = new HashMap<ForwardPort, ForwardPortStatus>(portsForwarded.size());
                for (ForwardPort port : portsForwarded) {
                    ForwardPortStatus fps = new ForwardPortStatus(ForwardPortStatus.DEFINITE_FAILURE, "UPnP device removed", port.portNumber);
                }
            }
            portsForwarded.clear();
        }
    }
    if (fpc != null) {
        fpc.portForwardStatus(removeMap);
    }
}
Also used : ForwardPortCallback(org.freenetproject.ForwardPortCallback) ForwardPort(org.freenetproject.ForwardPort) ForwardPortStatus(org.freenetproject.ForwardPortStatus)

Example 2 with ForwardPortStatus

use of org.freenetproject.ForwardPortStatus in project i2p.i2p by i2p.

the class UPnP method registerPorts.

/**
 *  postControlAction() can take many seconds, especially if it's failing,
 *  and onChangePublicPorts() may be called from threads we don't want to slow down,
 *  so throw this in a thread.
 */
private void registerPorts(Set<ForwardPort> portsToForwardNow) {
    if (_serviceLacksAPM) {
        if (_log.shouldLog(Log.WARN))
            _log.warn("UPnP device does not support port forwarding");
        Map<ForwardPort, ForwardPortStatus> map = new HashMap<ForwardPort, ForwardPortStatus>(portsToForwardNow.size());
        for (ForwardPort port : portsToForwardNow) {
            ForwardPortStatus fps = new ForwardPortStatus(ForwardPortStatus.DEFINITE_FAILURE, "UPnP device does not support port forwarding", port.portNumber);
            map.put(port, fps);
        }
        forwardCallback.portForwardStatus(map);
        return;
    }
    if (_log.shouldLog(Log.INFO))
        _log.info("Starting thread to forward " + portsToForwardNow.size() + " ports");
    Thread t = new I2PThread(new RegisterPortsThread(portsToForwardNow));
    t.setName("UPnP Port Opener " + __id.incrementAndGet());
    t.setDaemon(true);
    t.start();
}
Also used : ForwardPort(org.freenetproject.ForwardPort) HashMap(java.util.HashMap) I2PThread(net.i2p.util.I2PThread) ForwardPortStatus(org.freenetproject.ForwardPortStatus) I2PThread(net.i2p.util.I2PThread)

Aggregations

ForwardPort (org.freenetproject.ForwardPort)2 ForwardPortStatus (org.freenetproject.ForwardPortStatus)2 HashMap (java.util.HashMap)1 I2PThread (net.i2p.util.I2PThread)1 ForwardPortCallback (org.freenetproject.ForwardPortCallback)1