KeySync: Send GroupUpdate immediately after receiving GroupKeys when joining a group. This is intended to spread key that did lose the election to the group, without waiting for CannotDecrypt
authorEdouard Tisserant <edouard@pep-project.org>
Tue, 31 Jan 2017 12:06:33 +0100
changeset 1566fcb7bade5c5f
parent 1564 25d24eb99711
child 1567 7e51ef02ab31
KeySync: Send GroupUpdate immediately after receiving GroupKeys when joining a group. This is intended to spread key that did lose the election to the group, without waiting for CannotDecrypt
sync/devicegroup.fsm
sync/generated/sync_fsm.c
sync/generated/sync_fsm.h
sync/skeletons/sync_actions.c
     1.1 --- a/sync/devicegroup.fsm	Mon Jan 30 17:15:13 2017 +0100
     1.2 +++ b/sync/devicegroup.fsm	Tue Jan 31 12:06:33 2017 +0100
     1.3 @@ -85,6 +85,7 @@
     1.4              on HandshakeAccepted(Identity partner) {
     1.5                  do acceptHandshake(partner); 
     1.6                  if keyElectionWon(partner) {
     1.7 +                    do enterGroup;
     1.8                      do sendGroupKeys(partner);
     1.9                      do notifyAcceptedGroupCreated(partner);
    1.10                      go Grouped;
    1.11 @@ -103,6 +104,8 @@
    1.12              on GroupKeys(Identity partner, Stringlist keys) {
    1.13                  if sameIdentities(partner, expected) {
    1.14                      do storeGroupKeys(partner, keys);
    1.15 +                    do enterGroup;
    1.16 +                    do sendGroupUpdate;
    1.17                      do notifyAcceptedDeviceAdded(partner);
    1.18                      go Grouped;
    1.19                  }
    1.20 @@ -114,8 +117,6 @@
    1.21          }
    1.22  
    1.23          state Grouped end=1 {
    1.24 -            on Init 
    1.25 -                do enterGroup;
    1.26              on KeyGen
    1.27                  do sendGroupUpdate;
    1.28              on CannotDecrypt
     2.1 --- a/sync/generated/sync_fsm.c	Mon Jan 30 17:15:13 2017 +0100
     2.2 +++ b/sync/generated/sync_fsm.c	Tue Jan 31 12:06:33 2017 +0100
     2.3 @@ -272,6 +272,12 @@
     2.4                      if (cond_result < 0)
     2.5                          return cond_result;
     2.6                      if (cond_result) {
     2.7 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=enterGroup")
     2.8 +                        status = enterGroup(session, state, NULL, 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                          DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=sendGroupKeys")
    2.14                          status = sendGroupKeys(session, state, partner, NULL);
    2.15                          if (status == PEP_OUT_OF_MEMORY)
    2.16 @@ -361,6 +367,18 @@
    2.17                              return (int) invalid_out_of_memory;
    2.18                          if (status != PEP_STATUS_OK)
    2.19                              return (int) invalid_action;
    2.20 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=enterGroup")
    2.21 +                        status = enterGroup(session, state, NULL, NULL);
    2.22 +                        if (status == PEP_OUT_OF_MEMORY)
    2.23 +                            return (int) invalid_out_of_memory;
    2.24 +                        if (status != PEP_STATUS_OK)
    2.25 +                            return (int) invalid_action;
    2.26 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=sendGroupUpdate")
    2.27 +                        status = sendGroupUpdate(session, state, NULL, 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=WaitForGroupKeysSole, event=GroupKeys", "action=notifyAcceptedDeviceAdded")
    2.33                          status = notifyAcceptedDeviceAdded(session, state, partner, NULL);
    2.34                          if (status == PEP_OUT_OF_MEMORY)
    2.35 @@ -402,17 +420,7 @@
    2.36              *timeout = 0;
    2.37              DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=Grouped")
    2.38              switch (event) {
    2.39 -                case Init:
    2.40 -                {
    2.41 -                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=Init")
    2.42 -                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=Init", "action=enterGroup")
    2.43 -                    status = enterGroup(session, state, NULL, NULL);
    2.44 -                    if (status == PEP_OUT_OF_MEMORY)
    2.45 -                        return (int) invalid_out_of_memory;
    2.46 -                    if (status != PEP_STATUS_OK)
    2.47 -                        return (int) invalid_action;
    2.48 -                    break;
    2.49 -                }
    2.50 +                case Init: DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=Init") break;
    2.51                  case KeyGen:
    2.52                  {
    2.53                      DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=KeyGen")
     3.1 --- a/sync/generated/sync_fsm.h	Mon Jan 30 17:15:13 2017 +0100
     3.2 +++ b/sync/generated/sync_fsm.h	Tue Jan 31 12:06:33 2017 +0100
     3.3 @@ -81,13 +81,13 @@
     3.4  PEP_STATUS notifyInitAddOurDevice(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     3.5  PEP_STATUS rejectHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     3.6  PEP_STATUS acceptHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     3.7 +PEP_STATUS enterGroup(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     3.8  PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     3.9  PEP_STATUS notifyAcceptedGroupCreated(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    3.10  PEP_STATUS notifyTimeout(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    3.11  PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    3.12 +PEP_STATUS sendGroupUpdate(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    3.13  PEP_STATUS notifyAcceptedDeviceAdded(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    3.14 -PEP_STATUS enterGroup(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    3.15 -PEP_STATUS sendGroupUpdate(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    3.16  PEP_STATUS sendUpdateRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    3.17  
    3.18  // event injector
     4.1 --- a/sync/skeletons/sync_actions.c	Mon Jan 30 17:15:13 2017 +0100
     4.2 +++ b/sync/skeletons/sync_actions.c	Tue Jan 31 12:06:33 2017 +0100
     4.3 @@ -156,6 +156,43 @@
     4.4  }
     4.5  
     4.6  
     4.7 +// enterGroup() - 
     4.8 +//
     4.9 +//  params:
    4.10 +//      session (in)        session handle
    4.11 +//      state (in)          state the state machine is in
    4.12 +//      partner (in)        (must be NULL)
    4.13 +//
    4.14 +//  returns:
    4.15 +//      PEP_STATUS_OK or any other value on error
    4.16 +
    4.17 +PEP_STATUS enterGroup(
    4.18 +        PEP_SESSION session,
    4.19 +        DeviceState_state state,
    4.20 +        Identity partner,
    4.21 +        void *extra
    4.22 +    )
    4.23 +{
    4.24 +    PEP_STATUS status = PEP_STATUS_OK;
    4.25 +
    4.26 +    assert(session);
    4.27 +    assert(!partner);
    4.28 +    if (!(session && !partner))
    4.29 +        return PEP_ILLEGAL_VALUE;
    4.30 +
    4.31 +    // working code
    4.32 +
    4.33 +    // free extra
    4.34 +    return status;
    4.35 +
    4.36 +enomem:
    4.37 +    status = PEP_OUT_OF_MEMORY;
    4.38 +error:
    4.39 +    // free extra
    4.40 +    return status;
    4.41 +}
    4.42 +
    4.43 +
    4.44  // notifyAcceptedGroupCreated() - 
    4.45  //
    4.46  //  params:
    4.47 @@ -303,40 +340,3 @@
    4.48      return status;
    4.49  }
    4.50  
    4.51 -
    4.52 -// enterGroup() - 
    4.53 -//
    4.54 -//  params:
    4.55 -//      session (in)        session handle
    4.56 -//      state (in)          state the state machine is in
    4.57 -//      partner (in)        (must be NULL)
    4.58 -//
    4.59 -//  returns:
    4.60 -//      PEP_STATUS_OK or any other value on error
    4.61 -
    4.62 -PEP_STATUS enterGroup(
    4.63 -        PEP_SESSION session,
    4.64 -        DeviceState_state state,
    4.65 -        Identity partner,
    4.66 -        void *extra
    4.67 -    )
    4.68 -{
    4.69 -    PEP_STATUS status = PEP_STATUS_OK;
    4.70 -
    4.71 -    assert(session);
    4.72 -    assert(!partner);
    4.73 -    if (!(session && !partner))
    4.74 -        return PEP_ILLEGAL_VALUE;
    4.75 -
    4.76 -    // working code
    4.77 -
    4.78 -    // free extra
    4.79 -    return status;
    4.80 -
    4.81 -enomem:
    4.82 -    status = PEP_OUT_OF_MEMORY;
    4.83 -error:
    4.84 -    // free extra
    4.85 -    return status;
    4.86 -}
    4.87 -