sync/devicegroup.fsm
author Volker Birk <vb@pep-project.org>
Mon, 18 Jul 2016 10:15:06 +0200
changeset 907 8f5cca5bfa2d
parent 809 3a8dced942e3
child 939 ed7dfdae3031
permissions -rw-r--r--
adding OIDs
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@807
    12
    fsm DeviceState filename=sync {
vb@624
    13
        state InitState {
vb@624
    14
            on Init {
vb@624
    15
                if (storedGroupKeys)
vb@624
    16
                    go Grouped;
vb@624
    17
                go Sole;
vb@624
    18
            }
vb@563
    19
        }
vb@563
    20
vb@563
    21
        state Sole {
vb@563
    22
            on KeyGen
vb@563
    23
                do sendBeacon;
vb@563
    24
            on CannotDecrypt
vb@566
    25
                do sendBeacon;  // cry, baby
Edouard@594
    26
            on Beacon(Identity partner) // this event will not happen for already
vb@571
    27
                                        // rejected partners
vb@582
    28
                do sendHandshakeRequest(partner);
Edouard@594
    29
            on HandshakeRequest(Identity partner) {
vb@582
    30
                do sendHandshakeRequest(partner);
vb@563
    31
                go HandshakingSole(partner);
vb@563
    32
            }
vb@563
    33
        }
vb@563
    34
Edouard@594
    35
        state HandshakingSole(Identity partner) {
vb@582
    36
            on Init
vb@563
    37
                do showHandshake(partner);
Edouard@594
    38
            on HandshakeRejected(Identity partner) {
vb@907
    39
                do reject(partner);             // stores rejection of partner
vb@563
    40
                go Sole;
vb@563
    41
            }
Edouard@594
    42
            on HandshakeAccepted(Identity partner) {
vb@567
    43
                if keyElectionWon(partner) {    // an already existing group
vb@567
    44
                                                // always wins
vb@711
    45
                    ownGroupKeys;
vb@711
    46
                    sendGroupKeys(partner);
vb@563
    47
                    go Grouped;
vb@563
    48
                }
Edouard@594
    49
                go WaitForGroupKeys(Identity partner);
vb@563
    50
            }
vb@563
    51
        }
vb@563
    52
    
Edouard@594
    53
        state WaitForGroupKeys(Identity partner) {
vb@711
    54
            on GroupKeys(Identity partner, Stringlist keys) {
Edouard@605
    55
                do storeGroupKeys(partner, keys);
vb@563
    56
                go Grouped;
vb@563
    57
            }
vb@568
    58
            on Cancel go Sole;
Edouard@594
    59
            on Reject(Identity partner) {
vb@569
    60
                do reject(partner);
vb@569
    61
                go Sole;
vb@569
    62
            }
vb@563
    63
        }
vb@563
    64
vb@563
    65
        state Grouped {
vb@563
    66
            on KeyGen
vb@711
    67
                do sendGroupKeys; // always send all keys
Edouard@594
    68
            on HandshakeRequest(Identity partner) {
vb@582
    69
                do sendHandshakeRequest(partner);
vb@563
    70
                do showHandshake(partner);
vb@563
    71
            }
Edouard@594
    72
            on HandshakeRejected(Identity partner)
vb@563
    73
                do reject(partner);
Edouard@594
    74
            on HandshakeAccepted(Identity partner)
vb@711
    75
                do sendGroupKeys(partner);
Edouard@594
    76
            on Reject(Identity partner)
vb@570
    77
                do reject partner;
vb@563
    78
        }
Edouard@613
    79
vb@743
    80
        tag InitState 0;
vb@711
    81
        tag Beacon 1;
vb@711
    82
        tag HandshakeRequest 2;
vb@711
    83
        tag GroupKeys 3;
Edouard@613
    84
    }
vb@563
    85
}
vb@563
    86