mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Strip interface name from host address if present.
This commit is contained in:
@@ -184,7 +184,7 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
boolean site = addr.isSiteLocalAddress();
|
||||
if(link || site) {
|
||||
if(LOG.isLoggable(INFO))
|
||||
LOG.info("Preferring " + addr.getHostAddress());
|
||||
LOG.info("Preferring " + getHostAddress(addr));
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
@@ -194,7 +194,7 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
for(InetAddress addr : Collections.list(iface.getInetAddresses())) {
|
||||
if(addr.isLoopbackAddress()) continue;
|
||||
if(LOG.isLoggable(INFO))
|
||||
LOG.info("Accepting " + addr.getHostAddress());
|
||||
LOG.info("Accepting " + getHostAddress(addr));
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,11 +35,13 @@ class PortMapperImpl implements PortMapper {
|
||||
if(gateway == null) return null;
|
||||
InetAddress internal = gateway.getLocalAddress();
|
||||
if(internal == null) return null;
|
||||
if(LOG.isLoggable(INFO))
|
||||
LOG.info("Internal address " + getHostAddress(internal));
|
||||
boolean succeeded = false;
|
||||
InetAddress external = null;
|
||||
try {
|
||||
succeeded = gateway.addPortMapping(port, port,
|
||||
internal.getHostAddress(), "TCP", "TCP");
|
||||
getHostAddress(internal), "TCP", "TCP");
|
||||
if(succeeded) {
|
||||
shutdownManager.addShutdownHook(new Runnable() {
|
||||
public void run() {
|
||||
@@ -60,6 +62,13 @@ class PortMapperImpl implements PortMapper {
|
||||
return new MappingResult(internal, external, port, succeeded);
|
||||
}
|
||||
|
||||
private String getHostAddress(InetAddress a) {
|
||||
String addr = a.getHostAddress();
|
||||
int percent = addr.indexOf('%');
|
||||
if(percent == -1) return addr;
|
||||
return addr.substring(0, percent);
|
||||
}
|
||||
|
||||
private void start() {
|
||||
GatewayDiscover d = new GatewayDiscover();
|
||||
try {
|
||||
|
||||
@@ -93,7 +93,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
}
|
||||
socket = ss;
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
String addr = ss.getInetAddress().getHostAddress();
|
||||
String addr = getHostAddress(ss.getInetAddress());
|
||||
int port = ss.getLocalPort();
|
||||
LOG.info("Listening on " + addr + " " + port);
|
||||
}
|
||||
@@ -109,10 +109,16 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
protected String getHostAddress(InetAddress a) {
|
||||
String addr = a.getHostAddress();
|
||||
int percent = addr.indexOf('%');
|
||||
if(percent == -1) return addr;
|
||||
return addr.substring(0, percent);
|
||||
}
|
||||
|
||||
protected void setLocalSocketAddress(InetSocketAddress a) {
|
||||
InetAddress addr = a.getAddress();
|
||||
TransportProperties p = new TransportProperties();
|
||||
p.put("address", addr.getHostAddress());
|
||||
p.put("address", getHostAddress(a.getAddress()));
|
||||
p.put("port", String.valueOf(a.getPort()));
|
||||
callback.mergeLocalProperties(p);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ class WanTcpPlugin extends TcpPlugin {
|
||||
a = mappingResult.getExternal();
|
||||
}
|
||||
TransportProperties p = new TransportProperties();
|
||||
p.put("address", a.getAddress().getHostAddress());
|
||||
p.put("address", getHostAddress(a.getAddress()));
|
||||
p.put("port", String.valueOf(a.getPort()));
|
||||
callback.mergeLocalProperties(p);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user