Class SessionGeoLogger

java.lang.Object
com.iizix.server.geo.ip2location.SessionGeoLogger

public final class SessionGeoLogger extends Object
Logs the geolocation of a client session at its connection events - connect, reconnect and disconnect - through ILog, when the server setting ServerSettings.GEO_SESSION_LOG is on (it is off by default).

Where it is called from (the exact points, all in com.iizix.server):

  • connect: the end of the ClientSessionGyro constructor, which runs inside ClientTransactionProcessor.createRoot on the first TRANS_UPDATE of a new connection - after SessionTransMgr.onCommConnected has stored the remote address and after the user has been authenticated, so the user is known;
  • reconnect: ClientTransactionProcessor.onReconnected, which SessionTransMgr.processManagementTransactions calls on the client's MT_RECONNECTION acknowledgement, after SessionID.replaceReconnected has given the session the new connection's SessionInfo;
  • disconnect: the start of ClientSessionGyro.dispose(), reached from ClientTransactionProcessor.onDisposed when the session is disposed of (SessionTransMgr.doDispose) - a paused or broken connection is not a disconnect, the session lives on for reconnection.

Which address. ClientAddressResolver.resolve(InetAddress, ClientAddressResolver.ForwardedHeaders, ClientAddressResolver.TrustedProxies) over the remote address Jetty saw (SessionInfo.getRemoteAddress()) and the forwarded headers captured at the upgrade (ClientTransactionProcessor.getForwardedHeaders()), believed only from the trusted proxies of ServerSettings.GEO_TRUSTED_PROXIES. A private or local address is logged but never looked up (ClientAddressResolver.isPrivateOrLocal(InetAddress)).

Which provider. The default RegionLocationService - IP2Location when the local service is enabled, else the first registered web provider, else none - asked asynchronously: the connect event runs on the Jetty I/O thread, which must never block, so the line is written from the provider's reply thread unless the answer is already cached, in which case it is written at once. The device's own location ($geo), when the client has reported one, is appended with provenance DEVICE and the accuracy the device gave.

One log line per event, INFO, under this class:

Session geolocation connect: session=12 app=demo user=jane device=... ip=203.0.113.9 (source=REMOTE) provider=IP2Location provenance=IP accuracy=unknown country=SE region=Stockholms lan city=Stockholm

Author:
Christopher Mindus
  • Method Details

    • onConnected

      public static void onConnected(ClientSessionGyro clientGyro)
      Called when a client session has been created (connected and authenticated).
      Parameters:
      clientGyro - The client session gyro.
    • onReconnected

      public static void onReconnected(ClientSessionGyro clientGyro)
      Called when a client session has been reconnected on a new connection.
      Parameters:
      clientGyro - The client session gyro.
    • onDisconnected

      public static void onDisconnected(ClientSessionGyro clientGyro)
      Called when a client session is disposed of.
      Parameters:
      clientGyro - The client session gyro.
    • isEnabled

      public static boolean isEnabled()
      Returns if session geolocation logging is on.
      Returns:
      The state of the ServerSettings.GEO_SESSION_LOG setting, false without a server (ServerShellHolder.getInstance() is null until the server is built, where ServerShell.getInstance() would throw).