diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-01-15 10:07:44 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-01-15 10:07:44 +0000 |
commit | e379362f05a8f3ad770e54c165ab1cfb9a61a2ce (patch) | |
tree | f0aca777a8234065d9bb14d9ce23da1a5013bb8d | |
parent | 2e482e23a8d51f58e6ff80782e360cf9f47e174c (diff) | |
download | gnunet-e379362f05a8f3ad770e54c165ab1cfb9a61a2ce.tar.gz gnunet-e379362f05a8f3ad770e54c165ab1cfb9a61a2ce.zip |
further simplify API
-rw-r--r-- | src/transport/gnunet-service-transport.c | 97 | ||||
-rw-r--r-- | src/transport/plugin_transport.h | 24 | ||||
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 20 |
3 files changed, 29 insertions, 112 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 292f38039..6f3bc6e94 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -1285,83 +1285,6 @@ plugin_env_notify_address (void *cls, | |||
1285 | 1285 | ||
1286 | 1286 | ||
1287 | /** | 1287 | /** |
1288 | * FIXME: document. | ||
1289 | */ | ||
1290 | struct LookupHelloContext | ||
1291 | { | ||
1292 | GNUNET_TRANSPORT_AddressCallback iterator; | ||
1293 | |||
1294 | void *iterator_cls; | ||
1295 | }; | ||
1296 | |||
1297 | |||
1298 | /** | ||
1299 | * FIXME: document. | ||
1300 | */ | ||
1301 | static int | ||
1302 | lookup_address_callback (void *cls, | ||
1303 | const char *tname, | ||
1304 | struct GNUNET_TIME_Absolute expiration, | ||
1305 | const void *addr, size_t addrlen) | ||
1306 | { | ||
1307 | struct LookupHelloContext *lhc = cls; | ||
1308 | lhc->iterator (lhc->iterator_cls, tname, addr, addrlen); | ||
1309 | return GNUNET_OK; | ||
1310 | } | ||
1311 | |||
1312 | |||
1313 | /** | ||
1314 | * FIXME: document. | ||
1315 | */ | ||
1316 | static void | ||
1317 | lookup_hello_callback (void *cls, | ||
1318 | const struct GNUNET_PeerIdentity *peer, | ||
1319 | const struct GNUNET_HELLO_Message *h, uint32_t trust) | ||
1320 | { | ||
1321 | struct LookupHelloContext *lhc = cls; | ||
1322 | |||
1323 | if (peer == NULL) | ||
1324 | { | ||
1325 | lhc->iterator (lhc->iterator_cls, NULL, NULL, 0); | ||
1326 | GNUNET_free (lhc); | ||
1327 | return; | ||
1328 | } | ||
1329 | if (h == NULL) | ||
1330 | return; | ||
1331 | GNUNET_HELLO_iterate_addresses (h, | ||
1332 | GNUNET_NO, &lookup_address_callback, lhc); | ||
1333 | } | ||
1334 | |||
1335 | |||
1336 | /** | ||
1337 | * Function that allows a transport to query the known | ||
1338 | * network addresses for a given peer. | ||
1339 | * | ||
1340 | * @param cls closure | ||
1341 | * @param timeout after how long should we time out? | ||
1342 | * @param target which peer are we looking for? | ||
1343 | * @param iter function to call for each known address | ||
1344 | * @param iter_cls closure for iter | ||
1345 | */ | ||
1346 | static void | ||
1347 | plugin_env_lookup_address (void *cls, | ||
1348 | struct GNUNET_TIME_Relative timeout, | ||
1349 | const struct GNUNET_PeerIdentity *target, | ||
1350 | GNUNET_TRANSPORT_AddressCallback iter, | ||
1351 | void *iter_cls) | ||
1352 | { | ||
1353 | struct LookupHelloContext *lhc; | ||
1354 | |||
1355 | lhc = GNUNET_malloc (sizeof (struct LookupHelloContext)); | ||
1356 | lhc->iterator = iter; | ||
1357 | lhc->iterator_cls = iter_cls; | ||
1358 | GNUNET_PEERINFO_for_all (cfg, | ||
1359 | sched, | ||
1360 | target, 0, timeout, &lookup_hello_callback, &lhc); | ||
1361 | } | ||
1362 | |||
1363 | |||
1364 | /** | ||
1365 | * Notify all of our clients about a peer connecting. | 1288 | * Notify all of our clients about a peer connecting. |
1366 | */ | 1289 | */ |
1367 | static void | 1290 | static void |
@@ -1653,6 +1576,12 @@ struct CheckHelloValidatedContext | |||
1653 | */ | 1576 | */ |
1654 | struct ValidationList *e; | 1577 | struct ValidationList *e; |
1655 | 1578 | ||
1579 | /** | ||
1580 | * Context for peerinfo iteration. | ||
1581 | * NULL after we are done processing peerinfo's information. | ||
1582 | */ | ||
1583 | struct GNUNET_PEERINFO_IteratorContext *piter; | ||
1584 | |||
1656 | }; | 1585 | }; |
1657 | 1586 | ||
1658 | 1587 | ||
@@ -1723,6 +1652,7 @@ check_hello_validated (void *cls, | |||
1723 | first_call = GNUNET_NO; | 1652 | first_call = GNUNET_NO; |
1724 | if (chvc->e == NULL) | 1653 | if (chvc->e == NULL) |
1725 | { | 1654 | { |
1655 | chvc->piter = NULL; | ||
1726 | first_call = GNUNET_YES; | 1656 | first_call = GNUNET_YES; |
1727 | chvc->e = GNUNET_malloc (sizeof (struct ValidationList)); | 1657 | chvc->e = GNUNET_malloc (sizeof (struct ValidationList)); |
1728 | GNUNET_assert (GNUNET_OK == | 1658 | GNUNET_assert (GNUNET_OK == |
@@ -1858,12 +1788,12 @@ process_hello (struct TransportPlugin *plugin, | |||
1858 | memcpy (chvc->hello, hello, hsize); | 1788 | memcpy (chvc->hello, hello, hsize); |
1859 | /* finally, check if HELLO was previously validated | 1789 | /* finally, check if HELLO was previously validated |
1860 | (continuation will then schedule actual validation) */ | 1790 | (continuation will then schedule actual validation) */ |
1861 | GNUNET_PEERINFO_for_all (cfg, | 1791 | chvc->piter = GNUNET_PEERINFO_iterate (cfg, |
1862 | sched, | 1792 | sched, |
1863 | &target, | 1793 | &target, |
1864 | 0, | 1794 | 0, |
1865 | HELLO_VERIFICATION_TIMEOUT, | 1795 | HELLO_VERIFICATION_TIMEOUT, |
1866 | &check_hello_validated, chvc); | 1796 | &check_hello_validated, chvc); |
1867 | return GNUNET_OK; | 1797 | return GNUNET_OK; |
1868 | } | 1798 | } |
1869 | 1799 | ||
@@ -2542,7 +2472,6 @@ create_environment (struct TransportPlugin *plug) | |||
2542 | plug->env.my_identity = &my_identity; | 2472 | plug->env.my_identity = &my_identity; |
2543 | plug->env.cls = plug; | 2473 | plug->env.cls = plug; |
2544 | plug->env.receive = &plugin_env_receive; | 2474 | plug->env.receive = &plugin_env_receive; |
2545 | plug->env.lookup = &plugin_env_lookup_address; | ||
2546 | plug->env.notify_address = &plugin_env_notify_address; | 2475 | plug->env.notify_address = &plugin_env_notify_address; |
2547 | plug->env.notify_validation = &plugin_env_notify_validation; | 2476 | plug->env.notify_validation = &plugin_env_notify_validation; |
2548 | plug->env.default_quota_in = (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT + 59999) / (60 * 1000); | 2477 | plug->env.default_quota_in = (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT + 59999) / (60 * 1000); |
diff --git a/src/transport/plugin_transport.h b/src/transport/plugin_transport.h index a309f0edf..93564f8e2 100644 --- a/src/transport/plugin_transport.h +++ b/src/transport/plugin_transport.h | |||
@@ -145,25 +145,6 @@ typedef void (*GNUNET_TRANSPORT_AddressCallback) (void *cls, | |||
145 | 145 | ||
146 | 146 | ||
147 | /** | 147 | /** |
148 | * Function that allows a transport to query the known | ||
149 | * network addresses for a given peer. | ||
150 | * | ||
151 | * @param cls closure | ||
152 | * @param timeout after how long should we time out? | ||
153 | * @param target which peer are we looking for? | ||
154 | * @param iter function to call for each known address | ||
155 | * @param iter_cls closure for iter | ||
156 | */ | ||
157 | typedef void (*GNUNET_TRANSPORT_LookupAddress) (void *cls, | ||
158 | struct GNUNET_TIME_Relative | ||
159 | timeout, | ||
160 | const struct | ||
161 | GNUNET_PeerIdentity * target, | ||
162 | GNUNET_TRANSPORT_AddressCallback | ||
163 | iter, void *iter_cls); | ||
164 | |||
165 | |||
166 | /** | ||
167 | * The transport service will pass a pointer to a struct | 148 | * The transport service will pass a pointer to a struct |
168 | * of this type as the first and only argument to the | 149 | * of this type as the first and only argument to the |
169 | * entry point of each transport plugin. | 150 | * entry point of each transport plugin. |
@@ -207,11 +188,6 @@ struct GNUNET_TRANSPORT_PluginEnvironment | |||
207 | GNUNET_TRANSPORT_PluginReceiveCallback receive; | 188 | GNUNET_TRANSPORT_PluginReceiveCallback receive; |
208 | 189 | ||
209 | /** | 190 | /** |
210 | * Address lookup function. | ||
211 | */ | ||
212 | GNUNET_TRANSPORT_LookupAddress lookup; | ||
213 | |||
214 | /** | ||
215 | * Function that must be called by each plugin to notify the | 191 | * Function that must be called by each plugin to notify the |
216 | * transport service about the addresses under which the transport | 192 | * transport service about the addresses under which the transport |
217 | * provided by the plugin can be reached. | 193 | * provided by the plugin can be reached. |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 89fff4be0..6a0874656 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -291,6 +291,12 @@ struct Session | |||
291 | struct GNUNET_TIME_Absolute last_quota_update; | 291 | struct GNUNET_TIME_Absolute last_quota_update; |
292 | 292 | ||
293 | /** | 293 | /** |
294 | * Context for our iteration to find HELLOs for this peer. NULL | ||
295 | * after iteration has completed. | ||
296 | */ | ||
297 | struct GNUNET_PEERINFO_IteratorContext *ic; | ||
298 | |||
299 | /** | ||
294 | * Address of the other peer if WE initiated the connection | 300 | * Address of the other peer if WE initiated the connection |
295 | * (and hence can be sure what it is), otherwise NULL. | 301 | * (and hence can be sure what it is), otherwise NULL. |
296 | */ | 302 | */ |
@@ -799,6 +805,11 @@ disconnect_session (struct Session *session) | |||
799 | else | 805 | else |
800 | prev->next = session->next; | 806 | prev->next = session->next; |
801 | /* clean up state */ | 807 | /* clean up state */ |
808 | if (session->ic != NULL) | ||
809 | { | ||
810 | GNUNET_PEERINFO_iterate_cancel (session->ic); | ||
811 | session->ic = NULL; | ||
812 | } | ||
802 | if (session->transmit_handle != NULL) | 813 | if (session->transmit_handle != NULL) |
803 | { | 814 | { |
804 | GNUNET_CONNECTION_notify_transmit_ready_cancel (session->transmit_handle); | 815 | GNUNET_CONNECTION_notify_transmit_ready_cancel (session->transmit_handle); |
@@ -963,6 +974,7 @@ session_try_connect (void *cls, | |||
963 | 974 | ||
964 | if (peer == NULL) | 975 | if (peer == NULL) |
965 | { | 976 | { |
977 | session->ic = NULL; | ||
966 | /* last call, destroy session if we are still not | 978 | /* last call, destroy session if we are still not |
967 | connected */ | 979 | connected */ |
968 | if (session->client != NULL) | 980 | if (session->client != NULL) |
@@ -1106,10 +1118,10 @@ tcp_plugin_send (void *cls, | |||
1106 | session->expecting_welcome = GNUNET_YES; | 1118 | session->expecting_welcome = GNUNET_YES; |
1107 | session->pending_messages = pm; | 1119 | session->pending_messages = pm; |
1108 | session->service_context = service_context; | 1120 | session->service_context = service_context; |
1109 | GNUNET_PEERINFO_for_all (plugin->env->cfg, | 1121 | session->ic = GNUNET_PEERINFO_iterate (plugin->env->cfg, |
1110 | plugin->env->sched, | 1122 | plugin->env->sched, |
1111 | target, | 1123 | target, |
1112 | 0, timeout, &session_try_connect, session); | 1124 | 0, timeout, &session_try_connect, session); |
1113 | return; | 1125 | return; |
1114 | } | 1126 | } |
1115 | GNUNET_assert (session != NULL); | 1127 | GNUNET_assert (session != NULL); |