reworking send message sync
authorVolker Birk <vb@pep.foundation>
Tue, 21 Aug 2018 20:28:07 +0200
branchsync
changeset 286596aaa55b2a54
parent 2864 dcbed0d35466
child 2866 507d1368d088
reworking send message
sync/fsm.yml2
sync/gen_statemachine.ysl2
sync/sync.fsm
     1.1 --- a/sync/fsm.yml2	Tue Aug 21 17:35:00 2018 +0200
     1.2 +++ b/sync/fsm.yml2	Tue Aug 21 20:28:07 2018 +0200
     1.3 @@ -39,6 +39,11 @@
     1.4  
     1.5  decl action @name, do is action;
     1.6  
     1.7 +// send network messages
     1.8 +
     1.9 +decl send @name (type="unicast");
    1.10 +decl broadcast @name (type="broadcast") alias send;
    1.11 +
    1.12  // a condition is for different cases
    1.13  
    1.14  decl condition @name, if is condition;
     2.1 --- a/sync/gen_statemachine.ysl2	Tue Aug 21 17:35:00 2018 +0200
     2.2 +++ b/sync/gen_statemachine.ysl2	Tue Aug 21 20:28:07 2018 +0200
     2.3 @@ -141,8 +141,7 @@
     2.4          // actions
     2.5  
     2.6          ||
     2.7 -        const "name", "@name";
     2.8 -        for "func:distinctName(*//action[not(starts-with(@name, 'send'))])"
     2.9 +        for "func:distinctName(*//action)"
    2.10              | PEP_STATUS «@name»(PEP_SESSION session);
    2.11          ||
    2.12  
    2.13 @@ -652,12 +651,12 @@
    2.14  
    2.15      template "event", mode=fsm {
    2.16          | case «@name»: {
    2.17 -        if "condition|action" |> PEP_STATUS status;
    2.18 +        if "condition|action|send" |> PEP_STATUS status;
    2.19          if "condition" |> bool result = false;
    2.20 -        if "condition|action" |
    2.21 +        if "condition|action|send" |
    2.22          ||
    2.23              «../../@name»_SERVICE_LOG("received event", "«@name»");
    2.24 -            `` apply "transition|action|condition" with "protocol", "../../..", with "fsm", "../.."
    2.25 +            `` apply "transition|action|condition|send";
    2.26          ||
    2.27          if "name(*[last()])!='transition'" {
    2.28              |
    2.29 @@ -671,7 +670,7 @@
    2.30      }
    2.31  
    2.32      template "transition" {
    2.33 -        param "fsm";
    2.34 +        const "fsm", "ancestor::fsm";
    2.35          ||
    2.36  
    2.37          «$fsm/@name»_SERVICE_LOG("transition to state", "«@target»");
    2.38 @@ -679,26 +678,22 @@
    2.39          ||
    2.40      }
    2.41  
    2.42 +    template "send" {
    2.43 +        const "fsm", "ancestor::fsm";
    2.44 +        const "protocol", "ancestor::protocol";
    2.45 +        ||
    2.46 +
    2.47 +        «$fsm/@name»_SERVICE_LOG("send message", "«@name»");
    2.48 +        status = send_«$protocol/@name»_message(session, «$fsm/@id», «$fsm/@name»__payload_PR_«yml:mixedCase(@name)»);
    2.49 +        ||
    2.50 +    }
    2.51 +
    2.52      template "action" {
    2.53 -        param "protocol";
    2.54 -        param "fsm";
    2.55 -        choose {
    2.56 -            when "starts-with(@name, 'send')" {
    2.57 -                const "name", "substring(@name, 5)";
    2.58 -                ||
    2.59 +        const "fsm", "ancestor::fsm";
    2.60 +        ||
    2.61  
    2.62 -                «$fsm/@name»_SERVICE_LOG("send message", "«$name»");
    2.63 -                status = send_«$protocol/@name»_message(session, «$fsm/@id», «$fsm/@name»__payload_PR_«yml:mixedCase($name)»);
    2.64 -                ||
    2.65 -            }
    2.66 -            otherwise
    2.67 -                ||
    2.68 -
    2.69 -                «$fsm/@name»_SERVICE_LOG("do action", "«@name»");
    2.70 -                status = «@name»(session);
    2.71 -                ||
    2.72 -        }
    2.73 -        ||
    2.74 +        «$fsm/@name»_SERVICE_LOG("do action", "«@name»");
    2.75 +        status = «@name»(session);
    2.76          if (status) {
    2.77              «$fsm/@name»_ERR_LOG_HEX("executing action «@name»() failed", status);
    2.78              return invalid_action;
    2.79 @@ -707,8 +702,7 @@
    2.80      }
    2.81  
    2.82      template "condition" {
    2.83 -        param "protocol";
    2.84 -        param "fsm";
    2.85 +        const "fsm", "ancestor::fsm";
    2.86          ||
    2.87  
    2.88          status = «@name»(session, &result);
    2.89 @@ -719,8 +713,7 @@
    2.90          if (result) {
    2.91              «$fsm/@name»_SERVICE_LOG("condition applies", "«@name»");
    2.92          ||
    2.93 -            apply "transition|action|condition"
    2.94 -                with "protocol", "$protocol", with "fsm", "$fsm";
    2.95 +        apply "transition|action|condition|send";
    2.96          | }
    2.97      }
    2.98  }
     3.1 --- a/sync/sync.fsm	Tue Aug 21 17:35:00 2018 +0200
     3.2 +++ b/sync/sync.fsm	Tue Aug 21 20:28:07 2018 +0200
     3.3 @@ -32,26 +32,26 @@
     3.4                  do closeHandshakeDialog;
     3.5                  do clearState;
     3.6                  do openChallenge; // own challenge
     3.7 -                do sendBeacon;
     3.8 +                send Beacon;
     3.9              }
    3.10  
    3.11              on KeyGen
    3.12 -                do sendBeacon;
    3.13 +                send Beacon;
    3.14  
    3.15              on CannotDecrypt // cry baby
    3.16 -                do sendBeacon;
    3.17 +                send Beacon;
    3.18  
    3.19              on Beacon {
    3.20                  do storeChallenge; // partner's challenge
    3.21                  do openTransaction;
    3.22                  do storeTransaction;
    3.23 -                do sendHandshakeRequest;
    3.24 +                send HandshakeRequest;
    3.25              }
    3.26  
    3.27              on HandshakeRequest {
    3.28                  if challengeAccepted {
    3.29                      do storeTransaction;
    3.30 -                    do sendHandshakeAnswer;
    3.31 +                    send HandshakeAnswer;
    3.32                      if partnerIsGrouped
    3.33                          go HandshakingWithGroup;
    3.34  
    3.35 @@ -70,7 +70,7 @@
    3.36  
    3.37              // Cancel is Rollback
    3.38              on Cancel {
    3.39 -                do sendRollback;
    3.40 +                send Rollback;
    3.41                  go Sole;
    3.42              }
    3.43  
    3.44 @@ -79,7 +79,7 @@
    3.45  
    3.46              // Reject is CommitReject
    3.47              on Reject {
    3.48 -                do sendCommitReject;
    3.49 +                send CommitReject;
    3.50                  do disable;
    3.51                  go End;
    3.52              }
    3.53 @@ -91,7 +91,7 @@
    3.54  
    3.55              // Accept is Phase1Commit
    3.56              on Accept {
    3.57 -                do sendCommitAccept;
    3.58 +                send CommitAccept;
    3.59                  go HandshakingNewPhase1;
    3.60              }
    3.61  
    3.62 @@ -114,12 +114,12 @@
    3.63  
    3.64          state HandshakingNewPhase1Own {
    3.65              on Cancel {
    3.66 -                do sendRollback;
    3.67 +                send Rollback;
    3.68                  go Sole;
    3.69              }
    3.70  
    3.71              on Reject {
    3.72 -                do sendCommitReject;
    3.73 +                send CommitReject;
    3.74                  do disable;
    3.75                  go End;
    3.76              }
    3.77 @@ -130,7 +130,7 @@
    3.78  
    3.79          state NewGroup {
    3.80              on Init
    3.81 -                do sendGroupKeysAndClose; // we're not grouped yet, this is our own keys
    3.82 +                send GroupKeysAndClose; // we're not grouped yet, this is our own keys
    3.83  
    3.84              on GroupKeysAndClose {
    3.85                  do saveGroupKeys;
    3.86 @@ -149,7 +149,7 @@
    3.87  
    3.88              // Cancel is Rollback
    3.89              on Cancel {
    3.90 -                do sendRollback;
    3.91 +                send Rollback;
    3.92                  go Sole;
    3.93              }
    3.94  
    3.95 @@ -158,7 +158,7 @@
    3.96  
    3.97              // Reject is CommitReject
    3.98              on Reject {
    3.99 -                do sendCommitReject;
   3.100 +                send CommitReject;
   3.101                  do disable;
   3.102                  go End;
   3.103              }
   3.104 @@ -170,7 +170,7 @@
   3.105  
   3.106              // Accept is Phase1Commit
   3.107              on Accept {
   3.108 -                do sendCommitAccept;
   3.109 +                send CommitAccept;
   3.110                  go HandshakingJoinPhase1;
   3.111              }
   3.112  
   3.113 @@ -193,12 +193,12 @@
   3.114  
   3.115          state HandshakingJoinPhase1Own {
   3.116              on Cancel {
   3.117 -                do sendRollback;
   3.118 +                send Rollback;
   3.119                  go Sole;
   3.120              }
   3.121  
   3.122              on Reject {
   3.123 -                do sendCommitReject;
   3.124 +                send CommitReject;
   3.125                  do disable;
   3.126                  go End;
   3.127              }
   3.128 @@ -209,7 +209,7 @@
   3.129  
   3.130          state JoinGroup {
   3.131              on GroupKeysAndClose {
   3.132 -                do sendGroupKeys; // first send own keys
   3.133 +                send GroupKeys; // first send own keys
   3.134                  do saveGroupKeys; // then store new group keys
   3.135                  go Grouped;
   3.136              }
   3.137 @@ -225,10 +225,10 @@
   3.138                  do saveGroupKeys;
   3.139  
   3.140              on KeyGen
   3.141 -                do sendGroupKeys;
   3.142 +                send GroupKeys;
   3.143  
   3.144              on Beacon
   3.145 -                do sendHandshakeRequest;
   3.146 +                send HandshakeRequest;
   3.147  
   3.148              on HandshakeAnswer
   3.149                  go HandshakingGrouped;
   3.150 @@ -240,7 +240,7 @@
   3.151      
   3.152              // Cancel is Rollback
   3.153              on Cancel {
   3.154 -                do sendRollback;
   3.155 +                send Rollback;
   3.156                  go Grouped;
   3.157              }
   3.158  
   3.159 @@ -249,7 +249,7 @@
   3.160  
   3.161              // Reject is CommitReject
   3.162              on Reject {
   3.163 -                do sendCommitReject;
   3.164 +                send CommitReject;
   3.165                  go Grouped;
   3.166              }
   3.167  
   3.168 @@ -258,7 +258,7 @@
   3.169  
   3.170              // Accept is Phase1Commit
   3.171              on Accept {
   3.172 -                do sendCommitAccept;
   3.173 +                send CommitAccept;
   3.174                  go HandshakingGroupedPhase1;
   3.175              }
   3.176  
   3.177 @@ -277,7 +277,7 @@
   3.178                  go Grouped;
   3.179  
   3.180              on CommitAccept {
   3.181 -                do sendGroupKeysAndClose;
   3.182 +                send GroupKeysAndClose;
   3.183                  go Grouped;
   3.184              }
   3.185  
   3.186 @@ -287,17 +287,17 @@
   3.187  
   3.188          state HandshakingGroupedPhase1Own {
   3.189              on Cancel {
   3.190 -                do sendRollback;
   3.191 +                send Rollback;
   3.192                  go Grouped;
   3.193              }
   3.194  
   3.195              on Reject {
   3.196 -                do sendCommitReject;
   3.197 +                send CommitReject;
   3.198                  go Grouped;
   3.199              }
   3.200  
   3.201              on Accept {
   3.202 -                do sendGroupKeysAndClose;
   3.203 +                send GroupKeysAndClose;
   3.204                  go Grouped;
   3.205              }
   3.206