diff options
Diffstat (limited to 'src/core/test_core_api_send_to_self.c')
-rw-r--r-- | src/core/test_core_api_send_to_self.c | 123 |
1 files changed, 65 insertions, 58 deletions
diff --git a/src/core/test_core_api_send_to_self.c b/src/core/test_core_api_send_to_self.c index f2ddeb9fe..09d6edacc 100644 --- a/src/core/test_core_api_send_to_self.c +++ b/src/core/test_core_api_send_to_self.c | |||
@@ -66,18 +66,17 @@ cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tskctx) | |||
66 | die_task = GNUNET_SCHEDULER_NO_TASK; | 66 | die_task = GNUNET_SCHEDULER_NO_TASK; |
67 | 67 | ||
68 | if (core != NULL) | 68 | if (core != NULL) |
69 | { | 69 | { |
70 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting core.\n"); | 70 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting core.\n"); |
71 | GNUNET_CORE_disconnect (core); | 71 | GNUNET_CORE_disconnect (core); |
72 | core = NULL; | 72 | core = NULL; |
73 | } | 73 | } |
74 | 74 | ||
75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peer\n"); |
76 | "Stopping peer\n"); | ||
77 | if (0 != GNUNET_OS_process_kill (arm_proc, SIGTERM)) | 76 | if (0 != GNUNET_OS_process_kill (arm_proc, SIGTERM)) |
78 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 77 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
79 | 78 | ||
80 | if (GNUNET_OS_process_wait(arm_proc) != GNUNET_OK) | 79 | if (GNUNET_OS_process_wait (arm_proc) != GNUNET_OK) |
81 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 80 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
82 | 81 | ||
83 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -85,33 +84,37 @@ cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tskctx) | |||
85 | GNUNET_OS_process_close (arm_proc); | 84 | GNUNET_OS_process_close (arm_proc); |
86 | arm_proc = NULL; | 85 | arm_proc = NULL; |
87 | 86 | ||
88 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n"); | 87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n"); |
89 | } | 88 | } |
90 | 89 | ||
91 | static int | 90 | static int |
92 | receive(void* cls, const struct GNUNET_PeerIdentity* other, const struct GNUNET_MessageHeader* message, const struct GNUNET_TRANSPORT_ATS_Information* atsi) | 91 | receive (void *cls, const struct GNUNET_PeerIdentity *other, |
92 | const struct GNUNET_MessageHeader *message, | ||
93 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
93 | { | 94 | { |
94 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 95 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
95 | GNUNET_SCHEDULER_cancel(die_task); | 96 | GNUNET_SCHEDULER_cancel (die_task); |
96 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received message from peer %s\n", GNUNET_i2s(other)); | 97 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from peer %s\n", |
97 | GNUNET_SCHEDULER_add_now(&cleanup, NULL); | 98 | GNUNET_i2s (other)); |
99 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | ||
98 | ret = 0; | 100 | ret = 0; |
99 | return GNUNET_OK; | 101 | return GNUNET_OK; |
100 | } | 102 | } |
101 | 103 | ||
102 | static size_t | 104 | static size_t |
103 | send_message (void* cls, size_t size, void* buf) | 105 | send_message (void *cls, size_t size, void *buf) |
104 | { | 106 | { |
105 | if (size == 0 || buf == NULL) | 107 | if (size == 0 || buf == NULL) |
106 | { | 108 | { |
107 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Could not send; got 0 buffer\n"); | 109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not send; got 0 buffer\n"); |
108 | return 0; | 110 | return 0; |
109 | } | 111 | } |
110 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending!\n"); | 112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending!\n"); |
111 | struct GNUNET_MessageHeader *hdr = buf; | 113 | struct GNUNET_MessageHeader *hdr = buf; |
112 | hdr->size = htons(sizeof(struct GNUNET_MessageHeader)); | 114 | |
113 | hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP); | 115 | hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); |
114 | return ntohs(hdr->size); | 116 | hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP); |
117 | return ntohs (hdr->size); | ||
115 | } | 118 | } |
116 | 119 | ||
117 | static void | 120 | static void |
@@ -120,33 +123,33 @@ init (void *cls, struct GNUNET_CORE_Handle *core, | |||
120 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pk) | 123 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pk) |
121 | { | 124 | { |
122 | if (core == NULL) | 125 | if (core == NULL) |
123 | { | 126 | { |
124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could NOT connect to CORE;\n"); | 127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could NOT connect to CORE;\n"); |
125 | return; | 128 | return; |
126 | } | 129 | } |
127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
128 | "Correctly connected to CORE; we are the peer %s.\n", | 131 | "Correctly connected to CORE; we are the peer %s.\n", |
129 | GNUNET_i2s (my_identity)); | 132 | GNUNET_i2s (my_identity)); |
130 | memcpy (&myself, my_identity, sizeof (struct GNUNET_PeerIdentity)); | 133 | memcpy (&myself, my_identity, sizeof (struct GNUNET_PeerIdentity)); |
131 | } | 134 | } |
132 | 135 | ||
133 | static void | 136 | static void |
134 | connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer, | 137 | connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer, |
135 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 138 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
136 | { | 139 | { |
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s.\n", | 140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s.\n", |
138 | GNUNET_i2s (peer)); | 141 | GNUNET_i2s (peer)); |
139 | if (0 == memcmp (peer, &myself, sizeof (struct GNUNET_PeerIdentity))) | 142 | if (0 == memcmp (peer, &myself, sizeof (struct GNUNET_PeerIdentity))) |
140 | { | 143 | { |
141 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
142 | "Connected to myself; sending message!\n"); | 145 | "Connected to myself; sending message!\n"); |
143 | GNUNET_CORE_notify_transmit_ready (core, | 146 | GNUNET_CORE_notify_transmit_ready (core, |
144 | GNUNET_YES, | 147 | GNUNET_YES, |
145 | 0, GNUNET_TIME_UNIT_FOREVER_REL, | 148 | 0, GNUNET_TIME_UNIT_FOREVER_REL, |
146 | peer, | 149 | peer, |
147 | sizeof (struct GNUNET_MessageHeader), | 150 | sizeof (struct GNUNET_MessageHeader), |
148 | send_message, NULL); | 151 | send_message, NULL); |
149 | } | 152 | } |
150 | } | 153 | } |
151 | 154 | ||
152 | 155 | ||
@@ -161,8 +164,7 @@ connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
161 | static void | 164 | static void |
162 | run (void *cls, | 165 | run (void *cls, |
163 | char *const *args, | 166 | char *const *args, |
164 | const char *cfgfile, | 167 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
165 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
166 | { | 168 | { |
167 | const static struct GNUNET_CORE_MessageHandler handlers[] = { | 169 | const static struct GNUNET_CORE_MessageHandler handlers[] = { |
168 | {&receive, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP, 0}, | 170 | {&receive, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP, 0}, |
@@ -172,22 +174,27 @@ run (void *cls, | |||
172 | core_cfg = GNUNET_CONFIGURATION_create (); | 174 | core_cfg = GNUNET_CONFIGURATION_create (); |
173 | 175 | ||
174 | arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 176 | arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
175 | "gnunet-service-arm", | 177 | "gnunet-service-arm", |
176 | #if VERBOSE | 178 | #if VERBOSE |
177 | "-L", "DEBUG", | 179 | "-L", "DEBUG", |
178 | #endif | 180 | #endif |
179 | "-c", "test_core_api_peer1.conf", NULL); | 181 | "-c", "test_core_api_peer1.conf", NULL); |
180 | 182 | ||
181 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load (core_cfg, "test_core_api_peer1.conf")); | 183 | GNUNET_assert (GNUNET_OK == |
184 | GNUNET_CONFIGURATION_load (core_cfg, | ||
185 | "test_core_api_peer1.conf")); | ||
182 | 186 | ||
183 | core = GNUNET_CORE_connect (core_cfg, | 187 | core = GNUNET_CORE_connect (core_cfg, |
184 | 42, | 188 | 42, |
185 | NULL, | 189 | NULL, |
186 | &init, | 190 | &init, |
187 | &connect_cb, | 191 | &connect_cb, |
188 | NULL, NULL, NULL, 0, NULL, 0, handlers); | 192 | NULL, NULL, NULL, 0, NULL, 0, handlers); |
189 | 193 | ||
190 | die_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60), &cleanup, cls); | 194 | die_task = |
195 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
196 | (GNUNET_TIME_UNIT_SECONDS, 60), &cleanup, | ||
197 | cls); | ||
191 | } | 198 | } |
192 | 199 | ||
193 | 200 | ||
@@ -210,11 +217,11 @@ check () | |||
210 | ret = 1; | 217 | ret = 1; |
211 | 218 | ||
212 | return (GNUNET_OK == | 219 | return (GNUNET_OK == |
213 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 220 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
214 | argv, | 221 | argv, |
215 | "test_core_api_send_to_self", | 222 | "test_core_api_send_to_self", |
216 | gettext_noop ("help text"), | 223 | gettext_noop ("help text"), |
217 | options, &run, NULL)) ? ret : 1; | 224 | options, &run, NULL)) ? ret : 1; |
218 | } | 225 | } |
219 | 226 | ||
220 | /** | 227 | /** |