sync/devicegroup.fsm
author Volker Birk <vb@pep.foundation>
Sun, 31 Jul 2016 19:38:23 +0200
branchkeysync
changeset 951 dec407deb10e
parent 944 e97cf5e73b64
child 1047 2a4a2ec1340b
permissions -rw-r--r--
...
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@807
    12
    fsm DeviceState filename=sync {
vb@951
    13
        condition storedGroupKeys();
vb@951
    14
        condition keyElectionWon(Identity partner);
vb@951
    15
vb@624
    16
        state InitState {
vb@624
    17
            on Init {
vb@951
    18
                if storedGroupKeys()
vb@624
    19
                    go Grouped;
vb@624
    20
                go Sole;
vb@624
    21
            }
vb@563
    22
        }
vb@563
    23
vb@563
    24
        state Sole {
vb@944
    25
            on KeyGen // injected by generate_keypair()
vb@563
    26
                do sendBeacon;
vb@563
    27
            on CannotDecrypt
vb@566
    28
                do sendBeacon;  // cry, baby
Edouard@594
    29
            on Beacon(Identity partner) // this event will not happen for already
vb@571
    30
                                        // rejected partners
vb@582
    31
                do sendHandshakeRequest(partner);
Edouard@594
    32
            on HandshakeRequest(Identity partner) {
vb@582
    33
                do sendHandshakeRequest(partner);
vb@563
    34
                go HandshakingSole(partner);
vb@563
    35
            }
vb@563
    36
        }
vb@563
    37
Edouard@594
    38
        state HandshakingSole(Identity partner) {
vb@582
    39
            on Init
vb@563
    40
                do showHandshake(partner);
Edouard@594
    41
            on HandshakeRejected(Identity partner) {
vb@907
    42
                do reject(partner);             // stores rejection of partner
vb@563
    43
                go Sole;
vb@563
    44
            }
Edouard@594
    45
            on HandshakeAccepted(Identity partner) {
vb@567
    46
                if keyElectionWon(partner) {    // an already existing group
vb@567
    47
                                                // always wins
vb@711
    48
                    ownGroupKeys;
vb@711
    49
                    sendGroupKeys(partner);
vb@563
    50
                    go Grouped;
vb@563
    51
                }
Edouard@594
    52
                go WaitForGroupKeys(Identity partner);
vb@563
    53
            }
vb@563
    54
        }
vb@563
    55
    
Edouard@594
    56
        state WaitForGroupKeys(Identity partner) {
vb@711
    57
            on GroupKeys(Identity partner, Stringlist keys) {
Edouard@605
    58
                do storeGroupKeys(partner, keys);
vb@563
    59
                go Grouped;
vb@563
    60
            }
vb@568
    61
            on Cancel go Sole;
Edouard@594
    62
            on Reject(Identity partner) {
vb@569
    63
                do reject(partner);
vb@569
    64
                go Sole;
vb@569
    65
            }
vb@563
    66
        }
vb@563
    67
vb@563
    68
        state Grouped {
vb@563
    69
            on KeyGen
vb@711
    70
                do sendGroupKeys; // always send all keys
Edouard@594
    71
            on HandshakeRequest(Identity partner) {
vb@582
    72
                do sendHandshakeRequest(partner);
vb@563
    73
                do showHandshake(partner);
vb@563
    74
            }
Edouard@594
    75
            on HandshakeRejected(Identity partner)
vb@563
    76
                do reject(partner);
vb@939
    77
            on Hand
vb@939
    78
                hakeAccepted(Identity partner)
vb@711
    79
                do sendGroupKeys(partner);
Edouard@594
    80
            on Reject(Identity partner)
vb@570
    81
                do reject partner;
vb@563
    82
        }
Edouard@613
    83
vb@951
    84
        tag Init 1;
vb@951
    85
        tag Beacon 2;
vb@951
    86
        tag HandshakeRequest 3;
vb@951
    87
        tag GroupKeys 4;
Edouard@613
    88
    }
vb@563
    89
}
vb@563
    90