src/sync_fsm.h
author Volker Birk <vb@pep.foundation>
Sat, 20 Aug 2016 18:04:13 +0200
branchkeysync
changeset 1046 73be5d9af815
parent 1043 f786ee22e281
child 1047 2a4a2ec1340b
permissions -rw-r--r--
adding broadcast function
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@1043
    40
    // error values also in this namespace
vb@1043
    41
    DeviceState_state_invalid_state = (int) invalid_state,
vb@1043
    42
    DeviceState_state_invalid_event = (int) invalid_event,
vb@1043
    43
    DeviceState_state_invalid_condition = (int) invalid_condition,
vb@1043
    44
    DeviceState_state_invalid_action = (int) invalid_action,
vb@1043
    45
    DeviceState_state_invalid_out_of_memory = (int) invalid_out_of_memory,
vb@1043
    46
vb@951
    47
    DeviceState_state_NONE = 0,
vb@624
    48
    InitState, 
Edouard@613
    49
    Sole, 
Edouard@613
    50
    HandshakingSole, 
Edouard@613
    51
    WaitForGroupKeys, 
Edouard@613
    52
    Grouped
Edouard@613
    53
} DeviceState_state;
Edouard@613
    54
Edouard@613
    55
// events
Edouard@613
    56
Edouard@613
    57
typedef enum _DeviceState_event {
vb@951
    58
    DeviceState_event_NONE = 0,
vb@951
    59
    Init = 1,
vb@951
    60
    Beacon = 2,
vb@951
    61
    HandshakeRequest = 3,
vb@951
    62
    GroupKeys = 4,
Edouard@613
    63
    KeyGen, 
Edouard@613
    64
    CannotDecrypt, 
Edouard@613
    65
    HandshakeRejected, 
Edouard@613
    66
    HandshakeAccepted, 
Edouard@613
    67
    Cancel, 
vb@939
    68
    Reject, 
vb@939
    69
    Hand
Edouard@613
    70
} DeviceState_event;
Edouard@613
    71
Edouard@613
    72
// actions
Edouard@613
    73
vb@939
    74
PEP_STATUS sendBeacon(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    75
PEP_STATUS sendHandshakeRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    76
PEP_STATUS showHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    77
PEP_STATUS reject(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    78
PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
vb@939
    79
PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
Edouard@613
    80
vb@951
    81
// message receiver
vb@951
    82
vb@952
    83
PEP_STATUS receive_DeviceState_msg(PEP_SESSION session, message *msg);
vb@951
    84
vb@626
    85
// state machine
vb@626
    86
vb@626
    87
DeviceState_state fsm_DeviceState(
vb@627
    88
        PEP_SESSION session,
vb@626
    89
        DeviceState_state state,
vb@626
    90
        DeviceState_event event,
vb@939
    91
        Identity partner,
vb@951
    92
        void *extra
vb@626
    93
    );
vb@626
    94
Edouard@613
    95
// driver
Edouard@613
    96
vb@783
    97
DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
vb@690
    98
        PEP_SESSION session,
vb@690
    99
        DeviceState_event event,
vb@690
   100
        Identity partner,
vb@951
   101
        void *extra
vb@690
   102
    );
Edouard@613
   103
vb@1046
   104
// misc
vb@1046
   105
vb@1046
   106
PEP_STATUS broadcast_msg(PEP_SESSION session, Identity partner, char
vb@1046
   107
        *payload, size_t size);
vb@1046
   108
vb@676
   109
#ifdef __cplusplus
vb@676
   110
}
vb@676
   111
#endif
vb@676
   112