sync/devicegroup.fsm
author Krista Bennett <krista@pep-project.org>
Fri, 01 Jun 2018 10:30:22 +0200
branchENGINE-139
changeset 2735 731b17a2e52f
parent 1297 78f5f9894fbd
child 1409 e9bcd6142d54
permissions -rw-r--r--
close branch
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;
edouard@1297
    14
    broadcast sendUpdateRequest;
vb@1097
    15
    unencrypted sendBeacon;
vb@1047
    16
vb@807
    17
    fsm DeviceState filename=sync {
vb@951
    18
        condition storedGroupKeys();
vb@951
    19
        condition keyElectionWon(Identity partner);
vb@951
    20
vb@624
    21
        state InitState {
vb@624
    22
            on Init {
vb@951
    23
                if storedGroupKeys()
vb@624
    24
                    go Grouped;
vb@624
    25
                go Sole;
vb@624
    26
            }
vb@563
    27
        }
vb@563
    28
vb@563
    29
        state Sole {
vb@944
    30
            on KeyGen // injected by generate_keypair()
vb@1097
    31
                do sendBeacon;
vb@563
    32
            on CannotDecrypt
vb@566
    33
                do sendBeacon;  // cry, baby
Edouard@594
    34
            on Beacon(Identity partner) // this event will not happen for already
vb@571
    35
                                        // rejected partners
vb@582
    36
                do sendHandshakeRequest(partner);
Edouard@594
    37
            on HandshakeRequest(Identity partner) {
vb@582
    38
                do sendHandshakeRequest(partner);
vb@563
    39
                go HandshakingSole(partner);
vb@563
    40
            }
vb@563
    41
        }
vb@563
    42
Edouard@594
    43
        state HandshakingSole(Identity partner) {
vb@582
    44
            on Init
vb@563
    45
                do showHandshake(partner);
Edouard@594
    46
            on HandshakeRejected(Identity partner) {
edouard@1161
    47
                do rejectHandshake(partner);             // stores rejection of partner
vb@563
    48
                go Sole;
vb@563
    49
            }
Edouard@594
    50
            on HandshakeAccepted(Identity partner) {
edouard@1161
    51
                do acceptHandshake(partner); 
vb@567
    52
                if keyElectionWon(partner) {    // an already existing group
vb@567
    53
                                                // always wins
edouard@1161
    54
                    do sendGroupKeys(partner);
vb@563
    55
                    go Grouped;
vb@563
    56
                }
edouard@1216
    57
                go WaitForGroupKeysSole(Identity partner);
vb@563
    58
            }
vb@563
    59
        }
vb@563
    60
    
edouard@1216
    61
        state WaitForGroupKeysSole(Identity partner) {
vb@711
    62
            on GroupKeys(Identity partner, Stringlist keys) {
Edouard@605
    63
                do storeGroupKeys(partner, keys);
vb@563
    64
                go Grouped;
vb@563
    65
            }
vb@568
    66
            on Cancel go Sole;
Edouard@594
    67
            on Reject(Identity partner) {
edouard@1161
    68
                do rejectHandshake(partner);
vb@569
    69
                go Sole;
vb@569
    70
            }
vb@563
    71
        }
vb@563
    72
vb@563
    73
        state Grouped {
edouard@1297
    74
            on Init 
edouard@1297
    75
                do enterGroup;
vb@563
    76
            on KeyGen
edouard@1281
    77
                do sendGroupUpdate;
edouard@1297
    78
            on CannotDecrypt
edouard@1297
    79
                do sendUpdateRequest; // TODO: narrow request to missing key
edouard@1297
    80
            on UpdateRequest
edouard@1297
    81
                do sendGroupUpdate;
edouard@1216
    82
            on Beacon(Identity partner)
edouard@1216
    83
                do sendHandshakeRequest(partner);
Edouard@594
    84
            on HandshakeRequest(Identity partner) {
vb@582
    85
                do sendHandshakeRequest(partner);
edouard@1216
    86
                go HandshakingGrouped(partner);
edouard@1216
    87
            }
edouard@1281
    88
            on GroupUpdate(Identity partner, Stringlist keys)
edouard@1236
    89
                do storeGroupKeys(partner, keys);
edouard@1216
    90
        }
edouard@1216
    91
edouard@1216
    92
        state HandshakingGrouped(Identity partner) {
edouard@1216
    93
            on Init
vb@563
    94
                do showHandshake(partner);
edouard@1216
    95
            on HandshakeRejected(Identity partner) {
edouard@1216
    96
                do rejectHandshake(partner);             // stores rejection of partner
edouard@1216
    97
                go Grouped;
vb@563
    98
            }
edouard@1216
    99
            on HandshakeAccepted(Identity partner) {
edouard@1161
   100
                do acceptHandshake(partner); 
edouard@1216
   101
edouard@1216
   102
                // an already existing group always wins
vb@711
   103
                do sendGroupKeys(partner);
edouard@1216
   104
                go Grouped;
edouard@1161
   105
            }
vb@563
   106
        }
edouard@1216
   107
    
Edouard@613
   108
vb@951
   109
        tag Init 1;
vb@951
   110
        tag Beacon 2;
vb@951
   111
        tag HandshakeRequest 3;
vb@951
   112
        tag GroupKeys 4;
Edouard@613
   113
    }
vb@563
   114
}
vb@563
   115