sync/devicegroup.fsm
author Volker Birk <vb@pep-project.org>
Fri, 29 Jul 2016 10:45:13 +0200
branchkeysync
changeset 939 ed7dfdae3031
parent 907 8f5cca5bfa2d
child 944 e97cf5e73b64
permissions -rw-r--r--
changing message_api: adding flags to encrypt_message()
     1 // DeviceGroup protocol for p≡p
     2 
     3 // Copyleft (c) 2016, p≡p foundation
     4 
     5 // Written by Volker Birk
     6 
     7 include ./fsm.yml2
     8 
     9 protocol DeviceGroup {
    10     // all messages have a timestamp, time out and are removed after timeout
    11 
    12     fsm DeviceState filename=sync {
    13         state InitState {
    14             on Init {
    15                 if (storedGroupKeys)
    16                     go Grouped;
    17                 go Sole;
    18             }
    19         }
    20 
    21         state Sole {
    22             on KeyGen
    23                 do sendBeacon;
    24             on CannotDecrypt
    25                 do sendBeacon;  // cry, baby
    26             on Beacon(Identity partner) // this event will not happen for already
    27                                         // rejected partners
    28                 do sendHandshakeRequest(partner);
    29             on HandshakeRequest(Identity partner) {
    30                 do sendHandshakeRequest(partner);
    31                 go HandshakingSole(partner);
    32             }
    33         }
    34 
    35         state HandshakingSole(Identity partner) {
    36             on Init
    37                 do showHandshake(partner);
    38             on HandshakeRejected(Identity partner) {
    39                 do reject(partner);             // stores rejection of partner
    40                 go Sole;
    41             }
    42             on HandshakeAccepted(Identity partner) {
    43                 if keyElectionWon(partner) {    // an already existing group
    44                                                 // always wins
    45                     ownGroupKeys;
    46                     sendGroupKeys(partner);
    47                     go Grouped;
    48                 }
    49                 go WaitForGroupKeys(Identity partner);
    50             }
    51         }
    52     
    53         state WaitForGroupKeys(Identity partner) {
    54             on GroupKeys(Identity partner, Stringlist keys) {
    55                 do storeGroupKeys(partner, keys);
    56                 go Grouped;
    57             }
    58             on Cancel go Sole;
    59             on Reject(Identity partner) {
    60                 do reject(partner);
    61                 go Sole;
    62             }
    63         }
    64 
    65         state Grouped {
    66             on KeyGen
    67                 do sendGroupKeys; // always send all keys
    68             on HandshakeRequest(Identity partner) {
    69                 do sendHandshakeRequest(partner);
    70                 do showHandshake(partner);
    71             }
    72             on HandshakeRejected(Identity partner)
    73                 do reject(partner);
    74             on Hand
    75                 hakeAccepted(Identity partner)
    76                 do sendGroupKeys(partner);
    77             on Reject(Identity partner)
    78                 do reject partner;
    79         }
    80 
    81         tag InitState 0;
    82         tag Beacon 1;
    83         tag HandshakeRequest 2;
    84         tag GroupKeys 3;
    85     }
    86 }
    87