You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tw...@apache.org on 2022/04/15 17:50:25 UTC
[mina-sshd] 01/03: Simplify uses of the KEX future
This is an automated email from the ASF dual-hosted git repository.
twolf pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git
commit 7750c537cca9d42d4a6d9ee1a047d624f8a87c17
Author: Thomas Wolf <tw...@apache.org>
AuthorDate: Sat Apr 9 15:25:51 2022 +0200
Simplify uses of the KEX future
`DefaultKeyExchangeFuture.setValue()` allows setting the value only
once. Subsequent invocations are no-ops. It is thus not necessary to
synchronize on that future and set the value only if not set yet.
---
.../sshd/client/session/AbstractClientSession.java | 7 +-----
.../common/session/helpers/AbstractSession.java | 28 ++++------------------
2 files changed, 5 insertions(+), 30 deletions(-)
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java b/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
index cf21a9e9c..2858c400a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
@@ -644,12 +644,7 @@ public abstract class AbstractClientSession extends AbstractSession implements C
DefaultKeyExchangeFuture kexFuture = new DefaultKeyExchangeFuture(toString(), null);
DefaultKeyExchangeFuture prev = kexFutureHolder.getAndSet(kexFuture);
if (prev != null) {
- synchronized (prev) {
- Object value = prev.getValue();
- if (value == null) {
- prev.setValue(new SshException("Switch to none cipher while previous KEX is ongoing"));
- }
- }
+ prev.setValue(new SshException("Switch to none cipher while previous KEX is ongoing"));
}
String c2sEncServer;
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
index 1632c1ff6..e4032b9aa 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractSession.java
@@ -469,12 +469,7 @@ public abstract class AbstractSession extends SessionHelper {
DefaultKeyExchangeFuture kexFuture = kexFutureHolder.get();
// if have any ongoing KEX notify it about the failure
if (kexFuture != null) {
- synchronized (kexFuture) {
- Object value = kexFuture.getValue();
- if (value == null) {
- kexFuture.setValue(e);
- }
- }
+ kexFuture.setValue(e);
}
if (e instanceof Exception) {
@@ -799,12 +794,7 @@ public abstract class AbstractSession extends SessionHelper {
DefaultKeyExchangeFuture kexFuture = kexFutureHolder.get();
if (kexFuture != null) {
- synchronized (kexFuture) {
- Object value = kexFuture.getValue();
- if (value == null) {
- kexFuture.setValue(Boolean.TRUE);
- }
- }
+ kexFuture.setValue(Boolean.TRUE);
}
signalSessionEvent(SessionListener.Event.KeyEstablished);
@@ -887,12 +877,7 @@ public abstract class AbstractSession extends SessionHelper {
DefaultKeyExchangeFuture kexFuture = kexFutureHolder.get();
if (kexFuture != null) {
// if have any pending KEX then notify it about the closing session
- synchronized (kexFuture) {
- Object value = kexFuture.getValue();
- if (value == null) {
- kexFuture.setValue(new SshException("Session closing while KEX in progress"));
- }
- }
+ kexFuture.setValue(new SshException("Session closing while KEX in progress"));
}
// if anyone waiting for global response notify them about the closing session
@@ -2288,12 +2273,7 @@ public abstract class AbstractSession extends SessionHelper {
DefaultKeyExchangeFuture newFuture = new DefaultKeyExchangeFuture(toString(), null);
DefaultKeyExchangeFuture kexFuture = kexFutureHolder.getAndSet(newFuture);
if (kexFuture != null) {
- synchronized (kexFuture) {
- Object value = kexFuture.getValue();
- if (value == null) {
- kexFuture.setValue(new SshException("New KEX started while previous one still ongoing"));
- }
- }
+ kexFuture.setValue(new SshException("New KEX started while previous one still ongoing"));
}
return newFuture;