From 2b65a991d4747e7de016aee896fd5416366be6ae Mon Sep 17 00:00:00 2001 From: Ng Yat Yan Date: Sun, 13 Oct 2024 18:21:52 +0800 Subject: [PATCH] V1.1.2 Removed closed session from session map for clean up --- pom.xml | 2 +- .../java/com/example/sshd/core/EchoSessionListener.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4a91e89..2eed628 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.example.sshd echo-sshd-server - 1.1.1 + 1.1.2 ECHO SSH SERVER Learning Apache Mina SSHD library diff --git a/src/main/java/com/example/sshd/core/EchoSessionListener.java b/src/main/java/com/example/sshd/core/EchoSessionListener.java index 7fd14ed..fc701af 100644 --- a/src/main/java/com/example/sshd/core/EchoSessionListener.java +++ b/src/main/java/com/example/sshd/core/EchoSessionListener.java @@ -40,7 +40,13 @@ public class EchoSessionListener implements SessionListener { @Override public void sessionClosed(Session session) { - logger.info("sessionCreated: {}", session); + logger.info("sessionClosed: {}", session); + if (session.getIoSession().getRemoteAddress() instanceof InetSocketAddress) { + InetSocketAddress remoteAddress = (InetSocketAddress) session.getIoSession().getRemoteAddress(); + String remoteIpAddress = remoteAddress.getAddress().getHostAddress(); + logger.info("removing session: {} -> {}", remoteIpAddress, remoteSessionMapping.get(remoteIpAddress)); + remoteSessionMapping.remove(remoteIpAddress); + } } }