mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Resolve the address before binding.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package net.sf.briar.plugins.socket;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Map;
|
||||
@@ -36,17 +38,34 @@ public class SimpleSocketPlugin extends SocketPlugin {
|
||||
|
||||
@Override
|
||||
protected SocketAddress getLocalSocketAddress() {
|
||||
assert localProperties != null;
|
||||
return createSocketAddress(localProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SocketAddress getSocketAddress(ContactId c) {
|
||||
assert remoteProperties != null;
|
||||
Map<String, String> properties = remoteProperties.get(c);
|
||||
if(properties == null) return null;
|
||||
return createSocketAddress(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setLocalSocketAddress(SocketAddress s) {
|
||||
assert localProperties != null;
|
||||
if(!(s instanceof InetSocketAddress))
|
||||
throw new IllegalArgumentException();
|
||||
InetSocketAddress i = (InetSocketAddress) s;
|
||||
String host = i.getAddress().getHostAddress();
|
||||
String port = String.valueOf(i.getPort());
|
||||
// FIXME: Special handling for private IP addresses?
|
||||
localProperties.put("host", host);
|
||||
localProperties.put("port", port);
|
||||
callback.setLocalProperties(localProperties);
|
||||
}
|
||||
|
||||
private SocketAddress createSocketAddress(Map<String, String> properties) {
|
||||
assert properties != null;
|
||||
String host = properties.get("host");
|
||||
String portString = properties.get("port");
|
||||
if(host == null || portString == null) return null;
|
||||
@@ -56,16 +75,16 @@ public class SimpleSocketPlugin extends SocketPlugin {
|
||||
} catch(NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
return InetSocketAddress.createUnresolved(host, port);
|
||||
return new InetSocketAddress(host, port);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Socket createClientSocket() {
|
||||
protected Socket createClientSocket() throws IOException {
|
||||
return new Socket();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Socket createServerSocket() {
|
||||
return new Socket();
|
||||
protected ServerSocket createServerSocket() throws IOException {
|
||||
return new ServerSocket();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user