sync/devicegroup.fsm
author Roker <roker@pep-project.org>
Tue, 20 Sep 2016 15:54:57 +0200
branchroker-linux
changeset 1168 4d4e3ecbaf8b
parent 907 8f5cca5bfa2d
child 939 ed7dfdae3031
permissions -rw-r--r--
merge "default" into my branch
     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 HandshakeAccepted(Identity partner)
    75                 do sendGroupKeys(partner);
    76             on Reject(Identity partner)
    77                 do reject partner;
    78         }
    79 
    80         tag InitState 0;
    81         tag Beacon 1;
    82         tag HandshakeRequest 2;
    83         tag GroupKeys 3;
    84     }
    85 }
    86