sync/sync.fsm
author Volker Birk <vb@pep-project.org>
Sun, 15 May 2016 15:41:44 +0200
changeset 624 4892dffa9e70
parent 613 d59da438b2cb
child 711 d88dea0f5448
permissions -rw-r--r--
init state
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@563
    12
    fsm DeviceState {
vb@624
    13
        state InitState {
vb@624
    14
            on Init {
vb@624
    15
                if (storedGroupKeys)
vb@624
    16
                    go Grouped;
vb@624
    17
                go Sole;
vb@624
    18
            }
vb@563
    19
        }
vb@563
    20
vb@563
    21
        state Sole {
vb@563
    22
            on KeyGen
vb@563
    23
                do sendBeacon;
vb@563
    24
            on CannotDecrypt
vb@566
    25
                do sendBeacon;  // cry, baby
Edouard@594
    26
            on Beacon(Identity partner) // this event will not happen for already
vb@571
    27
                                        // rejected partners
vb@582
    28
                do sendHandshakeRequest(partner);
Edouard@594
    29
            on HandshakeRequest(Identity partner) {
vb@582
    30
                do sendHandshakeRequest(partner);
vb@563
    31
                go HandshakingSole(partner);
vb@563
    32
            }
vb@563
    33
        }
vb@563
    34
Edouard@594
    35
        state HandshakingSole(Identity partner) {
vb@582
    36
            on Init
vb@563
    37
                do showHandshake(partner);
Edouard@594
    38
            on HandshakeRejected(Identity partner) {
vb@570
    39
                do reject(partner);             // sends Reject to partner and
vb@570
    40
                                                // stores rejection of partner
vb@563
    41
                go Sole;
vb@563
    42
            }
Edouard@594
    43
            on HandshakeAccepted(Identity partner) {
vb@567
    44
                if keyElectionWon(partner) {    // an already existing group
vb@567
    45
                                                // always wins
vb@563
    46
                    storeOwnKeysAsGroupKeys;
vb@590
    47
                    transmitGroupKeys(partner);
vb@563
    48
                    go Grouped;
vb@563
    49
                }
Edouard@594
    50
                go WaitForGroupKeys(Identity partner);
vb@563
    51
            }
vb@563
    52
        }
vb@563
    53
    
Edouard@594
    54
        state WaitForGroupKeys(Identity partner) {
Edouard@594
    55
            on ReceiveGroupKeys(Identity partner, Stringlist keys) {
Edouard@605
    56
                do storeGroupKeys(partner, keys);
vb@563
    57
                go Grouped;
vb@563
    58
            }
vb@568
    59
            on Cancel go Sole;
Edouard@594
    60
            on Reject(Identity partner) {
vb@569
    61
                do reject(partner);
vb@569
    62
                go Sole;
vb@569
    63
            }
vb@563
    64
        }
vb@563
    65
vb@563
    66
        state Grouped {
vb@563
    67
            on KeyGen
vb@565
    68
                do sendOwnKeys; // always send all keys
Edouard@594
    69
            on HandshakeRequest(Identity partner) {
vb@582
    70
                do sendHandshakeRequest(partner);
vb@563
    71
                do showHandshake(partner);
vb@563
    72
            }
Edouard@594
    73
            on HandshakeRejected(Identity partner)
vb@563
    74
                do reject(partner);
Edouard@594
    75
            on HandshakeAccepted(Identity partner)
vb@590
    76
                do transmitGroupKeys(partner);
Edouard@594
    77
            on Reject(Identity partner)
vb@570
    78
                do reject partner;
vb@563
    79
        }
vb@563
    80
    }
Edouard@613
    81
Edouard@613
    82
    interface commons {
Edouard@613
    83
        Header head;
Edouard@613
    84
    }
Edouard@613
    85
Edouard@613
    86
    interface OwnKeys {
Edouard@613
    87
        Stringlist ownKeys;
Edouard@613
    88
    }
vb@563
    89
}
vb@563
    90