KeySync fsm : fixed storeGroupKeys instead of storeGroupUpdate, added more check, fixed wrong parameter type for storeGroupKeys GroupMerge
authorEdouard Tisserant <edouard@pep-project.org>
Sat, 18 Feb 2017 23:08:34 +0100
branchGroupMerge
changeset 15881a43a7eddf90
parent 1587 6db4fde2cdae
child 1589 c6dbfcea6e5a
child 1598 69684cf21c4a
KeySync fsm : fixed storeGroupKeys instead of storeGroupUpdate, added more check, fixed wrong parameter type for storeGroupKeys
sync/devicegroup.fsm
sync/generated/sync_fsm.c
     1.1 --- a/sync/devicegroup.fsm	Fri Feb 17 19:51:04 2017 +0100
     1.2 +++ b/sync/devicegroup.fsm	Sat Feb 18 23:08:34 2017 +0100
     1.3 @@ -82,14 +82,17 @@
     1.4                  go Sole;
     1.5              }
     1.6              on HandshakeAccepted(Identity partner) {
     1.7 -                do acceptHandshake(partner); 
     1.8 -                if keyElectionWon(partner) {
     1.9 -                    do makeGroup;
    1.10 -                    do sendGroupKeys(partner);
    1.11 -                    do notifyAcceptedGroupCreated(partner);
    1.12 -                    go Grouped;
    1.13 +                if sameIdentities(partner, expected) {
    1.14 +                    do acceptHandshake(partner); 
    1.15 +                    if keyElectionWon(partner) {
    1.16 +                        do makeGroup;
    1.17 +                        do sendGroupKeys(partner);
    1.18 +                        do notifyAcceptedGroupCreated(partner);
    1.19 +                        go Grouped;
    1.20 +                    }
    1.21 +                    go WaitForGroupKeysSole(partner);
    1.22                  }
    1.23 -                go WaitForGroupKeysSole(partner);
    1.24 +                go Sole;
    1.25              }
    1.26              on Cancel go Sole;
    1.27              on Timeout {
    1.28 @@ -100,7 +103,7 @@
    1.29          }
    1.30      
    1.31          state WaitForGroupKeysSole timeout=600 (Identity expected) {
    1.32 -            on GroupKeys(Identity partner, Stringlist keys) {
    1.33 +            on GroupKeys(Identity partner, identity_list keys) {
    1.34                  if sameIdentities(partner, expected) {
    1.35                      do storeGroupKeys(partner, keys);
    1.36                      do sendGroupUpdate;
    1.37 @@ -131,7 +134,7 @@
    1.38                  do sendHandshakeRequest(partner);
    1.39                  go HandshakingGrouped(partner);
    1.40              }
    1.41 -            on GroupUpdate(Identity partner, Stringlist keys)
    1.42 +            on GroupUpdate(Identity partner, identity_list keys)
    1.43                  do storeGroupUpdate(partner, keys);
    1.44          }
    1.45  
    1.46 @@ -156,8 +159,8 @@
    1.47                  }
    1.48                  go HandshakingGrouped(partner);
    1.49              }
    1.50 -            on GroupUpdate(Identity partner, Stringlist keys)
    1.51 -                do storeGroupKeys(partner, keys);
    1.52 +            on GroupUpdate(Identity partner, identity_list keys)
    1.53 +                do storeGroupUpdate(partner, keys);
    1.54              on Timeout go Grouped;
    1.55          }
    1.56  
    1.57 @@ -191,7 +194,7 @@
    1.58          }
    1.59  
    1.60          state WaitForGroupKeysGrouped timeout=600 (Identity expected) {
    1.61 -            on GroupKeys(Identity partner, Stringlist keys) {
    1.62 +            on GroupKeys(Identity partner, identity_list keys) {
    1.63                  if sameIdentities(partner, expected) {
    1.64                      do storeGroupKeys(partner, keys);
    1.65                      do sendGroupUpdate;
     2.1 --- a/sync/generated/sync_fsm.c	Fri Feb 17 19:51:04 2017 +0100
     2.2 +++ b/sync/generated/sync_fsm.c	Sat Feb 18 23:08:34 2017 +0100
     2.3 @@ -257,53 +257,69 @@
     2.4                  case HandshakeAccepted:
     2.5                  {
     2.6                      DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=HandshakeAccepted")
     2.7 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=acceptHandshake")
     2.8 -                    status = acceptHandshake(session, state, partner, NULL);
     2.9 -                    if (status == PEP_OUT_OF_MEMORY)
    2.10 -                        return (int) invalid_out_of_memory;
    2.11 -                    if (status != PEP_STATUS_OK)
    2.12 -                        return (int) invalid_action;
    2.13 -                    cond_result = keyElectionWon(session, partner);
    2.14 +                    cond_result = sameIdentities(session, partner, expected);
    2.15                      #ifndef NDEBUG
    2.16                      char resstr[11] = {0,};
    2.17                      snprintf(resstr,10,"result=%d",cond_result);
    2.18                      #endif
    2.19 -                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted, condition=keyElectionWon", resstr)
    2.20 +                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted, condition=sameIdentities", resstr)
    2.21                      if (cond_result < 0)
    2.22                          return cond_result;
    2.23                      if (cond_result) {
    2.24 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=makeGroup")
    2.25 -                        status = makeGroup(session, state, NULL, NULL);
    2.26 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=acceptHandshake")
    2.27 +                        status = acceptHandshake(session, state, partner, NULL);
    2.28                          if (status == PEP_OUT_OF_MEMORY)
    2.29                              return (int) invalid_out_of_memory;
    2.30                          if (status != PEP_STATUS_OK)
    2.31                              return (int) invalid_action;
    2.32 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=sendGroupKeys")
    2.33 -                        status = sendGroupKeys(session, state, partner, NULL);
    2.34 -                        if (status == PEP_OUT_OF_MEMORY)
    2.35 -                            return (int) invalid_out_of_memory;
    2.36 -                        if (status != PEP_STATUS_OK)
    2.37 -                            return (int) invalid_action;
    2.38 -                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=notifyAcceptedGroupCreated")
    2.39 -                        status = notifyAcceptedGroupCreated(session, state, partner, NULL);
    2.40 -                        if (status == PEP_OUT_OF_MEMORY)
    2.41 -                            return (int) invalid_out_of_memory;
    2.42 -                        if (status != PEP_STATUS_OK)
    2.43 -                            return (int) invalid_action;
    2.44 +                        cond_result = keyElectionWon(session, partner);
    2.45 +                        #ifndef NDEBUG
    2.46 +                        char resstr[11] = {0,};
    2.47 +                        snprintf(resstr,10,"result=%d",cond_result);
    2.48 +                        #endif
    2.49 +                        DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted, condition=keyElectionWon", resstr)
    2.50 +                        if (cond_result < 0)
    2.51 +                            return cond_result;
    2.52 +                        if (cond_result) {
    2.53 +                            DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=makeGroup")
    2.54 +                            status = makeGroup(session, state, NULL, NULL);
    2.55 +                            if (status == PEP_OUT_OF_MEMORY)
    2.56 +                                return (int) invalid_out_of_memory;
    2.57 +                            if (status != PEP_STATUS_OK)
    2.58 +                                return (int) invalid_action;
    2.59 +                            DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=sendGroupKeys")
    2.60 +                            status = sendGroupKeys(session, state, partner, NULL);
    2.61 +                            if (status == PEP_OUT_OF_MEMORY)
    2.62 +                                return (int) invalid_out_of_memory;
    2.63 +                            if (status != PEP_STATUS_OK)
    2.64 +                                return (int) invalid_action;
    2.65 +                            DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=notifyAcceptedGroupCreated")
    2.66 +                            status = notifyAcceptedGroupCreated(session, state, partner, NULL);
    2.67 +                            if (status == PEP_OUT_OF_MEMORY)
    2.68 +                                return (int) invalid_out_of_memory;
    2.69 +                            if (status != PEP_STATUS_OK)
    2.70 +                                return (int) invalid_action;
    2.71 +                            if(session->sync_state_payload){
    2.72 +                                free_identity((Identity)session->sync_state_payload);
    2.73 +                                session->sync_state_payload = NULL;
    2.74 +                            }
    2.75 +                            DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=Grouped")
    2.76 +                            return Grouped;
    2.77 +                        }
    2.78                          if(session->sync_state_payload){
    2.79                              free_identity((Identity)session->sync_state_payload);
    2.80                              session->sync_state_payload = NULL;
    2.81                          }
    2.82 -                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=Grouped")
    2.83 -                        return Grouped;
    2.84 +                        session->sync_state_payload = identity_dup(partner);
    2.85 +                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=WaitForGroupKeysSole")
    2.86 +                        return WaitForGroupKeysSole;
    2.87                      }
    2.88                      if(session->sync_state_payload){
    2.89                          free_identity((Identity)session->sync_state_payload);
    2.90                          session->sync_state_payload = NULL;
    2.91                      }
    2.92 -                    session->sync_state_payload = identity_dup(partner);
    2.93 -                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=WaitForGroupKeysSole")
    2.94 -                    return WaitForGroupKeysSole;
    2.95 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=Sole")
    2.96 +                    return Sole;
    2.97                  }
    2.98                  case Cancel:
    2.99                  {
   2.100 @@ -591,8 +607,8 @@
   2.101                  case GroupUpdate:
   2.102                  {
   2.103                      DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupedBeaconed", "event=GroupUpdate")
   2.104 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=GroupUpdate", "action=storeGroupKeys")
   2.105 -                    status = storeGroupKeys(session, state, partner, extra /*keys*/);
   2.106 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupedBeaconed, event=GroupUpdate", "action=storeGroupUpdate")
   2.107 +                    status = storeGroupUpdate(session, state, partner, extra /*keys*/);
   2.108                      if (status == PEP_OUT_OF_MEMORY)
   2.109                          return (int) invalid_out_of_memory;
   2.110                      if (status != PEP_STATUS_OK)