aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-05 12:10:06 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-05 12:10:06 +0000
commitb97332aac1d2c14ba8985e82fad90077673027c0 (patch)
tree1873c36b6b27e05335c49c096e0e38a52ea002cb /src
parent0b8a02cc156081ad9a087ea91952a5cfc4270475 (diff)
downloadgnunet-b97332aac1d2c14ba8985e82fad90077673027c0.tar.gz
gnunet-b97332aac1d2c14ba8985e82fad90077673027c0.zip
update remaining tests to use new MQ API
Diffstat (limited to 'src')
-rw-r--r--src/util/test_server_disconnect.c43
-rw-r--r--src/util/test_server_with_client.c64
-rw-r--r--src/util/test_server_with_client_unix.c48
3 files changed, 68 insertions, 87 deletions
diff --git a/src/util/test_server_disconnect.c b/src/util/test_server_disconnect.c
index f59fa547f..de9c4722d 100644
--- a/src/util/test_server_disconnect.c
+++ b/src/util/test_server_disconnect.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010 GNUnet e.V. 3 Copyright (C) 2009, 2010, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -33,7 +33,7 @@
33 33
34static struct GNUNET_SERVER_Handle *server; 34static struct GNUNET_SERVER_Handle *server;
35 35
36static struct GNUNET_CLIENT_Connection *cc; 36static struct GNUNET_MQ_Handle *mq;
37 37
38static struct GNUNET_CONFIGURATION_Handle *cfg; 38static struct GNUNET_CONFIGURATION_Handle *cfg;
39 39
@@ -46,7 +46,7 @@ finish_up (void *cls)
46 GNUNET_assert (ok == 5); 46 GNUNET_assert (ok == 5);
47 ok = 0; 47 ok = 0;
48 GNUNET_SERVER_destroy (server); 48 GNUNET_SERVER_destroy (server);
49 GNUNET_CLIENT_disconnect (cc); 49 GNUNET_MQ_destroy (mq);
50 GNUNET_CONFIGURATION_destroy (cfg); 50 GNUNET_CONFIGURATION_destroy (cfg);
51} 51}
52 52
@@ -96,27 +96,14 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = {
96}; 96};
97 97
98 98
99static size_t
100transmit_initial_message (void *cls, size_t size, void *buf)
101{
102 struct GNUNET_MessageHeader msg;
103
104 GNUNET_assert (ok == 1);
105 ok = 2;
106 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
107 msg.type = htons (MY_TYPE);
108 msg.size = htons (sizeof (struct GNUNET_MessageHeader));
109 memcpy (buf, &msg, sizeof (struct GNUNET_MessageHeader));
110 return sizeof (struct GNUNET_MessageHeader);
111}
112
113
114static void 99static void
115task (void *cls) 100task (void *cls)
116{ 101{
117 struct sockaddr_in sa; 102 struct sockaddr_in sa;
118 struct sockaddr *sap[2]; 103 struct sockaddr *sap[2];
119 socklen_t slens[2]; 104 socklen_t slens[2];
105 struct GNUNET_MQ_Envelope *env;
106 struct GNUNET_MessageHeader *msg;
120 107
121 sap[0] = (struct sockaddr *) &sa; 108 sap[0] = (struct sockaddr *) &sa;
122 slens[0] = sizeof (sa); 109 slens[0] = sizeof (sa);
@@ -138,15 +125,17 @@ task (void *cls)
138 "localhost"); 125 "localhost");
139 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 126 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
140 "localhost"); 127 "localhost");
141 cc = GNUNET_CLIENT_connect ("test-server", cfg); 128 mq = GNUNET_CLIENT_connecT (cfg,
142 GNUNET_assert (cc != NULL); 129 "test-server",
143 GNUNET_assert (NULL != 130 NULL,
144 GNUNET_CLIENT_notify_transmit_ready (cc, 131 NULL,
145 sizeof (struct 132 NULL);
146 GNUNET_MessageHeader), 133 GNUNET_assert (NULL != mq);
147 TIMEOUT, GNUNET_YES, 134 ok = 2;
148 &transmit_initial_message, 135 env = GNUNET_MQ_msg (msg,
149 NULL)); 136 MY_TYPE);
137 GNUNET_MQ_send (mq,
138 env);
150} 139}
151 140
152 141
diff --git a/src/util/test_server_with_client.c b/src/util/test_server_with_client.c
index 8a8f65474..59f9b6afd 100644
--- a/src/util/test_server_with_client.c
+++ b/src/util/test_server_with_client.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -33,12 +33,13 @@
33 33
34static struct GNUNET_SERVER_Handle *server; 34static struct GNUNET_SERVER_Handle *server;
35 35
36static struct GNUNET_CLIENT_Connection *client; 36static struct GNUNET_MQ_Handle *mq;
37 37
38static struct GNUNET_CONFIGURATION_Handle *cfg; 38static struct GNUNET_CONFIGURATION_Handle *cfg;
39 39
40static int ok; 40static int ok;
41 41
42
42static void 43static void
43send_done (void *cls) 44send_done (void *cls)
44{ 45{
@@ -51,7 +52,8 @@ send_done (void *cls)
51 52
52 53
53static void 54static void
54recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient, 55recv_cb (void *cls,
56 struct GNUNET_SERVER_Client *argclient,
55 const struct GNUNET_MessageHeader *message) 57 const struct GNUNET_MessageHeader *message)
56{ 58{
57 void *addr; 59 void *addr;
@@ -60,7 +62,9 @@ recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient,
60 struct sockaddr_in *have; 62 struct sockaddr_in *have;
61 63
62 GNUNET_assert (GNUNET_OK == 64 GNUNET_assert (GNUNET_OK ==
63 GNUNET_SERVER_client_get_address (argclient, &addr, &addrlen)); 65 GNUNET_SERVER_client_get_address (argclient,
66 &addr,
67 &addrlen));
64 68
65 GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); 69 GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
66 have = addr; 70 have = addr;
@@ -79,12 +83,14 @@ recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient,
79 ok++; 83 ok++;
80 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 84 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
81 (GNUNET_TIME_UNIT_MILLISECONDS, 50), 85 (GNUNET_TIME_UNIT_MILLISECONDS, 50),
82 &send_done, argclient); 86 &send_done,
87 argclient);
83 break; 88 break;
84 case 4: 89 case 4:
85 ok++; 90 ok++;
86 GNUNET_CLIENT_disconnect (client); 91 GNUNET_MQ_destroy (mq);
87 GNUNET_SERVER_receive_done (argclient, GNUNET_OK); 92 GNUNET_SERVER_receive_done (argclient,
93 GNUNET_OK);
88 break; 94 break;
89 default: 95 default:
90 GNUNET_assert (0); 96 GNUNET_assert (0);
@@ -111,7 +117,8 @@ clean_up (void *cls)
111 * @param client identification of the client 117 * @param client identification of the client
112 */ 118 */
113static void 119static void
114notify_disconnect (void *cls, struct GNUNET_SERVER_Client *client) 120notify_disconnect (void *cls,
121 struct GNUNET_SERVER_Client *client)
115{ 122{
116 if (client == NULL) 123 if (client == NULL)
117 return; 124 return;
@@ -121,24 +128,6 @@ notify_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
121} 128}
122 129
123 130
124static size_t
125notify_ready (void *cls, size_t size, void *buf)
126{
127 struct GNUNET_MessageHeader *msg;
128
129 GNUNET_assert (size >= 256);
130 GNUNET_assert (1 == ok);
131 ok++;
132 msg = buf;
133 msg->type = htons (MY_TYPE);
134 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
135 msg++;
136 msg->type = htons (MY_TYPE);
137 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
138 return 2 * sizeof (struct GNUNET_MessageHeader);
139}
140
141
142static struct GNUNET_SERVER_MessageHandler handlers[] = { 131static struct GNUNET_SERVER_MessageHandler handlers[] = {
143 {&recv_cb, NULL, MY_TYPE, sizeof (struct GNUNET_MessageHeader)}, 132 {&recv_cb, NULL, MY_TYPE, sizeof (struct GNUNET_MessageHeader)},
144 {NULL, NULL, 0, 0} 133 {NULL, NULL, 0, 0}
@@ -151,6 +140,8 @@ task (void *cls)
151 struct sockaddr_in sa; 140 struct sockaddr_in sa;
152 struct sockaddr *sap[2]; 141 struct sockaddr *sap[2];
153 socklen_t slens[2]; 142 socklen_t slens[2];
143 struct GNUNET_MQ_Envelope *env;
144 struct GNUNET_MessageHeader *msg;
154 145
155 sap[0] = (struct sockaddr *) &sa; 146 sap[0] = (struct sockaddr *) &sa;
156 slens[0] = sizeof (sa); 147 slens[0] = sizeof (sa);
@@ -175,12 +166,21 @@ task (void *cls)
175 GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost"); 166 GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost");
176 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 167 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
177 "localhost"); 168 "localhost");
178 client = GNUNET_CLIENT_connect ("test", cfg); 169 mq = GNUNET_CLIENT_connecT (cfg,
179 GNUNET_assert (client != NULL); 170 "test",
180 GNUNET_CLIENT_notify_transmit_ready (client, 256, 171 NULL,
181 GNUNET_TIME_relative_multiply 172 NULL,
182 (GNUNET_TIME_UNIT_MILLISECONDS, 250), 173 NULL);
183 GNUNET_NO, &notify_ready, NULL); 174 GNUNET_assert (NULL != mq);
175 ok = 2;
176 env = GNUNET_MQ_msg (msg,
177 MY_TYPE);
178 GNUNET_MQ_send (mq,
179 env);
180 env = GNUNET_MQ_msg (msg,
181 MY_TYPE);
182 GNUNET_MQ_send (mq,
183 env);
184} 184}
185 185
186 186
diff --git a/src/util/test_server_with_client_unix.c b/src/util/test_server_with_client_unix.c
index 64f1d9c23..ef48aabce 100644
--- a/src/util/test_server_with_client_unix.c
+++ b/src/util/test_server_with_client_unix.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -31,7 +31,7 @@
31 31
32static struct GNUNET_SERVER_Handle *server; 32static struct GNUNET_SERVER_Handle *server;
33 33
34static struct GNUNET_CLIENT_Connection *client; 34static struct GNUNET_MQ_Handle *mq;
35 35
36static struct GNUNET_CONFIGURATION_Handle *cfg; 36static struct GNUNET_CONFIGURATION_Handle *cfg;
37 37
@@ -65,7 +65,7 @@ recv_cb (void *cls,
65 break; 65 break;
66 case 4: 66 case 4:
67 ok++; 67 ok++;
68 GNUNET_CLIENT_disconnect (client); 68 GNUNET_MQ_destroy (mq);
69 GNUNET_SERVER_receive_done (argclient, GNUNET_OK); 69 GNUNET_SERVER_receive_done (argclient, GNUNET_OK);
70 break; 70 break;
71 default: 71 default:
@@ -104,24 +104,6 @@ notify_disconnect (void *cls,
104} 104}
105 105
106 106
107static size_t
108notify_ready (void *cls, size_t size, void *buf)
109{
110 struct GNUNET_MessageHeader *msg;
111
112 GNUNET_assert (size >= 256);
113 GNUNET_assert (1 == ok);
114 ok++;
115 msg = buf;
116 msg->type = htons (MY_TYPE);
117 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
118 msg++;
119 msg->type = htons (MY_TYPE);
120 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
121 return 2 * sizeof (struct GNUNET_MessageHeader);
122}
123
124
125static struct GNUNET_SERVER_MessageHandler handlers[] = { 107static struct GNUNET_SERVER_MessageHandler handlers[] = {
126 {&recv_cb, NULL, MY_TYPE, sizeof (struct GNUNET_MessageHeader)}, 108 {&recv_cb, NULL, MY_TYPE, sizeof (struct GNUNET_MessageHeader)},
127 {NULL, NULL, 0, 0} 109 {NULL, NULL, 0, 0}
@@ -135,6 +117,8 @@ task (void *cls)
135 const char *unixpath = "/tmp/testsock"; 117 const char *unixpath = "/tmp/testsock";
136 struct sockaddr *sap[2]; 118 struct sockaddr *sap[2];
137 socklen_t slens[2]; 119 socklen_t slens[2];
120 struct GNUNET_MQ_Envelope *env;
121 struct GNUNET_MessageHeader *msg;
138 122
139 memset (&un, 0, sizeof (un)); 123 memset (&un, 0, sizeof (un));
140 un.sun_family = AF_UNIX; 124 un.sun_family = AF_UNIX;
@@ -160,13 +144,21 @@ task (void *cls)
160 GNUNET_CONFIGURATION_set_value_string (cfg, "test", "UNIXPATH", unixpath); 144 GNUNET_CONFIGURATION_set_value_string (cfg, "test", "UNIXPATH", unixpath);
161 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 145 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
162 "localhost"); 146 "localhost");
163 147 mq = GNUNET_CLIENT_connecT (cfg,
164 client = GNUNET_CLIENT_connect ("test", cfg); 148 "test",
165 GNUNET_assert (client != NULL); 149 NULL,
166 GNUNET_CLIENT_notify_transmit_ready (client, 256, 150 NULL,
167 GNUNET_TIME_relative_multiply 151 NULL);
168 (GNUNET_TIME_UNIT_MILLISECONDS, 250), 152 GNUNET_assert (NULL != mq);
169 GNUNET_NO, &notify_ready, NULL); 153 ok = 2;
154 env = GNUNET_MQ_msg (msg,
155 MY_TYPE);
156 GNUNET_MQ_send (mq,
157 env);
158 env = GNUNET_MQ_msg (msg,
159 MY_TYPE);
160 GNUNET_MQ_send (mq,
161 env);
170} 162}
171 163
172 164