sync/sync.fsm
author Volker Birk <vb@pep-project.org>
Tue, 03 May 2016 08:35:09 +0200
changeset 566 3ddd22fa5cac
parent 565 e29bd4aeb5ea
child 567 798f20221c9c
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@563
    41
                if keyElectionWon(partner) {
vb@563
    42
                    storeOwnKeysAsGroupKeys;
vb@563
    43
                    sendGroupKeys(partner);
vb@563
    44
                    go Grouped;
vb@563
    45
                }
vb@563
    46
                go WaitForGroupKeys(partner);
vb@563
    47
            }
vb@563
    48
        }
vb@563
    49
    
vb@563
    50
        state WaitForGroupKeys(identity partner) {
vb@563
    51
            on ReceiveGroupKeys(partner) {
vb@563
    52
                storeGroupKeys(partner);
vb@563
    53
                go Grouped;
vb@563
    54
            }
vb@563
    55
        }
vb@563
    56
vb@563
    57
        state Grouped {
vb@563
    58
            on KeyGen
vb@565
    59
                do sendOwnKeys; // always send all keys
vb@563
    60
            on HandshakeRequest(identity partner) {
vb@563
    61
                do sendHandshakeRequest;
vb@563
    62
                do showHandshake(partner);
vb@563
    63
            }
vb@563
    64
            on HandshakeRejected {
vb@563
    65
                do reject(partner);
vb@563
    66
                go Grouped;
vb@563
    67
            }
vb@563
    68
            on HandshakeAccepted {
vb@563
    69
vb@563
    70
            }
vb@563
    71
        }
vb@563
    72
    }
vb@563
    73
}
vb@563
    74