three way handshake sync
authorVolker Birk <vb@pep-project.org>
Sat, 13 Apr 2019 23:23:35 +0200
branchsync
changeset 351098f79218de04
parent 3509 a9c0c6f31c56
child 3511 f0a747c09c45
three way handshake
sync/cond_act_sync.yml2
sync/sync.fsm
     1.1 --- a/sync/cond_act_sync.yml2	Sat Apr 13 22:18:57 2019 +0200
     1.2 +++ b/sync/cond_act_sync.yml2	Sat Apr 13 23:23:35 2019 +0200
     1.3 @@ -37,6 +37,14 @@
     1.4      *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
     1.5  ||
     1.6  
     1.7 +condition sameTransaction
     1.8 +||
     1.9 +    TID_t *t1 = &session->sync_state.keysync.transaction;
    1.10 +    TID_t *t2 = &session->own_sync_state.transaction;
    1.11 +
    1.12 +    *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
    1.13 +||
    1.14 +
    1.15  condition keyElectionWon
    1.16  ||
    1.17      pEp_identity *from = session->sync_state.common.from;
    1.18 @@ -91,7 +99,7 @@
    1.19      ||
    1.20  }
    1.21  
    1.22 -action openChallenge
    1.23 +action newChallenge
    1.24      call "new_UUID" with "dst" > &session->own_sync_state.challenge
    1.25  
    1.26  action storeChallenge call "copy_UUID" {
    1.27 @@ -99,8 +107,21 @@
    1.28      with "dst" > &session->own_sync_state.challenge
    1.29  }
    1.30  
    1.31 -action openTransaction
    1.32 +action openTransaction {
    1.33 +||
    1.34 +    for (int i=0; i<session->sync_state.keysync.transaction.size; ++i) {
    1.35 +        if (session->sync_state.keysync.transaction.buf[i])
    1.36 +            return PEP_STATUS_OK;
    1.37 +    }
    1.38 +||
    1.39      call "new_UUID" with "dst" > &session->sync_state.keysync.transaction
    1.40 +}
    1.41 +
    1.42 +action closeTransaction
    1.43 +||
    1.44 +    memset(session->sync_state.keysync.transaction.buf, 0,
    1.45 +            session->sync_state.keysync.transaction.size);
    1.46 +||
    1.47  
    1.48  action storeTransaction call "copy_UUID" {
    1.49      with "src" > &session->sync_state.keysync.transaction
     2.1 --- a/sync/sync.fsm	Sat Apr 13 22:18:57 2019 +0200
     2.2 +++ b/sync/sync.fsm	Sat Apr 13 23:23:35 2019 +0200
     2.3 @@ -23,7 +23,8 @@
     2.4  
     2.5          state Sole timeout=off {
     2.6              on Init {
     2.7 -                do openChallenge; // own challenge
     2.8 +                do newChallenge;
     2.9 +                do closeTransaction;
    2.10                  send Beacon;
    2.11              }
    2.12  
    2.13 @@ -46,28 +47,24 @@
    2.14                  }
    2.15              }
    2.16  
    2.17 -            on HandshakeRequest {
    2.18 -                if weAreFirst {
    2.19 -                    if challengeAccepted {
    2.20 -                        // first is receiving HandshakeRequest
    2.21 -                        do storeTransaction;
    2.22 -                        // first is sending HandshakeAnswer
    2.23 -                        send HandshakeAnswer;
    2.24 -                        if partnerIsGrouped
    2.25 -                            go HandshakingWithGroup;
    2.26 -                        go HandshakingNewFirst;
    2.27 -                    }
    2.28 +            on HandshakeRequest if challengeAccepted {
    2.29 +                if sameTransaction {
    2.30 +                    // this is our own handshake request; ignore
    2.31 +                }
    2.32 +                else {
    2.33 +                    // first is receiving HandshakeRequest
    2.34 +                    do storeTransaction;
    2.35 +                    // first is sending HandshakeAnswer
    2.36 +                    send HandshakeAnswer;
    2.37 +                    if partnerIsGrouped
    2.38 +                        go HandshakingWithGroup;
    2.39 +                    go HandshakingNewFirst;
    2.40                  }
    2.41              }
    2.42  
    2.43 -            on HandshakeAnswer {
    2.44 -                if weAreFirst {
    2.45 -                    // ignore
    2.46 -                }
    2.47 -                else {
    2.48 -                    // second is receiving HandshakeAnswer
    2.49 -                    go HandshakingNewSecond;
    2.50 -                }
    2.51 +            on HandshakeAnswer if sameTransaction {
    2.52 +                // second is receiving HandshakeAnswer
    2.53 +                go HandshakingNewSecond;
    2.54              }
    2.55          }
    2.56