src/sync_fsm.h
author Volker Birk <vb@pep.foundation>
Mon, 08 Aug 2016 17:32:51 +0200
branchkeysync
changeset 985 087d5d60c082
parent 964 ef02296c41ca
child 1043 f786ee22e281
permissions -rw-r--r--
moving #include and installing headers
     1 #pragma once
     2 
     3 // state machine for DeviceState
     4 
     5 #include "pEpEngine.h"
     6 #include "message.h"
     7 
     8 #ifdef __cplusplus
     9 extern "C" {
    10 #endif
    11 
    12 // types
    13 
    14 typedef pEp_identity * Identity;
    15 typedef stringlist_t * Stringlist;
    16 typedef union _param { Identity partner; stringlist_t *keylist; } param_t;
    17 
    18 // error values
    19 
    20 typedef enum _fsm_error {
    21     // these error values are corresponding to
    22     // PEP_SYNC_STATEMACHINE_ERROR - value
    23     invalid_state = -2,
    24     invalid_event = -3,
    25     invalid_condition = -4,
    26     invalid_action = -5,
    27 
    28     // out of memory condition
    29     invalid_out_of_memory = -128
    30 } fsm_error;
    31 
    32 // conditions
    33 
    34 int storedGroupKeys(PEP_SESSION session);
    35 int keyElectionWon(PEP_SESSION session, Identity partner);
    36 
    37 // states
    38 
    39 typedef enum _DeviceState_state {
    40     DeviceState_state_NONE = 0,
    41     InitState, 
    42     Sole, 
    43     HandshakingSole, 
    44     WaitForGroupKeys, 
    45     Grouped
    46 } DeviceState_state;
    47 
    48 // events
    49 
    50 typedef enum _DeviceState_event {
    51     DeviceState_event_NONE = 0,
    52     Init = 1,
    53     Beacon = 2,
    54     HandshakeRequest = 3,
    55     GroupKeys = 4,
    56     KeyGen, 
    57     CannotDecrypt, 
    58     HandshakeRejected, 
    59     HandshakeAccepted, 
    60     Cancel, 
    61     Reject, 
    62     Hand
    63 } DeviceState_event;
    64 
    65 // actions
    66 
    67 PEP_STATUS sendBeacon(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    68 PEP_STATUS sendHandshakeRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    69 PEP_STATUS showHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    70 PEP_STATUS reject(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    71 PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    72 PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    73 
    74 // message receiver
    75 
    76 PEP_STATUS receive_DeviceState_msg(PEP_SESSION session, message *msg);
    77 
    78 // state machine
    79 
    80 DeviceState_state fsm_DeviceState(
    81         PEP_SESSION session,
    82         DeviceState_state state,
    83         DeviceState_event event,
    84         Identity partner,
    85         void *extra
    86     );
    87 
    88 // driver
    89 
    90 DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
    91         PEP_SESSION session,
    92         DeviceState_event event,
    93         Identity partner,
    94         void *extra
    95     );
    96 
    97 #ifdef __cplusplus
    98 }
    99 #endif
   100