Better/easier checking if we are a session or not

This commit is contained in:
Robinson 2023-10-18 19:49:33 +02:00
parent 2a8ac38e55
commit d4e3e2e41d
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
3 changed files with 6 additions and 20 deletions

View File

@ -69,23 +69,12 @@ class ServerConfiguration : dorkbox.network.Configuration() {
field = value
}
/**
* If a connection is in a temporal state (in the middle of a reconnect), should the messages be saved in a `pending` queue, which will
* be sent once the connection (with the client/server) is re-established. After a connection has been disconnected for longer than
* `sessionTimeoutSeconds`, then the session will be closed.
*
* The server will send this configuration to the client
*/
var enableSessionManagement = false
set(value) {
require(!contextDefined) { errorMessage }
field = value
}
/**
* How long before a session times out, after the connection holding the session is disconnected?
* If a connection is in a temporal state (in the middle of a reconnect) and sessions are enabled -- then how long should we consider
* a new connection from the same client as part of the same session.
*
* The server will send this configuration to the client
* The session timeout cannot be shorter than 60 seconds, and the server will send this configuration to the client
*/
var sessionTimeoutSeconds = TimeUnit.MINUTES.toSeconds(2)
set(value) {
@ -132,7 +121,6 @@ class ServerConfiguration : dorkbox.network.Configuration() {
config.listenIpAddress = listenIpAddress
config.maxClientCount = maxClientCount
config.maxConnectionsPerIpAddress = maxConnectionsPerIpAddress
config.enableSessionManagement = enableSessionManagement
config.sessionTimeoutSeconds = sessionTimeoutSeconds
config.settingsStore = settingsStore
@ -149,7 +137,6 @@ class ServerConfiguration : dorkbox.network.Configuration() {
if (listenIpAddress != other.listenIpAddress) return false
if (maxClientCount != other.maxClientCount) return false
if (maxConnectionsPerIpAddress != other.maxConnectionsPerIpAddress) return false
if (enableSessionManagement != other.enableSessionManagement) return false
if (sessionTimeoutSeconds != other.sessionTimeoutSeconds) return false
if (settingsStore != other.settingsStore) return false
@ -161,7 +148,6 @@ class ServerConfiguration : dorkbox.network.Configuration() {
result = 31 * result + listenIpAddress.hashCode()
result = 31 * result + maxClientCount
result = 31 * result + maxConnectionsPerIpAddress
result = 31 * result + enableSessionManagement.hashCode()
result = 31 * result + sessionTimeoutSeconds.hashCode()
result = 31 * result + settingsStore.hashCode()
return result

View File

@ -106,7 +106,7 @@ open class Server<CONNECTION : Connection>(config: ServerConfiguration = ServerC
}
init {
if (config.enableSessionManagement) {
if (this is SessionServer) {
// only set this if we need to
sessionManager = SessionManagerFull(config, aeronDriver, config.sessionTimeoutSeconds)
}

View File

@ -392,7 +392,7 @@ internal class ServerHandshake<CONNECTION : Connection>(
sessionIdSub = connectionSessionIdSub,
streamIdPub = connectionStreamIdPub,
streamIdSub = connectionStreamIdSub,
enableSession = config.enableSessionManagement,
enableSession = newConnection is SessionConnection,
sessionTimeout = config.sessionTimeoutSeconds,
kryoRegDetails = serialization.getKryoRegistrationDetails()
)
@ -644,7 +644,7 @@ internal class ServerHandshake<CONNECTION : Connection>(
sessionIdSub = connectionSessionIdSub,
streamIdPub = connectionStreamIdPub,
streamIdSub = connectionStreamIdSub,
enableSession = config.enableSessionManagement,
enableSession = newConnection is SessionConnection,
sessionTimeout = config.sessionTimeoutSeconds,
kryoRegDetails = serialization.getKryoRegistrationDetails()
)