sync/sync.fsm
author Volker Birk <vb@pep-project.org>
Tue, 03 May 2016 08:30:22 +0200
changeset 563 6f0c0366fc63
child 565 e29bd4aeb5ea
permissions -rw-r--r--
draft handshake
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@563
    23
                do sendBeacon; // cry, baby
vb@563
    24
            on Beacon(partner)
vb@563
    25
                do sendHandshakeRequest;
vb@563
    26
            on HandshakeRequest(identity partner) {
vb@563
    27
                do sendHandshakeRequest;
vb@563
    28
                go HandshakingSole(partner);
vb@563
    29
            }
vb@563
    30
        }
vb@563
    31
vb@563
    32
        state HandshakingSole(identity partner) {
vb@563
    33
            on init
vb@563
    34
                do showHandshake(partner);
vb@563
    35
            on HandshakeRejected {
vb@563
    36
                do reject(partner);
vb@563
    37
                go Sole;
vb@563
    38
            }
vb@563
    39
            on HandshakeAccepted {
vb@563
    40
                if keyElectionWon(partner) {
vb@563
    41
                    storeOwnKeysAsGroupKeys;
vb@563
    42
                    sendGroupKeys(partner);
vb@563
    43
                    go Grouped;
vb@563
    44
                }
vb@563
    45
                go WaitForGroupKeys(partner);
vb@563
    46
            }
vb@563
    47
        }
vb@563
    48
    
vb@563
    49
        state WaitForGroupKeys(identity partner) {
vb@563
    50
            on ReceiveGroupKeys(partner) {
vb@563
    51
                storeGroupKeys(partner);
vb@563
    52
                go Grouped;
vb@563
    53
            }
vb@563
    54
        }
vb@563
    55
vb@563
    56
        state Grouped {
vb@563
    57
            on KeyGen
vb@563
    58
                do sendOwnKeys;
vb@563
    59
            on HandshakeRequest(identity partner) {
vb@563
    60
                do sendHandshakeRequest;
vb@563
    61
                do showHandshake(partner);
vb@563
    62
            }
vb@563
    63
            on HandshakeRejected {
vb@563
    64
                do reject(partner);
vb@563
    65
                go Grouped;
vb@563
    66
            }
vb@563
    67
            on HandshakeAccepted {
vb@563
    68
vb@563
    69
            }
vb@563
    70
        }
vb@563
    71
    }
vb@563
    72
}
vb@563
    73