src/sync_fsm.h
author Volker Birk <vb@pep.foundation>
Sun, 31 Jul 2016 19:38:23 +0200
branchkeysync
changeset 951 dec407deb10e
parent 939 ed7dfdae3031
child 952 986fd7b2eb8f
permissions -rw-r--r--
...
     1 #pragma once
     2 
     3 // state machine for DeviceState
     4 
     5 #include "pEpEngine.h"
     6 #include "../asn.1/DeviceGroup-Protocol.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     invalid_state = -2,
    22     invalid_event = -3
    23 } fsm_error;
    24 
    25 // conditions
    26 
    27 bool storedGroupKeys(PEP_SESSION session);
    28 bool keyElectionWon(PEP_SESSION session, Identity partner);
    29 
    30 // states
    31 
    32 typedef enum _DeviceState_state {
    33     DeviceState_state_NONE = 0,
    34     InitState, 
    35     Sole, 
    36     HandshakingSole, 
    37     WaitForGroupKeys, 
    38     Grouped
    39 } DeviceState_state;
    40 
    41 // events
    42 
    43 typedef enum _DeviceState_event {
    44     DeviceState_event_NONE = 0,
    45     Init = 1,
    46     Beacon = 2,
    47     HandshakeRequest = 3,
    48     GroupKeys = 4,
    49     KeyGen, 
    50     CannotDecrypt, 
    51     HandshakeRejected, 
    52     HandshakeAccepted, 
    53     Cancel, 
    54     Reject, 
    55     Hand
    56 } DeviceState_event;
    57 
    58 // actions
    59 
    60 PEP_STATUS sendBeacon(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    61 PEP_STATUS sendHandshakeRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    62 PEP_STATUS showHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    63 PEP_STATUS reject(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    64 PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    65 PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    66 
    67 // message receiver
    68 
    69 PEP_STATUS receive_DeviceState_msg(PEP_SESSION session, DeviceGroup_Protocol_t *msg);
    70 
    71 // state machine
    72 
    73 DeviceState_state fsm_DeviceState(
    74         PEP_SESSION session,
    75         DeviceState_state state,
    76         DeviceState_event event,
    77         Identity partner,
    78         void *extra
    79     );
    80 
    81 // driver
    82 
    83 DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
    84         PEP_SESSION session,
    85         DeviceState_event event,
    86         Identity partner,
    87         void *extra
    88     );
    89 
    90 #ifdef __cplusplus
    91 }
    92 #endif
    93