# All files handshake-state.ts

100% Statements 6/6
100% Branches 2/2
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51

    1x

    1x

    1x

    1x

    1x

    1x

     /**
     * States that the handshake process can be in. States depend on
     * whether the socket is the connection Initiator or Responder.
     *
     * Initiator:
     *   1.  create and send Iniatitor act1 and transition to
     *       AWAITING_RESPONDER_REPLY
     *   2.  process the Responder's reply as act2
     *   3.  create Initiator act3 reply to complete the handshake
     *       and transitions to READY
     *
     * Responder:
     *   1.  begins in AWAITING_INITIATOR waiting to receive act1
     *   2.  processes act1 and creates a reply as act2 and transitions
     *       to AWAITING_INITIATOR_REPLY
     *   3.  processes the Initiator's reply to complete the handshake
     *       and transition to READY
     */
    export enum HANDSHAKE_STATE {
      /**
       * Initial state for the Initiator. Initiator will transition to
       * AWAITING_RESPONDER_REPLY once act1 is completed and sent.
       */
      INITIATOR_INITIATING = 0,

      /**
       * Responders begin in this state and wait for the Intiator to begin
       * the handshake. Sockets originating from the NoiseServer will
       * begin in this state.
       */
      AWAITING_INITIATOR = 1,

      /**
       * Initiator has sent act1 and is awaiting the reply from the responder.
       * Once received, the intiator will create the reply
       */
      AWAITING_RESPONDER_REPLY = 2,

      /**
       * Responder has  sent a reply to the inititator, the Responder will be
       * waiting for the final stage of the handshake sent by the Initiator.
       */
      AWAITING_INITIATOR_REPLY = 3,

      /**
       * Responder/Initiator have completed the handshake and we're ready to
       * start sending and receiving over the socket.
       */
      READY = 100,
    }