merge
authorEdouard Tisserant
Sat, 09 Jul 2016 15:24:01 +0200
changeset 8132f069faaf513
parent 812 786f03e0cae4
parent 811 71418dbb493c
child 814 91f317ce921f
merge
sync/sync.fsm
     1.1 --- a/.hgignore	Sat Jul 09 15:20:23 2016 +0200
     1.2 +++ b/.hgignore	Sat Jul 09 15:24:01 2016 +0200
     1.3 @@ -33,4 +33,6 @@
     1.4  msg4.asc
     1.5  pep_Dokument_Titel.pdf
     1.6  pEpEngine.vcxproj.user
     1.7 -
     1.8 +*.skeleton
     1.9 +.skeletons
    1.10 +.statemachines
     2.1 --- a/Makefile	Sat Jul 09 15:20:23 2016 +0200
     2.2 +++ b/Makefile	Sat Jul 09 15:24:01 2016 +0200
     2.3 @@ -18,6 +18,7 @@
     2.4  	$(MAKE) -C src clean
     2.5  	$(MAKE) -C test clean
     2.6  	$(MAKE) -C db clean
     2.7 +	$(MAKE) -C sync clean
     2.8  	$(MAKE) -C asn.1 clean
     2.9  
    2.10  test: all
     3.1 --- a/src/Makefile	Sat Jul 09 15:20:23 2016 +0200
     3.2 +++ b/src/Makefile	Sat Jul 09 15:24:01 2016 +0200
     3.3 @@ -59,8 +59,7 @@
     3.4  
     3.5  all: $(TARGET)
     3.6  
     3.7 -sync_fsm.c: ../sync/sync.fsm
     3.8 -	make -C ../sync
     3.9 +include Makefile.protocols
    3.10  
    3.11  %.d: %.c
    3.12  	@set -e; rm -f $@; \
     4.1 --- a/src/sync_actions.c	Sat Jul 09 15:20:23 2016 +0200
     4.2 +++ b/src/sync_actions.c	Sat Jul 09 15:24:01 2016 +0200
     4.3 @@ -108,7 +108,7 @@
     4.4  //  params:
     4.5  //      session (in)        session handle
     4.6  //      state (in)          state the state machine is in
     4.7 -//      partner (in)        partner in sync
     4.8 +//      partner (in)        partner to communicate with
     4.9  //
    4.10  //  returns:
    4.11  //      PEP_STATUS_OK or any other value on error
    4.12 @@ -202,7 +202,7 @@
    4.13  //  params:
    4.14  //      session (in)        session handle
    4.15  //      state (in)          state the state machine is in
    4.16 -//      partner (in)        partner in sync
    4.17 +//      partner (in)        partner to communicate with
    4.18  //
    4.19  //  returns:
    4.20  //      PEP_STATUS_OK or any other value on error
    4.21 @@ -238,7 +238,7 @@
    4.22  //  params:
    4.23  //      session (in)        session handle
    4.24  //      state (in)          state the state machine is in
    4.25 -//      partner (in)        partner in sync
    4.26 +//      partner (in)        partner to communicate with
    4.27  //
    4.28  //  returns:
    4.29  //      PEP_STATUS_OK or any other value on error
    4.30 @@ -274,7 +274,7 @@
    4.31  //  params:
    4.32  //      session (in)        session handle
    4.33  //      state (in)          state the state machine is in
    4.34 -//      partner (in)        partner in sync
    4.35 +//      partner (in)        partner to communicate with
    4.36  //
    4.37  //  returns:
    4.38  //      PEP_STATUS_OK or any other value on error
    4.39 @@ -395,3 +395,4 @@
    4.40      return status;
    4.41  }
    4.42  
    4.43 +
     5.1 --- a/src/sync_fsm.c	Sat Jul 09 15:20:23 2016 +0200
     5.2 +++ b/src/sync_fsm.c	Sat Jul 09 15:24:01 2016 +0200
     5.3 @@ -98,3 +98,4 @@
     5.4  
     5.5      return state;
     5.6  }
     5.7 +
     6.1 --- a/sync/Makefile	Sat Jul 09 15:20:23 2016 +0200
     6.2 +++ b/sync/Makefile	Sat Jul 09 15:24:01 2016 +0200
     6.3 @@ -1,16 +1,16 @@
     6.4  include ../Makefile.conf
     6.5  
     6.6 -all: ../src/sync_fsm.c
     6.7 +all: .statemachines
     6.8  
     6.9 -skeleton: ../src/sync_actions.c.skeleton
    6.10 +skeleton: .skeletons
    6.11  
    6.12 -../src/sync_actions.c.skeleton: sync.fsm gen_actions_skeleton.ysl2 fsm.yml2 functions.ysl2
    6.13 +.skeletons: devicegroup.fsm gen_actions_skeleton.ysl2 fsm.yml2 functions.ysl2
    6.14  	$(YML2PROC) -y gen_actions_skeleton.ysl2 $< -o $@
    6.15  
    6.16 -../src/sync_fsm.c: sync.fsm gen_statemachine.ysl2 fsm.yml2 functions.ysl2
    6.17 +.statemachines: devicegroup.fsm gen_statemachine.ysl2 fsm.yml2 functions.ysl2
    6.18  	$(YML2PROC) -y gen_statemachine.ysl2 $< -o $@
    6.19  
    6.20  .PHONY: clean
    6.21  
    6.22  clean:
    6.23 -	rm -f *.xml *.xsl ../src/sync_fsm.* ../src/*.skeleton
    6.24 +	rm -f *.xml *.xsl ../src/sync_fsm.* ../src/*.skeleton .statemachines .skeletons
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/sync/devicegroup.fsm	Sat Jul 09 15:24:01 2016 +0200
     7.3 @@ -0,0 +1,87 @@
     7.4 +// DeviceGroup protocol for p≡p
     7.5 +
     7.6 +// Copyleft (c) 2016, p≡p foundation
     7.7 +
     7.8 +// Written by Volker Birk
     7.9 +
    7.10 +include ./fsm.yml2
    7.11 +
    7.12 +protocol DeviceGroup {
    7.13 +    // all messages have a timestamp, time out and are removed after timeout
    7.14 +
    7.15 +    fsm DeviceState filename=sync {
    7.16 +        state InitState {
    7.17 +            on Init {
    7.18 +                if (storedGroupKeys)
    7.19 +                    go Grouped;
    7.20 +                go Sole;
    7.21 +            }
    7.22 +        }
    7.23 +
    7.24 +        state Sole {
    7.25 +            on KeyGen
    7.26 +                do sendBeacon;
    7.27 +            on CannotDecrypt
    7.28 +                do sendBeacon;  // cry, baby
    7.29 +            on Beacon(Identity partner) // this event will not happen for already
    7.30 +                                        // rejected partners
    7.31 +                do sendHandshakeRequest(partner);
    7.32 +            on HandshakeRequest(Identity partner) {
    7.33 +                do sendHandshakeRequest(partner);
    7.34 +                go HandshakingSole(partner);
    7.35 +            }
    7.36 +        }
    7.37 +
    7.38 +        state HandshakingSole(Identity partner) {
    7.39 +            on Init
    7.40 +                do showHandshake(partner);
    7.41 +            on HandshakeRejected(Identity partner) {
    7.42 +                do reject(partner);             // sends Reject to partner and
    7.43 +                                                // stores rejection of partner
    7.44 +                go Sole;
    7.45 +            }
    7.46 +            on HandshakeAccepted(Identity partner) {
    7.47 +                if keyElectionWon(partner) {    // an already existing group
    7.48 +                                                // always wins
    7.49 +                    ownGroupKeys;
    7.50 +                    sendGroupKeys(partner);
    7.51 +                    go Grouped;
    7.52 +                }
    7.53 +                go WaitForGroupKeys(Identity partner);
    7.54 +            }
    7.55 +        }
    7.56 +    
    7.57 +        state WaitForGroupKeys(Identity partner) {
    7.58 +            on GroupKeys(Identity partner, Stringlist keys) {
    7.59 +                do storeGroupKeys(partner, keys);
    7.60 +                go Grouped;
    7.61 +            }
    7.62 +            on Cancel go Sole;
    7.63 +            on Reject(Identity partner) {
    7.64 +                do reject(partner);
    7.65 +                go Sole;
    7.66 +            }
    7.67 +        }
    7.68 +
    7.69 +        state Grouped {
    7.70 +            on KeyGen
    7.71 +                do sendGroupKeys; // always send all keys
    7.72 +            on HandshakeRequest(Identity partner) {
    7.73 +                do sendHandshakeRequest(partner);
    7.74 +                do showHandshake(partner);
    7.75 +            }
    7.76 +            on HandshakeRejected(Identity partner)
    7.77 +                do reject(partner);
    7.78 +            on HandshakeAccepted(Identity partner)
    7.79 +                do sendGroupKeys(partner);
    7.80 +            on Reject(Identity partner)
    7.81 +                do reject partner;
    7.82 +        }
    7.83 +
    7.84 +        tag InitState 0;
    7.85 +        tag Beacon 1;
    7.86 +        tag HandshakeRequest 2;
    7.87 +        tag GroupKeys 3;
    7.88 +    }
    7.89 +}
    7.90 +
     8.1 --- a/sync/gen_actions_skeleton.ysl2	Sat Jul 09 15:20:23 2016 +0200
     8.2 +++ b/sync/gen_actions_skeleton.ysl2	Sat Jul 09 15:24:01 2016 +0200
     8.3 @@ -9,21 +9,22 @@
     8.4  tstylesheet {
     8.5      include ./functions.ysl2
     8.6  
     8.7 -    template "/protocol/fsm" {
     8.8 +    template "/protocol/fsm" document "../src/{@filename}_actions.c.skeleton", "text" {
     8.9 +        const "name", "@name";
    8.10 +        const "filename", "@filename";
    8.11      ||
    8.12 -    `` const "name", "@name"
    8.13      // Actions for «@name» state machine
    8.14  
    8.15      #include <assert.h>
    8.16      #include "pEp_internal.h"
    8.17      #include "keymanagement.h"
    8.18      #include "message.h"
    8.19 -    #include "sync_fsm.h"
    8.20 +    #include "«@filename»_fsm.h"
    8.21      #include "baseprotocol.h"
    8.22      #include "map_asn1.h"
    8.23      `` for "func:distinctName(//action)" if "substring(@name, 1, 4) = 'send'" | #include "../asn.1/«substring(@name, 5, 255)».h"
    8.24  
    8.25 -    `` for "func:distinctName(//action)" call "action" with "action", ".", with "fsm", "$name";
    8.26 +    `` for "func:distinctName(//action)" call "action" with "action", ".", with "fsm", "$name", with "filename", "$filename";
    8.27  
    8.28      ||
    8.29      }
    8.30 @@ -31,13 +32,14 @@
    8.31      function "action" {
    8.32          param "action";
    8.33          param "fsm";
    8.34 +        param "filename", "'###'";
    8.35          choose {
    8.36              when "substring($action/@name, 1, 4) = 'send'"
    8.37                  call "send_action" with "action", "$action",
    8.38 -                     with "fsm", "$fsm";
    8.39 +                     with "fsm", "$fsm", with "filename", "$filename";
    8.40              otherwise
    8.41                  call "other_action" with "action", "$action",
    8.42 -                     with "fsm", "$fsm";
    8.43 +                     with "fsm", "$fsm", with "filename", "$filename";
    8.44          }
    8.45      }
    8.46  
    8.47 @@ -63,6 +65,7 @@
    8.48      function "other_action" {
    8.49          param "action";
    8.50          param "fsm";
    8.51 +        param "filename", "'###'";
    8.52  
    8.53          ||
    8.54  
    8.55 @@ -71,7 +74,7 @@
    8.56          //  params:
    8.57          //      session (in)        session handle
    8.58          //      state (in)          state the state machine is in
    8.59 -        `` if "parm"        | //      partner (in)        partner in sync
    8.60 +        `` if "parm"        | //      partner (in)        partner to communicate with
    8.61          `` if "not(parm)"   | //      partner (in)        (must be NULL)
    8.62          //
    8.63          //  returns:
    8.64 @@ -105,6 +108,7 @@
    8.65      function "send_action" {
    8.66          param "action";
    8.67          param "fsm";
    8.68 +        param "filename", "'###'";
    8.69          const "name", "substring($action/@name, 5, 255)";
    8.70  
    8.71          ||
    8.72 @@ -114,7 +118,7 @@
    8.73          //  params:
    8.74          //      session (in)        session handle
    8.75          //      state (in)          state the state machine is in
    8.76 -        `` if "parm"        | //      partner (in)        partner in sync
    8.77 +        `` if "parm"        | //      partner (in)        partner to communicate with
    8.78          `` if "not(parm)"   | //      partner (in)        (must be NULL)
    8.79          //
    8.80          //  returns:
    8.81 @@ -189,7 +193,7 @@
    8.82              free_identity(me);
    8.83              me = NULL;
    8.84  
    8.85 -            status = session->messageToSend(session->sync_obj, _message);
    8.86 +            status = session->messageToSend(session->«$filename»_obj, _message);
    8.87  
    8.88              free_message(_message);
    8.89              ASN_STRUCT_FREE(asn_DEF_«$name», msg);
     9.1 --- a/sync/gen_statemachine.ysl2	Sat Jul 09 15:20:23 2016 +0200
     9.2 +++ b/sync/gen_statemachine.ysl2	Sat Jul 09 15:24:01 2016 +0200
     9.3 @@ -9,8 +9,20 @@
     9.4  tstylesheet {
     9.5      include ./functions.ysl2
     9.6  
     9.7 -    template "/protocol/fsm" {
     9.8 -        document "../src/sync_fsm.h", "text" {
     9.9 +    template "/protocol" {
    9.10 +        document "../src/Makefile.protocols", "text"
    9.11 +            apply "fsm", 0, mode="make";
    9.12 +        apply "fsm", 0, mode=gen;
    9.13 +    }
    9.14 +
    9.15 +    template "fsm", mode=make
    9.16 +    ||
    9.17 +    «@filename»_fsm.c: ../sync/devicegroup.fsm
    9.18 +    \tmake -C ../«@filename»
    9.19 +    ||
    9.20 +
    9.21 +    template "fsm", mode=gen {
    9.22 +        document "../src/{@filename}_fsm.h", "text" {
    9.23          ||
    9.24          #pragma once
    9.25  
    9.26 @@ -85,7 +97,7 @@
    9.27  
    9.28          ||
    9.29          }
    9.30 -        document "../src/sync_driver.c", "text"
    9.31 +        document "../src/{@filename}_driver.c", "text"
    9.32          ||
    9.33          // Driver for «@name» state machine
    9.34  
    9.35 @@ -102,15 +114,16 @@
    9.36          {
    9.37              PEP_STATUS status = PEP_STATUS_OK;
    9.38  
    9.39 -            session->sync_state = fsm_«@name»(session, session->sync_state,
    9.40 +            session->«@filename»_state = fsm_«@name»(session, session->«@filename»_state,
    9.41                      event, partner, state_partner);
    9.42  
    9.43              return status;
    9.44          }
    9.45  
    9.46          ||
    9.47 +        document "../src/{@filename}_fsm.c", "text"
    9.48          ||
    9.49 -        #include "sync_fsm.h"
    9.50 +        #include "«@filename»_fsm.h"
    9.51  
    9.52          // state machine for «@name»
    9.53  
    10.1 --- a/sync/sync.fsm	Sat Jul 09 15:20:23 2016 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,87 +0,0 @@
    10.4 -// DeviceGroup protocol for p≡p
    10.5 -
    10.6 -// Copyleft (c) 2016, p≡p foundation
    10.7 -
    10.8 -// Written by Volker Birk
    10.9 -
   10.10 -include ./fsm.yml2
   10.11 -
   10.12 -protocol DeviceGroup {
   10.13 -    // all messages have a timestamp, time out and are removed after timeout
   10.14 -
   10.15 -    fsm DeviceState {
   10.16 -        state InitState {
   10.17 -            on Init {
   10.18 -                if (storedGroupKeys)
   10.19 -                    go Grouped;
   10.20 -                go Sole;
   10.21 -            }
   10.22 -        }
   10.23 -
   10.24 -        state Sole {
   10.25 -            on KeyGen
   10.26 -                do sendBeacon;
   10.27 -            on CannotDecrypt
   10.28 -                do sendBeacon;  // cry, baby
   10.29 -            on Beacon(Identity partner) // this event will not happen for already
   10.30 -                                        // rejected partners
   10.31 -                do sendHandshakeRequest(partner);
   10.32 -            on HandshakeRequest(Identity partner) {
   10.33 -                do sendHandshakeRequest(partner);
   10.34 -                go HandshakingSole(partner);
   10.35 -            }
   10.36 -        }
   10.37 -
   10.38 -        state HandshakingSole(Identity partner) {
   10.39 -            on Init
   10.40 -                do showHandshake(partner);
   10.41 -            on HandshakeRejected(Identity partner) {
   10.42 -                do reject(partner);             // sends Reject to partner and
   10.43 -                                                // stores rejection of partner
   10.44 -                go Sole;
   10.45 -            }
   10.46 -            on HandshakeAccepted(Identity partner) {
   10.47 -                if keyElectionWon(partner) {    // an already existing group
   10.48 -                                                // always wins
   10.49 -                    ownGroupKeys;
   10.50 -                    sendGroupKeys(partner);
   10.51 -                    go Grouped;
   10.52 -                }
   10.53 -                go WaitForGroupKeys(Identity partner);
   10.54 -            }
   10.55 -        }
   10.56 -    
   10.57 -        state WaitForGroupKeys(Identity partner) {
   10.58 -            on GroupKeys(Identity partner, Stringlist keys) {
   10.59 -                do storeGroupKeys(partner, keys);
   10.60 -                go Grouped;
   10.61 -            }
   10.62 -            on Cancel go Sole;
   10.63 -            on Reject(Identity partner) {
   10.64 -                do reject(partner);
   10.65 -                go Sole;
   10.66 -            }
   10.67 -        }
   10.68 -
   10.69 -        state Grouped {
   10.70 -            on KeyGen
   10.71 -                do sendGroupKeys; // always send all keys
   10.72 -            on HandshakeRequest(Identity partner) {
   10.73 -                do sendHandshakeRequest(partner);
   10.74 -                do showHandshake(partner);
   10.75 -            }
   10.76 -            on HandshakeRejected(Identity partner)
   10.77 -                do reject(partner);
   10.78 -            on HandshakeAccepted(Identity partner)
   10.79 -                do sendGroupKeys(partner);
   10.80 -            on Reject(Identity partner)
   10.81 -                do reject partner;
   10.82 -        }
   10.83 -
   10.84 -        tag InitState 0;
   10.85 -        tag Beacon 1;
   10.86 -        tag HandshakeRequest 2;
   10.87 -        tag GroupKeys 3;
   10.88 -    }
   10.89 -}
   10.90 -