aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-05 15:45:30 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-05 15:45:30 +0000
commit5d063af93ad3de2223ff3078acac13761ab308fb (patch)
tree81e3ad2c50f045a330117a5eb20f919f877273ec /src
parent4708a37d9085048e728d4e3ebc3c1a3c34703f89 (diff)
downloadgnunet-5d063af93ad3de2223ff3078acac13761ab308fb.tar.gz
gnunet-5d063af93ad3de2223ff3078acac13761ab308fb.zip
-cleaning up gnunet-service-ats_connectivity-*
Diffstat (limited to 'src')
-rw-r--r--src/ats/gnunet-service-ats.c4
-rw-r--r--src/ats/gnunet-service-ats_connectivity.c216
-rw-r--r--src/ats/gnunet-service-ats_connectivity.h28
3 files changed, 105 insertions, 143 deletions
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c
index d54d09a33..b000ae99c 100644
--- a/src/ats/gnunet-service-ats.c
+++ b/src/ats/gnunet-service-ats.c
@@ -189,6 +189,7 @@ run (void *cls,
189 GSA_server = server; 189 GSA_server = server;
190 GSA_stats = GNUNET_STATISTICS_create ("ats", cfg); 190 GSA_stats = GNUNET_STATISTICS_create ("ats", cfg);
191 GAS_reservations_init (); 191 GAS_reservations_init ();
192 GAS_connectivity_init ();
192 GAS_normalization_start (); 193 GAS_normalization_start ();
193 GAS_addresses_init (); 194 GAS_addresses_init ();
194 if (GNUNET_OK != 195 if (GNUNET_OK !=
@@ -198,6 +199,7 @@ run (void *cls,
198 GAS_addresses_done (); 199 GAS_addresses_done ();
199 GAS_normalization_stop (); 200 GAS_normalization_stop ();
200 GAS_reservations_done (); 201 GAS_reservations_done ();
202 GAS_connectivity_done ();
201 if (NULL != GSA_stats) 203 if (NULL != GSA_stats)
202 { 204 {
203 GNUNET_STATISTICS_destroy (GSA_stats, GNUNET_NO); 205 GNUNET_STATISTICS_destroy (GSA_stats, GNUNET_NO);
@@ -209,7 +211,7 @@ run (void *cls,
209 GAS_scheduling_init (server); 211 GAS_scheduling_init (server);
210 212
211 GNUNET_SERVER_disconnect_notify (server, 213 GNUNET_SERVER_disconnect_notify (server,
212 &client_disconnect_handler, 214 &client_disconnect_handler,
213 NULL); 215 NULL);
214 GNUNET_SERVER_add_handlers (server, handlers); 216 GNUNET_SERVER_add_handlers (server, handlers);
215 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 217 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
diff --git a/src/ats/gnunet-service-ats_connectivity.c b/src/ats/gnunet-service-ats_connectivity.c
index 4aee2ddb8..56d7abbeb 100644
--- a/src/ats/gnunet-service-ats_connectivity.c
+++ b/src/ats/gnunet-service-ats_connectivity.c
@@ -23,12 +23,6 @@
23 * @brief ats service, interaction with 'connecivity' API 23 * @brief ats service, interaction with 'connecivity' API
24 * @author Matthias Wachs 24 * @author Matthias Wachs
25 * @author Christian Grothoff 25 * @author Christian Grothoff
26 *
27 * FIXME:
28 * - we should track requests by client, and if a client
29 * disconnects cancel all associated requests; right
30 * now, they will persist forever unless the client
31 * explicitly sends us a cancel before disconnecting!
32 */ 26 */
33#include "platform.h" 27#include "platform.h"
34#include "gnunet-service-ats.h" 28#include "gnunet-service-ats.h"
@@ -39,117 +33,21 @@
39 33
40 34
41/** 35/**
42 * Pending Address suggestion requests 36 * Active connection requests.
43 */ 37 */
44struct GAS_Addresses_Suggestion_Requests 38struct ConnectionRequest
45{ 39{
46 /** 40 /**
47 * Next in DLL 41 * Client that made the request.
48 */
49 struct GAS_Addresses_Suggestion_Requests *next;
50
51 /**
52 * Previous in DLL
53 */
54 struct GAS_Addresses_Suggestion_Requests *prev;
55
56 /**
57 * Peer ID
58 */ 42 */
59 struct GNUNET_PeerIdentity id; 43 struct GNUNET_SERVER_Client *client;
60}; 44};
61 45
62 46
63/** 47/**
64 * Address suggestion requests DLL head. 48 * Address suggestion requests by peer.
65 * FIXME: This must become a Multipeermap! O(n) operations
66 * galore instead of O(1)!!!
67 */
68static struct GAS_Addresses_Suggestion_Requests *pending_requests_head;
69
70/**
71 * Address suggestion requests DLL tail
72 */
73static struct GAS_Addresses_Suggestion_Requests *pending_requests_tail;
74
75
76
77
78/**
79 * Cancel address suggestions for a peer
80 *
81 * @param peer the peer id
82 */ 49 */
83void 50static struct GNUNET_CONTAINER_MultiPeerMap *connection_requests;
84GAS_addresses_request_address_cancel (const struct GNUNET_PeerIdentity *peer)
85{
86 struct GAS_Addresses_Suggestion_Requests *cur = pending_requests_head;
87
88 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
89 "Received request: `%s' for peer %s\n",
90 "request_address_cancel",
91 GNUNET_i2s (peer));
92
93 while (NULL != cur)
94 {
95 if (0 == memcmp (peer, &cur->id, sizeof(cur->id)))
96 break; /* found */
97 cur = cur->next;
98 }
99
100 if (NULL == cur)
101 {
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
103 "No address requests pending for peer `%s', cannot remove!\n",
104 GNUNET_i2s (peer));
105 return;
106 }
107 GAS_plugin_request_connect_stop (peer);
108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
109 "Removed request pending for peer `%s\n",
110 GNUNET_i2s (peer));
111 GNUNET_CONTAINER_DLL_remove (pending_requests_head,
112 pending_requests_tail,
113 cur);
114 GNUNET_free (cur);
115}
116
117
118/**
119 * Request address suggestions for a peer
120 *
121 * @param peer the peer id
122 */
123void
124GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer)
125{
126 struct GAS_Addresses_Suggestion_Requests *cur = pending_requests_head;
127
128 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
129 "Received `%s' for peer `%s'\n",
130 "REQUEST ADDRESS",
131 GNUNET_i2s (peer));
132
133 while (NULL != cur)
134 {
135 if (0 == memcmp (peer, &cur->id, sizeof(cur->id)))
136 break; /* already suggesting */
137 cur = cur->next;
138 }
139 if (NULL == cur)
140 {
141 cur = GNUNET_new (struct GAS_Addresses_Suggestion_Requests);
142 cur->id = *peer;
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
144 "Adding new address suggestion request for `%s'\n",
145 GNUNET_i2s (peer));
146 GNUNET_CONTAINER_DLL_insert (pending_requests_head,
147 pending_requests_tail,
148 cur);
149 }
150 GAS_plugin_request_connect_start (peer);
151}
152
153 51
154 52
155/** 53/**
@@ -166,18 +64,58 @@ GAS_handle_request_address (void *cls,
166{ 64{
167 const struct RequestAddressMessage *msg = 65 const struct RequestAddressMessage *msg =
168 (const struct RequestAddressMessage *) message; 66 (const struct RequestAddressMessage *) message;
67 struct ConnectionRequest *cr;
169 68
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
171 "Received `%s' message\n", 70 "Received `%s' message\n",
172 "REQUEST_ADDRESS"); 71 "REQUEST_ADDRESS");
173 GNUNET_break (0 == ntohl (msg->reserved)); 72 GNUNET_break (0 == ntohl (msg->reserved));
174 GAS_addresses_request_address (&msg->peer); 73 cr = GNUNET_new (struct ConnectionRequest);
74 cr->client = client;
75 (void) GNUNET_CONTAINER_multipeermap_put (connection_requests,
76 &msg->peer,
77 cr,
78 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
79 GAS_plugin_request_connect_start (&msg->peer);
175 GNUNET_SERVER_receive_done (client, GNUNET_OK); 80 GNUNET_SERVER_receive_done (client, GNUNET_OK);
176} 81}
177 82
178 83
179/** 84/**
180 * Handle 'request address' messages from clients. 85 * Free the connection request from the map if the
86 * closure matches the client.
87 *
88 * @param cls the client to match
89 * @param pid peer for which the request was made
90 * @param value the `struct ConnectionRequest`
91 * @return #GNUNET_OK (continue to iterate)
92 */
93static int
94free_matching_requests (void *cls,
95 const struct GNUNET_PeerIdentity *pid,
96 void *value)
97{
98 struct GNUNET_SERVER_Client *client = cls;
99 struct ConnectionRequest *cr = value;
100
101 if (cr->client == client)
102 {
103 GAS_plugin_request_connect_stop (pid);
104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
105 "Removed request pending for peer `%s\n",
106 GNUNET_i2s (pid));
107 GNUNET_assert (GNUNET_YES ==
108 GNUNET_CONTAINER_multipeermap_remove (connection_requests,
109 pid,
110 cr));
111 GNUNET_free (cr);
112 }
113 return GNUNET_OK;
114}
115
116
117/**
118 * Handle 'request address cancel' messages from clients.
181 * 119 *
182 * @param cls unused, NULL 120 * @param cls unused, NULL
183 * @param client client that sent the request 121 * @param client client that sent the request
@@ -192,10 +130,13 @@ GAS_handle_request_address_cancel (void *cls,
192 (const struct RequestAddressMessage *) message; 130 (const struct RequestAddressMessage *) message;
193 131
194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
195 "Received `%s' message\n", 133 "Received REQUEST_ADDRESS_CANCEL message for peer %s\n",
196 "REQUEST_ADDRESS_CANCEL"); 134 GNUNET_i2s (&msg->peer));
197 GNUNET_break (0 == ntohl (msg->reserved)); 135 GNUNET_break (0 == ntohl (msg->reserved));
198 GAS_addresses_request_address_cancel (&msg->peer); 136 GNUNET_CONTAINER_multipeermap_get_multiple (connection_requests,
137 &msg->peer,
138 &free_matching_requests,
139 client);
199 GNUNET_SERVER_receive_done (client, GNUNET_OK); 140 GNUNET_SERVER_receive_done (client, GNUNET_OK);
200} 141}
201 142
@@ -209,7 +150,9 @@ GAS_handle_request_address_cancel (void *cls,
209void 150void
210GAS_connectivity_remove_client (struct GNUNET_SERVER_Client *client) 151GAS_connectivity_remove_client (struct GNUNET_SERVER_Client *client)
211{ 152{
212 // FIXME 153 GNUNET_CONTAINER_multipeermap_iterate (connection_requests,
154 &free_matching_requests,
155 client);
213} 156}
214 157
215 158
@@ -217,17 +160,44 @@ GAS_connectivity_remove_client (struct GNUNET_SERVER_Client *client)
217 * Shutdown connectivity subsystem. 160 * Shutdown connectivity subsystem.
218 */ 161 */
219void 162void
220GAS_connectivity_done () 163GAS_connectivity_init ()
221{ 164{
222 struct GAS_Addresses_Suggestion_Requests *cur; 165 connection_requests = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_NO);
166}
223 167
224 while (NULL != (cur = pending_requests_head)) 168
225 { 169/**
226 GNUNET_CONTAINER_DLL_remove (pending_requests_head, 170 * Free the connection request from the map.
227 pending_requests_tail, 171 *
228 cur); 172 * @param cls NULL
229 GNUNET_free(cur); 173 * @param pid peer for which the request was made
230 } 174 * @param value the `struct ConnectionRequest`
175 * @return #GNUNET_OK (continue to iterate)
176 */
177static int
178free_request (void *cls,
179 const struct GNUNET_PeerIdentity *pid,
180 void *value)
181{
182 struct ConnectionRequest *cr = value;
183
184 free_matching_requests (cr->client,
185 pid,
186 cr);
187 return GNUNET_OK;
188}
189
190
191/**
192 * Shutdown connectivity subsystem.
193 */
194void
195GAS_connectivity_done ()
196{
197 GNUNET_CONTAINER_multipeermap_iterate (connection_requests,
198 &free_request,
199 NULL);
200 GNUNET_CONTAINER_multipeermap_destroy (connection_requests);
231} 201}
232 202
233 203
diff --git a/src/ats/gnunet-service-ats_connectivity.h b/src/ats/gnunet-service-ats_connectivity.h
index faa00ac40..61c1d0ce5 100644
--- a/src/ats/gnunet-service-ats_connectivity.h
+++ b/src/ats/gnunet-service-ats_connectivity.h
@@ -17,34 +17,17 @@
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20
21/** 20/**
22 * @file ats/gnunet-service-ats_connectivity.h 21 * @file ats/gnunet-service-ats_connectivity.h
23 * @brief ats service, interaction with 'connecivity' API 22 * @brief ats service, interaction with 'connecivity' API
24 * @author Matthias Wachs 23 * @author Matthias Wachs
25 * @author Christian Grothoff 24 * @author Christian Grothoff
25 *
26 * TODO: will need API to query connectivity requests!
26 */ 27 */
27#ifndef GNUNET_SERVICE_ATS_CONNECTIVITY_H 28#ifndef GNUNET_SERVICE_ATS_CONNECTIVITY_H
28#define GNUNET_SERVICE_ATS_CONNECTIVITY_H 29#define GNUNET_SERVICE_ATS_CONNECTIVITY_H
29 30
30/**
31 * Request address suggestions for a peer
32 *
33 * @param peer the peer id
34 */
35void
36GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer);
37
38
39/**
40 * Cancel address suggestions for a peer
41 *
42 * @param peer the peer id
43 */
44void
45GAS_addresses_request_address_cancel (const struct GNUNET_PeerIdentity *peer);
46
47
48 31
49/** 32/**
50 * Handle 'request address' messages from clients. 33 * Handle 'request address' messages from clients.
@@ -83,6 +66,13 @@ GAS_connectivity_remove_client (struct GNUNET_SERVER_Client *client);
83 66
84 67
85/** 68/**
69 * Initialize connectivity subsystem.
70 */
71void
72GAS_connectivity_init (void);
73
74
75/**
86 * Shutdown connectivity subsystem. 76 * Shutdown connectivity subsystem.
87 */ 77 */
88void 78void