forked from I2P_Developers/i2p.i2p
* SSU, confignet: Add support for specifiying multiple addresses
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import net.i2p.router.Router;
|
||||
import net.i2p.router.transport.FIFOBandwidthRefiller;
|
||||
@ -94,9 +97,6 @@ public class ConfigNetHandler extends FormHandler {
|
||||
public void setUdpHost1(String host) {
|
||||
_udpHost1 = (host != null ? host.trim() : null);
|
||||
}
|
||||
public void setUdpHost2(String host) {
|
||||
_udpHost2 = (host != null ? host.trim() : null);
|
||||
}
|
||||
public void setUdpPort(String port) {
|
||||
_udpPort = (port != null ? port.trim() : null);
|
||||
}
|
||||
@ -160,26 +160,48 @@ public class ConfigNetHandler extends FormHandler {
|
||||
if (_udpAutoIP != null) {
|
||||
String uhost = "";
|
||||
if (_udpAutoIP.equals("fixed")) {
|
||||
if (_udpHost1 != null && _udpHost1.length() > 0)
|
||||
uhost = _udpHost1;
|
||||
else if (_udpHost2 != null && _udpHost2.length() > 0)
|
||||
uhost = _udpHost2;
|
||||
else
|
||||
_udpAutoIP = UDPTransport.DEFAULT_SOURCES;
|
||||
if (_settings == null)
|
||||
_settings = Collections.EMPTY_MAP;
|
||||
Set<String> addrs = new TreeSet();
|
||||
for (Object o : _settings.keySet()) {
|
||||
String k = (String) o;
|
||||
if (k.startsWith("addr_")) {
|
||||
String v = k.substring(5);
|
||||
if (v.length() > 0)
|
||||
addrs.add(v);
|
||||
}
|
||||
changes.put(UDPTransport.PROP_SOURCES, _udpAutoIP);
|
||||
boolean valid = true;
|
||||
if (uhost.length() > 0) {
|
||||
valid = verifyAddress(uhost);
|
||||
if (valid) {
|
||||
changes.put(UDPTransport.PROP_EXTERNAL_HOST, uhost);
|
||||
}
|
||||
if (getJettyString("addrnew") != null) {
|
||||
if (_udpHost1 != null && _udpHost1.length() > 0) {
|
||||
if (verifyAddress(_udpHost1)) {
|
||||
addrs.add(_udpHost1);
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
int tot = addrs.size();
|
||||
int i = 0;
|
||||
if (tot > 0) {
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
for (String addr : addrs) {
|
||||
buf.append(addr);
|
||||
if (++i < tot)
|
||||
buf.append(',');
|
||||
}
|
||||
uhost = buf.toString();
|
||||
changes.put(UDPTransport.PROP_EXTERNAL_HOST, uhost);
|
||||
} else {
|
||||
_udpAutoIP = UDPTransport.DEFAULT_SOURCES;
|
||||
removes.add(UDPTransport.PROP_EXTERNAL_HOST);
|
||||
}
|
||||
if (valid && ((!oldUdp.equals(_udpAutoIP)) || (!oldUHost.equals(uhost)))) {
|
||||
} else {
|
||||
// not fixed
|
||||
if (oldUHost.length() > 0)
|
||||
removes.add(UDPTransport.PROP_EXTERNAL_HOST);
|
||||
}
|
||||
changes.put(UDPTransport.PROP_SOURCES, _udpAutoIP);
|
||||
if ((!oldUdp.equals(_udpAutoIP)) || (!oldUHost.equals(uhost))) {
|
||||
addFormNotice(_("Updating IP address"));
|
||||
restartRequired = true;
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.RouterAddress;
|
||||
@ -18,10 +21,10 @@ import net.i2p.util.Addresses;
|
||||
public class ConfigNetHelper extends HelperBase {
|
||||
|
||||
/** copied from various private components */
|
||||
public final static String PROP_I2NP_NTCP_HOSTNAME = "i2np.ntcp.hostname";
|
||||
public final static String PROP_I2NP_NTCP_PORT = "i2np.ntcp.port";
|
||||
public final static String PROP_I2NP_NTCP_AUTO_PORT = "i2np.ntcp.autoport";
|
||||
public final static String PROP_I2NP_NTCP_AUTO_IP = "i2np.ntcp.autoip";
|
||||
final static String PROP_I2NP_NTCP_HOSTNAME = "i2np.ntcp.hostname";
|
||||
final static String PROP_I2NP_NTCP_PORT = "i2np.ntcp.port";
|
||||
final static String PROP_I2NP_NTCP_AUTO_PORT = "i2np.ntcp.autoport";
|
||||
final static String PROP_I2NP_NTCP_AUTO_IP = "i2np.ntcp.autoip";
|
||||
private final static String CHECKED = " checked=\"checked\" ";
|
||||
|
||||
public String getUdphostname() {
|
||||
@ -175,9 +178,48 @@ public class ConfigNetHelper extends HelperBase {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String[] getAddresses() {
|
||||
ArrayList<String> al = new ArrayList(Addresses.getAddresses());
|
||||
return al.toArray(new String[al.size()]);
|
||||
public Set<String> getAddresses() {
|
||||
// exclude local, include IPv6
|
||||
return Addresses.getAddresses(false, true);
|
||||
}
|
||||
|
||||
/** @since IPv6 */
|
||||
public String getAddressSelector() {
|
||||
Set<String> addrs = getAddresses();
|
||||
Set<String> configs;
|
||||
String cs = getUdphostname();
|
||||
if (cs.length() <= 0) {
|
||||
configs = Collections.EMPTY_SET;
|
||||
} else {
|
||||
configs = new HashSet(4);
|
||||
String[] ca = cs.split("[,; \r\n\t]");
|
||||
for (int i = 0; i < ca.length; i++) {
|
||||
String c = ca[i];
|
||||
if (c.length() > 0) {
|
||||
configs.add(c);
|
||||
addrs.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
buf.append("<div class=\"indent\">");
|
||||
for (String addr : addrs) {
|
||||
buf.append("\n " +
|
||||
"<input type=\"checkbox\" class=\"optbox\" value=\"foo\" name=\"addr_");
|
||||
buf.append(addr);
|
||||
buf.append('"');
|
||||
if (addrs.size() == 1 || configs.contains(addr))
|
||||
buf.append(CHECKED);
|
||||
buf.append("> ");
|
||||
buf.append(addr);
|
||||
buf.append("<br>");
|
||||
}
|
||||
buf.append("\n " +
|
||||
"<input type=\"checkbox\" class=\"optbox\" name=\"addrnew\"");
|
||||
buf.append(CHECKED);
|
||||
buf.append("><input name =\"udpHost1\" type=\"text\" size=\"16\" />" +
|
||||
"</div>");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String getInboundRate() {
|
||||
|
@ -40,25 +40,11 @@
|
||||
<%=intl._("Ignore local interface IP address")%><br>
|
||||
<input type="radio" class="optbox" name="udpAutoIP" value="ssu" <%=nethelper.getUdpAutoIPChecked(0) %> >
|
||||
<%=intl._("Use SSU IP address detection only")%><br>
|
||||
<input type="radio" class="optbox" name="udpAutoIP" value="fixed" <%=nethelper.getUdpAutoIPChecked(1) %> >
|
||||
<%=intl._("Specify hostname or IP")%>:
|
||||
<input name ="udpHost1" type="text" size="16" value="<jsp:getProperty name="nethelper" property="udphostname" />" >
|
||||
<% String[] ips = nethelper.getAddresses();
|
||||
if (ips.length > 0) {
|
||||
out.print(intl._("or") + " <select name=\"udpHost2\"><option value=\"\" selected=\"selected\">"+intl._("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" class="optbox" name="udpAutoIP" value="hidden" <%=nethelper.getUdpAutoIPChecked(2) %> >
|
||||
<%=intl._("Hidden mode - do not publish IP")%> <i><%=intl._("(prevents participating traffic)")%></i><br>
|
||||
<input type="radio" class="optbox" name="udpAutoIP" value="fixed" <%=nethelper.getUdpAutoIPChecked(1) %> >
|
||||
<%=intl._("Specify hostname or IP")%>:<br>
|
||||
<%=nethelper.getAddressSelector() %>
|
||||
</p><p>
|
||||
<%=intl._("Action when IP changes")%>:<br>
|
||||
<input type="checkbox" class="optbox" name="laptop" value="true" <jsp:getProperty name="nethelper" property="laptopChecked" /> >
|
||||
|
@ -1,3 +1,8 @@
|
||||
2013-08-30 zzz
|
||||
* Addresses: Treat Teredo addresses 2001:0::/32 as local
|
||||
* SSU, confignet: Add support for specifiying multiple addresses
|
||||
* SusiDNS: Don't require last subscription to be terminated by newline (ticket #1000)
|
||||
|
||||
2013-08-11 zzz
|
||||
* Jetty 7.6.12.v20130726
|
||||
|
||||
|
@ -18,7 +18,7 @@ public class RouterVersion {
|
||||
/** deprecated */
|
||||
public final static String ID = "Monotone";
|
||||
public final static String VERSION = CoreVersion.VERSION;
|
||||
public final static long BUILD = 20;
|
||||
public final static long BUILD = 21;
|
||||
|
||||
/** for example "-test" */
|
||||
public final static String EXTRA = "";
|
||||
|
@ -329,17 +329,23 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
}
|
||||
}
|
||||
|
||||
InetAddress bindToAddr = null;
|
||||
List<InetAddress> bindToAddrs = new ArrayList(4);
|
||||
if (bindTo != null) {
|
||||
String[] bta = bindTo.split("[,; \r\n\t]");
|
||||
for (int i = 0; i < bta.length; i++) {
|
||||
String bt = bta[i];
|
||||
if (bt.length() <= 0)
|
||||
continue;
|
||||
try {
|
||||
bindToAddr = InetAddress.getByName(bindTo);
|
||||
bindToAddrs.add(InetAddress.getByName(bt));
|
||||
} catch (UnknownHostException uhe) {
|
||||
_log.error("Invalid SSU bind interface specified [" + bindTo + "]", uhe);
|
||||
_log.error("Invalid SSU bind interface specified [" + bt + "]", uhe);
|
||||
//setReachabilityStatus(CommSystemFacade.STATUS_HOSED);
|
||||
//return;
|
||||
// fall thru...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Requested bind port
|
||||
// This may be -1 or may not be honored if busy,
|
||||
@ -355,15 +361,23 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
port = oldBindPort;
|
||||
else
|
||||
port = oldEPort;
|
||||
if (bindToAddr != null && _log.shouldLog(Log.WARN))
|
||||
_log.warn("Binding only to " + bindToAddr);
|
||||
if (!bindToAddrs.isEmpty() && _log.shouldLog(Log.WARN))
|
||||
_log.warn("Binding only to " + bindToAddrs);
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Binding to the port: " + port);
|
||||
if (_endpoints.isEmpty()) {
|
||||
// will always be empty since we are removing them above
|
||||
if (bindToAddrs.isEmpty()) {
|
||||
UDPEndpoint endpoint = new UDPEndpoint(_context, this, port, null);
|
||||
_endpoints.add(endpoint);
|
||||
setMTU(null);
|
||||
} else {
|
||||
for (InetAddress bindToAddr : bindToAddrs) {
|
||||
UDPEndpoint endpoint = new UDPEndpoint(_context, this, port, bindToAddr);
|
||||
_endpoints.add(endpoint);
|
||||
// TODO add additional endpoints for additional addresses/ports
|
||||
setMTU(bindToAddr);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// unused for now
|
||||
for (UDPEndpoint endpoint : _endpoints) {
|
||||
@ -375,7 +389,6 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
}
|
||||
}
|
||||
}
|
||||
setMTU(bindToAddr);
|
||||
|
||||
if (_establisher == null)
|
||||
_establisher = new EstablishmentManager(_context, this);
|
||||
@ -440,7 +453,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
// set up external addresses
|
||||
// REA param is false;
|
||||
// TransportManager.startListening() calls router.rebuildRouterInfo()
|
||||
if (newPort > 0 && bindToAddr == null) {
|
||||
if (newPort > 0 && bindToAddrs.isEmpty()) {
|
||||
for (InetAddress ia : getSavedLocalAddresses()) {
|
||||
rebuildExternalAddress(ia.getHostAddress(), newPort, false);
|
||||
}
|
||||
@ -1725,6 +1738,17 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
String host = null;
|
||||
if (explicitAddressSpecified()) {
|
||||
host = _context.getProperty(PROP_EXTERNAL_HOST);
|
||||
if (host != null) {
|
||||
String[] hosts = host.split("[,; \r\n\t]");
|
||||
RouterAddress rv = null;
|
||||
for (int i = 0; i < hosts.length; i++) {
|
||||
String h = hosts[i];
|
||||
if (h.length() <= 0)
|
||||
continue;
|
||||
rv = rebuildExternalAddress(h, port, allowRebuildRouterInfo);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
} else {
|
||||
RouterAddress cur = getCurrentAddress(false);
|
||||
if (cur != null)
|
||||
|
Reference in New Issue
Block a user