sync/sync.fsm
author Volker Birk <vb@pep-project.org>
Tue, 03 May 2016 08:37:38 +0200
changeset 567 798f20221c9c
parent 566 3ddd22fa5cac
child 568 17b2543e1350
permissions -rw-r--r--
doc
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@566
    24
            on Beacon(partner)  // this event will not happen for already
vb@566
    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@563
    36
            on HandshakeRejected {
vb@563
    37
                do reject(partner);
vb@563
    38
                go Sole;
vb@563
    39
            }
vb@563
    40
            on HandshakeAccepted {
vb@567
    41
                if keyElectionWon(partner) {    // an already existing group
vb@567
    42
                                                // always wins
vb@563
    43
                    storeOwnKeysAsGroupKeys;
vb@563
    44
                    sendGroupKeys(partner);
vb@563
    45
                    go Grouped;
vb@563
    46
                }
vb@563
    47
                go WaitForGroupKeys(partner);
vb@563
    48
            }
vb@563
    49
        }
vb@563
    50
    
vb@563
    51
        state WaitForGroupKeys(identity partner) {
vb@563
    52
            on ReceiveGroupKeys(partner) {
vb@563
    53
                storeGroupKeys(partner);
vb@563
    54
                go Grouped;
vb@563
    55
            }
vb@563
    56
        }
vb@563
    57
vb@563
    58
        state Grouped {
vb@563
    59
            on KeyGen
vb@565
    60
                do sendOwnKeys; // always send all keys
vb@563
    61
            on HandshakeRequest(identity partner) {
vb@563
    62
                do sendHandshakeRequest;
vb@563
    63
                do showHandshake(partner);
vb@563
    64
            }
vb@563
    65
            on HandshakeRejected {
vb@563
    66
                do reject(partner);
vb@563
    67
                go Grouped;
vb@563
    68
            }
vb@563
    69
            on HandshakeAccepted {
vb@563
    70
vb@563
    71
            }
vb@563
    72
        }
vb@563
    73
    }
vb@563
    74
}
vb@563
    75