a dangling else sync
authorVolker Birk <vb@pep.foundation>
Wed, 29 Aug 2018 23:01:09 +0200
branchsync
changeset 290792f22b19b09e
parent 2906 2d5db5aa47d6
child 2908 2bc360b56ad4
a dangling else
sync/cond_act_sync.yml2
sync/fsm.yml2
sync/gen_statemachine.ysl2
sync/sync.fsm
     1.1 --- a/sync/cond_act_sync.yml2	Wed Aug 29 22:16:18 2018 +0200
     1.2 +++ b/sync/cond_act_sync.yml2	Wed Aug 29 23:01:09 2018 +0200
     1.3 @@ -26,14 +26,6 @@
     1.4      *result = _TID_greater(t1, t2);
     1.5  ||
     1.6  
     1.7 -condition weAreSecond
     1.8 -||
     1.9 -    TID_t *t1 = &session->sync_state.keysync.challenge;
    1.10 -    TID_t *t2 = &session->own_sync_state.challenge;
    1.11 -
    1.12 -    *result = !_TID_greater(t1, t2);
    1.13 -||
    1.14 -
    1.15  condition partnerIsGrouped
    1.16  |> *result = session->sync_state.keysync.is_group;
    1.17  
     2.1 --- a/sync/fsm.yml2	Wed Aug 29 22:16:18 2018 +0200
     2.2 +++ b/sync/fsm.yml2	Wed Aug 29 23:01:09 2018 +0200
     2.3 @@ -46,6 +46,7 @@
     2.4  // a condition is for different cases
     2.5  
     2.6  decl condition @name, if is condition;
     2.7 +decl else;
     2.8  
     2.9  // some events have messages on the line signalling the event to the
    2.10  // communication partner
     3.1 --- a/sync/gen_statemachine.ysl2	Wed Aug 29 22:16:18 2018 +0200
     3.2 +++ b/sync/gen_statemachine.ysl2	Wed Aug 29 23:01:09 2018 +0200
     3.3 @@ -805,7 +805,7 @@
     3.4          if "condition|action|send" |
     3.5          ||
     3.6              «../../@name»_SERVICE_LOG("received event", "«@name»");
     3.7 -            `` apply "transition|action|condition|send";
     3.8 +            `` apply "transition|action|condition|else|send";
     3.9          ||
    3.10          if "name(*[last()])!='transition'" {
    3.11              |
    3.12 @@ -862,7 +862,17 @@
    3.13          if (result) {
    3.14              «$fsm/@name»_SERVICE_LOG("condition applies", "«@name»");
    3.15          ||
    3.16 -        apply "transition|action|condition|send";
    3.17 +        apply "transition|action|condition|else|send";
    3.18 +        | }
    3.19 +    }
    3.20 +
    3.21 +    template "else" {
    3.22 +        if "not(name(preceding-sibling::*[last()]) = 'condition')"
    3.23 +            error "else without if";
    3.24 +
    3.25 +        | else {
    3.26 +        |> «ancestor::fsm/@name»_SERVICE_LOG("condition does not apply", "«preceding-sibling::*[last()]/@name»");
    3.27 +        apply "transition|action|condition|else|send";
    3.28          | }
    3.29      }
    3.30  }
     4.1 --- a/sync/sync.fsm	Wed Aug 29 22:16:18 2018 +0200
     4.2 +++ b/sync/sync.fsm	Wed Aug 29 23:01:09 2018 +0200
     4.3 @@ -33,14 +33,15 @@
     4.4                  send Beacon;
     4.5  
     4.6              on Beacon {
     4.7 -                if weAreSecond {
     4.8 +                if weAreFirst {
     4.9 +                    send Beacon;
    4.10 +                }
    4.11 +                else {
    4.12                      do storeChallenge; // partner's challenge
    4.13                      do openTransaction;
    4.14                      do storeTransaction;
    4.15                      send HandshakeRequest;
    4.16                  }
    4.17 -                if weAreFirst
    4.18 -                    send Beacon;
    4.19              }
    4.20  
    4.21              on HandshakeRequest {