Force Init event when entering a new sync state keysync
authorEdouard Tisserant <edouard@pep-project.org>
Thu, 08 Sep 2016 16:40:20 +0200
branchkeysync
changeset 1152fde1a69448d2
parent 1149 daf519fd5f74
child 1154 cce44a694981
Force Init event when entering a new sync state
src/sync_driver.c
src/sync_fsm.c
sync/gen_statemachine.ysl2
     1.1 --- a/src/sync_driver.c	Thu Sep 08 12:57:58 2016 +0200
     1.2 +++ b/src/sync_driver.c	Thu Sep 08 16:40:20 2016 +0200
     1.3 @@ -15,14 +15,23 @@
     1.4      if (!session)
     1.5          return PEP_ILLEGAL_VALUE;
     1.6  
     1.7 -    DeviceState_state state = fsm_DeviceState(session,
     1.8 +    while(true)
     1.9 +    {
    1.10 +        DeviceState_state new_state = fsm_DeviceState(session,
    1.11              session->sync_state, event, partner, extra);
    1.12 -    if (state == DeviceState_state_invalid_out_of_memory)
    1.13 -        return PEP_OUT_OF_MEMORY;
    1.14 -    if (state < 0)
    1.15 -        return PEP_SYNC_STATEMACHINE_ERROR - state;
    1.16 +        if (new_state == DeviceState_state_invalid_out_of_memory)
    1.17 +            return PEP_OUT_OF_MEMORY;
    1.18 +        if (new_state < 0)
    1.19 +            return PEP_SYNC_STATEMACHINE_ERROR - new_state;
    1.20 +        
    1.21 +        if (new_state == session->sync_state)
    1.22 +            break;
    1.23 +        else
    1.24 +            event = Init;
    1.25  
    1.26 -    session->sync_state = state;
    1.27 +        session->sync_state = new_state;
    1.28 +    } 
    1.29 +
    1.30      return PEP_STATUS_OK;
    1.31  }
    1.32  
     2.1 --- a/src/sync_fsm.c	Thu Sep 08 12:57:58 2016 +0200
     2.2 +++ b/src/sync_fsm.c	Thu Sep 08 16:40:20 2016 +0200
     2.3 @@ -31,6 +31,7 @@
     2.4          
     2.5          case Sole:
     2.6              switch (event) {
     2.7 +                case Init: break;
     2.8                  case KeyGen:
     2.9                      status = sendBeacon(session, state, NULL, NULL);
    2.10                      if (status == PEP_OUT_OF_MEMORY)
    2.11 @@ -95,6 +96,7 @@
    2.12          
    2.13          case WaitForGroupKeys:
    2.14              switch (event) {
    2.15 +                case Init: break;
    2.16                  case GroupKeys:
    2.17                      status = storeGroupKeys(session, state, partner, NULL);
    2.18                      if (status == PEP_OUT_OF_MEMORY)
    2.19 @@ -118,6 +120,7 @@
    2.20          
    2.21          case Grouped:
    2.22              switch (event) {
    2.23 +                case Init: break;
    2.24                  case KeyGen:
    2.25                      status = sendGroupKeys(session, state, NULL, NULL);
    2.26                      if (status == PEP_OUT_OF_MEMORY)
     3.1 --- a/sync/gen_statemachine.ysl2	Thu Sep 08 12:57:58 2016 +0200
     3.2 +++ b/sync/gen_statemachine.ysl2	Thu Sep 08 16:40:20 2016 +0200
     3.3 @@ -139,14 +139,23 @@
     3.4              if (!session)
     3.5                  return PEP_ILLEGAL_VALUE;
     3.6  
     3.7 -            «@name»_state state = fsm_«@name»(session,
     3.8 +            while(true)
     3.9 +            {
    3.10 +                «@name»_state new_state = fsm_«@name»(session,
    3.11                      session->«@filename»_state, event, partner, extra);
    3.12 -            if (state == «@name»_state_invalid_out_of_memory)
    3.13 -                return PEP_OUT_OF_MEMORY;
    3.14 -            if (state < 0)
    3.15 -                return PEP_SYNC_STATEMACHINE_ERROR - state;
    3.16 +                if (new_state == «@name»_state_invalid_out_of_memory)
    3.17 +                    return PEP_OUT_OF_MEMORY;
    3.18 +                if (new_state < 0)
    3.19 +                    return PEP_SYNC_STATEMACHINE_ERROR - new_state;
    3.20 +                
    3.21 +                if (new_state == session->sync_state)
    3.22 +                    break;
    3.23 +                else
    3.24 +                    event = Init;
    3.25  
    3.26 -            session->«@filename»_state = state;
    3.27 +                session->«@filename»_state = new_state;
    3.28 +            } 
    3.29 +
    3.30              return PEP_STATUS_OK;
    3.31          }
    3.32  
    3.33 @@ -184,6 +193,7 @@
    3.34      ||
    3.35      case «@name»:
    3.36          switch (event) {
    3.37 +        ``if "not(event[@name='Init'])" |>> case Init: break;
    3.38          `` apply "event", 2
    3.39              default:
    3.40                  return («../@name»_state) invalid_event;