Package anbxj

Class AnB_Session


public class AnB_Session extends AnB_Crypto_Wrapper
AnB Session: implements a protocol session supporting cryptographic operations.
  • Constructor Details

    • AnB_Session

      public AnB_Session(Crypto_EncryptionEngine ee, String myAlias, Channel_Settings cs, Crypto_Config config, boolean exchange_id)
      Creates a new session that reuses an existing cryptographic engine. The channel is initialised based on the provided channel settings. If the configuration indicates use of a keystore, the channel is set up using keystore-based credentials; otherwise alias-based setup is used.
      Parameters:
      ee - the shared cryptographic engine (must not be null)
      myAlias - the alias of the local principal (must not be null)
      cs - the channel settings defining the communication parameters
      config - the cryptographic configuration (used to determine keystore usage)
      exchange_id - if true, the session will exchange identities after opening the channel
    • AnB_Session

      public AnB_Session(Crypto_EncryptionEngine ee, String myAlias, Channel_Settings cs, Crypto_Config config, String id_Remote_alias)
      Creates a new session that reuses an existing cryptographic engine and automatically sets the remote identity. Identity exchange is not performed.
      Parameters:
      ee - the shared cryptographic engine (must not be null)
      myAlias - the alias of the local principal (must not be null)
      cs - the channel settings defining the communication parameters
      config - the cryptographic configuration (used to determine keystore usage)
      id_Remote_alias - the alias of the remote principal (must not be null)
    • AnB_Session

      public AnB_Session(Crypto_EncryptionEngine ee, String myAlias, Channel_Abstraction channel)
      Creates a new session that reuses an existing cryptographic engine and uses an already connected socket channel (e.g., from a multi-threaded server). The channel is already established; this constructor simply wraps it.
      Parameters:
      ee - the shared cryptographic engine (must not be null)
      myAlias - the alias of the local principal (must not be null)
      channel - the already connected channel abstraction (must not be null)
    • AnB_Session

      public AnB_Session(AnB_Crypto_Wrapper wrapper, Channel_Abstraction channel)
      Creates a new session using an existing AnB_Crypto_Wrapper. The wrapper already holds a cryptographic engine and the local alias. The provided channel is used directly without re-initialisation.
      Parameters:
      wrapper - the existing crypto wrapper (must not be null)
      channel - the already connected channel abstraction (must not be null)
    • AnB_Session

      public AnB_Session(String myAlias, Channel_Settings cs, boolean exchange_id, Crypto_Config config)
      Constructs a new AnB_Session with the specified parameters.
      Parameters:
      myAlias - Alias of the principal.
      cs - The Channel_Settings for initialising channels.
      exchange_id - A boolean indicating whether to exchange ID.
      config - The Crypto_Config to be used.
    • AnB_Session

      public AnB_Session(Crypto_KeyStoreSettings_Map kssd, Channel_Settings cs, boolean exchange_id, Crypto_Config config)
      Constructs a new AnB_Session with the specified parameters.
      Parameters:
      kssd - The Crypto_KeyStoreSettings_Map to be used.
      cs - The Channel_Settings for initialising channels.
      exchange_id - A boolean indicating whether to exchange ID.
      config - The Crypto_Config to be used.
    • AnB_Session

      public AnB_Session(Crypto_KeyStoreSettings_Map kssd, Channel_Settings cs, AnBx_Agent id_Remote, Crypto_Config config)
      Constructs a new AnB_Session with the specified parameters.
      Parameters:
      kssd - The Crypto_KeyStoreSettings_Map to be used.
      cs - The Channel_Settings for initialising channels.
      id_Remote - The AnBx_Agent representing the remote ID.
      config - The Crypto_Config to be used.
    • AnB_Session

      public AnB_Session(Crypto_KeyStoreSettings_Map kssd, Channel_Settings cs, String id_Remote_alias, Crypto_Config config)
      Constructs a new AnB_Session with the specified parameters.
      Parameters:
      kssd - The Crypto_KeyStoreSettings_Map to be used.
      cs - The Channel_Settings for initialising channels.
      id_Remote_alias - The alias for the remote ID.
      config - The Crypto_Config to be used.
    • AnB_Session

      public AnB_Session(String myAlias, Channel_Settings cs, String id_Remote_alias, Crypto_Config config)
      Constructs a new AnB_Session with the specified parameters.
      Parameters:
      myAlias - Alias of the principal.
      cs - The Channel_Settings for initialising channels.
      id_Remote_alias - The alias for the remote ID.
      config - The Crypto_Config to be used.
    • AnB_Session

      public AnB_Session(Crypto_KeyStoreSettings_Map kssd, Channel_Abstraction channel, Crypto_Config config)
      Constructs a new AnB_Session with the specified parameters.
      Parameters:
      kssd - The Crypto_KeyStoreSettings_Map to be used.
      channel - The already connected channel abstraction (must not be null)
      config - The Crypto_Config to be used.
    • AnB_Session

      public AnB_Session(Crypto_EncryptionEngine ee, String myAlias, Channel_Settings cs, Crypto_Config config, String id_Remote_alias, Channel_MessageSerializer serializer)
      Creates a new client-side session that uses Protocol Buffers serialisation and does not exchange identities.
      Parameters:
      ee - the shared cryptographic engine
      myAlias - the alias of the local principal
      cs - the channel settings
      config - the cryptographic configuration
      id_Remote_alias - the alias of the remote principal (used to set the remote identity)
      serializer - the protocol-specific message serializer
    • AnB_Session

      public AnB_Session(Crypto_EncryptionEngine ee, String myAlias, Channel_Settings cs, Crypto_Config config, boolean exchange_id, Channel_MessageSerializer serializer)
      Creates a new client-side session that uses Protocol Buffers serialisation and optionally exchanges identities after opening the channel.
      Parameters:
      ee - the shared cryptographic engine
      myAlias - the alias of the local principal
      cs - the channel settings
      config - the cryptographic configuration
      exchange_id - if true, identities are exchanged after opening
      serializer - the protocol-specific message serializer
  • Method Details

    • setDefaultSerializer

      public static void setDefaultSerializer(Channel_MessageSerializer serializer)
      Sets the global default message serializer that will be used by all subsequently created AnB_Session objects.
      Parameters:
      serializer - the message serializer to use, or null to revert to standard Java serialisation
      See Also:
    • getDefaultSerializer

      public static Channel_MessageSerializer getDefaultSerializer()
      Returns the global default message serializer that is currently configured.
      Returns:
      the current default serializer, or null if none
      See Also:
    • setStepDescriptors

      public static void setStepDescriptors(Map<Integer,Channel_ProtobufSerializer.StepDescriptor> descriptors)
      Sets the step descriptors for this session (called during setup). The same map is typically shared with the Channel_ProtobufSerializer.
      Parameters:
      descriptors - a map from step number to its corresponding Channel_ProtobufSerializer.StepDescriptor; must not be null
      Throws:
      NullPointerException - if descriptors is null
      See Also:
    • Open

      public void Open()
      Opens the session by initiating the channel, exchanging IDs if required.
    • Close

      public void Close()
      Closes the session by closing the channel and logging the closure.
    • Receive

      public Object Receive()
      Receives an object using the current channel.
      Returns:
      The received object.
    • Send

      public void Send(Object obj)
      Sends an object using the current channel.
      Parameters:
      obj - The object to be sent.
    • Receive_RemoteId

      public AnBx_Agent Receive_RemoteId()
      Receives the remote identity (AnBx_Agent) using the current channel.
      Returns:
      The received AnBx_Agent representing the remote identity.
    • Send_Id

      public void Send_Id()
      Sends the local identity (me) using the current channel.
    • getChannel

      public Channel_Abstraction getChannel()
      Gets the current channel.
      Returns:
      The current channel.
    • getId_Remote

      public AnBx_Agent getId_Remote()
      Gets the remote identity (AnBx_Agent).
      Returns:
      The remote identity.
    • setChannel

      public void setChannel(Channel_Abstraction c)
      Sets the current channel.
      Parameters:
      c - The channel to be set.
    • setId_Remote

      public void setId_Remote(AnBx_Agent id_Remote)
      Sets the remote identity (AnBx_Agent).
      Parameters:
      id_Remote - The remote identity to be set.
    • getChannelSettings

      public Channel_Settings getChannelSettings()
      Returns the channel settings of the underlying communication channel.
      Returns:
      the Channel_Settings object containing the configuration (host, port, channel type, role, etc.) of this session's channel.
    • isServer

      public boolean isServer()
      Determines whether the current session is acting as a server.
      Returns:
      true if this session's channel role is SERVER, false otherwise.
    • getDesc

      public Channel_ProtobufSerializer.StepDescriptor getDesc(int step)
      Retrieves the Channel_ProtobufSerializer.StepDescriptor associated with the given step.
      Parameters:
      step - the step number
      Returns:
      the step descriptor, never null
      Throws:
      IllegalArgumentException - if no descriptor is registered for step