2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file transport/test_transport_api_disconnect.c
20 * @brief base test case for transport implementations
22 * This test case tests disconnect notifications in peer shutdown.
23 * Starts two peers, has them connect, sends a message in between,
24 * stops one peer, expects the others to send a disconnect notification.
27 #include "gnunet_transport_service.h"
28 #include "transport-testing.h"
31 * How long until we give up on transmitting the message?
33 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
36 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
42 notify_disconnect (void *cls,
43 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
44 const struct GNUNET_PeerIdentity *other)
48 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
51 if (GNUNET_YES == shutdown_)
53 ccc->global_ret = GNUNET_OK;
54 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
55 "Test good, shutting down...\n");
56 GNUNET_SCHEDULER_shutdown ();
64 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
65 "Shutting down peer %u (`%s')\n",
67 GNUNET_i2s (&ccc->p[1]->id));
68 shutdown_ = GNUNET_YES;
69 GNUNET_TRANSPORT_TESTING_stop_peer (ccc->p[1]);
75 notify_receive (void *cls,
76 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
77 const struct GNUNET_PeerIdentity *sender,
78 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
81 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
84 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
87 ntohs (message->header.type),
88 ntohs (message->header.size),
92 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) &&
93 (sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) == ntohs (message->header.size)))
95 GNUNET_SCHEDULER_add_now (&stop_peer,
106 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
109 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
110 .connect_continuation = &GNUNET_TRANSPORT_TESTING_simple_send,
111 .connect_continuation_cls = &sc,
112 .config_file = "test_transport_api_data.conf",
113 .rec = ¬ify_receive,
114 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
115 .nd = ¬ify_disconnect,
117 .global_ret = GNUNET_SYSERR
123 GNUNET_TRANSPORT_TESTING_main (2,
124 &GNUNET_TRANSPORT_TESTING_connect_check,
130 /* end of test_transport_api_disconnect.c */