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