forked from I2P_Developers/i2p.i2p
start of new address configuration
This commit is contained in:
@ -5,6 +5,7 @@ import net.i2p.router.CommSystemFacade;
|
|||||||
import net.i2p.router.LoadTestManager;
|
import net.i2p.router.LoadTestManager;
|
||||||
import net.i2p.router.Router;
|
import net.i2p.router.Router;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
|
import net.i2p.router.transport.Addresses;
|
||||||
import net.i2p.router.transport.TransportManager;
|
import net.i2p.router.transport.TransportManager;
|
||||||
import net.i2p.router.transport.udp.UDPAddress;
|
import net.i2p.router.transport.udp.UDPAddress;
|
||||||
import net.i2p.router.transport.udp.UDPTransport;
|
import net.i2p.router.transport.udp.UDPTransport;
|
||||||
@ -20,6 +21,13 @@ public class ConfigNetHelper extends HelperBase {
|
|||||||
public final static String PROP_I2NP_NTCP_AUTO_IP = "i2np.ntcp.autoip";
|
public final static String PROP_I2NP_NTCP_AUTO_IP = "i2np.ntcp.autoip";
|
||||||
private final static String CHECKED = " checked=\"true\" ";
|
private final static String CHECKED = " checked=\"true\" ";
|
||||||
private final static String DISABLED = " disabled=\"true\" ";
|
private final static String DISABLED = " disabled=\"true\" ";
|
||||||
|
|
||||||
|
public String getUdphostname() {
|
||||||
|
String hostname = _context.getProperty(UDPTransport.PROP_EXTERNAL_HOST);
|
||||||
|
if (hostname == null) return "";
|
||||||
|
return hostname;
|
||||||
|
}
|
||||||
|
|
||||||
public String getNtcphostname() {
|
public String getNtcphostname() {
|
||||||
if (!TransportManager.enableNTCP(_context))
|
if (!TransportManager.enableNTCP(_context))
|
||||||
return "\" disabled=\"true";
|
return "\" disabled=\"true";
|
||||||
@ -116,6 +124,18 @@ public class ConfigNetHelper extends HelperBase {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////// FIXME
|
||||||
|
public String getUdpAutoIPChecked(int mode) {
|
||||||
|
String hostname = _context.getProperty(PROP_I2NP_NTCP_HOSTNAME);
|
||||||
|
boolean specified = hostname != null && hostname.length() > 0;
|
||||||
|
boolean auto = Boolean.valueOf(_context.getProperty(PROP_I2NP_NTCP_AUTO_IP)).booleanValue();
|
||||||
|
if ((mode == 0 && (!specified) && !auto) ||
|
||||||
|
(mode == 1 && specified && !auto) ||
|
||||||
|
(mode == 2 && auto))
|
||||||
|
return CHECKED;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public String getUpnpChecked() {
|
public String getUpnpChecked() {
|
||||||
return getChecked(TransportManager.PROP_ENABLE_UPNP);
|
return getChecked(TransportManager.PROP_ENABLE_UPNP);
|
||||||
}
|
}
|
||||||
@ -133,6 +153,10 @@ public class ConfigNetHelper extends HelperBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String[] getAddresses() {
|
||||||
|
return Addresses.getAddresses();
|
||||||
|
}
|
||||||
|
|
||||||
public String getInboundRate() {
|
public String getInboundRate() {
|
||||||
return "" + _context.bandwidthLimiter().getInboundKBytesPerSecond();
|
return "" + _context.bandwidthLimiter().getInboundKBytesPerSecond();
|
||||||
}
|
}
|
||||||
|
@ -68,17 +68,46 @@
|
|||||||
<hr />
|
<hr />
|
||||||
-->
|
-->
|
||||||
<b>UDP Configuration:</b><br />
|
<b>UDP Configuration:</b><br />
|
||||||
|
Externally reachable hostname or IP address:<br />
|
||||||
|
<input type="radio" name="udpAutoIP" value="0" <%=nethelper.getUdpAutoIPChecked(0) %> />
|
||||||
|
Use SSU detection only<br />
|
||||||
|
<input type="radio" name="udpAutoIP" value="24" <%=nethelper.getUdpAutoIPChecked(24) %> />
|
||||||
|
Use local public address if available, then UPnP detection, then SSU detection<br />
|
||||||
|
<input type="radio" name="udpAutoIP" value="16" <%=nethelper.getUdpAutoIPChecked(16) %> />
|
||||||
|
Use local public address if available, then SSU detection<br />
|
||||||
|
<input type="radio" name="udpAutoIP" value="8" <%=nethelper.getUdpAutoIPChecked(8) %> />
|
||||||
|
Use UPnP detection if available, then SSU detection<br />
|
||||||
|
<input type="radio" name="udpAutoIP" value="1" <%=nethelper.getUdpAutoIPChecked(1) %> />
|
||||||
|
Specify hostname or IP:
|
||||||
|
<input name ="udphost" type="text" size="16" value="<jsp:getProperty name="nethelper" property="udphostname" />" />
|
||||||
|
<% String[] ips = nethelper.getAddresses();
|
||||||
|
if (ips.length > 0) {
|
||||||
|
out.print(" or <select name=\"interface\"><option value=\"\" selected=\"true\">Select Interface</option>\n");
|
||||||
|
for (int i = 0; i < ips.length; i++) {
|
||||||
|
out.print("<option value=\"");
|
||||||
|
out.print(ips[i]);
|
||||||
|
out.print("\">");
|
||||||
|
out.print(ips[i]);
|
||||||
|
out.print("</option>\n");
|
||||||
|
}
|
||||||
|
out.print("</select>\n");
|
||||||
|
}
|
||||||
|
%>
|
||||||
|
<br />
|
||||||
|
<input type="radio" name="udpAutoIP" value="2" <%=nethelper.getUdpAutoIPChecked(2) %> />
|
||||||
|
Hidden mode - do not publish IP<i>(not recommended)</i><br />
|
||||||
Internal UDP port:
|
Internal UDP port:
|
||||||
<input name ="udpPort" type="text" size="6" value="<jsp:getProperty name="nethelper" property="configuredUdpPort" />" /><br />
|
<input name ="udpPort" type="text" size="6" value="<jsp:getProperty name="nethelper" property="configuredUdpPort" />" /><br />
|
||||||
External UDP address: <i><jsp:getProperty name="nethelper" property="udpAddress" /></i><br />
|
<input type="checkbox" name="requireIntroductions" value="true" <jsp:getProperty name="nethelper" property="requireIntroductionsChecked" /> />
|
||||||
Require SSU introductions?
|
Require SSU introductions
|
||||||
<input type="checkbox" name="requireIntroductions" value="true" <jsp:getProperty name="nethelper" property="requireIntroductionsChecked" /> /><br />
|
<i>(Enable if you cannot open your firewall)</i><br />
|
||||||
|
Current External UDP address: <i><jsp:getProperty name="nethelper" property="udpAddress" /></i><br />
|
||||||
<p>If you can, please poke a hole in your NAT or firewall to allow unsolicited UDP packets to reach
|
<p>If you can, please poke a hole in your NAT or firewall to allow unsolicited UDP packets to reach
|
||||||
you on your external UDP address. If you can't, I2P now includes supports UDP hole punching
|
you on your external UDP address. If you can't, I2P now includes supports UDP hole punching
|
||||||
with "SSU introductions" - peers who will relay a request from someone you don't know to your
|
with "SSU introductions" - peers who will relay a request from someone you don't know to your
|
||||||
router for your router so that you can make an outbound connection to them. I2P will use these
|
router for your router so that you can make an outbound connection to them. I2P will use these
|
||||||
introductions automatically if it detects that the port is not forwarded (as shown by
|
introductions automatically if it detects that the port is not forwarded (as shown by
|
||||||
the <i>Status: Firewalled</i> line), or you can manually require them here.
|
the <i>Reachability: Firewalled</i> line), or you can manually require them here.
|
||||||
Users behind symmetric NATs, such as OpenBSD's pf, are not currently supported.</p>
|
Users behind symmetric NATs, such as OpenBSD's pf, are not currently supported.</p>
|
||||||
<input type="submit" name="recheckReachability" value="Check network reachability..." />
|
<input type="submit" name="recheckReachability" value="Check network reachability..." />
|
||||||
<p>
|
<p>
|
||||||
@ -88,18 +117,18 @@
|
|||||||
Disable<br />
|
Disable<br />
|
||||||
<input type="radio" name="ntcpAutoIP" value="2" <%=nethelper.getTcpAutoIPChecked(2) %> />
|
<input type="radio" name="ntcpAutoIP" value="2" <%=nethelper.getTcpAutoIPChecked(2) %> />
|
||||||
Use IP address detected by SSU
|
Use IP address detected by SSU
|
||||||
(currently <jsp:getProperty name="nethelper" property="udpIP" />)<br />
|
<i>(currently <jsp:getProperty name="nethelper" property="udpIP" />)</i><br />
|
||||||
<input type="radio" name="ntcpAutoIP" value="1" <%=nethelper.getTcpAutoIPChecked(1) %> />
|
<input type="radio" name="ntcpAutoIP" value="1" <%=nethelper.getTcpAutoIPChecked(1) %> />
|
||||||
Specify hostname or IP:
|
Specify hostname or IP:
|
||||||
<input name ="ntcphost" type="text" size="16" value="<jsp:getProperty name="nethelper" property="ntcphostname" />" />
|
<input name ="ntcphost" type="text" size="16" value="<jsp:getProperty name="nethelper" property="ntcphostname" />" />
|
||||||
(dyndns and the like are fine)<br />
|
<i>(dyndns and the like are fine)</i><br />
|
||||||
<p>
|
<p>
|
||||||
Externally reachable TCP port:<br />
|
Externally reachable TCP port:<br />
|
||||||
<input type="radio" name="ntcpAutoPort" value="0" <%=nethelper.getTcpAutoPortChecked(0) %> />
|
<input type="radio" name="ntcpAutoPort" value="0" <%=nethelper.getTcpAutoPortChecked(0) %> />
|
||||||
Disable<br />
|
Disable<br />
|
||||||
<input type="radio" name="ntcpAutoPort" value="2" <%=nethelper.getTcpAutoPortChecked(2) %> />
|
<input type="radio" name="ntcpAutoPort" value="2" <%=nethelper.getTcpAutoPortChecked(2) %> />
|
||||||
Use the same port configured for SSU
|
Use the same port configured for SSU
|
||||||
(currently <jsp:getProperty name="nethelper" property="udpPort" />)?<br />
|
<i>(currently <jsp:getProperty name="nethelper" property="udpPort" />)</i><br />
|
||||||
<input type="radio" name="ntcpAutoPort" value="1" <%=nethelper.getTcpAutoPortChecked(1) %> />
|
<input type="radio" name="ntcpAutoPort" value="1" <%=nethelper.getTcpAutoPortChecked(1) %> />
|
||||||
Specify Port:
|
Specify Port:
|
||||||
<input name ="ntcpport" type="text" size="6" value="<jsp:getProperty name="nethelper" property="ntcpport" />" /><br />
|
<input name ="ntcpport" type="text" size="6" value="<jsp:getProperty name="nethelper" property="ntcpport" />" /><br />
|
||||||
|
80
router/java/src/net/i2p/router/transport/Addresses.java
Normal file
80
router/java/src/net/i2p/router/transport/Addresses.java
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
package net.i2p.router.transport;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.Inet4Address;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the local addresses
|
||||||
|
*
|
||||||
|
* @author zzz
|
||||||
|
*/
|
||||||
|
public class Addresses {
|
||||||
|
|
||||||
|
/** return the first non-local address it finds, or null */
|
||||||
|
public static String getAnyAddress() {
|
||||||
|
String[] a = getAddresses();
|
||||||
|
if (a.length > 0)
|
||||||
|
return a[0];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of all addresses, excluding
|
||||||
|
* IPv6, local, broadcast, multicast, etc.
|
||||||
|
*/
|
||||||
|
public static String[] getAddresses() {
|
||||||
|
Set<String> rv = new HashSet(4);
|
||||||
|
try {
|
||||||
|
InetAddress localhost = InetAddress.getLocalHost();
|
||||||
|
InetAddress[] allMyIps = InetAddress.getAllByName(localhost.getCanonicalHostName());
|
||||||
|
if (allMyIps != null) {
|
||||||
|
for (int i = 0; i < allMyIps.length; i++)
|
||||||
|
add(rv, allMyIps[i]);
|
||||||
|
}
|
||||||
|
} catch (UnknownHostException e) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
for(Enumeration<NetworkInterface> ifcs = NetworkInterface.getNetworkInterfaces(); ifcs.hasMoreElements();) {
|
||||||
|
NetworkInterface ifc = ifcs.nextElement();
|
||||||
|
for(Enumeration<InetAddress> addrs = ifc.getInetAddresses(); addrs.hasMoreElements();) {
|
||||||
|
InetAddress addr = addrs.nextElement();
|
||||||
|
add(rv, addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SocketException e) {}
|
||||||
|
|
||||||
|
return rv.toArray(new String[rv.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void add(Set<String> set, InetAddress ia) {
|
||||||
|
if (ia.isAnyLocalAddress() ||
|
||||||
|
ia.isLinkLocalAddress() ||
|
||||||
|
ia.isLoopbackAddress() ||
|
||||||
|
ia.isMulticastAddress() ||
|
||||||
|
ia.isSiteLocalAddress() ||
|
||||||
|
!(ia instanceof Inet4Address)) {
|
||||||
|
///////// testing
|
||||||
|
// System.err.println("Skipping: " + ia.getHostAddress());
|
||||||
|
// return;
|
||||||
|
}
|
||||||
|
String ip = ia.getHostAddress();
|
||||||
|
set.add(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String[] a = getAddresses();
|
||||||
|
for (String s : a)
|
||||||
|
System.err.println("Address: " + s);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user