sync/devicegroup.fsm
author Edouard Tisserant <edouard@pep-project.org>
Sat, 15 Oct 2016 17:45:16 +0200
changeset 1281 efff88dcdc59
parent 1236 991afc1aa2a1
child 1297 78f5f9894fbd
permissions -rw-r--r--
Sync : added group update, on keygen for now
vb@563
     1
// DeviceGroup protocol for p≡p
vb@563
     2
vb@563
     3
// Copyleft (c) 2016, p≡p foundation
vb@563
     4
vb@563
     5
// Written by Volker Birk
vb@563
     6
vb@563
     7
include ./fsm.yml2
vb@563
     8
vb@563
     9
protocol DeviceGroup {
vb@563
    10
    // all messages have a timestamp, time out and are removed after timeout
vb@563
    11
vb@1047
    12
    broadcast sendBeacon;
edouard@1281
    13
    broadcast sendGroupUpdate;
vb@1097
    14
    unencrypted sendBeacon;
vb@1047
    15
vb@807
    16
    fsm DeviceState filename=sync {
vb@951
    17
        condition storedGroupKeys();
vb@951
    18
        condition keyElectionWon(Identity partner);
vb@951
    19
vb@624
    20
        state InitState {
vb@624
    21
            on Init {
vb@951
    22
                if storedGroupKeys()
vb@624
    23
                    go Grouped;
vb@624
    24
                go Sole;
vb@624
    25
            }
vb@563
    26
        }
vb@563
    27
vb@563
    28
        state Sole {
vb@944
    29
            on KeyGen // injected by generate_keypair()
vb@1097
    30
                do sendBeacon;
vb@563
    31
            on CannotDecrypt
vb@566
    32
                do sendBeacon;  // cry, baby
Edouard@594
    33
            on Beacon(Identity partner) // this event will not happen for already
vb@571
    34
                                        // rejected partners
vb@582
    35
                do sendHandshakeRequest(partner);
Edouard@594
    36
            on HandshakeRequest(Identity partner) {
vb@582
    37
                do sendHandshakeRequest(partner);
vb@563
    38
                go HandshakingSole(partner);
vb@563
    39
            }
vb@563
    40
        }
vb@563
    41
Edouard@594
    42
        state HandshakingSole(Identity partner) {
vb@582
    43
            on Init
vb@563
    44
                do showHandshake(partner);
Edouard@594
    45
            on HandshakeRejected(Identity partner) {
edouard@1161
    46
                do rejectHandshake(partner);             // stores rejection of partner
vb@563
    47
                go Sole;
vb@563
    48
            }
Edouard@594
    49
            on HandshakeAccepted(Identity partner) {
edouard@1161
    50
                do acceptHandshake(partner); 
vb@567
    51
                if keyElectionWon(partner) {    // an already existing group
vb@567
    52
                                                // always wins
edouard@1161
    53
                    do sendGroupKeys(partner);
vb@563
    54
                    go Grouped;
vb@563
    55
                }
edouard@1216
    56
                go WaitForGroupKeysSole(Identity partner);
vb@563
    57
            }
vb@563
    58
        }
vb@563
    59
    
edouard@1216
    60
        state WaitForGroupKeysSole(Identity partner) {
vb@711
    61
            on GroupKeys(Identity partner, Stringlist keys) {
Edouard@605
    62
                do storeGroupKeys(partner, keys);
vb@563
    63
                go Grouped;
vb@563
    64
            }
vb@568
    65
            on Cancel go Sole;
Edouard@594
    66
            on Reject(Identity partner) {
edouard@1161
    67
                do rejectHandshake(partner);
vb@569
    68
                go Sole;
vb@569
    69
            }
vb@563
    70
        }
vb@563
    71
vb@563
    72
        state Grouped {
vb@563
    73
            on KeyGen
edouard@1281
    74
                do sendGroupUpdate;
edouard@1216
    75
            on Beacon(Identity partner)
edouard@1216
    76
                do sendHandshakeRequest(partner);
Edouard@594
    77
            on HandshakeRequest(Identity partner) {
vb@582
    78
                do sendHandshakeRequest(partner);
edouard@1216
    79
                go HandshakingGrouped(partner);
edouard@1216
    80
            }
edouard@1281
    81
            on GroupUpdate(Identity partner, Stringlist keys)
edouard@1236
    82
                do storeGroupKeys(partner, keys);
edouard@1216
    83
        }
edouard@1216
    84
edouard@1216
    85
        state HandshakingGrouped(Identity partner) {
edouard@1216
    86
            on Init
vb@563
    87
                do showHandshake(partner);
edouard@1216
    88
            on HandshakeRejected(Identity partner) {
edouard@1216
    89
                do rejectHandshake(partner);             // stores rejection of partner
edouard@1216
    90
                go Grouped;
vb@563
    91
            }
edouard@1216
    92
            on HandshakeAccepted(Identity partner) {
edouard@1161
    93
                do acceptHandshake(partner); 
edouard@1216
    94
edouard@1216
    95
                // an already existing group always wins
vb@711
    96
                do sendGroupKeys(partner);
edouard@1216
    97
                go Grouped;
edouard@1161
    98
            }
vb@563
    99
        }
edouard@1216
   100
    
Edouard@613
   101
vb@951
   102
        tag Init 1;
vb@951
   103
        tag Beacon 2;
vb@951
   104
        tag HandshakeRequest 3;
vb@951
   105
        tag GroupKeys 4;
Edouard@613
   106
    }
vb@563
   107
}
vb@563
   108