src/sync_fsm.c
author Volker Birk <vb@pep-project.org>
Thu, 02 Jun 2016 13:46:38 +0200
changeset 711 d88dea0f5448
parent 690 3ae86b68fdfe
child 743 e4b613ebac2f
permissions -rw-r--r--
slightly redesigning things
     1 #include "sync_fsm.h"
     2 
     3 // state machine for DeviceState
     4 
     5 DeviceState_state fsm_DeviceState(
     6         PEP_SESSION session,
     7         DeviceState_state state,
     8         DeviceState_event event,
     9         const Identity partner,
    10         DeviceState_state state_partner
    11     )
    12 {
    13     switch (state) {
    14     case InitState:
    15         switch (event) {
    16             case Init:
    17                 return Sole;
    18         default:
    19             return invalid_event;
    20         }
    21         break;
    22     
    23     case Sole:
    24         switch (event) {
    25             case KeyGen:
    26                 sendBeacon(session, state, NULL);
    27                 break;
    28             case CannotDecrypt:
    29                 sendBeacon(session, state, NULL);
    30                 break;
    31             case Beacon:
    32                 sendHandshakeRequest(session, state, partner);
    33                 break;
    34             case HandshakeRequest:
    35                 sendHandshakeRequest(session, state, partner);
    36                 return HandshakingSole;
    37         default:
    38             return invalid_event;
    39         }
    40         break;
    41     
    42     case HandshakingSole:
    43         switch (event) {
    44             case Init:
    45                 showHandshake(session, state, partner);
    46                 break;
    47             case HandshakeRejected:
    48                 reject(session, state, partner);
    49                 return Sole;
    50             case HandshakeAccepted:
    51                 return WaitForGroupKeys;
    52         default:
    53             return invalid_event;
    54         }
    55         break;
    56     
    57     case WaitForGroupKeys:
    58         switch (event) {
    59             case GroupKeys:
    60                 storeGroupKeys(session, state, partner);
    61                 return Grouped;
    62             case Cancel:
    63                 return Sole;
    64             case Reject:
    65                 reject(session, state, partner);
    66                 return Sole;
    67         default:
    68             return invalid_event;
    69         }
    70         break;
    71     
    72     case Grouped:
    73         switch (event) {
    74             case KeyGen:
    75                 sendGroupKeys(session, state, NULL);
    76                 break;
    77             case HandshakeRequest:
    78                 sendHandshakeRequest(session, state, partner);
    79                 showHandshake(session, state, partner);
    80                 break;
    81             case HandshakeRejected:
    82                 reject(session, state, partner);
    83                 break;
    84             case HandshakeAccepted:
    85                 sendGroupKeys(session, state, partner);
    86                 break;
    87             case Reject:
    88                 reject(session, state, NULL);
    89                 break;
    90         default:
    91             return invalid_event;
    92         }
    93         break;
    94     
    95         default:
    96             return invalid_state;
    97     }
    98 
    99     return state;
   100 }