add broadcast implementation sync
authorVolker Birk <vb@pep.foundation>
Wed, 22 Aug 2018 15:25:25 +0200
branchsync
changeset 2868d812e7a24b52
parent 2867 3e1e674fee7d
child 2869 e06e7024a1cd
add broadcast implementation
src/pEpEngine.h
sync/fsm.yml2
sync/gen_statemachine.ysl2
     1.1 --- a/src/pEpEngine.h	Wed Aug 22 14:25:26 2018 +0200
     1.2 +++ b/src/pEpEngine.h	Wed Aug 22 15:25:25 2018 +0200
     1.3 @@ -91,6 +91,7 @@
     1.4      PEP_SYNC_NO_NOTIFY_CALLBACK                     = 0x0901,
     1.5      PEP_SYNC_ILLEGAL_MESSAGE                        = 0x0902,
     1.6      PEP_SYNC_NO_INJECT_CALLBACK                     = 0x0903,
     1.7 +    PEP_SYNC_NO_CHANNEL                             = 0x0904,
     1.8  
     1.9      PEP_CANNOT_INCREASE_SEQUENCE                    = 0x0971,
    1.10  
     2.1 --- a/sync/fsm.yml2	Wed Aug 22 14:25:26 2018 +0200
     2.2 +++ b/sync/fsm.yml2	Wed Aug 22 15:25:25 2018 +0200
     2.3 @@ -42,7 +42,6 @@
     2.4  // send network messages
     2.5  
     2.6  decl send @name (type="unicast");
     2.7 -decl broadcast @name (type="broadcast") alias send;
     2.8  
     2.9  // a condition is for different cases
    2.10  
     3.1 --- a/sync/gen_statemachine.ysl2	Wed Aug 22 14:25:26 2018 +0200
     3.2 +++ b/sync/gen_statemachine.ysl2	Wed Aug 22 15:25:25 2018 +0200
     3.3 @@ -335,6 +335,7 @@
     3.4  
     3.5              char *data = NULL;
     3.6              message *m = NULL;
     3.7 +            identity_list *channels = NULL;
     3.8  
     3.9              status = update_«@name»_message(session, msg);
    3.10              if (status)
    3.11 @@ -345,19 +346,56 @@
    3.12              if (status)
    3.13                  goto the_end;
    3.14  
    3.15 -            status = base_prepare_message(
    3.16 -                    session->«yml:lcase(@name)»_state.common.from,
    3.17 -                    session->«yml:lcase(@name)»_state.common.from,
    3.18 -                    data,
    3.19 -                    size,
    3.20 -                    &m
    3.21 -                );
    3.22 -            if (status)
    3.23 -                goto the_end;
    3.24 -            
    3.25 -            status = session->messageToSend(session->«yml:lcase(@name)»_obj, m);
    3.26 +            switch (message_type) {
    3.27 +                // these messages are broadcasted
    3.28 +                `` for "fsm/message[@type='broadcast']" |>> case «@name»:
    3.29 +                    status = _own_identities_retrieve(session, &channels, PEP_idf_not_for_sync);
    3.30 +                    if (!status)
    3.31 +                        goto the_end;
    3.32 +                    break;
    3.33 +
    3.34 +                // all other go unicast
    3.35 +                default: {
    3.36 +                    if (!(session->«yml:lcase(@name)»_state.common.from &&
    3.37 +                        (session->«yml:lcase(@name)»_state.common.from->flags &
    3.38 +                        PEP_idf_not_for_sync)))
    3.39 +                    {
    3.40 +                        status = PEP_SYNC_NO_CHANNEL;
    3.41 +                        goto the_end;
    3.42 +                    }
    3.43 +
    3.44 +                    pEp_identity *channel = identity_dup(session->«yml:lcase(@name)»_state.common.from);
    3.45 +                    if (!channel) {
    3.46 +                        status = PEP_OUT_OF_MEMORY;
    3.47 +                        goto the_end;
    3.48 +                    }
    3.49 +
    3.50 +                    channels = new_identity_list(channel);
    3.51 +                    if (!channels) {
    3.52 +                        status = PEP_OUT_OF_MEMORY;
    3.53 +                        goto the_end;
    3.54 +                    }
    3.55 +                }
    3.56 +            }
    3.57 +
    3.58 +            for (identity_list *li = channels; li && li->ident ; li = li->next) {
    3.59 +                status = base_prepare_message(
    3.60 +                        li->ident,
    3.61 +                        li->ident,
    3.62 +                        data,
    3.63 +                        size,
    3.64 +                        &m
    3.65 +                    );
    3.66 +                if (status)
    3.67 +                    goto the_end;
    3.68 +                
    3.69 +                status = session->messageToSend(session->«yml:lcase(@name)»_obj, m);
    3.70 +                free_message(m);
    3.71 +                m = NULL;
    3.72 +            }
    3.73  
    3.74          the_end:
    3.75 +            free_identity_list(channels);
    3.76              free_message(m);
    3.77              free(data);
    3.78              free_«@name»_message(msg);