use of org.freenetproject.ForwardPort 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);
}
}
use of org.freenetproject.ForwardPort in project i2p.i2p by i2p.
the class UPnP method renderStatusHTML.
/**
* warning - slow
*/
public String renderStatusHTML() {
final StringBuilder sb = new StringBuilder();
sb.append("<h3 id=\"upnp\">").append(_t("UPnP Status")).append("</h3><div id=\"upnpscan\">");
synchronized (_otherUDNs) {
if (!_otherUDNs.isEmpty()) {
sb.append(_t("Disabled UPnP Devices"));
sb.append("<ul>");
for (Map.Entry<String, String> e : _otherUDNs.entrySet()) {
String udn = e.getKey();
String name = e.getValue();
sb.append("<li>").append(DataHelper.escapeHTML(name));
sb.append("<br>UDN: ").append(DataHelper.escapeHTML(udn)).append("</li>");
}
sb.append("</ul>");
}
}
if (isDisabled) {
sb.append("<p>");
sb.append(_t("UPnP has been disabled; Do you have more than one UPnP Internet Gateway Device on your LAN ?"));
return sb.toString();
} else if (!isNATPresent()) {
sb.append("<p>");
sb.append(_t("UPnP has not found any UPnP-aware, compatible device on your LAN."));
return sb.toString();
}
Device router;
synchronized (lock) {
router = _router;
}
if (router != null)
listSubDev(null, router, sb);
String addr = getNATAddress();
sb.append("<p>");
if (addr != null)
sb.append(_t("The current external IP address reported by UPnP is {0}", DataHelper.escapeHTML(addr)));
else
sb.append(_t("The current external IP address is not available."));
int downstreamMaxBitRate = getDownstreamMaxBitRate();
int upstreamMaxBitRate = getUpstreamMaxBitRate();
if (downstreamMaxBitRate > 0)
sb.append("<br>").append(_t("UPnP reports the maximum downstream bit rate is {0}bits/sec", DataHelper.formatSize2Decimal(downstreamMaxBitRate)));
if (upstreamMaxBitRate > 0)
sb.append("<br>").append(_t("UPnP reports the maximum upstream bit rate is {0}bits/sec", DataHelper.formatSize2Decimal(upstreamMaxBitRate)));
synchronized (lock) {
for (ForwardPort port : portsToForward) {
sb.append("<br>");
if (portsForwarded.contains(port))
// {0} is TCP or UDP
// {1,number,#####} prevents 12345 from being output as 12,345 in the English locale.
// If you want the digit separator in your locale, translate as {1}.
sb.append(_t("{0} port {1,number,#####} was successfully forwarded by UPnP.", protoToString(port.protocol), port.portNumber));
else
sb.append(_t("{0} port {1,number,#####} was not forwarded by UPnP.", protoToString(port.protocol), port.portNumber));
}
}
sb.append("</p></div>");
return sb.toString();
}
use of org.freenetproject.ForwardPort 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();
}
use of org.freenetproject.ForwardPort in project i2p.i2p by i2p.
the class UPnPManager method update.
/**
* Call when the ports might have changed
* The transports can call this pretty quickly at startup,
* which can have multiple UPnP threads running at once, but
* that should be ok.
*/
public void update(Set<TransportManager.Port> ports) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("UPnP Update with " + ports.size() + " ports");
// start();
if (!_isRunning)
return;
// }
Set<ForwardPort> forwards = new HashSet<ForwardPort>(ports.size());
for (TransportManager.Port entry : ports) {
String style = entry.style;
int port = entry.port;
int protocol = -1;
if ("SSU".equals(style))
protocol = ForwardPort.PROTOCOL_UDP_IPV4;
else if ("NTCP".equals(style))
protocol = ForwardPort.PROTOCOL_TCP_IPV4;
else
continue;
if (_log.shouldLog(Log.DEBUG))
_log.debug("Adding: " + style + " " + port);
ForwardPort fp = new ForwardPort(style, false, protocol, port);
forwards.add(fp);
}
// non-blocking
_upnp.onChangePublicPorts(forwards, _upnpCallback);
}
Aggregations