aboutsummaryrefslogtreecommitdiff
path: root/src/core/test_core_api_send_to_self.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-30 23:52:20 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-30 23:52:20 +0000
commit46efc8e8412f01166744d00f6008338a811e9d99 (patch)
treeb3caac7da4cd5f6618d07fa301c92ec464d184b5 /src/core/test_core_api_send_to_self.c
parent5838ccbde451b0fae44079e1f2ead027b1428144 (diff)
downloadgnunet-46efc8e8412f01166744d00f6008338a811e9d99.tar.gz
gnunet-46efc8e8412f01166744d00f6008338a811e9d99.zip
convert another test to new API
Diffstat (limited to 'src/core/test_core_api_send_to_self.c')
-rw-r--r--src/core/test_core_api_send_to_self.c81
1 files changed, 31 insertions, 50 deletions
diff --git a/src/core/test_core_api_send_to_self.c b/src/core/test_core_api_send_to_self.c
index 1387296da..111aea900 100644
--- a/src/core/test_core_api_send_to_self.c
+++ b/src/core/test_core_api_send_to_self.c
@@ -22,6 +22,7 @@
22 * @file core/test_core_api_send_to_self.c 22 * @file core/test_core_api_send_to_self.c
23 * @brief test that sending a message to ourselves via CORE works 23 * @brief test that sending a message to ourselves via CORE works
24 * @author Philipp Toelke 24 * @author Philipp Toelke
25 * @author Christian Grothoff
25 */ 26 */
26#include "platform.h" 27#include "platform.h"
27#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
@@ -64,7 +65,7 @@ cleanup (void *cls)
64 } 65 }
65 if (NULL != core) 66 if (NULL != core)
66 { 67 {
67 GNUNET_CORE_disconnect (core); 68 GNUNET_CORE_disconnecT (core);
68 core = NULL; 69 core = NULL;
69 } 70 }
70 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 71 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -85,39 +86,12 @@ do_timeout (void *cls)
85} 86}
86 87
87 88
88static int 89static void
89receive (void *cls, 90handle_test (void *cls,
90 const struct GNUNET_PeerIdentity *other, 91 const struct GNUNET_MessageHeader *message)
91 const struct GNUNET_MessageHeader *message)
92{ 92{
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
94 "Received message from peer %s\n",
95 GNUNET_i2s (other));
96 GNUNET_assert (GNUNET_MESSAGE_TYPE_DUMMY == ntohs (message->type));
97 GNUNET_assert (0 == memcmp (other, &myself, sizeof (myself)));
98 GNUNET_SCHEDULER_shutdown (); 93 GNUNET_SCHEDULER_shutdown ();
99 ret = 0; 94 ret = 0;
100 return GNUNET_OK;
101}
102
103
104static size_t
105send_message (void *cls,
106 size_t size,
107 void *buf)
108{
109 struct GNUNET_MessageHeader *hdr = buf;
110 if ( (size == 0) || (buf == NULL) )
111 {
112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
113 "Could not send; got 0 buffer\n");
114 return 0;
115 }
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
117 "Sending!\n");
118 hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
119 hdr->type = htons (GNUNET_MESSAGE_TYPE_DUMMY);
120 return ntohs (hdr->size);
121} 95}
122 96
123 97
@@ -134,14 +108,15 @@ init (void *cls,
134 "Correctly connected to CORE; we are the peer %s.\n", 108 "Correctly connected to CORE; we are the peer %s.\n",
135 GNUNET_i2s (my_identity)); 109 GNUNET_i2s (my_identity));
136 GNUNET_memcpy (&myself, 110 GNUNET_memcpy (&myself,
137 my_identity, 111 my_identity,
138 sizeof (struct GNUNET_PeerIdentity)); 112 sizeof (struct GNUNET_PeerIdentity));
139} 113}
140 114
141 115
142static void 116static void *
143connect_cb (void *cls, 117connect_cb (void *cls,
144 const struct GNUNET_PeerIdentity *peer) 118 const struct GNUNET_PeerIdentity *peer,
119 struct GNUNET_MQ_Handle *mq)
145{ 120{
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 "Connected to peer %s.\n", 122 "Connected to peer %s.\n",
@@ -150,16 +125,17 @@ connect_cb (void *cls,
150 &myself, 125 &myself,
151 sizeof (struct GNUNET_PeerIdentity))) 126 sizeof (struct GNUNET_PeerIdentity)))
152 { 127 {
128 struct GNUNET_MQ_Envelope *env;
129 struct GNUNET_MessageHeader *msg;
130
153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
154 "Connected to myself; sending message!\n"); 132 "Connected to myself; sending message!\n");
155 GNUNET_CORE_notify_transmit_ready (core, 133 env = GNUNET_MQ_msg (msg,
156 GNUNET_YES, 134 GNUNET_MESSAGE_TYPE_DUMMY);
157 0, 135 GNUNET_MQ_send (mq,
158 GNUNET_TIME_UNIT_FOREVER_REL, 136 env);
159 peer,
160 sizeof (struct GNUNET_MessageHeader),
161 &send_message, NULL);
162 } 137 }
138 return NULL;
163} 139}
164 140
165 141
@@ -174,16 +150,21 @@ run (void *cls,
174 const struct GNUNET_CONFIGURATION_Handle *cfg, 150 const struct GNUNET_CONFIGURATION_Handle *cfg,
175 struct GNUNET_TESTING_Peer *peer) 151 struct GNUNET_TESTING_Peer *peer)
176{ 152{
177 const static struct GNUNET_CORE_MessageHandler handlers[] = { 153 GNUNET_MQ_hd_fixed_size (test,
178 { &receive, 154 GNUNET_MESSAGE_TYPE_DUMMY,
179 GNUNET_MESSAGE_TYPE_DUMMY, 155 struct GNUNET_MessageHeader);
180 sizeof (struct GNUNET_MessageHeader) }, 156 struct GNUNET_MQ_MessageHandler handlers[] = {
181 {NULL, 0, 0} 157 make_test_handler (NULL),
158 GNUNET_MQ_handler_end ()
182 }; 159 };
160
183 core = 161 core =
184 GNUNET_CORE_connect (cfg, NULL, &init, 162 GNUNET_CORE_connecT (cfg,
185 &connect_cb, NULL, NULL, 163 NULL,
186 0, NULL, 0, handlers); 164 &init,
165 &connect_cb,
166 NULL,
167 handlers);
187 GNUNET_SCHEDULER_add_shutdown (&cleanup, 168 GNUNET_SCHEDULER_add_shutdown (&cleanup,
188 NULL); 169 NULL);
189 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 170 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,