Simple TCP socket plugin (untested).

This commit is contained in:
akwizgran
2011-10-06 09:17:22 +01:00
parent 80cba1e7f7
commit 45fd4c9060
10 changed files with 261 additions and 25 deletions

View File

@@ -0,0 +1,79 @@
package net.sf.briar.plugins.socket;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.Map;
import java.util.concurrent.Executor;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.TransportId;
public class SimpleSocketPlugin extends SocketPlugin {
public static final int TRANSPORT_ID = 1;
private static final TransportId id = new TransportId(TRANSPORT_ID);
private final long pollingInterval;
SimpleSocketPlugin(Executor executor, long pollingInterval) {
super(executor);
this.pollingInterval = pollingInterval;
}
public TransportId getId() {
return id;
}
public boolean shouldPoll() {
return true;
}
public long getPollingInterval() {
return pollingInterval;
}
@Override
protected SocketAddress getLocalSocketAddress() {
Map<String, String> properties;
synchronized(this) {
properties = localProperties;
}
if(properties == null) return null;
return createSocketAddress(properties);
}
@Override
protected SocketAddress getSocketAddress(ContactId c) {
Map<String, String> properties;
synchronized(this) {
properties = remoteProperties.get(c);
}
if(properties == null) return null;
return createSocketAddress(properties);
}
private SocketAddress createSocketAddress(Map<String, String> properties) {
String host = properties.get("host");
String portString = properties.get("port");
if(host == null || portString == null) return null;
int port;
try {
port = Integer.valueOf(portString);
} catch(NumberFormatException e) {
return null;
}
return InetSocketAddress.createUnresolved(host, port);
}
@Override
protected Socket createClientSocket() {
return new Socket();
}
@Override
protected Socket createServerSocket() {
return new Socket();
}
}