sync/sync.fsm
author Volker Birk <vb@pep-project.org>
Tue, 03 May 2016 08:49:27 +0200
changeset 571 2b1666bc1b45
parent 570 963682eaf5c8
child 582 fa50f202b57c
permissions -rw-r--r--
bugfixes
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@563
    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
vb@571
    24
            on Beacon(identity partner) // this event will not happen for already
vb@571
    25
                                        // rejected partners
vb@563
    26
                do sendHandshakeRequest;
vb@563
    27
            on HandshakeRequest(identity partner) {
vb@563
    28
                do sendHandshakeRequest;
vb@563
    29
                go HandshakingSole(partner);
vb@563
    30
            }
vb@563
    31
        }
vb@563
    32
vb@563
    33
        state HandshakingSole(identity partner) {
vb@563
    34
            on init
vb@563
    35
                do showHandshake(partner);
vb@571
    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
            }
vb@571
    41
            on HandshakeAccepted(partner) {
vb@567
    42
                if keyElectionWon(partner) {    // an already existing group
vb@567
    43
                                                // always wins
vb@563
    44
                    storeOwnKeysAsGroupKeys;
vb@563
    45
                    sendGroupKeys(partner);
vb@563
    46
                    go Grouped;
vb@563
    47
                }
vb@563
    48
                go WaitForGroupKeys(partner);
vb@563
    49
            }
vb@563
    50
        }
vb@563
    51
    
vb@563
    52
        state WaitForGroupKeys(identity partner) {
vb@569
    53
            on ReceiveGroupKeys(identity partner) {
vb@563
    54
                storeGroupKeys(partner);
vb@563
    55
                go Grouped;
vb@563
    56
            }
vb@568
    57
            on Cancel go Sole;
vb@570
    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
vb@563
    67
            on HandshakeRequest(identity partner) {
vb@563
    68
                do sendHandshakeRequest;
vb@563
    69
                do showHandshake(partner);
vb@563
    70
            }
vb@569
    71
            on HandshakeRejected(identity partner)
vb@563
    72
                do reject(partner);
vb@569
    73
            on HandshakeAccepted(identity partner)
vb@570
    74
                do sendGroupKeys(partner);
vb@570
    75
            on Reject(identity partner)
vb@570
    76
                do reject partner;
vb@563
    77
        }
vb@563
    78
    }
vb@563
    79
}
vb@563
    80