mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Merge branch '1745-try-to-bind-on-connectivity-change' into 'master'
Try to bind IPv4 and IPv6 sockets whenever connectivity changes Closes #1745 See merge request briar/briar!1275
This commit is contained in:
@@ -277,11 +277,11 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
|||||||
// make outgoing connections on API 21+ if another network
|
// make outgoing connections on API 21+ if another network
|
||||||
// has internet access
|
// has internet access
|
||||||
socketFactory = SocketFactory.getDefault();
|
socketFactory = SocketFactory.getDefault();
|
||||||
if (s == INACTIVE) bind();
|
bind();
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Connected to wifi");
|
LOG.info("Connected to wifi");
|
||||||
socketFactory = getSocketFactory();
|
socketFactory = getSocketFactory();
|
||||||
if (s == INACTIVE) bind();
|
bind();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,15 +149,21 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
|||||||
|
|
||||||
protected void bind() {
|
protected void bind() {
|
||||||
bindExecutor.execute(() -> {
|
bindExecutor.execute(() -> {
|
||||||
if (getState() != INACTIVE) return;
|
State s = getState();
|
||||||
|
if (s != ACTIVE && s != INACTIVE) return;
|
||||||
bind(true);
|
bind(true);
|
||||||
bind(false);
|
bind(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bind(boolean ipv4) {
|
private void bind(boolean ipv4) {
|
||||||
|
ServerSocket old = state.getServerSocket(ipv4);
|
||||||
ServerSocket ss = null;
|
ServerSocket ss = null;
|
||||||
for (InetSocketAddress addr : getLocalSocketAddresses(ipv4)) {
|
for (InetSocketAddress addr : getLocalSocketAddresses(ipv4)) {
|
||||||
|
if (old != null && addr.equals(old.getLocalSocketAddress())) {
|
||||||
|
LOG.info("Server socket already bound");
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
ss = new ServerSocket();
|
ss = new ServerSocket();
|
||||||
ss.bind(addr);
|
ss.bind(addr);
|
||||||
|
|||||||
Reference in New Issue
Block a user