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