Added sync some protocol payload definitions
authorEdouard Tisserant
Thu, 12 May 2016 18:26:19 +0200
changeset 613d59da438b2cb
parent 610 1e3d39516f43
child 614 6bf3b8a6fb1b
Added sync some protocol payload definitions
src/sync_codec.c
src/sync_fsm.h
sync/Makefile
sync/fsm.yml2
sync/gen_codec.ysl2
sync/sync.fsm
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/sync_codec.c	Thu May 12 18:26:19 2016 +0200
     1.3 @@ -0,0 +1,15 @@
     1.4 +// encoders and decoders state for DeviceGroup protocol
     1.5 +
     1.6 +#include "pEpEngine.h"
     1.7 +
     1.8 +// decoders
     1.9 +
    1.10 +void decodeBeacon(const char **bufp, size_t *sizep);
    1.11 +void decodeHandshakeRequest(const char **bufp, size_t *sizep, Identity partner);
    1.12 +void decodeOwnKeys(const char **bufp, size_t *sizep, Stringlist *ownKeys);
    1.13 +
    1.14 +// encoders 
    1.15 +
    1.16 +void encodeBeacon(const char **bufp, size_t *sizep);
    1.17 +void encodeHandshakeRequest(const char **bufp, size_t *sizep, Identity partner);
    1.18 +void encodeOwnKeys(const char **bufp, size_t *sizep, Stringlist *ownKeys);
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/sync_fsm.h	Thu May 12 18:26:19 2016 +0200
     2.3 @@ -0,0 +1,56 @@
     2.4 +#pragma once
     2.5 +
     2.6 +// state machine for DeviceState
     2.7 +
     2.8 +#include "pEpEngine.h"
     2.9 +
    2.10 +// types
    2.11 +
    2.12 +typedef pEp_identity * Identity;
    2.13 +typedef union _param { const Identity partner; const stringlist_t *keylist; } param_t;
    2.14 +
    2.15 +// error values
    2.16 +
    2.17 +typedef enum _fsm_error {
    2.18 +    invalid_state = -1,
    2.19 +    invalid_event = -2
    2.20 +} fsm_error;
    2.21 +
    2.22 +// states
    2.23 +
    2.24 +typedef enum _DeviceState_state {
    2.25 +    Sole, 
    2.26 +    HandshakingSole, 
    2.27 +    WaitForGroupKeys, 
    2.28 +    Grouped
    2.29 +} DeviceState_state;
    2.30 +
    2.31 +// events
    2.32 +
    2.33 +typedef enum _DeviceState_event {
    2.34 +    KeyGen, 
    2.35 +    CannotDecrypt, 
    2.36 +    Beacon, 
    2.37 +    HandshakeRequest, 
    2.38 +    Init, 
    2.39 +    HandshakeRejected, 
    2.40 +    HandshakeAccepted, 
    2.41 +    ReceiveGroupKeys, 
    2.42 +    Cancel, 
    2.43 +    Reject
    2.44 +} DeviceState_event;
    2.45 +
    2.46 +// actions
    2.47 +
    2.48 +void sendBeacon(const Identity partner);
    2.49 +void sendHandshakeRequest(const Identity partner);
    2.50 +void showHandshake(const Identity partner);
    2.51 +void reject(const Identity partner);
    2.52 +void storeGroupKeys(const Identity partner);
    2.53 +void sendOwnKeys(const Identity partner);
    2.54 +void transmitGroupKeys(const Identity partner);
    2.55 +
    2.56 +// driver
    2.57 +
    2.58 +void fsm_DeviceState_inject(PEP_SESSION session, DeviceState_event event);
    2.59 +
     3.1 --- a/sync/Makefile	Thu May 12 12:58:40 2016 +0200
     3.2 +++ b/sync/Makefile	Thu May 12 18:26:19 2016 +0200
     3.3 @@ -1,7 +1,7 @@
     3.4 -../src/sync_fsm.c: sync.fsm gen_statemachine.ysl2
     3.5 +../src/sync_fsm.c: sync.fsm gen_statemachine.ysl2 fsm.yml2
     3.6  	yml2proc -y gen_statemachine.ysl2 $< -o $@
     3.7  
     3.8 -../src/sync_codec.c: sync.fsm gen_codec.ysl2
     3.9 +../src/sync_codec.c: sync.fsm gen_codec.ysl2 fsm.yml2
    3.10  	yml2proc -y gen_codec.ysl2 $< -o $@
    3.11  
    3.12  sync.xml: sync.fsm fsm.yml2
     4.1 --- a/sync/fsm.yml2	Thu May 12 12:58:40 2016 +0200
     4.2 +++ b/sync/fsm.yml2	Thu May 12 18:26:19 2016 +0200
     4.3 @@ -11,3 +11,4 @@
     4.4  decl transition @target, go is transition;
     4.5  decl action @name, do is action;
     4.6  decl condition @flag, if is condition;
     4.7 +decl interface @name;
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/sync/gen_codec.ysl2	Thu May 12 18:26:19 2016 +0200
     5.3 @@ -0,0 +1,68 @@
     5.4 +// generate encoder and decoders for protocol messages
     5.5 +
     5.6 +// Copyleft (c) 2016, p≡p foundation
     5.7 +
     5.8 +include yslt.yml2
     5.9 +
    5.10 +tstylesheet {
    5.11 +
    5.12 +    key "ActionByNames", "/protocol/fsm/state/event//action", "@name";
    5.13 +    variable "UniqueActions", "/protocol/fsm/state/event//action[generate-id()=generate-id(key('ActionByNames',@name)[1])]";
    5.14 +    variable "UniqueSendActions", "$UniqueActions[starts-with(@name,'send')]";
    5.15 +
    5.16 +    template "/protocol"
    5.17 +    ||
    5.18 +    // encoders and decoders state for «@name» protocol
    5.19 +
    5.20 +    #include "pEpEngine.h"
    5.21 +
    5.22 +    // decoders
    5.23 +
    5.24 +    `` apply "$UniqueSendActions",0 mode="proto" with "pfx", "'decode'"
    5.25 +
    5.26 +    // encoders 
    5.27 +
    5.28 +    `` apply "$UniqueSendActions",0 mode="proto" with "pfx", "'encode'"
    5.29 +
    5.30 +    ||
    5.31 +
    5.32 +    def "xsl:typeOfActionParam" {
    5.33 +        param "n", "name(.)";
    5.34 +        result "name(ancestor::event/child::parm[child::*[position()=2 and name(.)=$n]]/child::*[position()=1])";
    5.35 +    }
    5.36 +    
    5.37 +    function "interfaces_params" {
    5.38 +        param "ifaceName";
    5.39 +        // variable "ifaceCommons", "/protocol/interface[@name = 'commons']/*";
    5.40 +        variable "ifaceParams", "$UniqueActions[@name = concat('send',$ifaceName)]/parm/*";
    5.41 +        variable "ifaceAdditions", "/protocol/interface[@name = $ifaceName]/*";
    5.42 +
    5.43 +        // if "count($ifaceCommons) != 0" > , 
    5.44 +        // for "$ifaceCommons" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
    5.45 +
    5.46 +        if "count($ifaceParams) != 0" > , 
    5.47 +        for "set:distinct($ifaceParams)" {
    5.48 +            > «xsl:typeOfActionParam()» «name(.)»
    5.49 +            if "position() != last()" > ,
    5.50 +        }
    5.51 +
    5.52 +        if "count($ifaceAdditions) != 0" > , 
    5.53 +        for "$ifaceAdditions" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
    5.54 +    }
    5.55 +
    5.56 +    template "action", mode="func_header" {
    5.57 +        param "pfx";
    5.58 +        variable "ifaceName", "substring-after(@name, 'send')";
    5.59 +
    5.60 +        > void «$pfx»«$ifaceName»(const char **bufp, size_t *sizep
    5.61 +        call("interfaces_params") with "ifaceName", "$ifaceName";
    5.62 +        > )
    5.63 +    }
    5.64 +
    5.65 +    template "action", mode="proto" {
    5.66 +        param "pfx";
    5.67 +        apply ".",0 mode="func_header" with "pfx", "$pfx" ;
    5.68 +        | ;
    5.69 +    }
    5.70 +}
    5.71 +
     6.1 --- a/sync/sync.fsm	Thu May 12 12:58:40 2016 +0200
     6.2 +++ b/sync/sync.fsm	Thu May 12 18:26:19 2016 +0200
     6.3 @@ -76,5 +76,13 @@
     6.4                  do reject partner;
     6.5          }
     6.6      }
     6.7 +
     6.8 +    interface commons {
     6.9 +        Header head;
    6.10 +    }
    6.11 +
    6.12 +    interface OwnKeys {
    6.13 +        Stringlist ownKeys;
    6.14 +    }
    6.15  }
    6.16