renaming things so they make sense sync
authorVolker Birk <vb@pep-project.org>
Wed, 29 May 2019 16:34:12 +0200
branchsync
changeset 3772f4d6efa63ee1
parent 3768 7fc561191d28
child 3773 874ce1a8837a
renaming things so they make sense
src/pEp_internal.h
sync/cond_act_sync.yml2
sync/gen_message_func.ysl2
     1.1 --- a/src/pEp_internal.h	Wed May 29 16:15:30 2019 +0200
     1.2 +++ b/src/pEp_internal.h	Wed May 29 16:34:12 2019 +0200
     1.3 @@ -251,7 +251,6 @@
     1.4      void *sync_management;
     1.5      void *sync_obj;
     1.6      struct Sync_state_s sync_state;
     1.7 -    struct own_Sync_state_s own_sync_state;
     1.8  
     1.9  //     void* sync_state_payload;
    1.10  //     char sync_uuid[37];
     2.1 --- a/sync/cond_act_sync.yml2	Wed May 29 16:15:30 2019 +0200
     2.2 +++ b/sync/cond_act_sync.yml2	Wed May 29 16:34:12 2019 +0200
     2.3 @@ -20,35 +20,35 @@
     2.4  
     2.5  condition weAreFirst
     2.6  ||
     2.7 -    TID_t *t1 = &session->sync_state.keysync.challenge;
     2.8 -    TID_t *t2 = &session->own_sync_state.challenge;
     2.9 +    TID_t *t1 = &session->sync_state.keysync_buf.challenge;
    2.10 +    TID_t *t2 = &session->sync_state.own.challenge;
    2.11  
    2.12      *result = _TID_greater(t1, t2);
    2.13  ||
    2.14  
    2.15  condition partnerIsGrouped
    2.16 -|> *result = session->sync_state.keysync.is_group;
    2.17 +|> *result = session->sync_state.keysync_buf.is_group;
    2.18  
    2.19  condition challengeAccepted
    2.20  ||
    2.21 -    TID_t *t1 = &session->sync_state.keysync.challenge;
    2.22 -    TID_t *t2 = &session->own_sync_state.challenge;
    2.23 +    TID_t *t1 = &session->sync_state.keysync_buf.challenge;
    2.24 +    TID_t *t2 = &session->sync_state.own.challenge;
    2.25  
    2.26      *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
    2.27  ||
    2.28  
    2.29  condition sameChallenge
    2.30  ||
    2.31 -    TID_t *t1 = &session->sync_state.keysync.challenge;
    2.32 -    TID_t *t2 = &session->own_sync_state.challenge;
    2.33 +    TID_t *t1 = &session->sync_state.keysync_buf.challenge;
    2.34 +    TID_t *t2 = &session->sync_state.own.challenge;
    2.35  
    2.36      *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
    2.37  ||
    2.38  
    2.39  condition sameTransaction
    2.40  ||
    2.41 -    TID_t *t1 = &session->sync_state.keysync.negotiation;
    2.42 -    TID_t *t2 = &session->own_sync_state.negotiation;
    2.43 +    TID_t *t1 = &session->sync_state.keysync_buf.negotiation;
    2.44 +    TID_t *t2 = &session->sync_state.own.negotiation;
    2.45  
    2.46      // test if TID is identical
    2.47      *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0;
    2.48 @@ -56,11 +56,11 @@
    2.49  
    2.50  condition sameTransactionAndPartner
    2.51  ||
    2.52 -    TID_t *t1 = &session->sync_state.keysync.negotiation;
    2.53 -    TID_t *t2 = &session->own_sync_state.negotiation;
    2.54 +    TID_t *t1 = &session->sync_state.keysync_buf.negotiation;
    2.55 +    TID_t *t2 = &session->sync_state.own.negotiation;
    2.56  
    2.57      const char *s1 = session->sync_state.comm_partner.signature_fpr;
    2.58 -    const char *s2 = session->own_sync_state.signature_fpr;
    2.59 +    const char *s2 = session->sync_state.own.signature_fpr;
    2.60  
    2.61      // test if TID is identical
    2.62      *result = t1->size == t2->size && memcmp(t1->buf, t2->buf, t1->size) == 0
    2.63 @@ -143,73 +143,68 @@
    2.64  
    2.65  action newChallenge {
    2.66      // random new challenge
    2.67 -    call "new_UUID" with "dst" > &session->own_sync_state.challenge
    2.68 -    // store a copy of this challenge
    2.69 -    call "copy_UUID" {
    2.70 -        with "src" > &session->own_sync_state.challenge
    2.71 -        with "dst" > &session->sync_state.temp.challenge
    2.72 -    }
    2.73 +    call "new_UUID" with "dst" > &session->sync_state.own.challenge
    2.74  }
    2.75  
    2.76  action replyChallenge call "copy_UUID" {
    2.77 -    with "src" > &session->sync_state.keysync.challenge
    2.78 -    with "dst" > &session->own_sync_state.challenge
    2.79 +    with "src" > &session->sync_state.keysync_buf.challenge
    2.80 +    with "dst" > &session->sync_state.comm_partner.challenge
    2.81  }
    2.82  
    2.83  action useOwnChallenge call "copy_UUID" {
    2.84 -    with "src" > &session->sync_state.temp.challenge
    2.85 -    with "dst" > &session->own_sync_state.challenge
    2.86 +    with "src" > &session->sync_state.own.challenge
    2.87 +    with "dst" > &session->sync_state.keysync_buf.challenge
    2.88  }
    2.89  
    2.90  action newTransaction {
    2.91  ||
    2.92      // sender key must be stable while transaction
    2.93      assert(session->sync_state.comm_partner.signature_fpr);
    2.94 -    free(session->own_sync_state.signature_fpr);
    2.95 -    session->own_sync_state.signature_fpr
    2.96 +    free(session->sync_state.own.signature_fpr);
    2.97 +    session->sync_state.own.signature_fpr
    2.98              = strdup(session->sync_state.comm_partner.signature_fpr);
    2.99 -    assert(session->own_sync_state.signature_fpr);
   2.100 -    if (!session->own_sync_state.signature_fpr)
   2.101 +    assert(session->sync_state.own.signature_fpr);
   2.102 +    if (!session->sync_state.own.signature_fpr)
   2.103          return PEP_OUT_OF_MEMORY;
   2.104  
   2.105  ||
   2.106      call "copy_UUID" {
   2.107 -        with "src" > &session->sync_state.keysync.challenge
   2.108 -        with "dst" > &session->sync_state.keysync.negotiation
   2.109 +        with "src" > &session->sync_state.keysync_buf.challenge
   2.110 +        with "dst" > &session->sync_state.keysync_buf.negotiation
   2.111      }
   2.112      call "xor_UUID" {
   2.113 -        with "src" > &session->own_sync_state.challenge
   2.114 -        with "dst" > &session->sync_state.keysync.negotiation
   2.115 +        with "src" > &session->sync_state.own.challenge
   2.116 +        with "dst" > &session->sync_state.keysync_buf.negotiation
   2.117      }
   2.118      call "copy_UUID" {
   2.119 -        with "src" > &session->sync_state.keysync.negotiation
   2.120 -        with "dst" > &session->own_sync_state.negotiation
   2.121 +        with "src" > &session->sync_state.keysync_buf.negotiation
   2.122 +        with "dst" > &session->sync_state.own.negotiation
   2.123      }
   2.124  }
   2.125  
   2.126  action closeTransaction
   2.127  ||
   2.128 -    memset(session->sync_state.keysync.negotiation.buf, 0,
   2.129 -            session->sync_state.keysync.negotiation.size);
   2.130 -    memset(session->own_sync_state.negotiation.buf, 0,
   2.131 -            session->own_sync_state.negotiation.size);
   2.132 +    memset(session->sync_state.keysync_buf.negotiation.buf, 0,
   2.133 +            session->sync_state.keysync_buf.negotiation.size);
   2.134 +    memset(session->sync_state.own.negotiation.buf, 0,
   2.135 +            session->sync_state.own.negotiation.size);
   2.136  ||
   2.137  
   2.138  action storeTransaction {
   2.139  ||
   2.140      // sender key must be stable while transaction
   2.141      assert(session->sync_state.comm_partner.signature_fpr);
   2.142 -    free(session->own_sync_state.signature_fpr);
   2.143 -    session->own_sync_state.signature_fpr
   2.144 +    free(session->sync_state.own.signature_fpr);
   2.145 +    session->sync_state.own.signature_fpr
   2.146              = strdup(session->sync_state.comm_partner.signature_fpr);
   2.147 -    assert(session->own_sync_state.signature_fpr);
   2.148 -    if (!session->own_sync_state.signature_fpr)
   2.149 +    assert(session->sync_state.own.signature_fpr);
   2.150 +    if (!session->sync_state.own.signature_fpr)
   2.151          return PEP_OUT_OF_MEMORY;
   2.152  
   2.153  ||
   2.154      call "copy_UUID" {
   2.155 -        with "src" > &session->sync_state.keysync.negotiation
   2.156 -        with "dst" > &session->own_sync_state.negotiation
   2.157 +        with "src" > &session->sync_state.keysync_buf.negotiation
   2.158 +        with "dst" > &session->sync_state.own.negotiation
   2.159      }
   2.160  }
   2.161  
   2.162 @@ -323,22 +318,22 @@
   2.163      if (status)
   2.164          return status;
   2.165  
   2.166 -    if (session->own_sync_state.own_keys)
   2.167 -        free_stringlist(session->own_sync_state.own_keys);
   2.168 -    session->own_sync_state.own_keys = own_keys;
   2.169 +    if (session->sync_state.own.keys)
   2.170 +        free_stringlist(session->sync_state.own.keys);
   2.171 +    session->sync_state.own.keys = own_keys;
   2.172  
   2.173      identity_list *il;
   2.174      status = _own_identities_retrieve(session, &il, PEP_idf_not_for_sync);
   2.175      if (status)
   2.176          return status;
   2.177  
   2.178 -    IdentityList_from_identity_list(il, &session->sync_state.keysync.ownIdentities);
   2.179 +    IdentityList_from_identity_list(il, &session->sync_state.keysync_buf.ownIdentities);
   2.180      free_identity_list(il);
   2.181  ||
   2.182  
   2.183  action saveGroupKeys
   2.184  ||
   2.185 -    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.ownIdentities, NULL);
   2.186 +    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync_buf.ownIdentities, NULL);
   2.187      if (!il)
   2.188          return PEP_OUT_OF_MEMORY;
   2.189      
   2.190 @@ -359,7 +354,7 @@
   2.191      PEP_STATUS status = PEP_STATUS_OK;
   2.192  
   2.193      // set flag for current keys
   2.194 -    for (identity_list *il = session->own_sync_state.own_identities; il && il->ident ; il = il->next) {
   2.195 +    for (identity_list *il = session->sync_state.own.identities; il && il->ident ; il = il->next) {
   2.196          if (!(il->ident->flags && PEP_idf_not_for_sync)) {
   2.197              status = set_identity_flags(session, il->ident, PEP_idf_devicegroup);
   2.198              if (status)
   2.199 @@ -373,7 +368,7 @@
   2.200      PEP_STATUS status = PEP_STATUS_OK;
   2.201  
   2.202      // set flag for current keys
   2.203 -    for (identity_list *il = session->own_sync_state.own_identities; il && il->ident ; il = il->next) {
   2.204 +    for (identity_list *il = session->sync_state.own.identities; il && il->ident ; il = il->next) {
   2.205          if (!(il->ident->flags && PEP_idf_not_for_sync)) {
   2.206              status = set_identity_flags(session, il->ident, PEP_idf_devicegroup);
   2.207              if (status)
   2.208 @@ -381,11 +376,11 @@
   2.209          }
   2.210      }
   2.211  
   2.212 -    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.ownIdentities, NULL);
   2.213 +    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync_buf.ownIdentities, NULL);
   2.214      if (!il)
   2.215          return PEP_OUT_OF_MEMORY;
   2.216  
   2.217 -    for (il = session->own_sync_state.own_identities; il && il->ident ; il = il->next) {
   2.218 +    for (il = session->sync_state.own.identities; il && il->ident ; il = il->next) {
   2.219          // replace partner's user_id with own user_id
   2.220          free(il->ident->user_id);
   2.221          il->ident->user_id = strdup(session->sync_state.comm_partner.from->user_id);
   2.222 @@ -433,7 +428,7 @@
   2.223          return status;
   2.224      }
   2.225  
   2.226 -    OCTET_STRING_fromBuf(&session->sync_state.keysync.key, ident->fpr, strlen(ident->fpr));
   2.227 +    OCTET_STRING_fromBuf(&session->sync_state.keysync_buf.key, ident->fpr, strlen(ident->fpr));
   2.228      free_identity(ident);
   2.229  ||
   2.230  
   2.231 @@ -454,17 +449,17 @@
   2.232      if (status)
   2.233          return status;
   2.234  
   2.235 -    OCTET_STRING_fromBuf(&session->sync_state.keysync.key, "", 0);
   2.236 +    OCTET_STRING_fromBuf(&session->sync_state.keysync_buf.key, "", 0);
   2.237  ||
   2.238  
   2.239  action tellWeAreGrouped
   2.240  ||
   2.241 -    session->sync_state.keysync.is_group = true;
   2.242 +    session->sync_state.keysync_buf.is_group = true;
   2.243  ||
   2.244  
   2.245  action tellWeAreNotGrouped
   2.246  ||
   2.247 -    session->sync_state.keysync.is_group = false;
   2.248 +    session->sync_state.keysync_buf.is_group = false;
   2.249  ||
   2.250  
   2.251  action disable;
     3.1 --- a/sync/gen_message_func.ysl2	Wed May 29 16:15:30 2019 +0200
     3.2 +++ b/sync/gen_message_func.ysl2	Wed May 29 16:34:12 2019 +0200
     3.3 @@ -39,35 +39,37 @@
     3.4  // state
     3.5  
     3.6  struct «@name»_state_s {
     3.7 -    // state about our communication partner
     3.8 +    // own state
     3.9 +
    3.10 +    struct own_«@name»_state_s {
    3.11 +        stringlist_t *keys;
    3.12 +        identity_list *identities;
    3.13 +
    3.14 +        `` if "func:distinctName(fsm/message/field[@type='TID'])" |>> // TIDs we're using ourselves
    3.15 +        `` for "func:distinctName(fsm/message/field[@type='TID'])" |>> «func:ctype()» «@name»;
    3.16 +    } own;
    3.17 +
    3.18 +    // state we learned about our communication partner
    3.19  
    3.20      struct comm_partner_state_s {
    3.21 -        // transport data
    3.22 +        // transport data we expect
    3.23          pEp_identity *from;
    3.24          char *signature_fpr;
    3.25 +
    3.26 +        // TIDs our comm partner wants to have
    3.27 +        TID_t challenge;
    3.28      } comm_partner;
    3.29  
    3.30 -    struct temporary_state_s {
    3.31 -        // intermediate state / clipboard
    3.32 -        TID_t challenge;
    3.33 -    } temp;
    3.34 +    // buffer for actual transport data coming in
    3.35  
    3.36 +    struct transport_data_s {
    3.37 +        // transport data we got
    3.38 +        pEp_identity *from;
    3.39 +        char *signature_fpr;
    3.40 +    } transport_buf;
    3.41      `` apply "fsm", mode=state
    3.42  };
    3.43  
    3.44 -// own state
    3.45 -
    3.46 -struct own_«@name»_state_s {
    3.47 -    stringlist_t *own_keys;
    3.48 -    identity_list *own_identities;
    3.49 -
    3.50 -    `` if "func:distinctName(fsm/message/field[@type='TID'])" |> // active TIDs
    3.51 -    `` for "func:distinctName(fsm/message/field[@type='TID'])" |> «func:ctype()» «@name»;
    3.52 -
    3.53 -    // transport data
    3.54 -    char *signature_fpr;
    3.55 -};
    3.56 -
    3.57  void free_«@name»_state(PEP_SESSION session);
    3.58  
    3.59  // functions for protocol «@name»
    3.60 @@ -95,7 +97,7 @@
    3.61      int state;
    3.62  
    3.63      `` for "func:distinctName(message/field)" |> «func:ctype()» «@name»;
    3.64 -} «yml:lcase(@name)»;
    3.65 +} «yml:lcase(@name)»_buf;
    3.66  ||
    3.67  
    3.68  template "protocol", mode=impl