summaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_connectivity.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/gnunet-service-ats_connectivity.c')
-rw-r--r--src/ats/gnunet-service-ats_connectivity.c117
1 files changed, 59 insertions, 58 deletions
diff --git a/src/ats/gnunet-service-ats_connectivity.c b/src/ats/gnunet-service-ats_connectivity.c
index f71d18e82..05046f007 100644
--- a/src/ats/gnunet-service-ats_connectivity.c
+++ b/src/ats/gnunet-service-ats_connectivity.c
@@ -35,7 +35,8 @@
35/** 35/**
36 * Active connection requests. 36 * Active connection requests.
37 */ 37 */
38struct ConnectionRequest { 38struct ConnectionRequest
39{
39 /** 40 /**
40 * Client that made the request. 41 * Client that made the request.
41 */ 42 */
@@ -60,14 +61,14 @@ static struct GNUNET_CONTAINER_MultiPeerMap *connection_requests;
60 * @return #GNUNET_YES if so, #GNUNET_NO if not 61 * @return #GNUNET_YES if so, #GNUNET_NO if not
61 */ 62 */
62unsigned int 63unsigned int
63GAS_connectivity_has_peer(void *cls, 64GAS_connectivity_has_peer (void *cls,
64 const struct GNUNET_PeerIdentity *peer) 65 const struct GNUNET_PeerIdentity *peer)
65{ 66{
66 if (NULL == connection_requests) 67 if (NULL == connection_requests)
67 return 0; 68 return 0;
68 /* TODO: return sum of 'strength's of connectivity requests */ 69 /* TODO: return sum of 'strength's of connectivity requests */
69 return GNUNET_CONTAINER_multipeermap_contains(connection_requests, 70 return GNUNET_CONTAINER_multipeermap_contains (connection_requests,
70 peer); 71 peer);
71} 72}
72 73
73 74
@@ -78,22 +79,22 @@ GAS_connectivity_has_peer(void *cls,
78 * @param message the request message 79 * @param message the request message
79 */ 80 */
80void 81void
81GAS_handle_request_address(struct GNUNET_SERVICE_Client *client, 82GAS_handle_request_address (struct GNUNET_SERVICE_Client *client,
82 const struct RequestAddressMessage *msg) 83 const struct RequestAddressMessage *msg)
83{ 84{
84 struct ConnectionRequest *cr; 85 struct ConnectionRequest *cr;
85 86
86 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 87 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
87 "Received `%s' message\n", 88 "Received `%s' message\n",
88 "GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS"); 89 "GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS");
89 /* FIXME: should not ignore "msg->strength" */ 90 /* FIXME: should not ignore "msg->strength" */
90 cr = GNUNET_new(struct ConnectionRequest); 91 cr = GNUNET_new (struct ConnectionRequest);
91 cr->client = client; 92 cr->client = client;
92 (void)GNUNET_CONTAINER_multipeermap_put(connection_requests, 93 (void) GNUNET_CONTAINER_multipeermap_put (connection_requests,
93 &msg->peer, 94 &msg->peer,
94 cr, 95 cr,
95 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 96 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
96 GAS_plugin_request_connect_start(&msg->peer); 97 GAS_plugin_request_connect_start (&msg->peer);
97} 98}
98 99
99 100
@@ -107,25 +108,25 @@ GAS_handle_request_address(struct GNUNET_SERVICE_Client *client,
107 * @return #GNUNET_OK (continue to iterate) 108 * @return #GNUNET_OK (continue to iterate)
108 */ 109 */
109static int 110static int
110free_matching_requests(void *cls, 111free_matching_requests (void *cls,
111 const struct GNUNET_PeerIdentity *pid, 112 const struct GNUNET_PeerIdentity *pid,
112 void *value) 113 void *value)
113{ 114{
114 struct GNUNET_SERVICE_Client *client = cls; 115 struct GNUNET_SERVICE_Client *client = cls;
115 struct ConnectionRequest *cr = value; 116 struct ConnectionRequest *cr = value;
116 117
117 if (cr->client == client) 118 if (cr->client == client)
118 { 119 {
119 GAS_plugin_request_connect_stop(pid); 120 GAS_plugin_request_connect_stop (pid);
120 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
121 "Removed request pending for peer `%s\n", 122 "Removed request pending for peer `%s\n",
122 GNUNET_i2s(pid)); 123 GNUNET_i2s (pid));
123 GNUNET_assert(GNUNET_YES == 124 GNUNET_assert (GNUNET_YES ==
124 GNUNET_CONTAINER_multipeermap_remove(connection_requests, 125 GNUNET_CONTAINER_multipeermap_remove (connection_requests,
125 pid, 126 pid,
126 cr)); 127 cr));
127 GNUNET_free(cr); 128 GNUNET_free (cr);
128 } 129 }
129 return GNUNET_OK; 130 return GNUNET_OK;
130} 131}
131 132
@@ -138,17 +139,17 @@ free_matching_requests(void *cls,
138 * @param msg the request message 139 * @param msg the request message
139 */ 140 */
140void 141void
141GAS_handle_request_address_cancel(struct GNUNET_SERVICE_Client *client, 142GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client,
142 const struct RequestAddressMessage *msg) 143 const struct RequestAddressMessage *msg)
143{ 144{
144 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "Received GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL message for peer %s\n", 146 "Received GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL message for peer %s\n",
146 GNUNET_i2s(&msg->peer)); 147 GNUNET_i2s (&msg->peer));
147 GNUNET_break(0 == ntohl(msg->strength)); 148 GNUNET_break (0 == ntohl (msg->strength));
148 GNUNET_CONTAINER_multipeermap_get_multiple(connection_requests, 149 GNUNET_CONTAINER_multipeermap_get_multiple (connection_requests,
149 &msg->peer, 150 &msg->peer,
150 &free_matching_requests, 151 &free_matching_requests,
151 client); 152 client);
152} 153}
153 154
154 155
@@ -159,11 +160,11 @@ GAS_handle_request_address_cancel(struct GNUNET_SERVICE_Client *client,
159 * @param client handle of the (now dead) client 160 * @param client handle of the (now dead) client
160 */ 161 */
161void 162void
162GAS_connectivity_remove_client(struct GNUNET_SERVICE_Client *client) 163GAS_connectivity_remove_client (struct GNUNET_SERVICE_Client *client)
163{ 164{
164 GNUNET_CONTAINER_multipeermap_iterate(connection_requests, 165 GNUNET_CONTAINER_multipeermap_iterate (connection_requests,
165 &free_matching_requests, 166 &free_matching_requests,
166 client); 167 client);
167} 168}
168 169
169 170
@@ -171,11 +172,11 @@ GAS_connectivity_remove_client(struct GNUNET_SERVICE_Client *client)
171 * Shutdown connectivity subsystem. 172 * Shutdown connectivity subsystem.
172 */ 173 */
173void 174void
174GAS_connectivity_init() 175GAS_connectivity_init ()
175{ 176{
176 connection_requests 177 connection_requests
177 = GNUNET_CONTAINER_multipeermap_create(32, 178 = GNUNET_CONTAINER_multipeermap_create (32,
178 GNUNET_NO); 179 GNUNET_NO);
179} 180}
180 181
181 182
@@ -188,15 +189,15 @@ GAS_connectivity_init()
188 * @return #GNUNET_OK (continue to iterate) 189 * @return #GNUNET_OK (continue to iterate)
189 */ 190 */
190static int 191static int
191free_request(void *cls, 192free_request (void *cls,
192 const struct GNUNET_PeerIdentity *pid, 193 const struct GNUNET_PeerIdentity *pid,
193 void *value) 194 void *value)
194{ 195{
195 struct ConnectionRequest *cr = value; 196 struct ConnectionRequest *cr = value;
196 197
197 free_matching_requests(cr->client, 198 free_matching_requests (cr->client,
198 pid, 199 pid,
199 cr); 200 cr);
200 return GNUNET_OK; 201 return GNUNET_OK;
201} 202}
202 203
@@ -205,14 +206,14 @@ free_request(void *cls,
205 * Shutdown connectivity subsystem. 206 * Shutdown connectivity subsystem.
206 */ 207 */
207void 208void
208GAS_connectivity_done() 209GAS_connectivity_done ()
209{ 210{
210 GAS_plugin_solver_lock(); 211 GAS_plugin_solver_lock ();
211 GNUNET_CONTAINER_multipeermap_iterate(connection_requests, 212 GNUNET_CONTAINER_multipeermap_iterate (connection_requests,
212 &free_request, 213 &free_request,
213 NULL); 214 NULL);
214 GAS_plugin_solver_unlock(); 215 GAS_plugin_solver_unlock ();
215 GNUNET_CONTAINER_multipeermap_destroy(connection_requests); 216 GNUNET_CONTAINER_multipeermap_destroy (connection_requests);
216 connection_requests = NULL; 217 connection_requests = NULL;
217} 218}
218 219