Sync: enable fast polling right after sending beacon
authorEdouard Tisserant <edouard@pep-project.org>
Fri, 28 Apr 2017 19:03:21 +0200
changeset 173973374beaca6f
parent 1738 a7c4c6241b93
child 1740 961f325d7a85
child 1742 fe5c1dc9d028
Sync: enable fast polling right after sending beacon
sync/devicegroup.fsm
sync/generated/sync_fsm.c
sync/generated/sync_fsm.h
     1.1 --- a/sync/devicegroup.fsm	Fri Apr 28 12:02:57 2017 +0200
     1.2 +++ b/sync/devicegroup.fsm	Fri Apr 28 19:03:21 2017 +0200
     1.3 @@ -32,10 +32,14 @@
     1.4          }
     1.5  
     1.6          state Sole end=1 {
     1.7 -            on KeyGen
     1.8 +            on KeyGen {
     1.9                  do sendBeacon;
    1.10 -            on CannotDecrypt
    1.11 +                go SoleWaiting;
    1.12 +            }
    1.13 +            on CannotDecrypt {
    1.14                  do sendBeacon;
    1.15 +                go SoleWaiting;
    1.16 +            }
    1.17              on Beacon(Identity partner){
    1.18                  do sendHandshakeRequest(partner);
    1.19                  go SoleBeaconed(partner);
    1.20 @@ -46,6 +50,26 @@
    1.21              }
    1.22          }
    1.23  
    1.24 +        // copy of sole state with a timeout to enable fast polling for a second
    1.25 +        // TODO use more YSLT power here (substates ?) 
    1.26 +        state SoleWaiting timeout=60 {
    1.27 +            on KeyGen {
    1.28 +                do sendBeacon;
    1.29 +            }
    1.30 +            on CannotDecrypt {
    1.31 +                do sendBeacon;
    1.32 +            }
    1.33 +            on Beacon(Identity partner){
    1.34 +                do sendHandshakeRequest(partner);
    1.35 +                go SoleBeaconed(partner);
    1.36 +            }
    1.37 +            on HandshakeRequest(Identity partner) {
    1.38 +                do sendHandshakeRequest(partner);
    1.39 +                go HandshakingSole(partner);
    1.40 +            }
    1.41 +            on Timeout go Sole;
    1.42 +        }
    1.43 +
    1.44          state SoleBeaconed timeout=600 (Identity expected) {
    1.45              on KeyGen{
    1.46                  do sendBeacon;
    1.47 @@ -161,6 +185,7 @@
    1.48              on CannotDecrypt {
    1.49                  do sendUpdateRequest;
    1.50                  do sendBeacon;
    1.51 +                go GroupWaiting;
    1.52              }
    1.53              on UpdateRequest
    1.54                  do sendGroupUpdate;
    1.55 @@ -176,6 +201,29 @@
    1.56                  do storeGroupUpdate(partner, keys);
    1.57          }
    1.58  
    1.59 +        // copy of grouped state, with a timeout to enable fast poling for a minut
    1.60 +        state GroupWaiting timeout=60 {
    1.61 +            on KeyGen
    1.62 +                do sendGroupUpdate;
    1.63 +            on CannotDecrypt {
    1.64 +                do sendUpdateRequest;
    1.65 +                do sendBeacon;
    1.66 +            }
    1.67 +            on UpdateRequest
    1.68 +                do sendGroupUpdate;
    1.69 +            on Beacon(Identity partner){
    1.70 +                do sendHandshakeRequest(partner);
    1.71 +                go GroupedBeaconed(partner);
    1.72 +            }
    1.73 +            on HandshakeRequest(Identity partner) {
    1.74 +                do sendHandshakeRequest(partner);
    1.75 +                go HandshakingGrouped(partner);
    1.76 +            }
    1.77 +            on GroupUpdate(Identity partner, IdentityList keys)
    1.78 +                do storeGroupUpdate(partner, keys);
    1.79 +            on Timeout go Grouped;
    1.80 +        }
    1.81 +
    1.82          state GroupedBeaconed timeout=600 (Identity expected){
    1.83              on KeyGen
    1.84                  do sendGroupUpdate;
     2.1 --- a/sync/generated/sync_fsm.c	Fri Apr 28 12:02:57 2017 +0200
     2.2 +++ b/sync/generated/sync_fsm.c	Fri Apr 28 19:03:21 2017 +0200
     2.3 @@ -100,7 +100,8 @@
     2.4                          return (int) invalid_out_of_memory;
     2.5                      if (status != PEP_STATUS_OK)
     2.6                          return (int) invalid_action;
     2.7 -                    break;
     2.8 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Sole, event=KeyGen", "target=SoleWaiting")
     2.9 +                    return SoleWaiting;
    2.10                  }
    2.11                  case CannotDecrypt:
    2.12                  {
    2.13 @@ -111,7 +112,8 @@
    2.14                          return (int) invalid_out_of_memory;
    2.15                      if (status != PEP_STATUS_OK)
    2.16                          return (int) invalid_action;
    2.17 -                    break;
    2.18 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Sole, event=CannotDecrypt", "target=SoleWaiting")
    2.19 +                    return SoleWaiting;
    2.20                  }
    2.21                  case Beacon:
    2.22                  {
    2.23 @@ -152,6 +154,81 @@
    2.24              }
    2.25              break;
    2.26          }
    2.27 +        case SoleWaiting:
    2.28 +        {
    2.29 +            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=SoleWaiting")
    2.30 +            switch (event) {
    2.31 +                case Init: 
    2.32 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleWaiting", "event=Init") 
    2.33 +                    *timeout = 60;
    2.34 +                    break;
    2.35 +                case KeyGen:
    2.36 +                {
    2.37 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleWaiting", "event=KeyGen")
    2.38 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleWaiting, event=KeyGen", "action=sendBeacon")
    2.39 +                    status = sendBeacon(session, state, NULL, NULL);
    2.40 +                    if (status == PEP_OUT_OF_MEMORY)
    2.41 +                        return (int) invalid_out_of_memory;
    2.42 +                    if (status != PEP_STATUS_OK)
    2.43 +                        return (int) invalid_action;
    2.44 +                    break;
    2.45 +                }
    2.46 +                case CannotDecrypt:
    2.47 +                {
    2.48 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleWaiting", "event=CannotDecrypt")
    2.49 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleWaiting, event=CannotDecrypt", "action=sendBeacon")
    2.50 +                    status = sendBeacon(session, state, NULL, NULL);
    2.51 +                    if (status == PEP_OUT_OF_MEMORY)
    2.52 +                        return (int) invalid_out_of_memory;
    2.53 +                    if (status != PEP_STATUS_OK)
    2.54 +                        return (int) invalid_action;
    2.55 +                    break;
    2.56 +                }
    2.57 +                case Beacon:
    2.58 +                {
    2.59 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleWaiting", "event=Beacon")
    2.60 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleWaiting, event=Beacon", "action=sendHandshakeRequest")
    2.61 +                    status = sendHandshakeRequest(session, state, partner, NULL);
    2.62 +                    if (status == PEP_OUT_OF_MEMORY)
    2.63 +                        return (int) invalid_out_of_memory;
    2.64 +                    if (status != PEP_STATUS_OK)
    2.65 +                        return (int) invalid_action;
    2.66 +                    session->sync_state_payload = malloc(sizeof(SoleBeaconed_state_payload_t));
    2.67 +                    assert(session->sync_state_payload);
    2.68 +                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
    2.69 +                    ((SoleBeaconed_state_payload_t*)session->sync_state_payload)->expected =
    2.70 +                        identity_dup(partner);
    2.71 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleWaiting, event=Beacon", "target=SoleBeaconed")
    2.72 +                    return SoleBeaconed;
    2.73 +                }
    2.74 +                case HandshakeRequest:
    2.75 +                {
    2.76 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleWaiting", "event=HandshakeRequest")
    2.77 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=SoleWaiting, event=HandshakeRequest", "action=sendHandshakeRequest")
    2.78 +                    status = sendHandshakeRequest(session, state, partner, NULL);
    2.79 +                    if (status == PEP_OUT_OF_MEMORY)
    2.80 +                        return (int) invalid_out_of_memory;
    2.81 +                    if (status != PEP_STATUS_OK)
    2.82 +                        return (int) invalid_action;
    2.83 +                    session->sync_state_payload = malloc(sizeof(HandshakingSole_state_payload_t));
    2.84 +                    assert(session->sync_state_payload);
    2.85 +                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
    2.86 +                    ((HandshakingSole_state_payload_t*)session->sync_state_payload)->expected =
    2.87 +                        identity_dup(partner);
    2.88 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleWaiting, event=HandshakeRequest", "target=HandshakingSole")
    2.89 +                    return HandshakingSole;
    2.90 +                }
    2.91 +                case Timeout:
    2.92 +                {
    2.93 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=SoleWaiting", "event=Timeout")
    2.94 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=SoleWaiting, event=Timeout", "target=Sole")
    2.95 +                    return Sole;
    2.96 +                }
    2.97 +                default:
    2.98 +                    return (DeviceState_state) invalid_event;
    2.99 +            }
   2.100 +            break;
   2.101 +        }
   2.102          case SoleBeaconed:
   2.103          {
   2.104              DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=SoleBeaconed")
   2.105 @@ -739,7 +816,8 @@
   2.106                          return (int) invalid_out_of_memory;
   2.107                      if (status != PEP_STATUS_OK)
   2.108                          return (int) invalid_action;
   2.109 -                    break;
   2.110 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Grouped, event=CannotDecrypt", "target=GroupWaiting")
   2.111 +                    return GroupWaiting;
   2.112                  }
   2.113                  case UpdateRequest:
   2.114                  {
   2.115 @@ -803,6 +881,110 @@
   2.116              }
   2.117              break;
   2.118          }
   2.119 +        case GroupWaiting:
   2.120 +        {
   2.121 +            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=GroupWaiting")
   2.122 +            switch (event) {
   2.123 +                case Init: 
   2.124 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=Init") 
   2.125 +                    *timeout = 60;
   2.126 +                    break;
   2.127 +                case KeyGen:
   2.128 +                {
   2.129 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=KeyGen")
   2.130 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupWaiting, event=KeyGen", "action=sendGroupUpdate")
   2.131 +                    status = sendGroupUpdate(session, state, NULL, NULL);
   2.132 +                    if (status == PEP_OUT_OF_MEMORY)
   2.133 +                        return (int) invalid_out_of_memory;
   2.134 +                    if (status != PEP_STATUS_OK)
   2.135 +                        return (int) invalid_action;
   2.136 +                    break;
   2.137 +                }
   2.138 +                case CannotDecrypt:
   2.139 +                {
   2.140 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=CannotDecrypt")
   2.141 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupWaiting, event=CannotDecrypt", "action=sendUpdateRequest")
   2.142 +                    status = sendUpdateRequest(session, state, NULL, NULL);
   2.143 +                    if (status == PEP_OUT_OF_MEMORY)
   2.144 +                        return (int) invalid_out_of_memory;
   2.145 +                    if (status != PEP_STATUS_OK)
   2.146 +                        return (int) invalid_action;
   2.147 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupWaiting, event=CannotDecrypt", "action=sendBeacon")
   2.148 +                    status = sendBeacon(session, state, NULL, NULL);
   2.149 +                    if (status == PEP_OUT_OF_MEMORY)
   2.150 +                        return (int) invalid_out_of_memory;
   2.151 +                    if (status != PEP_STATUS_OK)
   2.152 +                        return (int) invalid_action;
   2.153 +                    break;
   2.154 +                }
   2.155 +                case UpdateRequest:
   2.156 +                {
   2.157 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=UpdateRequest")
   2.158 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupWaiting, event=UpdateRequest", "action=sendGroupUpdate")
   2.159 +                    status = sendGroupUpdate(session, state, NULL, NULL);
   2.160 +                    if (status == PEP_OUT_OF_MEMORY)
   2.161 +                        return (int) invalid_out_of_memory;
   2.162 +                    if (status != PEP_STATUS_OK)
   2.163 +                        return (int) invalid_action;
   2.164 +                    break;
   2.165 +                }
   2.166 +                case Beacon:
   2.167 +                {
   2.168 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=Beacon")
   2.169 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupWaiting, event=Beacon", "action=sendHandshakeRequest")
   2.170 +                    status = sendHandshakeRequest(session, state, partner, NULL);
   2.171 +                    if (status == PEP_OUT_OF_MEMORY)
   2.172 +                        return (int) invalid_out_of_memory;
   2.173 +                    if (status != PEP_STATUS_OK)
   2.174 +                        return (int) invalid_action;
   2.175 +                    session->sync_state_payload = malloc(sizeof(GroupedBeaconed_state_payload_t));
   2.176 +                    assert(session->sync_state_payload);
   2.177 +                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
   2.178 +                    ((GroupedBeaconed_state_payload_t*)session->sync_state_payload)->expected =
   2.179 +                        identity_dup(partner);
   2.180 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupWaiting, event=Beacon", "target=GroupedBeaconed")
   2.181 +                    return GroupedBeaconed;
   2.182 +                }
   2.183 +                case HandshakeRequest:
   2.184 +                {
   2.185 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=HandshakeRequest")
   2.186 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupWaiting, event=HandshakeRequest", "action=sendHandshakeRequest")
   2.187 +                    status = sendHandshakeRequest(session, state, partner, NULL);
   2.188 +                    if (status == PEP_OUT_OF_MEMORY)
   2.189 +                        return (int) invalid_out_of_memory;
   2.190 +                    if (status != PEP_STATUS_OK)
   2.191 +                        return (int) invalid_action;
   2.192 +                    session->sync_state_payload = malloc(sizeof(HandshakingGrouped_state_payload_t));
   2.193 +                    assert(session->sync_state_payload);
   2.194 +                    if(!session->sync_state_payload) return (DeviceState_state) invalid_out_of_memory;
   2.195 +                    ((HandshakingGrouped_state_payload_t*)session->sync_state_payload)->expected =
   2.196 +                        identity_dup(partner);
   2.197 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupWaiting, event=HandshakeRequest", "target=HandshakingGrouped")
   2.198 +                    return HandshakingGrouped;
   2.199 +                }
   2.200 +                case GroupUpdate:
   2.201 +                {
   2.202 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=GroupUpdate")
   2.203 +                    identity_list* keys = (identity_list*)extra;
   2.204 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=GroupWaiting, event=GroupUpdate", "action=storeGroupUpdate")
   2.205 +                    status = storeGroupUpdate(session, state, partner, keys);
   2.206 +                    if (status == PEP_OUT_OF_MEMORY)
   2.207 +                        return (int) invalid_out_of_memory;
   2.208 +                    if (status != PEP_STATUS_OK)
   2.209 +                        return (int) invalid_action;
   2.210 +                    break;
   2.211 +                }
   2.212 +                case Timeout:
   2.213 +                {
   2.214 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=GroupWaiting", "event=Timeout")
   2.215 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=GroupWaiting, event=Timeout", "target=Grouped")
   2.216 +                    return Grouped;
   2.217 +                }
   2.218 +                default:
   2.219 +                    return (DeviceState_state) invalid_event;
   2.220 +            }
   2.221 +            break;
   2.222 +        }
   2.223          case GroupedBeaconed:
   2.224          {
   2.225              DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=GroupedBeaconed")
     3.1 --- a/sync/generated/sync_fsm.h	Fri Apr 28 12:02:57 2017 +0200
     3.2 +++ b/sync/generated/sync_fsm.h	Fri Apr 28 19:03:21 2017 +0200
     3.3 @@ -47,11 +47,13 @@
     3.4      DeviceState_state_NONE = 0,
     3.5      InitState, 
     3.6      Sole, 
     3.7 +    SoleWaiting, 
     3.8      SoleBeaconed, 
     3.9      HandshakingSole, 
    3.10      WaitForGroupKeysSole, 
    3.11      WaitForAcceptSole, 
    3.12      Grouped, 
    3.13 +    GroupWaiting, 
    3.14      GroupedBeaconed, 
    3.15      HandshakingGrouped, 
    3.16      WaitForGroupKeysGrouped,