KeySync: fixed problem with GroupKeys events not being generated. Added better memory handling policy for keysync events extras. GroupMerge
authorEdouard Tisserant <edouard@pep-project.org>
Fri, 17 Feb 2017 19:51:04 +0100
branchGroupMerge
changeset 15876db4fde2cdae
parent 1586 599deda50386
child 1588 1a43a7eddf90
KeySync: fixed problem with GroupKeys events not being generated. Added better memory handling policy for keysync events extras.
src/sync_actions.c
src/sync_impl.c
sync/gen_statemachine.ysl2
sync/generated/sync_fsm.h
     1.1 --- a/src/sync_actions.c	Thu Feb 16 12:43:35 2017 +0100
     1.2 +++ b/src/sync_actions.c	Fri Feb 17 19:51:04 2017 +0100
     1.3 @@ -220,6 +220,10 @@
     1.4  
     1.5      for (identity_list *il = group_keys; il && il->ident; il = il->next) {
     1.6  
     1.7 +        if (strcmp(il->ident->user_id, PEP_OWN_USERID)!=0) {
     1.8 +            assert(0);
     1.9 +            continue;
    1.10 +        }
    1.11          // Check that identity isn't excluded from sync.
    1.12          pEp_identity *stored_identity = NULL;
    1.13          status = get_identity(session, il->ident->address, PEP_OWN_USERID,
    1.14 @@ -232,19 +236,11 @@
    1.15              free_identity(stored_identity);
    1.16          }
    1.17  
    1.18 -        free(il->ident->user_id);
    1.19 -        il->ident->user_id = strdup(PEP_OWN_USERID);
    1.20 -        assert(il->ident->user_id);
    1.21 -        if (!il->ident->user_id){
    1.22 -            status = PEP_OUT_OF_MEMORY;
    1.23 -            break;
    1.24 -        }
    1.25          status = set_identity(session, il->ident);
    1.26          if (status != PEP_STATUS_OK)
    1.27              break;
    1.28      }
    1.29  
    1.30 -    free_identity_list(group_keys);
    1.31      return status;
    1.32  }
    1.33      
    1.34 @@ -282,12 +278,12 @@
    1.35  
    1.36      status = _storeGroupKeys(session, group_keys);
    1.37      if (status != PEP_STATUS_OK)
    1.38 -        goto exitfree;
    1.39 +        return status;
    1.40  
    1.41      // set group id according to given group-id
    1.42      status = set_device_group(session, group_id);
    1.43      if (status != PEP_STATUS_OK)
    1.44 -        goto exitfree;
    1.45 +        return status;
    1.46      
    1.47      // change sync_uuid when entering group 
    1.48      // thus ignoring unprocessed handshakes
    1.49 @@ -296,11 +292,6 @@
    1.50      uuid_generate_random(uuid);
    1.51      uuid_unparse_upper(uuid, session->sync_uuid);
    1.52  
    1.53 -exitfree:
    1.54 -    free_identity_list(group_keys);
    1.55 -    free(group_id);
    1.56 -    free(group_keys_extra);
    1.57 -
    1.58      return status;
    1.59  }
    1.60  
    1.61 @@ -333,12 +324,8 @@
    1.62      identity_list *group_keys = (identity_list*) group_keys_;
    1.63  
    1.64      status = _storeGroupKeys(session, group_keys);
    1.65 -    if (status != PEP_STATUS_OK)
    1.66 -        goto exitfree;
    1.67  
    1.68 -exitfree:
    1.69  
    1.70 -    free_identity_list(group_keys);
    1.71      return status;
    1.72  }
    1.73  // makeGroup() - 
     2.1 --- a/src/sync_impl.c	Thu Feb 16 12:43:35 2017 +0100
     2.2 +++ b/src/sync_impl.c	Fri Feb 17 19:51:04 2017 +0100
     2.3 @@ -123,10 +123,7 @@
     2.4                  group_keys_extra->group_id = group_id;
     2.5  
     2.6                  identity_list *group_keys = IdentityList_to_identity_list(
     2.7 -                        msg->payload.present == 
     2.8 -                          DeviceGroup_Protocol__payload_PR_groupKeys ?
     2.9 -                            &msg->payload.choice.groupKeys.ownIdentities :
    2.10 -                            &msg->payload.choice.groupUpdate.ownIdentities,
    2.11 +                        &msg->payload.choice.groupKeys.ownIdentities,
    2.12                          NULL);
    2.13                  if (!group_keys) {
    2.14                      status = PEP_OUT_OF_MEMORY;
    2.15 @@ -138,6 +135,7 @@
    2.16                  group_keys_extra->group_keys = group_keys;
    2.17  
    2.18                  extra = (void *) group_keys_extra;
    2.19 +                event = GroupKeys;
    2.20  
    2.21                  break;
    2.22              }
    2.23 @@ -192,7 +190,6 @@
    2.24      if(last != NULL){
    2.25          time_t now = time(NULL);
    2.26          if(*last != 0 && (*last + SYNC_INHIBIT_TIME) > now ){
    2.27 -            free_identity(partner);
    2.28              status = PEP_STATEMACHINE_INHIBITED_EVENT;
    2.29              goto error;
    2.30          }
    2.31 @@ -254,9 +251,32 @@
    2.32  
    2.33      status = fsm_DeviceState_inject(session, event, partner, extra, timeout);
    2.34  
    2.35 +error:
    2.36 +
    2.37      free_identity(partner);
    2.38  
    2.39 -error:
    2.40 +    switch(event){
    2.41 +        case GroupKeys:
    2.42 +        {
    2.43 +            group_keys_extra_t *group_keys_extra = (group_keys_extra_t*) extra;
    2.44 +            identity_list *group_keys = group_keys_extra->group_keys;
    2.45 +            char *group_id = group_keys_extra->group_id;
    2.46 +            free_identity_list(group_keys);
    2.47 +            free(group_id);
    2.48 +            free(group_keys_extra);
    2.49 +            break;
    2.50 +        }
    2.51 +        case GroupUpdate:
    2.52 +        {
    2.53 +            identity_list *group_keys = (identity_list*) extra;
    2.54 +            free_identity_list(group_keys);
    2.55 +            break;
    2.56 +        }
    2.57 +        default:
    2.58 +            assert(extra==NULL);
    2.59 +            break;
    2.60 +    }
    2.61 +
    2.62      free(sync_msg);
    2.63  
    2.64      return status;
     3.1 --- a/sync/gen_statemachine.ysl2	Thu Feb 16 12:43:35 2017 +0100
     3.2 +++ b/sync/gen_statemachine.ysl2	Fri Feb 17 19:51:04 2017 +0100
     3.3 @@ -42,7 +42,6 @@
     3.4  
     3.5          typedef pEp_identity * Identity;
     3.6          typedef stringlist_t * Stringlist;
     3.7 -        typedef union _param { Identity partner; stringlist_t *keylist; } param_t;
     3.8  
     3.9          // error values
    3.10  
     4.1 --- a/sync/generated/sync_fsm.h	Thu Feb 16 12:43:35 2017 +0100
     4.2 +++ b/sync/generated/sync_fsm.h	Fri Feb 17 19:51:04 2017 +0100
     4.3 @@ -12,7 +12,6 @@
     4.4  
     4.5  typedef pEp_identity * Identity;
     4.6  typedef stringlist_t * Stringlist;
     4.7 -typedef union _param { Identity partner; stringlist_t *keylist; } param_t;
     4.8  
     4.9  // error values
    4.10