... sync
authorVolker Birk <vb@pep.foundation>
Fri, 17 Aug 2018 15:23:08 +0200
branchsync
changeset 2856451ac4260963
parent 2855 4db88ce549ee
child 2857 dc81cb891159
...
src/sync_actions.c
src/sync_impl.h
sync/cond_act_sync.yml2
sync/gen_message_func.ysl2
sync/sync.fsm
     1.1 --- a/src/sync_actions.c	Thu Aug 16 23:57:52 2018 +0200
     1.2 +++ b/src/sync_actions.c	Fri Aug 17 15:23:08 2018 +0200
     1.3 @@ -109,6 +109,17 @@
     1.4      return PEP_STATUS_OK;
     1.5  }
     1.6  
     1.7 +PEP_STATUS clearState(PEP_SESSION session)
     1.8 +{
     1.9 +    assert(session);
    1.10 +    if (!session)
    1.11 +        return PEP_ILLEGAL_VALUE;
    1.12 +
    1.13 +    free_Sync_state(session);
    1.14 +
    1.15 +    return PEP_STATUS_OK;
    1.16 +}
    1.17 +
    1.18  PEP_STATUS openChallenge(PEP_SESSION session)
    1.19  {
    1.20      assert(session);
     2.1 --- a/src/sync_impl.h	Thu Aug 16 23:57:52 2018 +0200
     2.2 +++ b/src/sync_impl.h	Fri Aug 17 15:23:08 2018 +0200
     2.3 @@ -21,6 +21,7 @@
     2.4  // actions
     2.5  
     2.6  PEP_STATUS closeHandshakeDialog(PEP_SESSION session);
     2.7 +PEP_STATUS clearState(PEP_SESSION session);
     2.8  PEP_STATUS openChallenge(PEP_SESSION session);
     2.9  PEP_STATUS storeChallenge(PEP_SESSION session);
    2.10  PEP_STATUS openTransaction(PEP_SESSION session);
     3.1 --- a/sync/cond_act_sync.yml2	Thu Aug 16 23:57:52 2018 +0200
     3.2 +++ b/sync/cond_act_sync.yml2	Fri Aug 17 15:23:08 2018 +0200
     3.3 @@ -92,6 +92,9 @@
     3.4      ||
     3.5  }
     3.6  
     3.7 +action clearState
     3.8 +    |> free_Sync_state(session);
     3.9 +
    3.10  action openChallenge
    3.11      call "new_UUID" with "dst" > &session->own_sync_state.challenge
    3.12  
     4.1 --- a/sync/gen_message_func.ysl2	Thu Aug 16 23:57:52 2018 +0200
     4.2 +++ b/sync/gen_message_func.ysl2	Fri Aug 17 15:23:08 2018 +0200
     4.3 @@ -161,8 +161,6 @@
     4.4  
     4.5  PEP_STATUS update_«@name»_message(PEP_SESSION session, «@name»_t *msg)
     4.6  {
     4.7 -    int result = 0;
     4.8 -
     4.9      assert(session && msg);
    4.10      if (!(session && msg))
    4.11          return PEP_ILLEGAL_VALUE;
    4.12 @@ -203,18 +201,18 @@
    4.13  ||
    4.14  
    4.15  template "message", mode=update_message {
    4.16 -    const "message_name", "concat(yml:lcase(substring(@name,1,1)), substring(@name,2))";
    4.17      ||
    4.18 -    case «../@name»__payload_PR_«$message_name»:
    4.19 +    case «../@name»__payload_PR_«yml:mixedCase(@name)»:
    4.20          `` apply "auto"
    4.21 -        `` apply "field", mode=update_message with "message_name", "$message_name"
    4.22 +        `` apply "field", mode=update_message
    4.23          break;
    4.24  
    4.25      ||
    4.26  }
    4.27  
    4.28  template "auto" choose {
    4.29 -    when "@type = 'Version'"
    4.30 +    when "@type = 'Version'" {
    4.31 +        const "fsm", "ancestor::fsm";
    4.32          ||
    4.33          {
    4.34              long *major = (long *) malloc(sizeof(long));
    4.35 @@ -223,33 +221,41 @@
    4.36              if (!(major && minor))
    4.37                  return PEP_OUT_OF_MEMORY;
    4.38  
    4.39 -            *major = «../../version/@major»;
    4.40 -            *minor = «../../version/@minor»;
    4.41 +            *major = «$fsm/version/@major»;
    4.42 +            *minor = «$fsm/version/@minor»;
    4.43  
    4.44 -            msg->choice.«yml:lcase(../../@name)».payload.choice.«yml:mixedCase(../@name)».«@name».major = major;
    4.45 -            msg->choice.«yml:lcase(../../@name)».payload.choice.«yml:mixedCase(../@name)».«@name».minor = minor;
    4.46 +            msg->choice.«yml:lcase($fsm/@name)».payload.choice.«yml:mixedCase(../@name)».«@name».major = major;
    4.47 +            msg->choice.«yml:lcase($fsm/@name)».payload.choice.«yml:mixedCase(../@name)».«@name».minor = minor;
    4.48          }
    4.49  
    4.50          ||
    4.51 +    }
    4.52  
    4.53      otherwise
    4.54          error "unkown type for auto in message: {@type}; allowed types: Version";
    4.55  }
    4.56  
    4.57  template "field", mode=update_message {
    4.58 -    param "message_name";
    4.59 +    const "message_name", "yml:mixedCase(../@name)";
    4.60 +    const "state" choose {
    4.61 +        when "@type='TID'"
    4.62 +            > own_«yml:lcase(ancestor::protocol/@name)»_state
    4.63 +        otherwise
    4.64 +            > «yml:lcase(ancestor::protocol/@name)»_state.«yml:lcase(ancestor::fsm/@name)»
    4.65 +    }
    4.66 +
    4.67      choose {
    4.68          when "func:basicType()" // copyable
    4.69          ||
    4.70          msg->choice.«yml:lcase(../../@name)».payload.choice.«$message_name».«@name»
    4.71 -                 = session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name»;
    4.72 +                 = session->«$state».«@name»;
    4.73  
    4.74          ||
    4.75          when "@type='IdentityList'"
    4.76          ||
    4.77          {
    4.78              identity_list *il = IdentityList_to_identity_list(
    4.79 -                    &session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name», NULL);
    4.80 +                    &session->«$state».«@name», NULL);
    4.81              if (!il)
    4.82                  return PEP_OUT_OF_MEMORY;
    4.83              IdentityList_t *_il = IdentityList_from_identity_list(il,
    4.84 @@ -262,12 +268,15 @@
    4.85          ||
    4.86          otherwise // string based
    4.87          ||
    4.88 -        result = OCTET_STRING_fromBuf(&msg->choice.«yml:lcase(../../@name)».payload.choice.«$message_name».«@name»,
    4.89 -                (char *) session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name».buf,
    4.90 -                session->«yml:lcase(../../../@name)»_state.«yml:lcase(../../@name)».«@name».size);
    4.91 -        if (result)
    4.92 -            return PEP_OUT_OF_MEMORY;
    4.93 -
    4.94 +        {
    4.95 +            int result = OCTET_STRING_fromBuf(
    4.96 +                    &msg->choice.«yml:lcase(../../@name)».payload.choice.«$message_name».«@name»,
    4.97 +                    (char *) session->«$state».«@name».buf,
    4.98 +                    session->«$state».«@name».size
    4.99 +                );
   4.100 +            if (result)
   4.101 +                return PEP_OUT_OF_MEMORY;
   4.102 +        }
   4.103          ||
   4.104      }
   4.105  }
     5.1 --- a/sync/sync.fsm	Thu Aug 16 23:57:52 2018 +0200
     5.2 +++ b/sync/sync.fsm	Fri Aug 17 15:23:08 2018 +0200
     5.3 @@ -30,6 +30,7 @@
     5.4          state Sole {
     5.5              on Init {
     5.6                  do closeHandshakeDialog;
     5.7 +                do clearState;
     5.8                  do openChallenge; // own challenge
     5.9                  do sendBeacon;
    5.10              }
    5.11 @@ -215,8 +216,10 @@
    5.12          }
    5.13  
    5.14          state Grouped {
    5.15 -            on Init
    5.16 +            on Init {
    5.17                  do closeHandshakeDialog;
    5.18 +                do clearState;
    5.19 +            }
    5.20  
    5.21              on GroupKeys
    5.22                  do saveGroupKeys;