aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_scheduling.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-09-21 10:56:28 +0000
committerChristian Grothoff <christian@grothoff.org>2016-09-21 10:56:28 +0000
commitd4afc6e37a14fe3257263c377a243c1a22ed9ee5 (patch)
treeccfce6d4f92808372d3e7ebfe9f5372e9f21f50c /src/ats/gnunet-service-ats_scheduling.c
parent60d02b5b0899f454cb65408bd2ed4c453fa75a3d (diff)
downloadgnunet-d4afc6e37a14fe3257263c377a243c1a22ed9ee5.tar.gz
gnunet-d4afc6e37a14fe3257263c377a243c1a22ed9ee5.zip
migrating more services to new service API
Diffstat (limited to 'src/ats/gnunet-service-ats_scheduling.c')
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c136
1 files changed, 28 insertions, 108 deletions
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index f19370f7a..fd7eff8fb 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011-2014 GNUnet e.V. 3 Copyright (C) 2011-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
@@ -29,16 +29,10 @@
29#include "gnunet-service-ats_scheduling.h" 29#include "gnunet-service-ats_scheduling.h"
30#include "ats.h" 30#include "ats.h"
31 31
32
33/**
34 * Context for sending messages to clients.
35 */
36static struct GNUNET_SERVER_NotificationContext *nc;
37
38/** 32/**
39 * Actual handle to the client. 33 * Actual handle to the client.
40 */ 34 */
41static struct GNUNET_SERVER_Client *my_client; 35static struct GNUNET_SERVICE_Client *my_client;
42 36
43 37
44/** 38/**
@@ -48,7 +42,7 @@ static struct GNUNET_SERVER_Client *my_client;
48 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 42 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
49 */ 43 */
50int 44int
51GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client) 45GAS_scheduling_add_client (struct GNUNET_SERVICE_Client *client)
52{ 46{
53 if (NULL != my_client) 47 if (NULL != my_client)
54 { 48 {
@@ -57,10 +51,6 @@ GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client)
57 return GNUNET_SYSERR; 51 return GNUNET_SYSERR;
58 } 52 }
59 my_client = client; 53 my_client = client;
60 GNUNET_SERVER_notification_context_add (nc,
61 client);
62 GNUNET_SERVER_client_set_user_context (client,
63 &nc);
64 return GNUNET_OK; 54 return GNUNET_OK;
65} 55}
66 56
@@ -72,7 +62,7 @@ GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client)
72 * @param client handle of the (now dead) client 62 * @param client handle of the (now dead) client
73 */ 63 */
74void 64void
75GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client) 65GAS_scheduling_remove_client (struct GNUNET_SERVICE_Client *client)
76{ 66{
77 if (my_client != client) 67 if (my_client != client)
78 return; 68 return;
@@ -96,7 +86,8 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe
96 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 86 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
97 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 87 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
98{ 88{
99 struct AddressSuggestionMessage msg; 89 struct GNUNET_MQ_Envelope *env;
90 struct AddressSuggestionMessage *msg;
100 91
101 if (NULL == my_client) 92 if (NULL == my_client)
102 return; 93 return;
@@ -104,55 +95,39 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe
104 "# address suggestions made", 95 "# address suggestions made",
105 1, 96 1,
106 GNUNET_NO); 97 GNUNET_NO);
107 msg.header.size = htons (sizeof (struct AddressSuggestionMessage)); 98 env = GNUNET_MQ_msg (msg,
108 msg.header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); 99 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
109 msg.peer = *peer; 100 msg->peer = *peer;
110 msg.session_id = htonl (session_id); 101 msg->session_id = htonl (session_id);
111 msg.bandwidth_out = bandwidth_out; 102 msg->bandwidth_out = bandwidth_out;
112 msg.bandwidth_in = bandwidth_in; 103 msg->bandwidth_in = bandwidth_in;
113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
114 "ATS sends quota for peer `%s': (in/out) %u/%u\n", 105 "ATS sends quota for peer `%s': (in/out) %u/%u\n",
115 GNUNET_i2s (peer), 106 GNUNET_i2s (peer),
116 (unsigned int) ntohl (bandwidth_in.value__), 107 (unsigned int) ntohl (bandwidth_in.value__),
117 (unsigned int) ntohl (bandwidth_out.value__)); 108 (unsigned int) ntohl (bandwidth_out.value__));
118 GNUNET_SERVER_notification_context_unicast (nc, 109 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client),
119 my_client, 110 env);
120 &msg.header,
121 GNUNET_YES);
122} 111}
123 112
124 113
125/** 114/**
126 * Handle 'address add' messages from clients. 115 * Handle 'address add' messages from clients.
127 * 116 *
128 * @param cls unused, NULL 117 * @param m the request message
129 * @param client client that sent the request
130 * @param message the request message
131 */ 118 */
132void 119void
133GAS_handle_address_add (void *cls, 120GAS_handle_address_add (const struct AddressAddMessage *m)
134 struct GNUNET_SERVER_Client *client,
135 const struct GNUNET_MessageHeader *message)
136{ 121{
137 const struct AddressAddMessage *m;
138 const char *address; 122 const char *address;
139 const char *plugin_name; 123 const char *plugin_name;
140 uint16_t address_length; 124 uint16_t address_length;
141 uint16_t plugin_name_length; 125 uint16_t plugin_name_length;
142 uint16_t size;
143 struct GNUNET_ATS_Properties prop; 126 struct GNUNET_ATS_Properties prop;
144 127
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
146 "Received `%s' message\n", 129 "Received `%s' message\n",
147 "ADDRESS_ADD"); 130 "ADDRESS_ADD");
148 size = ntohs (message->size);
149 if (size < sizeof (struct AddressAddMessage))
150 {
151 GNUNET_break (0);
152 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
153 return;
154 }
155 m = (const struct AddressAddMessage *) message;
156 address_length = ntohs (m->address_length); 131 address_length = ntohs (m->address_length);
157 plugin_name_length = ntohs (m->plugin_name_length); 132 plugin_name_length = ntohs (m->plugin_name_length);
158 address = (const char *) &m[1]; 133 address = (const char *) &m[1];
@@ -160,16 +135,6 @@ GAS_handle_address_add (void *cls,
160 plugin_name = &address[address_length]; 135 plugin_name = &address[address_length];
161 else 136 else
162 plugin_name = ""; 137 plugin_name = "";
163
164 if ((address_length + plugin_name_length +
165 sizeof (struct AddressAddMessage) != ntohs (message->size)) ||
166 ( (plugin_name_length > 0) &&
167 (plugin_name[plugin_name_length - 1] != '\0') ) )
168 {
169 GNUNET_break (0);
170 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
171 return;
172 }
173 GNUNET_STATISTICS_update (GSA_stats, 138 GNUNET_STATISTICS_update (GSA_stats,
174 "# addresses created", 139 "# addresses created",
175 1, 140 1,
@@ -184,27 +149,19 @@ GAS_handle_address_add (void *cls,
184 ntohl (m->address_local_info), 149 ntohl (m->address_local_info),
185 ntohl (m->session_id), 150 ntohl (m->session_id),
186 &prop); 151 &prop);
187 GNUNET_SERVER_receive_done (client,
188 GNUNET_OK);
189} 152}
190 153
191 154
192/** 155/**
193 * Handle 'address update' messages from clients. 156 * Handle 'address update' messages from clients.
194 * 157 *
195 * @param cls unused, NULL 158 * @param m the request message
196 * @param client client that sent the request
197 * @param message the request message
198 */ 159 */
199void 160void
200GAS_handle_address_update (void *cls, 161GAS_handle_address_update (const struct AddressUpdateMessage *m)
201 struct GNUNET_SERVER_Client *client,
202 const struct GNUNET_MessageHeader *message)
203{ 162{
204 const struct AddressUpdateMessage *m;
205 struct GNUNET_ATS_Properties prop; 163 struct GNUNET_ATS_Properties prop;
206 164
207 m = (const struct AddressUpdateMessage *) message;
208 GNUNET_STATISTICS_update (GSA_stats, 165 GNUNET_STATISTICS_update (GSA_stats,
209 "# address updates received", 166 "# address updates received",
210 1, 167 1,
@@ -214,27 +171,20 @@ GAS_handle_address_update (void *cls,
214 GAS_addresses_update (&m->peer, 171 GAS_addresses_update (&m->peer,
215 ntohl (m->session_id), 172 ntohl (m->session_id),
216 &prop); 173 &prop);
217 GNUNET_SERVER_receive_done (client,
218 GNUNET_OK);
219} 174}
220 175
221 176
222/** 177/**
223 * Handle 'address destroyed' messages from clients. 178 * Handle 'address destroyed' messages from clients.
224 * 179 *
225 * @param cls unused, NULL 180 * @param m the request message
226 * @param client client that sent the request
227 * @param message the request message
228 */ 181 */
229void 182void
230GAS_handle_address_destroyed (void *cls, 183GAS_handle_address_destroyed (const struct AddressDestroyedMessage *m)
231 struct GNUNET_SERVER_Client *client,
232 const struct GNUNET_MessageHeader *message)
233{ 184{
234 const struct AddressDestroyedMessage *m; 185 struct GNUNET_MQ_Envelope *env;
235 struct GNUNET_ATS_SessionReleaseMessage srm; 186 struct GNUNET_ATS_SessionReleaseMessage *srm;
236 187
237 m = (const struct AddressDestroyedMessage *) message;
238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
239 "Received `%s' message\n", 189 "Received `%s' message\n",
240 "ADDRESS_DESTROYED"); 190 "ADDRESS_DESTROYED");
@@ -244,42 +194,12 @@ GAS_handle_address_destroyed (void *cls,
244 GNUNET_NO); 194 GNUNET_NO);
245 GAS_addresses_destroy (&m->peer, 195 GAS_addresses_destroy (&m->peer,
246 ntohl (m->session_id)); 196 ntohl (m->session_id));
247 srm.header.type = ntohs (GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE); 197 env = GNUNET_MQ_msg (srm,
248 srm.header.size = ntohs (sizeof (struct GNUNET_ATS_SessionReleaseMessage)); 198 GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE);
249 srm.session_id = m->session_id; 199 srm->session_id = m->session_id;
250 srm.peer = m->peer; 200 srm->peer = m->peer;
251 GNUNET_SERVER_notification_context_unicast (nc, 201 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client),
252 client, 202 env);
253 &srm.header,
254 GNUNET_NO);
255 GNUNET_SERVER_receive_done (client, GNUNET_OK);
256}
257
258
259/**
260 * Initialize scheduling subsystem.
261 *
262 * @param server handle to our server
263 */
264void
265GAS_scheduling_init (struct GNUNET_SERVER_Handle *server)
266{
267 nc = GNUNET_SERVER_notification_context_create (server, 128);
268}
269
270
271/**
272 * Shutdown scheduling subsystem.
273 */
274void
275GAS_scheduling_done ()
276{
277 if (NULL != my_client)
278 {
279 my_client = NULL;
280 }
281 GNUNET_SERVER_notification_context_destroy (nc);
282 nc = NULL;
283} 203}
284 204
285 205