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