ENGINE-133 added more feedback for the app in case of handshake success or failure, because of timeout ENGINE-133
authorEdouard Tisserant <edouard@pep-project.org>
Thu, 01 Dec 2016 17:56:05 +0100
branchENGINE-133
changeset 1459ab329d7db8d7
parent 1458 443278ea9c47
child 1460 66ceb5a7f718
ENGINE-133 added more feedback for the app in case of handshake success or failure, because of timeout
src/pEpEngine.h
src/pEp_internal.h
src/sync.c
src/sync.h
src/sync_actions.c
src/sync_fsm.h
sync/devicegroup.fsm
     1.1 --- a/src/pEpEngine.h	Thu Dec 01 10:47:28 2016 +0100
     1.2 +++ b/src/pEpEngine.h	Thu Dec 01 17:56:05 2016 +0100
     1.3 @@ -74,7 +74,7 @@
     1.4      PEP_CONTRAINTS_VIOLATED                         = 0x0802,
     1.5      PEP_CANNOT_ENCODE                               = 0x0803,
     1.6  
     1.7 -    PEP_SYNC_NO_TRUSTWORDS_CALLBACK                 = 0x0901,
     1.8 +    PEP_SYNC_NO_NOTIFY_CALLBACK                 = 0x0901,
     1.9      PEP_SYNC_ILLEGAL_MESSAGE                        = 0x0902,
    1.10      PEP_SYNC_NO_INJECT_CALLBACK                     = 0x0903,
    1.11  
     2.1 --- a/src/pEp_internal.h	Thu Dec 01 10:47:28 2016 +0100
     2.2 +++ b/src/pEp_internal.h	Thu Dec 01 17:56:05 2016 +0100
     2.3 @@ -136,7 +136,7 @@
     2.4      void *examine_management;
     2.5      void *sync_obj;
     2.6      messageToSend_t messageToSend;
     2.7 -    showHandshake_t showHandshake;
     2.8 +    notifyHandshake_t notifyHandshake;
     2.9      inject_sync_msg_t inject_sync_msg;
    2.10      retrieve_next_sync_msg_t retrieve_next_sync_msg;
    2.11  
     3.1 --- a/src/sync.c	Thu Dec 01 10:47:28 2016 +0100
     3.2 +++ b/src/sync.c	Thu Dec 01 17:56:05 2016 +0100
     3.3 @@ -18,13 +18,13 @@
     3.4          PEP_SESSION session,
     3.5          void *obj,
     3.6          messageToSend_t messageToSend,
     3.7 -        showHandshake_t showHandshake,
     3.8 +        notifyHandshake_t notifyHandshake,
     3.9          inject_sync_msg_t inject_sync_msg,
    3.10          retrieve_next_sync_msg_t retrieve_next_sync_msg
    3.11      )
    3.12  {
    3.13 -    assert(session && obj && messageToSend && showHandshake && inject_sync_msg && retrieve_next_sync_msg);
    3.14 -    if (!(session && obj && messageToSend && showHandshake && inject_sync_msg && retrieve_next_sync_msg))
    3.15 +    assert(session && obj && messageToSend && notifyHandshake && inject_sync_msg && retrieve_next_sync_msg);
    3.16 +    if (!(session && obj && messageToSend && notifyHandshake && inject_sync_msg && retrieve_next_sync_msg))
    3.17          return PEP_ILLEGAL_VALUE;
    3.18  
    3.19      pEpUUID uuid;
    3.20 @@ -33,7 +33,7 @@
    3.21  
    3.22      session->sync_obj = obj;
    3.23      session->messageToSend = messageToSend;
    3.24 -    session->showHandshake = showHandshake;
    3.25 +    session->notifyHandshake = notifyHandshake;
    3.26      session->inject_sync_msg = inject_sync_msg;
    3.27      session->retrieve_next_sync_msg = retrieve_next_sync_msg;
    3.28  
    3.29 @@ -93,7 +93,7 @@
    3.30      // unregister
    3.31      session->sync_obj = NULL;
    3.32      session->messageToSend = NULL;
    3.33 -    session->showHandshake = NULL;
    3.34 +    session->notifyHandshake = NULL;
    3.35      session->inject_sync_msg = NULL;
    3.36      session->retrieve_next_sync_msg = NULL;
    3.37  }
     4.1 --- a/src/sync.h	Thu Dec 01 10:47:28 2016 +0100
     4.2 +++ b/src/sync.h	Thu Dec 01 17:56:05 2016 +0100
     4.3 @@ -26,19 +26,22 @@
     4.4  
     4.5  typedef PEP_STATUS (*messageToSend_t)(void *obj, message *msg);
     4.6  
     4.7 +typedef enum _sync_handshake_signal {
     4.8 +    SYNC_HANDSHAKE_DISMISS_DIALOG = 0,
     4.9 +    SYNC_HANDSHAKE_SHOW_DIALOG = 1,
    4.10 +    SYNC_HANDSHAKE_SUCCESS = 2,
    4.11 +    SYNC_HANDSHAKE_FAILURE = 3,
    4.12 +    SYNC_DEVICE_ADDED = 4,
    4.13 +    SYNC_GROUP_CREATED = 5
    4.14 +} sync_handshake_signal;
    4.15  
    4.16 -typedef enum _sync_handshake_result {
    4.17 -    SYNC_HANDSHAKE_CANCEL = -1,
    4.18 -    SYNC_HANDSHAKE_ACCEPTED = 0,
    4.19 -    SYNC_HANDSHAKE_REJECTED = 1
    4.20 -} sync_handshake_result;
    4.21 -
    4.22 -// showHandshake() - do a handshake by showing the handshake dialog
    4.23 +// notifyHandshake() - notify UI about sync handshaking process
    4.24  //
    4.25  //  parameters:
    4.26  //      obj (in)        object handle (implementation defined)
    4.27  //      me (in)         own identity
    4.28  //      partner (in)    identity of partner
    4.29 +//      signal (in)     reason of the notification
    4.30  //
    4.31  //  return value:
    4.32  //      PEP_STATUS_OK or any other value on error
    4.33 @@ -46,12 +49,18 @@
    4.34  //  caveat:
    4.35  //      ownership of self and partner go to the callee
    4.36  
    4.37 -typedef PEP_STATUS (*showHandshake_t)(
    4.38 +typedef PEP_STATUS (*notifyHandshake_t)(
    4.39          void *obj,
    4.40          pEp_identity *me,
    4.41 -        pEp_identity *partner
    4.42 +        pEp_identity *partner,
    4.43 +        sync_handshake_signal signal
    4.44      );
    4.45  
    4.46 +typedef enum _sync_handshake_result {
    4.47 +    SYNC_HANDSHAKE_CANCEL = -1,
    4.48 +    SYNC_HANDSHAKE_ACCEPTED = 0,
    4.49 +    SYNC_HANDSHAKE_REJECTED = 1
    4.50 +} sync_handshake_result;
    4.51  
    4.52  // deliverHandshakeResult() - give the result of the handshake dialog
    4.53  //
    4.54 @@ -100,7 +109,7 @@
    4.55  //      session (in)                session where to store obj handle
    4.56  //      obj (in)                    object handle (implementation defined)
    4.57  //      messageToSend (in)          callback for sending message
    4.58 -//      showHandshake (in)          callback for doing the handshake
    4.59 +//      notifyHandshake (in)          callback for doing the handshake
    4.60  //      retrieve_next_sync_msg (in) callback for receiving sync messages
    4.61  //
    4.62  //  return value:
    4.63 @@ -113,7 +122,7 @@
    4.64          PEP_SESSION session,
    4.65          void *obj,
    4.66          messageToSend_t messageToSend,
    4.67 -        showHandshake_t showHandshake,
    4.68 +        notifyHandshake_t notifyHandshake,
    4.69          inject_sync_msg_t inject_sync_msg,
    4.70          retrieve_next_sync_msg_t retrieve_next_sync_msg
    4.71      );
     5.1 --- a/src/sync_actions.c	Thu Dec 01 10:47:28 2016 +0100
     5.2 +++ b/src/sync_actions.c	Thu Dec 01 17:56:05 2016 +0100
     5.3 @@ -97,6 +97,48 @@
     5.4      return result;
     5.5  }
     5.6  
     5.7 +static PEP_STATUS _notifyHandshake(
     5.8 +        PEP_SESSION session,
     5.9 +        Identity partner,
    5.10 +        sync_handshake_signal signal
    5.11 +    )
    5.12 +{
    5.13 +    PEP_STATUS status = PEP_STATUS_OK;
    5.14 +
    5.15 +    assert(session);
    5.16 +    assert(partner);
    5.17 +
    5.18 +    if (!(session && partner))
    5.19 +        return PEP_ILLEGAL_VALUE;
    5.20 +
    5.21 +    assert(session->notifyHandshake);
    5.22 +    if (!session->notifyHandshake)
    5.23 +        return PEP_SYNC_NO_NOTIFY_CALLBACK;
    5.24 +
    5.25 +    // notifyHandshake take ownership of given identities
    5.26 +    pEp_identity *me = NULL;
    5.27 +    status = get_identity(session, partner->address, PEP_OWN_USERID, &me);
    5.28 +    if (status != PEP_STATUS_OK)
    5.29 +        goto error;
    5.30 +    
    5.31 +    pEp_identity *_partner = NULL;
    5.32 +    _partner = identity_dup(partner);
    5.33 +    if (_partner == NULL){
    5.34 +        status = PEP_OUT_OF_MEMORY;
    5.35 +        goto error;
    5.36 +    }
    5.37 +
    5.38 +    status = session->notifyHandshake(session->sync_obj, me, _partner, signal);
    5.39 +    if (status != PEP_STATUS_OK)
    5.40 +        goto error;
    5.41 +
    5.42 +    return status;
    5.43 +
    5.44 +error:
    5.45 +    free_identity(me);
    5.46 +    return status;
    5.47 +}
    5.48 +
    5.49  // showHandshake() - trigger the handshake dialog of the application
    5.50  //
    5.51  //  params:
    5.52 @@ -114,43 +156,115 @@
    5.53          void *extra
    5.54      )
    5.55  {
    5.56 -    PEP_STATUS status = PEP_STATUS_OK;
    5.57 -
    5.58 -    assert(session);
    5.59 -    assert(partner);
    5.60 -    assert(extra == NULL);
    5.61 -
    5.62 -    if (!(session && partner))
    5.63 -        return PEP_ILLEGAL_VALUE;
    5.64 -
    5.65 -    assert(session->showHandshake);
    5.66 -    if (!session->showHandshake)
    5.67 -        return PEP_SYNC_NO_TRUSTWORDS_CALLBACK;
    5.68 -
    5.69 -    // showHandshake take ownership of given identities
    5.70 -    pEp_identity *me = NULL;
    5.71 -    status = get_identity(session, partner->address, PEP_OWN_USERID, &me);
    5.72 -    if (status != PEP_STATUS_OK)
    5.73 -        goto error;
    5.74 -    
    5.75 -    pEp_identity *_partner = NULL;
    5.76 -    _partner = identity_dup(partner);
    5.77 -    if (_partner == NULL){
    5.78 -        status = PEP_OUT_OF_MEMORY;
    5.79 -        goto error;
    5.80 -    }
    5.81 -
    5.82 -    status = session->showHandshake(session->sync_obj, me, _partner);
    5.83 -    if (status != PEP_STATUS_OK)
    5.84 -        goto error;
    5.85 -
    5.86 -    return status;
    5.87 -
    5.88 -error:
    5.89 -    free_identity(me);
    5.90 -    return status;
    5.91 +   assert(extra == NULL);
    5.92 +   return _notifyHandshake(session, partner, SYNC_HANDSHAKE_SHOW_DIALOG);
    5.93  }
    5.94  
    5.95 +// dismissHandshake() - kill the handshake dialog of the application
    5.96 +//
    5.97 +//  params:
    5.98 +//      session (in)        session handle
    5.99 +//      state (in)          state the state machine is in
   5.100 +//      partner (in)        partner to communicate with
   5.101 +//
   5.102 +//  returns:
   5.103 +//      PEP_STATUS_OK or any other value on error
   5.104 +
   5.105 +PEP_STATUS dismissHandshake(
   5.106 +        PEP_SESSION session,
   5.107 +        DeviceState_state state,
   5.108 +        Identity partner,
   5.109 +        void *extra
   5.110 +    )
   5.111 +{
   5.112 +   assert(extra == NULL);
   5.113 +   return _notifyHandshake(session, partner, SYNC_HANDSHAKE_DISMISS_DIALOG);
   5.114 +}
   5.115 +
   5.116 +// handshakeSuccess() - notify the application that handshake succeeded
   5.117 +//
   5.118 +//  params:
   5.119 +//      session (in)        session handle
   5.120 +//      state (in)          state the state machine is in
   5.121 +//      partner (in)        partner to communicate with
   5.122 +//
   5.123 +//  returns:
   5.124 +//      PEP_STATUS_OK or any other value on error
   5.125 +
   5.126 +PEP_STATUS handshakeSuccess(
   5.127 +        PEP_SESSION session,
   5.128 +        DeviceState_state state,
   5.129 +        Identity partner,
   5.130 +        void *extra
   5.131 +    )
   5.132 +{
   5.133 +   assert(extra == NULL);
   5.134 +   return _notifyHandshake(session, partner, SYNC_HANDSHAKE_SUCCESS);
   5.135 +}
   5.136 +
   5.137 +// handshakeGroupCreated() - notify the application that initial group was created
   5.138 +//                           and partner's device was included in group
   5.139 +//
   5.140 +//  params:
   5.141 +//      session (in)        session handle
   5.142 +//      state (in)          state the state machine is in
   5.143 +//      partner (in)        partner to communicate with
   5.144 +//
   5.145 +//  returns:
   5.146 +//      PEP_STATUS_OK or any other value on error
   5.147 +
   5.148 +PEP_STATUS handshakeGroupCreated(
   5.149 +        PEP_SESSION session,
   5.150 +        DeviceState_state state,
   5.151 +        Identity partner,
   5.152 +        void *extra
   5.153 +    )
   5.154 +{
   5.155 +   assert(extra == NULL);
   5.156 +   return _notifyHandshake(session, partner, SYNC_GROUP_CREATED);
   5.157 +}
   5.158 +
   5.159 +// handshakeDeviceAdded() - notify the application that partner's device was added to group
   5.160 +//
   5.161 +//  params:
   5.162 +//      session (in)        session handle
   5.163 +//      state (in)          state the state machine is in
   5.164 +//      partner (in)        partner to communicate with
   5.165 +//
   5.166 +//  returns:
   5.167 +//      PEP_STATUS_OK or any other value on error
   5.168 +
   5.169 +PEP_STATUS handshakeDeviceAdded(
   5.170 +        PEP_SESSION session,
   5.171 +        DeviceState_state state,
   5.172 +        Identity partner,
   5.173 +        void *extra
   5.174 +    )
   5.175 +{
   5.176 +   assert(extra == NULL);
   5.177 +   return _notifyHandshake(session, partner, SYNC_DEVICE_ADDED);
   5.178 +}
   5.179 +
   5.180 +// handshakeFailure() - notify the application that handshake failed
   5.181 +//
   5.182 +//  params:
   5.183 +//      session (in)        session handle
   5.184 +//      state (in)          state the state machine is in
   5.185 +//      partner (in)        partner to communicate with
   5.186 +//
   5.187 +//  returns:
   5.188 +//      PEP_STATUS_OK or any other value on error
   5.189 +
   5.190 +PEP_STATUS handshakeFailure(
   5.191 +        PEP_SESSION session,
   5.192 +        DeviceState_state state,
   5.193 +        Identity partner,
   5.194 +        void *extra
   5.195 +    )
   5.196 +{
   5.197 +   assert(extra == NULL);
   5.198 +   return _notifyHandshake(session, partner, SYNC_HANDSHAKE_FAILURE);
   5.199 +}
   5.200  
   5.201  // acceptHandshake() - stores acception of partner
   5.202  //
     6.1 --- a/src/sync_fsm.h	Thu Dec 01 10:47:28 2016 +0100
     6.2 +++ b/src/sync_fsm.h	Thu Dec 01 17:56:05 2016 +0100
     6.3 @@ -78,10 +78,15 @@
     6.4  PEP_STATUS rejectHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     6.5  PEP_STATUS acceptHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     6.6  PEP_STATUS sendGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     6.7 +PEP_STATUS handshakeGroupCreated(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     6.8 +PEP_STATUS dismissHandshake(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
     6.9  PEP_STATUS storeGroupKeys(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    6.10 +PEP_STATUS handshakeSuccess(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    6.11 +PEP_STATUS handshakeFailure(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    6.12  PEP_STATUS enterGroup(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    6.13  PEP_STATUS sendGroupUpdate(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    6.14  PEP_STATUS sendUpdateRequest(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    6.15 +PEP_STATUS handshakeDeviceAdded(PEP_SESSION session, DeviceState_state state, Identity partner, void *extra);
    6.16  
    6.17  // event injector
    6.18  
     7.1 --- a/sync/devicegroup.fsm	Thu Dec 01 10:47:28 2016 +0100
     7.2 +++ b/sync/devicegroup.fsm	Thu Dec 01 17:56:05 2016 +0100
     7.3 @@ -52,14 +52,14 @@
     7.4                  if keyElectionWon(partner) {    // an already existing group
     7.5                                                  // always wins
     7.6                      do sendGroupKeys(partner);
     7.7 +                    do handshakeGroupCreated(partner);
     7.8                      go Grouped;
     7.9                  }
    7.10                  go WaitForGroupKeysSole(Identity partner);
    7.11              }
    7.12              on Cancel go Sole;
    7.13              on Timeout {
    7.14 -                // TODO signal group failure to app
    7.15 -                // do dismissHandshake(partner);
    7.16 +                do dismissHandshake(partner);
    7.17                  go Sole;
    7.18              }
    7.19          }
    7.20 @@ -67,13 +67,11 @@
    7.21          state WaitForGroupKeysSole timeout=10 (Identity partner) {
    7.22              on GroupKeys(Identity partner, Stringlist keys) {
    7.23                  do storeGroupKeys(partner, keys);
    7.24 -                // TODO signal group success to app
    7.25 -                // do groupSuccess(partner);
    7.26 +                do handshakeSuccess(partner);
    7.27                  go Grouped;
    7.28              }
    7.29              on Timeout {
    7.30 -                // TODO signal group failure to app
    7.31 -                // do groupTimeout(partner);
    7.32 +                do handshakeFailure(partner);
    7.33                  go Sole;
    7.34              }
    7.35          }
    7.36 @@ -110,14 +108,12 @@
    7.37                  // an already existing group always wins
    7.38                  do sendGroupKeys(partner);
    7.39  
    7.40 -                // TODO signal group success to app
    7.41 -                // do groupSuccess(partner);
    7.42 +                do handshakeDeviceAdded(partner);
    7.43  
    7.44                  go Grouped;
    7.45              }
    7.46              on Timeout {
    7.47 -                // TODO kill Handshake dialog in app
    7.48 -                // do dismissHandshake();
    7.49 +                do handshakeFailure(partner);
    7.50                  go Grouped;
    7.51              }
    7.52          }