sync/devicegroup.fsm
branchkeysync
changeset 1216 76e7a6748913
parent 1161 9a1f9ec6561a
child 1236 991afc1aa2a1
     1.1 --- a/sync/devicegroup.fsm	Tue Sep 27 23:26:41 2016 +0200
     1.2 +++ b/sync/devicegroup.fsm	Wed Sep 28 14:34:36 2016 +0200
     1.3 @@ -52,13 +52,14 @@
     1.4                      do sendGroupKeys(partner);
     1.5                      go Grouped;
     1.6                  }
     1.7 -                go WaitForGroupKeys(Identity partner);
     1.8 +                go WaitForGroupKeysSole(Identity partner);
     1.9              }
    1.10          }
    1.11      
    1.12 -        state WaitForGroupKeys(Identity partner) {
    1.13 +        state WaitForGroupKeysSole(Identity partner) {
    1.14              on GroupKeys(Identity partner, Stringlist keys) {
    1.15                  do storeGroupKeys(partner, keys);
    1.16 +                // TODO : add a callback to signal finished waiting for group keys
    1.17                  go Grouped;
    1.18              }
    1.19              on Cancel go Sole;
    1.20 @@ -71,19 +72,30 @@
    1.21          state Grouped {
    1.22              on KeyGen
    1.23                  do sendGroupKeys; // always send all keys
    1.24 +            on Beacon(Identity partner)
    1.25 +                do sendHandshakeRequest(partner);
    1.26              on HandshakeRequest(Identity partner) {
    1.27                  do sendHandshakeRequest(partner);
    1.28 -                do showHandshake(partner);
    1.29 +                go HandshakingGrouped(partner);
    1.30              }
    1.31 -            on HandshakeRejected(Identity partner)
    1.32 -                do rejectHandshake(partner);
    1.33 -            on HandshakeAccepted(Identity partner){
    1.34 +        }
    1.35 +
    1.36 +        state HandshakingGrouped(Identity partner) {
    1.37 +            on Init
    1.38 +                do showHandshake(partner);
    1.39 +            on HandshakeRejected(Identity partner) {
    1.40 +                do rejectHandshake(partner);             // stores rejection of partner
    1.41 +                go Grouped;
    1.42 +            }
    1.43 +            on HandshakeAccepted(Identity partner) {
    1.44                  do acceptHandshake(partner); 
    1.45 +
    1.46 +                // an already existing group always wins
    1.47                  do sendGroupKeys(partner);
    1.48 +                go Grouped;
    1.49              }
    1.50 -            on Reject(Identity partner)
    1.51 -                do rejectHandshake partner;
    1.52          }
    1.53 +    
    1.54  
    1.55          tag Init 1;
    1.56          tag Beacon 2;