summaryrefslogtreecommitdiffstats
path: root/src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java
diff options
context:
space:
mode:
authorUdo Walter2020-05-14 00:26:58 +0200
committerUdo Walter2020-05-14 00:26:58 +0200
commit22afa1455e509b09d60745e758bd7b2aecafe646 (patch)
tree01c696826f86a80f0a801322230cb01e8469f610 /src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java
parentAdd some debug logs. Rename the 'virtual' locations to groups. (diff)
downloadbwlp-guacamole-ext-22afa1455e509b09d60745e758bd7b2aecafe646.tar.gz
bwlp-guacamole-ext-22afa1455e509b09d60745e758bd7b2aecafe646.tar.xz
bwlp-guacamole-ext-22afa1455e509b09d60745e758bd7b2aecafe646.zip
Fix two ways a client could be listed as free but be not connectable.
1. User gets assigned a client but never connects to the vnc. Client is "in use" but ist actually idleing in the login screen. The client gets updated and the state set to IDLE but the inUseBy is not reset because the vnc password stays the same for some time. Clients in IDLE state with no user connected to the vnc tunnel now get reset to not in use. 2. If a client is missing from the JSON list and had IDLE as the last status it was still listed as IDLE until the timeout (5 minutes) where it is removed entirely. Missing clients waiting to timeout are now set to OFFLINE state.
Diffstat (limited to 'src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java')
-rw-r--r--src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java b/src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java
index 0a9e8ec..5d551d9 100644
--- a/src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java
+++ b/src/main/java/de/bwlehrpool/bwlp_guac/AvailableClient.java
@@ -28,6 +28,8 @@ public class AvailableClient implements Cloneable {
private String inUseBy;
+ private WrappedConnection connection;
+
private long deadline;
private long lastConnectionCheck;
@@ -52,6 +54,13 @@ public class AvailableClient implements Cloneable {
* can't possibly be in use by the old user anymore.
*/
public synchronized void update(JsonClient source) {
+ if (this.inUseBy != null && source.state != State.OCCUPIED && !TunnelListener.hasTunnel(this.inUseBy)) {
+ LOGGER.info("Free client blocked by a disconnected user detected.");
+ LOGGER.info("Client " + this + " is available again");
+ this.inUseBy = null;
+ if (this.connection != null) this.connection.invalidate();
+ }
+
if (this.password == null || !this.password.equals(source.password)) {
if (source.state != State.OCCUPIED) {
if (this.inUseBy != null) {
@@ -62,7 +71,10 @@ public class AvailableClient implements Cloneable {
this.lastConnectionCheck = 0;
this.password = source.password;
}
- this.state = source.state;
+
+ if (this.inUseBy == null || source.state != State.IDLE)
+ this.state = source.state;
+
this.deadline = 0;
}
@@ -82,13 +94,17 @@ public class AvailableClient implements Cloneable {
}
public synchronized WrappedConnection getConnection(String expectedOwner) {
- if (isInUseBy(expectedOwner))
- return new WrappedConnection(this.clientip + "/" + CON_ID.incrementAndGet(), this);
+ if (isInUseBy(expectedOwner)) {
+ if (this.connection == null || !this.connection.isValid())
+ this.connection = new WrappedConnection(this.clientip + "/" + CON_ID.incrementAndGet(), this);
+ return this.connection;
+ }
return null;
}
public synchronized void releaseConnection(String expectedOwner) {
if (isInUseBy(expectedOwner)) {
+ if (this.connection != null) this.connection.invalidate();
LOGGER.info("Prematurely releasing client " + this);
this.inUseBy = null;
} else {
@@ -121,6 +137,10 @@ public class AvailableClient implements Cloneable {
return locationid;
}
+ public void markAsMissing() {
+ this.state = State.OFFLINE;
+ }
+
public GuacamoleConfiguration toGuacConfig() {
GuacamoleConfiguration cfg = new GuacamoleConfiguration();
cfg.setProtocol("vnc");