small fixes and initial setup trustsync
authorVolker Birk <vb@pep-project.org>
Wed, 22 Apr 2020 19:00:53 +0200
branchtrustsync
changeset 45842185248904dd
parent 4583 29ddc8a400ab
child 4585 af441dfc1d2c
small fixes and initial setup
asn.1/Makefile
sync/gen_messages.ysl2
sync/gen_statemachine.ysl2
sync/sync.fsm
     1.1 --- a/asn.1/Makefile	Wed Apr 22 10:59:39 2020 +0200
     1.2 +++ b/asn.1/Makefile	Wed Apr 22 19:00:53 2020 +0200
     1.3 @@ -20,7 +20,7 @@
     1.4  	$(CC) $(CPPFLAGS) $(CFLAGS) $(OPTIMIZE) $(ASN1C_INC) -c $< -o $@
     1.5  
     1.6  Sync.c: sync.asn1 keysync.asn1 pEp.asn1
     1.7 -	$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=auto pEp.asn1 keysync.asn1 $<
     1.8 +	$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=auto pEp.asn1 keysync.asn1 trustsync.asn1 $<
     1.9  	rm -f converter-sample.c
    1.10  	touch Sync.c
    1.11  
     2.1 --- a/sync/gen_messages.ysl2	Wed Apr 22 10:59:39 2020 +0200
     2.2 +++ b/sync/gen_messages.ysl2	Wed Apr 22 19:00:53 2020 +0200
     2.3 @@ -45,7 +45,7 @@
     2.4  
     2.5          BEGIN
     2.6  
     2.7 -        `` for "fsm" | IMPORTS «@name» FROM «yml:ucase(@name)»;
     2.8 +        IMPORTS `apply "fsm", mode=imports`;
     2.9  
    2.10          «@name» ::= CHOICE {
    2.11              `` for "fsm" |> «yml:lcase(@name)» [APPLICATION «@id»] «@name»`if "position()!=last()" > , `
    2.12 @@ -56,6 +56,11 @@
    2.13          ||
    2.14      }
    2.15  
    2.16 +    template "fsm", mode=imports {
    2.17 +        > «@name» FROM «yml:ucase(@name)»
    2.18 +        if "position()!=last()" >  
    2.19 +    }
    2.20 +
    2.21      template "fsm", mode=individual
    2.22          document "generated/{yml:lcase(@name)}.asn1", "text" {
    2.23  
     3.1 --- a/sync/gen_statemachine.ysl2	Wed Apr 22 10:59:39 2020 +0200
     3.2 +++ b/sync/gen_statemachine.ysl2	Wed Apr 22 19:00:53 2020 +0200
     3.3 @@ -487,67 +487,91 @@
     3.4                      }
     3.5                  }
     3.6  
     3.7 -                switch (message_type) {
     3.8 -                    // these messages are being broadcasted
     3.9 -                    `` for "fsm/message[@type='broadcast']" |>> case «../@name»_PR_«yml:mixedCase(@name)»:
    3.10 -                        status = _own_identities_retrieve(session, &channels, PEP_idf_not_for_«yml:lcase(@name)»);
    3.11 -                        if (status)
    3.12 -                            goto the_end;
    3.13 +                switch (fsm) {
    3.14 +            ||
    3.15 +            for "fsm" {
    3.16 +            ||
    3.17 +                    case Sync_PR_«yml:lcase(@name)»:
    3.18 +                        switch (message_type) {
    3.19 +                            `` for "message[@type='broadcast']" |>>>> case «../@name»_PR_«yml:mixedCase(@name)»:
    3.20 +            ||
    3.21 +            if "message[@type='broadcast']"
    3.22 +            ||
    3.23 +                                // these messages are being broadcasted
    3.24 +                                status = _own_identities_retrieve(session, &channels, PEP_idf_not_for_«yml:lcase(../@name)»);
    3.25 +                                if (status)
    3.26 +                                    goto the_end;
    3.27  
    3.28 -                        if (!(channels && channels->ident)) {
    3.29 -                            // status = PEP_«yml:ucase(@name)»_NO_CHANNEL;
    3.30 -                            // we don't check for having a channel, because if
    3.31 -                            // this is initial setup before having an own
    3.32 -                            // identity we're fine
    3.33 -                            goto the_end;
    3.34 +                                if (!(channels && channels->ident)) {
    3.35 +                                    // status = PEP_«yml:ucase(../@name)»_NO_CHANNEL;
    3.36 +                                    // we don't check for having a channel, because if
    3.37 +                                    // this is initial setup before having an own
    3.38 +                                    // identity we're fine
    3.39 +                                    goto the_end;
    3.40 +                                }
    3.41 +                                break;
    3.42 +
    3.43 +            ||
    3.44 +            ||
    3.45 +                            `` for "message[@type='anycast']" |>>>> case «../@name»_PR_«yml:mixedCase(@name)»:
    3.46 +            ||
    3.47 +            if "message[@type='anycast']"
    3.48 +            ||
    3.49 +                                // these go anycast; previously used address is sticky (unicast)
    3.50 +                                // if we have a comm_partner fixed send it there
    3.51 +                                if (session->«yml:lcase(../@name)»_state.comm_partner.identity) {
    3.52 +                                    pEp_identity *channel = identity_dup(session->«yml:lcase(../@name)»_state.comm_partner.identity);
    3.53 +                                    if (!channel) {
    3.54 +                                        status = PEP_OUT_OF_MEMORY;
    3.55 +                                        goto the_end;
    3.56 +                                    }
    3.57 +
    3.58 +                                    channels = new_identity_list(channel);
    3.59 +                                    if (!channels) {
    3.60 +                                        status = PEP_OUT_OF_MEMORY;
    3.61 +                                        goto the_end;
    3.62 +                                    }
    3.63 +                                }
    3.64 +                                // if we can reply just do
    3.65 +                                else if (session->«yml:lcase(../@name)»_state.transport.from) {
    3.66 +                                    pEp_identity *channel = identity_dup(session->«yml:lcase(../@name)»_state.transport.from);
    3.67 +                                    if (!channel) {
    3.68 +                                        status = PEP_OUT_OF_MEMORY;
    3.69 +                                        goto the_end;
    3.70 +                                    }
    3.71 +
    3.72 +                                    channels = new_identity_list(channel);
    3.73 +                                    if (!channels) {
    3.74 +                                        status = PEP_OUT_OF_MEMORY;
    3.75 +                                        goto the_end;
    3.76 +                                    }
    3.77 +                                }
    3.78 +                                // real anycast, send it to the first matching
    3.79 +                                else {
    3.80 +                                    status = _own_identities_retrieve(session, &channels, PEP_idf_not_for_«yml:lcase(../@name)»);
    3.81 +                                    if (status)
    3.82 +                                        goto the_end;
    3.83 +                                    if (!channels)
    3.84 +                                        goto the_end;
    3.85 +
    3.86 +                                    if (channels->next) {
    3.87 +                                        free_identity_list(channels->next);
    3.88 +                                        channels->next = NULL;
    3.89 +                                    }
    3.90 +                                }
    3.91 +                                break;
    3.92 +
    3.93 +            ||
    3.94 +            ||
    3.95 +                            default:
    3.96 +                                status = PEP_«yml:ucase(../@name)»_ILLEGAL_MESSAGE;
    3.97 +                                goto the_end;
    3.98                          }
    3.99                          break;
   3.100  
   3.101 -                    // these go anycast; previously used address is sticky (unicast)
   3.102 -                    `` for "fsm/message[@type='anycast']" |>> case «../@name»_PR_«yml:mixedCase(@name)»:
   3.103 -                        // if we have a comm_partner fixed send it there
   3.104 -                        if (session->«yml:lcase(@name)»_state.comm_partner.identity) {
   3.105 -                            pEp_identity *channel = identity_dup(session->«yml:lcase(@name)»_state.comm_partner.identity);
   3.106 -                            if (!channel) {
   3.107 -                                status = PEP_OUT_OF_MEMORY;
   3.108 -                                goto the_end;
   3.109 -                            }
   3.110 -
   3.111 -                            channels = new_identity_list(channel);
   3.112 -                            if (!channels) {
   3.113 -                                status = PEP_OUT_OF_MEMORY;
   3.114 -                                goto the_end;
   3.115 -                            }
   3.116 -                        }
   3.117 -                        // if we can reply just do
   3.118 -                        else if (session->«yml:lcase(@name)»_state.transport.from) {
   3.119 -                            pEp_identity *channel = identity_dup(session->«yml:lcase(@name)»_state.transport.from);
   3.120 -                            if (!channel) {
   3.121 -                                status = PEP_OUT_OF_MEMORY;
   3.122 -                                goto the_end;
   3.123 -                            }
   3.124 -
   3.125 -                            channels = new_identity_list(channel);
   3.126 -                            if (!channels) {
   3.127 -                                status = PEP_OUT_OF_MEMORY;
   3.128 -                                goto the_end;
   3.129 -                            }
   3.130 -                        }
   3.131 -                        // real anycast, send it to the first matching
   3.132 -                        else {
   3.133 -                            status = _own_identities_retrieve(session, &channels, PEP_idf_not_for_«yml:lcase(@name)»);
   3.134 -                            if (status)
   3.135 -                                goto the_end;
   3.136 -                            if (!channels)
   3.137 -                                goto the_end;
   3.138 -
   3.139 -                            if (channels->next) {
   3.140 -                                free_identity_list(channels->next);
   3.141 -                                channels->next = NULL;
   3.142 -                            }
   3.143 -                        }
   3.144 -                        break;
   3.145 -
   3.146 +            ||
   3.147 +            }
   3.148 +            ||
   3.149                      default:
   3.150                          status = PEP_«yml:ucase(@name)»_ILLEGAL_MESSAGE;
   3.151                          goto the_end;
     4.1 --- a/sync/sync.fsm	Wed Apr 22 10:59:39 2020 +0200
     4.2 +++ b/sync/sync.fsm	Wed Apr 22 19:00:53 2020 +0200
     4.3 @@ -671,4 +671,14 @@
     4.4          message SynchronizeGroupKeys 21, ratelimit=60 {
     4.5          }
     4.6      }
     4.7 +
     4.8 +    fsm TrustSync 2, threshold=300 {
     4.9 +        version 1, 0;
    4.10 +
    4.11 +        state InitState;
    4.12 +
    4.13 +        message TrustUpdate 2 {
    4.14 +            auto Version version;
    4.15 +        }
    4.16 +    }
    4.17  }