ENGINE-133 added state 'payload' pointer to data attached to the state, allocated/dealocated on transitions. This state payload allows spontaneous transitions having no context (i.e. timeout) to get some context about the state. It can be used in other cases like checking that received group keys are from the partner we expect (TODO) ENGINE-133
authorEdouard Tisserant <edouard@pep-project.org>
Sun, 04 Dec 2016 02:51:59 +0100
branchENGINE-133
changeset 146066ceb5a7f718
parent 1459 ab329d7db8d7
child 1462 b93663bfc7c6
ENGINE-133 added state 'payload' pointer to data attached to the state, allocated/dealocated on transitions. This state payload allows spontaneous transitions having no context (i.e. timeout) to get some context about the state. It can be used in other cases like checking that received group keys are from the partner we expect (TODO)
src/pEp_internal.h
src/sync.c
sync/devicegroup.fsm
sync/gen_statemachine.ysl2
     1.1 --- a/src/pEp_internal.h	Thu Dec 01 17:56:05 2016 +0100
     1.2 +++ b/src/pEp_internal.h	Sun Dec 04 02:51:59 2016 +0100
     1.3 @@ -142,6 +142,7 @@
     1.4  
     1.5      // key sync
     1.6      DeviceState_state sync_state;
     1.7 +    void* sync_state_payload;
     1.8      char sync_uuid[37];
     1.9      time_t LastCannotDecrypt;
    1.10      time_t LastUpdateRequest;
     2.1 --- a/src/sync.c	Thu Dec 01 17:56:05 2016 +0100
     2.2 +++ b/src/sync.c	Sun Dec 04 02:51:59 2016 +0100
     2.3 @@ -6,7 +6,7 @@
     2.4  #include "asn1_helper.h"
     2.5  #include "../asn.1/DeviceGroup-Protocol.h"
     2.6  
     2.7 -// receive_sync_msg is defined in the sync_actions
     2.8 +// receive_sync_msg is defined in the sync_impl
     2.9  
    2.10  PEP_STATUS receive_sync_msg(
    2.11          PEP_SESSION session,
     3.1 --- a/sync/devicegroup.fsm	Thu Dec 01 17:56:05 2016 +0100
     3.2 +++ b/sync/devicegroup.fsm	Sun Dec 04 02:51:59 2016 +0100
     3.3 @@ -40,7 +40,7 @@
     3.4              }
     3.5          }
     3.6  
     3.7 -        state HandshakingSole timeout=10 (Identity partner) {
     3.8 +        state HandshakingSole timeout=600 (Identity expected) {
     3.9              on Init
    3.10                  do showHandshake(partner);
    3.11              on HandshakeRejected(Identity partner) {
    3.12 @@ -55,23 +55,24 @@
    3.13                      do handshakeGroupCreated(partner);
    3.14                      go Grouped;
    3.15                  }
    3.16 -                go WaitForGroupKeysSole(Identity partner);
    3.17 +                go WaitForGroupKeysSole(partner);
    3.18              }
    3.19              on Cancel go Sole;
    3.20              on Timeout {
    3.21 -                do dismissHandshake(partner);
    3.22 +                do dismissHandshake(expected);
    3.23                  go Sole;
    3.24              }
    3.25          }
    3.26      
    3.27 -        state WaitForGroupKeysSole timeout=10 (Identity partner) {
    3.28 +        state WaitForGroupKeysSole timeout=600 (Identity expected) {
    3.29              on GroupKeys(Identity partner, Stringlist keys) {
    3.30 +                // TODO ensure partner == expected
    3.31                  do storeGroupKeys(partner, keys);
    3.32                  do handshakeSuccess(partner);
    3.33                  go Grouped;
    3.34              }
    3.35              on Timeout {
    3.36 -                do handshakeFailure(partner);
    3.37 +                do handshakeFailure(expected);
    3.38                  go Sole;
    3.39              }
    3.40          }
    3.41 @@ -95,7 +96,7 @@
    3.42                  do storeGroupKeys(partner, keys);
    3.43          }
    3.44  
    3.45 -        state HandshakingGrouped timeout=10 (Identity partner) {
    3.46 +        state HandshakingGrouped timeout=600 (Identity expected) {
    3.47              on Init
    3.48                  do showHandshake(partner);
    3.49              on HandshakeRejected(Identity partner) {
    3.50 @@ -113,11 +114,10 @@
    3.51                  go Grouped;
    3.52              }
    3.53              on Timeout {
    3.54 -                do handshakeFailure(partner);
    3.55 +                do handshakeFailure(expected);
    3.56                  go Grouped;
    3.57              }
    3.58          }
    3.59 -    
    3.60  
    3.61          tag Init 1;
    3.62          tag Beacon 2;
     4.1 --- a/sync/gen_statemachine.ysl2	Thu Dec 01 17:56:05 2016 +0100
     4.2 +++ b/sync/gen_statemachine.ysl2	Sun Dec 04 02:51:59 2016 +0100
     4.3 @@ -7,6 +7,7 @@
     4.4  include yslt.yml2
     4.5  
     4.6  tstylesheet {
     4.7 +    include standardlib.ysl2
     4.8      include ./functions.ysl2
     4.9  
    4.10      template "/protocol" {
    4.11 @@ -181,6 +182,7 @@
    4.12          document "../src/{@filename}_fsm.c", "text"
    4.13          ||
    4.14          #include "«@filename»_fsm.h"
    4.15 +        #include "pEp_internal.h"
    4.16  
    4.17          // state machine for «@name»
    4.18  
    4.19 @@ -211,6 +213,9 @@
    4.20      template "state"
    4.21      ||
    4.22      case «@name»:
    4.23 +    {
    4.24 +        `` if "count(parm) > 1" error | # TODO composite state payload 
    4.25 +        `` apply "parm", 1 mode="stateParm"
    4.26          *timeout = «@timeout»;
    4.27          switch (event) {
    4.28          `` if "not(event[@name='Init'])" |>> case Init: break;
    4.29 @@ -219,14 +224,21 @@
    4.30                  return («../@name»_state) invalid_event;
    4.31          }
    4.32          break;
    4.33 +    }
    4.34 +    ||
    4.35  
    4.36 -    ||
    4.37 +    template "parm" mode="stateParm" 
    4.38 +    {
    4.39 +        | «name(*[1])» «name(*[2])» = («name(*[1])»)session->sync_state_payload;
    4.40 +    }
    4.41  
    4.42      template "event"
    4.43      ||
    4.44      case «@name»:
    4.45 +    {
    4.46      `` apply "action|transition|condition";
    4.47      `` if "name(*[position()=last()]) != 'transition'" |> break;
    4.48 +    }
    4.49      ||
    4.50  
    4.51      template "action" {
    4.52 @@ -263,6 +275,20 @@
    4.53              > , «name(*[1])» «name(*[2])»
    4.54      }
    4.55  
    4.56 -    template "transition" | return «@target»;
    4.57 +    template "transition"{
    4.58 +        const "stateparm", "ancestor::state/child::parm";
    4.59 +        if "$stateparm" {
    4.60 +            | if(session->sync_state_payload){
    4.61 +            |     free_«yml:lcase(name($stateparm[1]/*))»((«name($stateparm[1]/*)»)session->sync_state_payload);
    4.62 +            |     session->sync_state_payload = NULL;
    4.63 +            | }
    4.64 +        }
    4.65 +        if "parm" {
    4.66 +            const "nextstatename", "@target";
    4.67 +            const "nextstateparm", "ancestor::fsm/child::state[@name = $nextstatename]/child::parm";
    4.68 +            | session->sync_state_payload = «yml:lcase(name($nextstateparm/*))»_dup(«name(parm/*)»);
    4.69 +        }
    4.70 +        | return «@target»;
    4.71 +    }
    4.72  }
    4.73