move into Sync implementation sync
authorVolker Birk <vb@pep-project.org>
Sun, 14 Apr 2019 09:59:45 +0200
branchsync
changeset 3514ff5d113bf2b3
parent 3513 ba228219d1f9
child 3515 287699a9aa7c
move into Sync implementation
src/message_api.c
sync/cond_act_sync.yml2
sync/sync.fsm
     1.1 --- a/src/message_api.c	Sat Apr 13 23:44:30 2019 +0200
     1.2 +++ b/src/message_api.c	Sun Apr 14 09:59:45 2019 +0200
     1.3 @@ -3792,12 +3792,6 @@
     1.4      return status;
     1.5  }
     1.6  
     1.7 -static bool _own_sync_beacon(PEP_STATUS status, const char *sync_fpr,
     1.8 -        const char *from_fpr) {
     1.9 -    return status == PEP_UNENCRYPTED && sync_fpr && sync_fpr[0] &&
    1.10 -        from_fpr && from_fpr[0] && strcmp(sync_fpr, from_fpr) == 0;
    1.11 -}
    1.12 -
    1.13  DYNAMIC_API PEP_STATUS decrypt_message(
    1.14          PEP_SESSION session,
    1.15          message *src,
    1.16 @@ -3830,10 +3824,8 @@
    1.17          const char *data;
    1.18          char *sync_fpr = NULL;
    1.19          PEP_STATUS tmpstatus = base_extract_message(session, msg, &size, &data, &sync_fpr);
    1.20 -        if (!tmpstatus && size && data) {
    1.21 -            if (!_own_sync_beacon(status, sync_fpr, msg->from->fpr))
    1.22 -                signal_Sync_message(session, *rating, data, size, msg->from, sync_fpr);
    1.23 -        }
    1.24 +        if (!tmpstatus && size && data)
    1.25 +            signal_Sync_message(session, *rating, data, size, msg->from, sync_fpr);
    1.26          free(sync_fpr);
    1.27      }
    1.28  
     2.1 --- a/sync/cond_act_sync.yml2	Sat Apr 13 23:44:30 2019 +0200
     2.2 +++ b/sync/cond_act_sync.yml2	Sun Apr 14 09:59:45 2019 +0200
     2.3 @@ -37,6 +37,14 @@
     2.4      *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
     2.5  ||
     2.6  
     2.7 +condition sameChallenge
     2.8 +||
     2.9 +    TID_t *t1 = &session->sync_state.keysync.challenge;
    2.10 +    TID_t *t2 = &session->own_sync_state.challenge;
    2.11 +
    2.12 +    *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
    2.13 +||
    2.14 +
    2.15  condition sameTransaction
    2.16  ||
    2.17      TID_t *t1 = &session->sync_state.keysync.transaction;
     3.1 --- a/sync/sync.fsm	Sat Apr 13 23:44:30 2019 +0200
     3.2 +++ b/sync/sync.fsm	Sun Apr 14 09:59:45 2019 +0200
     3.3 @@ -35,15 +35,20 @@
     3.4                  send Beacon;
     3.5  
     3.6              on Beacon {
     3.7 -                if weAreFirst {
     3.8 -                    send Beacon;
     3.9 +                if sameChallenge {
    3.10 +                    // this is out own beacon; ignore
    3.11                  }
    3.12 -                else /* we are second */ {
    3.13 -                    do storeChallenge; // partner's challenge
    3.14 -                    do openTransaction; // NOP if transaction already open
    3.15 -                    do storeTransaction;
    3.16 -                    // second is sending HandshakeRequest
    3.17 -                    send HandshakeRequest;
    3.18 +                else {
    3.19 +                    if weAreFirst {
    3.20 +                        send Beacon;
    3.21 +                    }
    3.22 +                    else /* we are second */ {
    3.23 +                        do storeChallenge; // partner's challenge
    3.24 +                        do openTransaction; // NOP if transaction already open
    3.25 +                        do storeTransaction;
    3.26 +                        // second is sending HandshakeRequest
    3.27 +                        send HandshakeRequest;
    3.28 +                    }
    3.29                  }
    3.30              }
    3.31