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