grouping sync
authorVolker Birk <vb@pep-project.org>
Sun, 14 Apr 2019 20:56:02 +0200
branchsync
changeset 352503981c2354de
parent 3524 c87c6b4f3e08
child 3526 626d29e1d4eb
child 3527 a4c50a8eeccf
grouping
src/sync_api.h
sync/cond_act_sync.yml2
sync/sync.fsm
     1.1 --- a/src/sync_api.h	Sun Apr 14 16:54:48 2019 +0200
     1.2 +++ b/src/sync_api.h	Sun Apr 14 20:56:02 2019 +0200
     1.3 @@ -30,7 +30,11 @@
     1.4      // SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED = 8,
     1.5  
     1.6      // handshake dialog must be closed
     1.7 -    SYNC_NOTIFY_OVERTAKEN = 9
     1.8 +    SYNC_NOTIFY_OVERTAKEN = 9,
     1.9 +
    1.10 +    // notificaton of actual group status
    1.11 +    SYNC_NOTIFY_SOLE = 254,
    1.12 +    SYNC_NOTIFY_IN_GROUP = 255
    1.13  } sync_handshake_signal;
    1.14  
    1.15  
     2.1 --- a/sync/cond_act_sync.yml2	Sun Apr 14 16:54:48 2019 +0200
     2.2 +++ b/sync/cond_act_sync.yml2	Sun Apr 14 20:56:02 2019 +0200
     2.3 @@ -14,7 +14,7 @@
     2.4  
     2.5  condition deviceGrouped {
     2.6      call "exec_sql_int" with "sql"
     2.7 -        > "select count(*) from identity where is_own = 1 and (flags & 4) = 4;"
     2.8 +        > "select count(*) from identity where is_own = 1 and (flags & 0x100) = 0x100;"
     2.9      |> *result = _result > 0;
    2.10  }
    2.11  
    2.12 @@ -143,6 +143,25 @@
    2.13          if (!session->notifyHandshake)
    2.14              return PEP_SYNC_NO_NOTIFY_CALLBACK;
    2.15       
    2.16 +    ||
    2.17 +    choose {
    2.18 +    when "$type = 'SYNC_NOTIFY_TIMEOUT' or $type = 'SYNC_NOTIFY_SOLE' or $type = 'SYNC_NOTIFY_IN_GROUP'"
    2.19 +    ||
    2.20 +        pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
    2.21 +        pEp_identity *partner = new_identity(NULL, NULL, NULL, NULL);
    2.22 +        assert(me && partner);
    2.23 +        if (!(me && partner)) {
    2.24 +            free_identity(me);
    2.25 +            free_identity(partner);
    2.26 +            return PEP_OUT_OF_MEMORY;
    2.27 +        }
    2.28 +
    2.29 +        PEP_STATUS status = session->notifyHandshake(me, partner, «$type»);
    2.30 +        if (status)
    2.31 +            return status;
    2.32 +    ||
    2.33 +    otherwise
    2.34 +    ||
    2.35          assert(session->sync_state.common.from);
    2.36          if (!session->sync_state.common.from)
    2.37              return PEP_ILLEGAL_VALUE;
    2.38 @@ -181,6 +200,7 @@
    2.39          if (status)
    2.40              return status;
    2.41      ||
    2.42 +    }
    2.43  }
    2.44  
    2.45  action showSoleHandshake
    2.46 @@ -201,6 +221,12 @@
    2.47  action showGroupCreated
    2.48      call "show_handshake" with "type" > SYNC_NOTIFY_ACCEPTED_GROUP_CREATED
    2.49  
    2.50 +action showBeingSole
    2.51 +    call "show_handshake" with "type" > SYNC_NOTIFY_SOLE
    2.52 +
    2.53 +action showBeingInGroup
    2.54 +    call "show_handshake" with "type" > SYNC_NOTIFY_IN_GROUP
    2.55 +
    2.56  timeout KeySync
    2.57      call "show_handshake" with "type" > SYNC_NOTIFY_TIMEOUT
    2.58  
    2.59 @@ -255,7 +281,37 @@
    2.60      }
    2.61  ||
    2.62  
    2.63 -action receivedKeysAreGroupKeys;
    2.64 +action receivedKeysAreGroupKeys
    2.65 +||
    2.66 +    PEP_STATUS status = PEP_STATUS_OK;
    2.67 +    identity_list *il = IdentityList_to_identity_list(&session->sync_state.keysync.ownIdentities, NULL);
    2.68 +    if (!il)
    2.69 +        return PEP_OUT_OF_MEMORY;
    2.70 +
    2.71 +    for (il = session->sync_state.common.own_identities; il && il->ident ; il = il->next) {
    2.72 +        // replace partner's user_id with own user_id
    2.73 +        free(il->ident->user_id);
    2.74 +        il->ident->user_id = strdup(session->sync_state.common.from->user_id);
    2.75 +        if (!il->ident->user_id) {
    2.76 +            free_identity_list(il);
    2.77 +            return PEP_OUT_OF_MEMORY;
    2.78 +        }
    2.79 +
    2.80 +        status = myself(session, il->ident);
    2.81 +        if (status) {
    2.82 +            free_identity_list(il);
    2.83 +            return status;
    2.84 +        }
    2.85 +
    2.86 +        status = set_identity_flags(session, il->ident, PEP_idf_devicegroup);
    2.87 +        if (status) {
    2.88 +            free_identity_list(il);
    2.89 +            return status;
    2.90 +        }
    2.91 +    }
    2.92 +
    2.93 +    free_identity_list(il);
    2.94 +||
    2.95  
    2.96  action storeThisKey
    2.97  ||
     3.1 --- a/sync/sync.fsm	Sun Apr 14 16:54:48 2019 +0200
     3.2 +++ b/sync/sync.fsm	Sun Apr 14 20:56:02 2019 +0200
     3.3 @@ -23,6 +23,7 @@
     3.4  
     3.5          state Sole timeout=off {
     3.6              on Init {
     3.7 +                do showBeingSole;
     3.8                  do newChallenge;
     3.9                  do closeTransaction;
    3.10                  send Beacon;
    3.11 @@ -255,8 +256,10 @@
    3.12          }
    3.13  
    3.14          state Grouped timeout=off {
    3.15 -            on Init
    3.16 +            on Init {
    3.17 +                do showBeingInGroup;
    3.18                  do closeTransaction;
    3.19 +            }
    3.20  
    3.21              on GroupKeys
    3.22                  do saveGroupKeys;