diff options
Diffstat (limited to 'src/transport/test_transport_api_blacklisting.c')
-rw-r--r-- | src/transport/test_transport_api_blacklisting.c | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/src/transport/test_transport_api_blacklisting.c b/src/transport/test_transport_api_blacklisting.c new file mode 100644 index 000000000..8e5e14725 --- /dev/null +++ b/src/transport/test_transport_api_blacklisting.c | |||
@@ -0,0 +1,159 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
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 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file transport/transport_api_blacklisting.c | ||
23 | * @brief test for the blacklisting API | ||
24 | * @author Matthias Wachs | ||
25 | * | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_common.h" | ||
29 | #include "gnunet_hello_lib.h" | ||
30 | #include "gnunet_getopt_lib.h" | ||
31 | #include "gnunet_os_lib.h" | ||
32 | #include "gnunet_program_lib.h" | ||
33 | #include "gnunet_scheduler_lib.h" | ||
34 | #include "gnunet_transport_service.h" | ||
35 | #include "transport.h" | ||
36 | #include "transport-testing.h" | ||
37 | |||
38 | #define VERBOSE GNUNET_EXTRA_LOGGING | ||
39 | #define VERBOSE_ARM GNUNET_EXTRA_LOGGING | ||
40 | |||
41 | #define START_ARM GNUNET_YES | ||
42 | |||
43 | /** | ||
44 | * How long until we give up on transmitting the message? | ||
45 | */ | ||
46 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | ||
47 | |||
48 | /** | ||
49 | * How long until we give up on transmitting the message? | ||
50 | */ | ||
51 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | ||
52 | |||
53 | #define MTYPE 12345 | ||
54 | |||
55 | static int ok; | ||
56 | |||
57 | struct GNUNET_TRANSPORT_Blacklist * blacklist; | ||
58 | |||
59 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
60 | |||
61 | #if VERBOSE | ||
62 | #define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | ||
63 | #else | ||
64 | #define OKPP do { ok++; } while (0) | ||
65 | #endif | ||
66 | |||
67 | |||
68 | static void | ||
69 | end () | ||
70 | { | ||
71 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping\n"); | ||
72 | |||
73 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
74 | GNUNET_SCHEDULER_cancel (die_task); | ||
75 | |||
76 | ok = 0; | ||
77 | } | ||
78 | |||
79 | static void | ||
80 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
81 | { | ||
82 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
83 | |||
84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail!\n"); | ||
85 | |||
86 | ok = GNUNET_SYSERR; | ||
87 | } | ||
88 | |||
89 | |||
90 | int blacklist_cb (void *cls, | ||
91 | const struct | ||
92 | GNUNET_PeerIdentity * pid) | ||
93 | { | ||
94 | return GNUNET_YES; | ||
95 | } | ||
96 | |||
97 | static void | ||
98 | run (void *cls, char *const *args, const char *cfgfile, | ||
99 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
100 | { | ||
101 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
102 | |||
103 | blacklist = GNUNET_TRANSPORT_blacklist (cfg, | ||
104 | &blacklist_cb, | ||
105 | NULL); | ||
106 | |||
107 | GNUNET_assert (blacklist != NULL); | ||
108 | |||
109 | GNUNET_TRANSPORT_blacklist_cancel (blacklist); | ||
110 | |||
111 | end (); | ||
112 | } | ||
113 | |||
114 | |||
115 | static int | ||
116 | check () | ||
117 | { | ||
118 | static char *const argv[] = { "test-transport-api-blacklisting", | ||
119 | "-c", | ||
120 | "test_transport_api_data.conf", | ||
121 | #if VERBOSE | ||
122 | "-L", "DEBUG", | ||
123 | #endif | ||
124 | NULL | ||
125 | }; | ||
126 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
127 | GNUNET_GETOPT_OPTION_END | ||
128 | }; | ||
129 | |||
130 | #if WRITECONFIG | ||
131 | setTransportOptions ("test_transport_api_data.conf"); | ||
132 | #endif | ||
133 | |||
134 | ok = 1; | ||
135 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-transport-api-blacklisting", | ||
136 | "nohelp", options, &run, &ok); | ||
137 | |||
138 | return ok; | ||
139 | } | ||
140 | |||
141 | int | ||
142 | main (int argc, char *argv[]) | ||
143 | { | ||
144 | int ret; | ||
145 | |||
146 | GNUNET_log_setup ("test-transport-api-blacklisting", | ||
147 | #if VERBOSE | ||
148 | "DEBUG", | ||
149 | #else | ||
150 | "WARNING", | ||
151 | #endif | ||
152 | NULL); | ||
153 | |||
154 | ret = check (); | ||
155 | |||
156 | return ret; | ||
157 | } | ||
158 | |||
159 | /* end of transport_api_blacklisting.c */ | ||