Transport: Add methods to force-disconnect a peer

This commit is contained in:
zzz
2018-12-02 19:14:36 +00:00
parent ee722b7688
commit 6e053689b9
6 changed files with 59 additions and 0 deletions

View File

@ -103,6 +103,13 @@ public abstract class CommSystemFacade implements Service {
*/ */
public void mayDisconnect(Hash peer) {} public void mayDisconnect(Hash peer) {}
/**
* Tell the comm system to disconnect from this peer.
*
* @since 0.9.38
*/
public void forceDisconnect(Hash peer) {}
/** @since 0.8.11 */ /** @since 0.8.11 */
public String getOurCountry() { return null; } public String getOurCountry() { return null; }

View File

@ -195,6 +195,16 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
_manager.mayDisconnect(peer); _manager.mayDisconnect(peer);
} }
/**
* Tell the comm system to disconnect from this peer.
*
* @since 0.9.38
*/
@Override
public void forceDisconnect(Hash peer) {
_manager.forceDisconnect(peer);
}
@Override @Override
public List<String> getMostRecentErrorMessages() { public List<String> getMostRecentErrorMessages() {
return _manager.getMostRecentErrorMessages(); return _manager.getMostRecentErrorMessages();

View File

@ -196,4 +196,11 @@ public interface Transport {
* @since 0.9.24 * @since 0.9.24
*/ */
public void mayDisconnect(Hash peer); public void mayDisconnect(Hash peer);
/**
* Tell the transport to disconnect from this peer.
*
* @since 0.9.38
*/
public void forceDisconnect(Hash peer);
} }

View File

@ -555,6 +555,17 @@ public class TransportManager implements TransportEventListener {
} }
} }
/**
* Tell the transports to disconnect from this peer.
*
* @since 0.9.38
*/
void forceDisconnect(Hash peer) {
for (Transport t : _transports.values()) {
t.forceDisconnect(peer);
}
}
/** /**
* Was the peer UNreachable (outbound only) on any transport, * Was the peer UNreachable (outbound only) on any transport,
* based on the last time we tried it for each transport? * based on the last time we tried it for each transport?

View File

@ -640,6 +640,18 @@ public class NTCPTransport extends TransportImpl {
} }
} }
/**
* Tell the transport to disconnect from this peer.
*
* @since 0.9.38
*/
public void forceDisconnect(Hash peer) {
NTCPConnection con = _conByIdent.remove(peer);
if (con != null) {
con.close();
}
}
/** /**
* @return usually the con passed in, but possibly a second connection with the same peer... * @return usually the con passed in, but possibly a second connection with the same peer...
* only con or null as of 0.9.37 * only con or null as of 0.9.37

View File

@ -2679,6 +2679,18 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
} }
} }
/**
* Tell the transport to disconnect from this peer.
*
* @since 0.9.38
*/
public void forceDisconnect(Hash peer) {
PeerState ps = _peersByIdent.get(peer);
if (ps != null) {
dropPeer(ps, true, "router");
}
}
public boolean allowConnection() { public boolean allowConnection() {
return _peersByIdent.size() < getMaxConnections(); return _peersByIdent.size() < getMaxConnections();
} }