resolve handshake symmetry sync
authorVolker Birk <vb@pep.foundation>
Wed, 29 Aug 2018 21:40:59 +0200
branchsync
changeset 29025692b0768f9e
parent 2901 0d30b013e1b2
child 2903 33549a7c7191
resolve handshake symmetry
sync/cond_act_sync.yml2
sync/gen_actions.ysl2
sync/sync.fsm
     1.1 --- a/sync/cond_act_sync.yml2	Wed Aug 29 20:38:40 2018 +0200
     1.2 +++ b/sync/cond_act_sync.yml2	Wed Aug 29 21:40:59 2018 +0200
     1.3 @@ -18,6 +18,42 @@
     1.4      |> *result = _result > 0;
     1.5  }
     1.6  
     1.7 +condition weAreFirst
     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 +    assert(t1 && t2);
    1.13 +
    1.14 +    if (!t2) {
    1.15 +        *result = false;
    1.16 +    }
    1.17 +    else {
    1.18 +        if (!t1)
    1.19 +            *result = true;
    1.20 +        else
    1.21 +            *result = _TID_greater(t1, t2);
    1.22 +    }
    1.23 +||
    1.24 +
    1.25 +condition weAreSecond
    1.26 +||
    1.27 +    TID_t *t1 = &session->sync_state.keysync.challenge;
    1.28 +    TID_t *t2 = &session->own_sync_state.challenge;
    1.29 +
    1.30 +    assert(t1 && t2);
    1.31 +
    1.32 +    if (!t1) {
    1.33 +        *result = false;
    1.34 +    }
    1.35 +    else {
    1.36 +        if (!t2)
    1.37 +            *result = true;
    1.38 +        else
    1.39 +            *result = !_TID_greater(t1, t2);
    1.40 +    }
    1.41 +||
    1.42 +
    1.43  condition partnerIsGrouped
    1.44  |> *result = session->sync_state.keysync.is_group;
    1.45  
     2.1 --- a/sync/gen_actions.ysl2	Wed Aug 29 20:38:40 2018 +0200
     2.2 +++ b/sync/gen_actions.ysl2	Wed Aug 29 21:40:59 2018 +0200
     2.3 @@ -35,6 +35,22 @@
     2.4              #include "«@name»_impl.h"
     2.5              `` for "fsm" | #include "«@name»_fsm.h"
     2.6  
     2.7 +            static bool _TID_greater(TID_t *t1, TID_t *t2)
     2.8 +            {
     2.9 +                if (t1->size > t2->size)
    2.10 +                    return true;
    2.11 +
    2.12 +                if (t2->size > t1->size)
    2.13 +                    return false;
    2.14 +
    2.15 +                for (int i=0; i<t1->size; i++) {
    2.16 +                    if (t1->buf[i] > t2->buf[i])
    2.17 +                        return true;
    2.18 +                }
    2.19 +
    2.20 +                return false;
    2.21 +            }
    2.22 +
    2.23              ||
    2.24              apply "func:distinctName(//condition)", 0;
    2.25              apply "func:distinctName(//action[not(starts-with(@name, 'send'))])", 0;
     3.1 --- a/sync/sync.fsm	Wed Aug 29 20:38:40 2018 +0200
     3.2 +++ b/sync/sync.fsm	Wed Aug 29 21:40:59 2018 +0200
     3.3 @@ -33,10 +33,14 @@
     3.4                  send Beacon;
     3.5  
     3.6              on Beacon {
     3.7 -                do storeChallenge; // partner's challenge
     3.8 -                do openTransaction;
     3.9 -                do storeTransaction;
    3.10 -                send HandshakeRequest;
    3.11 +                if weAreSecond {
    3.12 +                    do storeChallenge; // partner's challenge
    3.13 +                    do openTransaction;
    3.14 +                    do storeTransaction;
    3.15 +                    send HandshakeRequest;
    3.16 +                }
    3.17 +                if weAreFirst
    3.18 +                    send Beacon;
    3.19              }
    3.20  
    3.21              on HandshakeRequest {