* 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/>.
*/
/**
#include "gnunet_common.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib.h"
-#include "gnunet_core_service.h"
#include "gnunet_multicast_service.h"
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
static const struct GNUNET_CONFIGURATION_Handle *cfg;
-struct GNUNET_CORE_Handle *core;
struct GNUNET_PeerIdentity this_peer;
struct GNUNET_MULTICAST_Origin *origin;
static void
cleanup ()
{
- if (NULL != core)
- {
- GNUNET_CORE_disconnect (core);
- core = NULL;
- }
if (NULL != member)
{
GNUNET_MULTICAST_member_part (member, NULL, NULL);
{
res = 0;
cleanup ();
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test PASSED.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test PASSED.\n");
}
tmit->paused = GNUNET_NO;
*data_size = size;
- memcpy (data, tmit->data[tmit->n], size);
+ GNUNET_memcpy (data, tmit->data[tmit->n], size);
return ++tmit->n < tmit->data_count ? GNUNET_NO : GNUNET_YES;
}
const struct GNUNET_MessageHeader *join_msg,
struct GNUNET_MULTICAST_JoinHandle *jh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: member_recv_join_request()\n", test);
}
static void
origin_stopped (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: origin_stopped()\n", test);
end ();
}
schedule_origin_stop (void *cls)
{
test = TEST_ORIGIN_STOP;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: origin_stop()\n", test);
GNUNET_MULTICAST_origin_stop (origin, origin_stopped, NULL);
origin = NULL;
static void
member_parted (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: member_parted()\n", test);
member = NULL;
switch (test)
{
case TEST_MEMBER_JOIN_REFUSE:
+ // Test 3 starts here
member_join (TEST_MEMBER_JOIN_ADMIT);
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Invalid test #%d in member_recv_join_decision()\n", test);
+ "Invalid test #%d in member_parted()\n", test);
GNUNET_assert (0);
}
}
static void
schedule_member_part (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: schedule_member_part()\n", test);
GNUNET_MULTICAST_member_part (member, member_parted, NULL);
}
member_part ()
{
test = TEST_MEMBER_PART;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: member_part()\n", test);
+ // Test 10 starts here
GNUNET_SCHEDULER_add_now (&schedule_member_part, NULL);
}
static void
member_replay_ok ()
{
+ // Execution of test 8 here
test = TEST_MEMBER_REPLAY_OK;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: member_replay_ok()\n", test);
replay_fragment_id = 1;
replay_flags = 1 | 1<<11;
member_replay_error ()
{
test = TEST_MEMBER_REPLAY_ERROR;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: member_replay_error()\n", test);
replay_fragment_id = 1234;
replay_flags = 11 | 1<<11;
uint64_t flags,
struct GNUNET_MULTICAST_ReplayHandle *rh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: origin_recv_replay_msg()\n", test);
GNUNET_assert (0);
}
uint64_t flags,
struct GNUNET_MULTICAST_ReplayHandle *rh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: member_recv_replay_msg()\n", test);
GNUNET_assert (0);
}
uint64_t flags,
struct GNUNET_MULTICAST_ReplayHandle *rh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: origin_recv_replay_frag()"
" - fragment_id=%" PRIu64 " flags=%" PRIu64 "\n",
test, fragment_id, flags);
switch (test)
{
case TEST_MEMBER_REPLAY_ERROR:
+ // Test 8 starts here
GNUNET_MULTICAST_replay_response (rh, NULL, GNUNET_SYSERR);
member_replay_ok ();
break;
uint64_t flags,
struct GNUNET_MULTICAST_ReplayHandle *rh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: member_recv_replay_frag()\n", test);
GNUNET_assert (0);
}
const struct GNUNET_MULTICAST_RequestHeader *req)
{
struct OriginClosure *ocls = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: origin_recv_request()\n", test);
if (++ocls->n != ocls->msgs_expected)
return;
GNUNET_assert (0 == memcmp (&req->member_pub_key,
&member_pub_key, sizeof (member_pub_key)));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Test #%u: verify message content, take first 3 bytes: %.3s\n",
+ test, (char *)&req[1]);
+ GNUNET_assert (0 == memcmp (&req[1], "abc", 3));
- // FIXME: check message content
-
+ // Test 7 starts here
member_replay_error ();
}
member_to_origin ()
{
test = TEST_MEMBER_TO_ORIGIN;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: member_to_origin()\n", test);
struct TransmitClosure *tmit = &tmit_cls;
{
struct MemberClosure *mcls = cls;
+ // Test 5 starts here after message has been received from origin
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Test #%u: member_recv_message() %u/%u\n",
test,
switch (test)
{
+ case TEST_ORIGIN_TO_ALL:
+ test = TEST_ORIGIN_TO_ALL_RECV;
+ break;
+
case TEST_ORIGIN_TO_ALL_RECV:
+ // Test 6 starts here
member_to_origin ();
break;
case TEST_MEMBER_REPLAY_OK:
+ // Test 9 starts here
GNUNET_assert (replay_fragment_id == GNUNET_ntohll (msg->fragment_id));
member_part ();
break;
const struct GNUNET_MULTICAST_MessageHeader *msg)
{
struct OriginClosure *ocls = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: origin_recv_message() %u/%u\n",
test, ocls->n + 1, ocls->msgs_expected);
if (++ocls->n != ocls->msgs_expected)
switch (test)
{
case TEST_ORIGIN_TO_ALL:
+ // Prepare to execute test 5
test = TEST_ORIGIN_TO_ALL_RECV;
break;
+ case TEST_ORIGIN_TO_ALL_RECV:
+ // Test 6 starts here
+ member_to_origin ();
+ break;
+
default:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Invalid test #%d in origin_recv_message()\n", test);
origin_to_all ()
{
test = TEST_ORIGIN_TO_ALL;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: origin_to_all()\n", test);
struct TransmitClosure *tmit = &tmit_cls;
const struct GNUNET_PeerIdentity *relays,
const struct GNUNET_MessageHeader *join_msg)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: member_recv_join_decision() - is_admitted: %d\n",
test, is_admitted);
{
case TEST_MEMBER_JOIN_REFUSE:
GNUNET_assert (0 == relay_count);
+ // Test 3 starts here
GNUNET_SCHEDULER_add_now (&schedule_member_part, NULL);
break;
case TEST_MEMBER_JOIN_ADMIT:
GNUNET_assert (1 == relay_count);
GNUNET_assert (0 == memcmp (relays, &this_peer, sizeof (this_peer)));
+ // Test 4 starts here
origin_to_all ();
break;
}
}
-
+/**
+ * Test: origin receives join request
+ */
static void
origin_recv_join_request (void *cls,
const struct GNUNET_CRYPTO_EcdsaPublicKey *mem_key,
const struct GNUNET_MessageHeader *join_msg,
struct GNUNET_MULTICAST_JoinHandle *jh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: origin_recv_join_request()\n", test);
GNUNET_assert (0 == memcmp (mem_key, &member_pub_key, sizeof (member_pub_key)));
join_resp = GNUNET_malloc (sizeof (join_resp) + data_size);
join_resp->size = htons (sizeof (join_resp) + data_size);
join_resp->type = htons (456);
- memcpy (&join_resp[1], data, data_size);
+ GNUNET_memcpy (&join_resp[1], data, data_size);
switch (test)
{
case TEST_MEMBER_JOIN_REFUSE:
+ // Test 3 starts here
GNUNET_MULTICAST_join_decision (jh, GNUNET_NO, 0, NULL, join_resp);
break;
case TEST_MEMBER_JOIN_ADMIT:
+ // Test 3 is running
GNUNET_MULTICAST_join_decision (jh, GNUNET_YES, 1, &this_peer, join_resp);
break;
}
}
-
+/**
+ * Test: member joins multicast group
+ */
static void
member_join (int t)
{
test = t;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: member_join()\n", test);
member_key = GNUNET_CRYPTO_ecdsa_key_create ();
join_req = GNUNET_malloc (sizeof (join_req) + data_size);
join_req->size = htons (sizeof (join_req) + data_size);
join_req->type = htons (123);
- memcpy (&join_req[1], data, data_size);
+ GNUNET_memcpy (&join_req[1], data, data_size);
member = GNUNET_MULTICAST_member_join (cfg, &group_pub_key, member_key,
&this_peer, 1, &this_peer, join_req,
&member_cls);
}
-
+/**
+ * Test: Start a multicast group as origin
+ */
static void
origin_start ()
{
test = TEST_ORIGIN_START;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test #%u: origin_start()\n", test);
group_key = GNUNET_CRYPTO_eddsa_key_create ();
origin_recv_request,
origin_recv_message,
&origin_cls);
+ // Test 2 starts here
member_join (TEST_MEMBER_JOIN_REFUSE);
}
-static void
-core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity)
-{
- this_peer = *my_identity;
- origin_start ();
-}
-
-
/**
* Main function of the test, run from scheduler.
*
cfg = c;
end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&end_badly, NULL);
- core = GNUNET_CORE_connect (cfg, NULL,
- &core_connected, NULL, NULL,
- NULL, GNUNET_NO,
- NULL, GNUNET_NO,
- NULL);
+ GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer);
+
+ // Test 1 starts here
+ origin_start ();
}