src/sync_fsm.c
author Volker Birk <vb@pep-project.org>
Sun, 15 May 2016 21:23:36 +0200
changeset 627 ef1fdfde8ced
parent 624 4892dffa9e70
child 690 3ae86b68fdfe
permissions -rw-r--r--
adding session handles
     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     )
    11 {
    12     switch (state) {
    13     case InitState:
    14         switch (event) {
    15             case Init:
    16                 return Sole;
    17         default:
    18             return invalid_event;
    19         }
    20         break;
    21     
    22     case Sole:
    23         switch (event) {
    24             case KeyGen:
    25                 sendBeacon(session, NULL);
    26                 break;
    27             case CannotDecrypt:
    28                 sendBeacon(session, NULL);
    29                 break;
    30             case Beacon:
    31                 sendHandshakeRequest(session, partner);
    32                 break;
    33             case HandshakeRequest:
    34                 sendHandshakeRequest(session, partner);
    35                 return HandshakingSole;
    36         default:
    37             return invalid_event;
    38         }
    39         break;
    40     
    41     case HandshakingSole:
    42         switch (event) {
    43             case Init:
    44                 showHandshake(session, partner);
    45                 break;
    46             case HandshakeRejected:
    47                 reject(session, partner);
    48                 return Sole;
    49             case HandshakeAccepted:
    50                 return WaitForGroupKeys;
    51         default:
    52             return invalid_event;
    53         }
    54         break;
    55     
    56     case WaitForGroupKeys:
    57         switch (event) {
    58             case ReceiveGroupKeys:
    59                 storeGroupKeys(session, partner);
    60                 return Grouped;
    61             case Cancel:
    62                 return Sole;
    63             case Reject:
    64                 reject(session, partner);
    65                 return Sole;
    66         default:
    67             return invalid_event;
    68         }
    69         break;
    70     
    71     case Grouped:
    72         switch (event) {
    73             case KeyGen:
    74                 sendOwnKeys(session, NULL);
    75                 break;
    76             case HandshakeRequest:
    77                 sendHandshakeRequest(session, partner);
    78                 showHandshake(session, partner);
    79                 break;
    80             case HandshakeRejected:
    81                 reject(session, partner);
    82                 break;
    83             case HandshakeAccepted:
    84                 transmitGroupKeys(session, partner);
    85                 break;
    86             case Reject:
    87                 reject(session, NULL);
    88                 break;
    89         default:
    90             return invalid_event;
    91         }
    92         break;
    93     
    94         default:
    95             return invalid_state;
    96     }
    97 
    98     return state;
    99 }