* 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 <http://www.gnu.org/licenses/>.
*/
/**
* @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
*/
}
-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;
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;
GNUNET_SCHEDULER_shutdown ();
}
+
static void
origin_join_request (void *cls,
const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
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,
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;
}
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,
NULL);
}
+
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");
}
{
member = ca_result;
- if (NULL != member)
+ if (NULL == member)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to multicast service of member\n");
+ result = GNUNET_SYSERR;
+ GNUNET_SCHEDULER_shutdown ();
}
else
{
- result = GNUNET_SYSERR;
- GNUNET_SCHEDULER_shutdown ();
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to multicast service of member\n");
}
}
+
static void
multicast_da1 (void *cls,
void * op_result)
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);
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],
NULL, /* no test for member_replay_msg */
member_message,
NULL);
+ GNUNET_free (join_msg);
+ return ret;
}
{
int i = (int) (long) cls;
- if (NULL == pinfo)
+ if (NULL == pinfo)
{
result = GNUNET_SYSERR;
GNUNET_SCHEDULER_shutdown ();
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 */
multicast_da1, /* callback to be called when closing the
opened service connection */
NULL); /* closure for the above two callbacks */
- }
+ }
}
+
/**
* Test logic of peer "0" being origin starts here.
*
result = GNUNET_SYSERR;
ret = GNUNET_TESTBED_test_run
- ("test-multicast-multipeer", /* test case name */
+ ("test-multicast-2peers", /* test case name */
"test_multicast.conf", /* template configuration */
NUM_PEERS, /* number of peers to start */
0LL, /* Event mask - set to 0 for no event notifications */
return 0;
}
-/* end of test_multicast_multipeer.c */
+
+/* end of test_multicast_2peers.c */