
//////////////////////////////////////////////////////////////////////////////
//
//   FlatBuffers schema for WAMP v2 messages
//   Copyright (c) typedef int GmbH and contributors
//   Licensed under the MIT License (MIT)
//
//////////////////////////////////////////////////////////////////////////////

include "types.fbs";
include "roles.fbs";
include "auth.fbs";

namespace wamp.proto;


// [Category 1: Neither Payload nor Forwarding] HELLO message (message_type = 1): Client initiates session.
table Hello
{
    // The WAMP session ID on the node this session is (directly) attached to.
    session: uint64;

    // The WAMP session roles and client library features to announce.
    roles: ClientRoles (required);

    // The URI of the WAMP realm the client wants to join.
    realm: string (uri);

    // The authentication methods to announce.
    authmethods: [AuthMethod];

    // The (client) authentication ID to announce.
    authid: string (principal);

    // The (client) authentication role to announce.
    authrole: string (principal);

    // authmethod specific extra data to be forwarded to the client.
    authextra: Map;

    // Whether the client wants this to be a session that can be
    // later resumed (HELLO.Details.resumable).
    resumable: bool;

    // The session the client would like to resume (HELLO.Details.resume_session).
    resume_session: uint64;

    // The secure authorisation token to resume the session (HELLO.Details.resume_token).
    resume_token: string;
}


// [Category 1: Neither Payload nor Forwarding] WELCOME message (message_type = 2): Router accepts session.
table Welcome
{
    // The WAMP session ID on the node this session is (directly) attached to.
    session: uint64;

    // The WAMP roles to announce.
    roles: RouterRoles (required);

    // The effective realm the session is joined on.
    realm: string (required, uri);

    // The authentication ID assigned.
    authid: string (required, principal);

    // The authentication method in use.
    authrole: string (required, principal);

    // The authentication method in use.
    authmethod: AuthMethod;

    // The authentication provided in use.
    authprovider: string;

    // Application-specific "extra data" to be forwarded to the client.
    authextra: Map;

    // Whether the session is a resumed one.
    resumed: bool;

    // Whether this session can be resumed later.
    resumable: bool;

    // The secure authorisation token to resume the session.
    resume_token: string;
}


// [Category 1: Neither Payload nor Forwarding] ABORT message (message_type = 3): Session aborted during handshake.
table Abort
{
    // The WAMP session ID on the node this session is (directly) attached to.
    session: uint64;

    // WAMP or application error URI for aborting reason.
    reason: string (required, uri);

    // Optional human-readable closing message, e.g. for logging purposes.
    message: string;
}


// [Category 1: Neither Payload nor Forwarding] CHALLENGE message (message_type = 4): Router sends authentication challenge.
table Challenge
{
    // The WAMP session ID on the node this session is (directly) attached to.
    session: uint64;

    // The challenge method.
    method: AuthMethod;

    // Challenge method specific information.
    extra: Map;
}


// [Category 1: Neither Payload nor Forwarding] AUTHENTICATE message (message_type = 5): Client responds to authentication challenge.
table Authenticate
{
    // The WAMP session ID on the node this session is (directly) attached to.
    session: uint64;

    // The signature for the authentication challenge.
    signature: string (required);

    // Authentication method specific information.
    extra: Map;
}


// [Category 1: Neither Payload nor Forwarding] GOODBYE message (message_type = 6): Session closed gracefully.
table Goodbye
{
    // The WAMP session ID on the node this session is (directly) attached to.
    session: uint64;

    // Optional WAMP or application error URI for closing reason.
    reason: string (required, uri);

    // Optional human-readable closing message, e.g. for logging purposes.
    message: string;

    // From the server: Whether the session is able to be resumed (true) or destroyed (false). From the client: Whether it should be resumable (true) or destroyed (false).
    resumable: bool;
}


// [Category 4: Both Payload and Forwarding] ERROR message (message_type = 8): Error response with optional application payload.
table Error
{
    // The WAMP session ID on the node this session is (directly) attached to.
    session: uint64;

    // The WAMP message type code for the original request.
    request_type: MessageType;

    // The WAMP request ID of the original request (CALL, SUBSCRIBE, ...) this error occurred for.
    request: uint64 (key);

    // The WAMP or application error URI for the error that occurred.
    error: string (required, uri);

    /// Positional values for application-defined error details.
    args: [uint8];

    /// Keyword values for application-defined error details.
    kwargs: [uint8];

    /// Alternative, transparent payload. If given, ``args`` and ``kwargs`` must be left unset.
    payload: [uint8];

    /// The specific scheme in use with Payload Passthru (PPT) mode for the application payload.
    ppt_scheme: PPTScheme;

    /// The specific serializer encoding the application payload with the Payload Passthru (PPT) scheme in use.
    ppt_serializer: PPTSerializer;

    /// The cryptographic algorithm ("cipher") encrypting the application payload with the Payload Passthru (PPT) scheme in use.
    ppt_cipher: PPTCipher;

    /// The identifier or reference to the encryption key that was used to encrypt the payload with the Payload Passthru (PPT) scheme and cipher in use.
    ppt_keyid: string (ppt_keyid);

    // R2R-link message forwarding route that was taken.
    forward_for: [Principal];
}
