diff --git a/router/java/src/net/i2p/router/CommSystemFacade.java b/router/java/src/net/i2p/router/CommSystemFacade.java index 378ac52b11aa7c8f5a9ca352637caa6e0b4156b2..49760ae85ae9ac55bd75df5ae56f703f220b05a2 100644 --- a/router/java/src/net/i2p/router/CommSystemFacade.java +++ b/router/java/src/net/i2p/router/CommSystemFacade.java @@ -102,6 +102,13 @@ public abstract class CommSystemFacade implements Service { * @since 0.9.24 */ 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 */ public String getOurCountry() { return null; } diff --git a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java index a411e0640871e01d0eb922e28223d82dd198e005..37ab3ac3954946c5fe4e42e93690464b01f1c9ba 100644 --- a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java +++ b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java @@ -195,6 +195,16 @@ public class CommSystemFacadeImpl extends CommSystemFacade { _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 public List<String> getMostRecentErrorMessages() { return _manager.getMostRecentErrorMessages(); diff --git a/router/java/src/net/i2p/router/transport/Transport.java b/router/java/src/net/i2p/router/transport/Transport.java index efeb10ec714431f2dacffbc3ed94db9c942a62cd..a6fed0efa86755c65d997c040aff5f5ff3fa0474 100644 --- a/router/java/src/net/i2p/router/transport/Transport.java +++ b/router/java/src/net/i2p/router/transport/Transport.java @@ -196,4 +196,11 @@ public interface Transport { * @since 0.9.24 */ public void mayDisconnect(Hash peer); + + /** + * Tell the transport to disconnect from this peer. + * + * @since 0.9.38 + */ + public void forceDisconnect(Hash peer); } diff --git a/router/java/src/net/i2p/router/transport/TransportManager.java b/router/java/src/net/i2p/router/transport/TransportManager.java index f9ac84796861e9fe7ebd8623c964ec5bd51098b5..a09e8986c60b2e1225f61e8cfb587e7379f59e39 100644 --- a/router/java/src/net/i2p/router/transport/TransportManager.java +++ b/router/java/src/net/i2p/router/transport/TransportManager.java @@ -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, * based on the last time we tried it for each transport? diff --git a/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java b/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java index c20aca596b155c2db73374ff6cafdab72bb8fc7f..cf43fb8a5c8fe20933eaa2682b72c101c20915c2 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java +++ b/router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java @@ -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... * only con or null as of 0.9.37 diff --git a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java index 7f1c55ceecb38c89534e814bb033c2d23140168a..93420c27c6ea8dcde842862bf9c7efe36a0930d5 100644 --- a/router/java/src/net/i2p/router/transport/udp/UDPTransport.java +++ b/router/java/src/net/i2p/router/transport/udp/UDPTransport.java @@ -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() { return _peersByIdent.size() < getMaxConnections(); }