X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fmulticast%2Ftest_multicast_2peers.c;h=325d814988c496ab6ee10e031bcf11f9f2640171;hb=99f858c66be3206f5660c9d031cd6e6345a1267d;hp=9d1f42063eb68eb37b40403ce6e841f28160a8d4;hpb=501c1f7794be6e8a2ea15200dbdadd4c066edb89;p=oweals%2Fgnunet.git diff --git a/src/multicast/test_multicast_2peers.c b/src/multicast/test_multicast_2peers.c index 9d1f42063..325d81498 100644 --- a/src/multicast/test_multicast_2peers.c +++ b/src/multicast/test_multicast_2peers.c @@ -2,25 +2,23 @@ * This file is part of GNUnet * Copyright (C) 2013 GNUnet e.V. * - * GNUnet is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 3, or (at your - * option) any later version. + * GNUnet is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. * * GNUnet is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * Affero General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with GNUnet; see the file COPYING. If not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ /** * @file multicast/test_multicast_2peers.c - * @brief Tests for the Multicast API with two peers doing the ping + * @brief Tests for the Multicast API with two peers doing the ping * pong test. * @author xrs */ @@ -118,16 +116,17 @@ member_join_request (void *cls, } -int notify (void *cls, - size_t *data_size, - void *data) +static int +notify (void *cls, + size_t *data_size, + void *data) { char text[] = "ping"; *data_size = strlen(text)+1; GNUNET_memcpy(data, text, *data_size); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Member sents message to origin: %s\n", text); return GNUNET_YES; @@ -142,26 +141,30 @@ member_join_decision (void *cls, const struct GNUNET_PeerIdentity *relays, const struct GNUNET_MessageHeader *join_msg) { - struct GNUNET_MULTICAST_MemberTransmitHandle *req; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Member received a decision from origin: %s\n", (GNUNET_YES == is_admitted)?"accepted":"rejected"); - + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Member received a decision from origin: %s\n", + (GNUNET_YES == is_admitted) + ? "accepted" + : "rejected"); + if (GNUNET_YES == is_admitted) { + struct GNUNET_MULTICAST_MemberTransmitHandle *req; + + // FIXME: move to MQ-style API! req = GNUNET_MULTICAST_member_to_origin (member, 0, - notify, + ¬ify, NULL); } } static void -member_message (void *cls, +member_message (void *cls, const struct GNUNET_MULTICAST_MessageHeader *msg) { - if (0 != strncmp ("pong", (char *)&msg[1], 4)) + if (0 != strncmp ("pong", (char *)&msg[1], 4)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "member did not receive pong\n"); result = GNUNET_SYSERR; @@ -187,19 +190,19 @@ origin_join_request (void *cls, uint8_t data_size = ntohs (join_msg->size); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin got a join request...\n"); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin receives: '%s'\n", (char *)&join_msg[1]); - char data[] = "Come in!"; + const char data[] = "Come in!"; data_size = strlen (data) + 1; join_resp = GNUNET_malloc (sizeof (join_resp) + data_size); join_resp->size = htons (sizeof (join_resp) + data_size); join_resp->type = htons (123); GNUNET_memcpy (&join_resp[1], data, data_size); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends: '%s'\n", data); GNUNET_MULTICAST_join_decision (jh, @@ -207,23 +210,26 @@ origin_join_request (void *cls, 0, NULL, join_resp); - + GNUNET_free (join_resp); result = GNUNET_OK; } int -origin_notify (void *cls, - size_t *data_size, +origin_notify (void *cls, + size_t *data_size, void *data) { char text[] = "pong"; + *data_size = strlen(text)+1; - memcpy(data, text, *data_size); + GNUNET_memcpy (data, + text, + *data_size); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends (to all): %s\n", text); - return GNUNET_YES; + return GNUNET_YES; } @@ -232,8 +238,8 @@ origin_request (void *cls, const struct GNUNET_MULTICAST_RequestHeader *req) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin receives: %s\n", (char *)&req[1]); - - if (0 != strncmp ("ping", (char *)&req[1], 4)) + + if (0 != strncmp ("ping", (char *)&req[1], 4)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "origin didn't reveice a correct request"); GNUNET_MULTICAST_origin_to_all (origin, @@ -246,7 +252,7 @@ origin_request (void *cls, static void origin_message (void *cls, - const struct GNUNET_MULTICAST_MessageHeader *msg) + const struct GNUNET_MULTICAST_MessageHeader *msg) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n"); } @@ -288,11 +294,12 @@ multicast_ca1 (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_MessageHeader *join_msg; + void *ret; // Get members keys member_key = GNUNET_CRYPTO_ecdsa_key_create (); GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key); - + char data[] = "Hi, can I enter?"; uint8_t data_size = strlen (data) + 1; join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); @@ -303,7 +310,7 @@ multicast_ca1 (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Members tries to join multicast group\n"); - return GNUNET_MULTICAST_member_join (cfg, + ret = GNUNET_MULTICAST_member_join (cfg, &group_pub_key, member_key, peer_id[0], @@ -316,6 +323,8 @@ multicast_ca1 (void *cls, NULL, /* no test for member_replay_msg */ member_message, NULL); + GNUNET_free (join_msg); + return ret; } @@ -327,7 +336,7 @@ peer_information_cb (void *cls, { int i = (int) (long) cls; - if (NULL == pinfo) + if (NULL == pinfo) { result = GNUNET_SYSERR; GNUNET_SCHEDULER_shutdown (); @@ -341,7 +350,7 @@ peer_information_cb (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Create member peer\n"); - if (0 == i) + if (0 == i) { /* connect to multicast service of member */ op1 = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */