sync/sync.fsm
author Volker Birk <vb@pep-project.org>
Tue, 10 May 2016 10:32:47 +0200
changeset 582 fa50f202b57c
parent 571 2b1666bc1b45
child 590 d28f8852ac45
permissions -rw-r--r--
parms
     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 {
    13         on Init {
    14             if (storedGroupKeys)
    15                 go Grouped;
    16             go Sole;
    17         }
    18 
    19         state Sole {
    20             on KeyGen
    21                 do sendBeacon;
    22             on CannotDecrypt
    23                 do sendBeacon;  // cry, baby
    24             on Beacon(identity partner) // this event will not happen for already
    25                                         // rejected partners
    26                 do sendHandshakeRequest(partner);
    27             on HandshakeRequest(identity partner) {
    28                 do sendHandshakeRequest(partner);
    29                 go HandshakingSole(partner);
    30             }
    31         }
    32 
    33         state HandshakingSole(identity partner) {
    34             on Init
    35                 do showHandshake(partner);
    36             on HandshakeRejected(identity partner) {
    37                 do reject(partner);             // sends Reject to partner and
    38                                                 // stores rejection of partner
    39                 go Sole;
    40             }
    41             on HandshakeAccepted(partner) {
    42                 if keyElectionWon(partner) {    // an already existing group
    43                                                 // always wins
    44                     storeOwnKeysAsGroupKeys;
    45                     sendGroupKeys(partner);
    46                     go Grouped;
    47                 }
    48                 go WaitForGroupKeys(partner);
    49             }
    50         }
    51     
    52         state WaitForGroupKeys(identity partner) {
    53             on ReceiveGroupKeys(identity partner) {
    54                 storeGroupKeys(partner);
    55                 go Grouped;
    56             }
    57             on Cancel go Sole;
    58             on Reject(identity partner) {
    59                 do reject(partner);
    60                 go Sole;
    61             }
    62         }
    63 
    64         state Grouped {
    65             on KeyGen
    66                 do sendOwnKeys; // always send all keys
    67             on HandshakeRequest(identity partner) {
    68                 do sendHandshakeRequest(partner);
    69                 do showHandshake(partner);
    70             }
    71             on HandshakeRejected(identity partner)
    72                 do reject(partner);
    73             on HandshakeAccepted(identity partner)
    74                 do sendGroupKeys(partner);
    75             on Reject(identity partner)
    76                 do reject partner;
    77         }
    78     }
    79 }
    80