mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Plugin refactoring.
This commit is contained in:
@@ -39,13 +39,13 @@ class SimpleSocketPlugin extends SocketPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SocketAddress getLocalSocketAddress() {
|
protected SocketAddress getLocalSocketAddress() {
|
||||||
assert started && localProperties != null;
|
assert started;
|
||||||
return createSocketAddress(localProperties);
|
return createSocketAddress(localProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SocketAddress getSocketAddress(ContactId c) {
|
protected SocketAddress getSocketAddress(ContactId c) {
|
||||||
assert started && remoteProperties != null;
|
assert started;
|
||||||
Map<String, String> properties = remoteProperties.get(c);
|
Map<String, String> properties = remoteProperties.get(c);
|
||||||
if(properties == null) return null;
|
if(properties == null) return null;
|
||||||
return createSocketAddress(properties);
|
return createSocketAddress(properties);
|
||||||
@@ -67,7 +67,7 @@ class SimpleSocketPlugin extends SocketPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setLocalSocketAddress(SocketAddress s) {
|
protected void setLocalSocketAddress(SocketAddress s) {
|
||||||
assert started && localProperties != null;
|
assert started;
|
||||||
if(!(s instanceof InetSocketAddress))
|
if(!(s instanceof InetSocketAddress))
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
InetSocketAddress i = (InetSocketAddress) s;
|
InetSocketAddress i = (InetSocketAddress) s;
|
||||||
|
|||||||
@@ -66,7 +66,14 @@ implements StreamTransportPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
if(!started) return;
|
if(!started) {
|
||||||
|
try {
|
||||||
|
ss.close();
|
||||||
|
} catch(IOException e) {
|
||||||
|
// FIXME: Logging
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
socket = ss;
|
socket = ss;
|
||||||
setLocalSocketAddress(ss.getLocalSocketAddress());
|
setLocalSocketAddress(ss.getLocalSocketAddress());
|
||||||
startListener();
|
startListener();
|
||||||
@@ -151,13 +158,13 @@ implements StreamTransportPlugin {
|
|||||||
private Runnable createConnector(final ContactId c) {
|
private Runnable createConnector(final ContactId c) {
|
||||||
return new Runnable() {
|
return new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
connect(c);
|
connectAndCallBack(c);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void connect(ContactId c) {
|
private void connectAndCallBack(ContactId c) {
|
||||||
StreamTransportConnection conn = createAndConnectSocket(c);
|
StreamTransportConnection conn = createConnection(c);
|
||||||
if(conn != null) {
|
if(conn != null) {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
if(started) callback.outgoingConnectionCreated(c, conn);
|
if(started) callback.outgoingConnectionCreated(c, conn);
|
||||||
@@ -165,7 +172,7 @@ implements StreamTransportPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private StreamTransportConnection createAndConnectSocket(ContactId c) {
|
public StreamTransportConnection createConnection(ContactId c) {
|
||||||
SocketAddress addr;
|
SocketAddress addr;
|
||||||
Socket s;
|
Socket s;
|
||||||
try {
|
try {
|
||||||
@@ -181,11 +188,4 @@ implements StreamTransportPlugin {
|
|||||||
}
|
}
|
||||||
return new SocketTransportConnection(s);
|
return new SocketTransportConnection(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamTransportConnection createConnection(ContactId c) {
|
|
||||||
synchronized(this) {
|
|
||||||
if(!started) return null;
|
|
||||||
}
|
|
||||||
return createAndConnectSocket(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user