From: Christian Grothoff Date: Fri, 15 Jan 2010 10:07:44 +0000 (+0000) Subject: further simplify API X-Git-Tag: initial-import-from-subversion-38251~22967 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e379362f05a8f3ad770e54c165ab1cfb9a61a2ce;p=oweals%2Fgnunet.git further simplify API --- 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 @@ -1284,83 +1284,6 @@ plugin_env_notify_address (void *cls, } -/** - * FIXME: document. - */ -struct LookupHelloContext -{ - GNUNET_TRANSPORT_AddressCallback iterator; - - void *iterator_cls; -}; - - -/** - * FIXME: document. - */ -static int -lookup_address_callback (void *cls, - const char *tname, - struct GNUNET_TIME_Absolute expiration, - const void *addr, size_t addrlen) -{ - struct LookupHelloContext *lhc = cls; - lhc->iterator (lhc->iterator_cls, tname, addr, addrlen); - return GNUNET_OK; -} - - -/** - * FIXME: document. - */ -static void -lookup_hello_callback (void *cls, - const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *h, uint32_t trust) -{ - struct LookupHelloContext *lhc = cls; - - if (peer == NULL) - { - lhc->iterator (lhc->iterator_cls, NULL, NULL, 0); - GNUNET_free (lhc); - return; - } - if (h == NULL) - return; - GNUNET_HELLO_iterate_addresses (h, - GNUNET_NO, &lookup_address_callback, lhc); -} - - -/** - * Function that allows a transport to query the known - * network addresses for a given peer. - * - * @param cls closure - * @param timeout after how long should we time out? - * @param target which peer are we looking for? - * @param iter function to call for each known address - * @param iter_cls closure for iter - */ -static void -plugin_env_lookup_address (void *cls, - struct GNUNET_TIME_Relative timeout, - const struct GNUNET_PeerIdentity *target, - GNUNET_TRANSPORT_AddressCallback iter, - void *iter_cls) -{ - struct LookupHelloContext *lhc; - - lhc = GNUNET_malloc (sizeof (struct LookupHelloContext)); - lhc->iterator = iter; - lhc->iterator_cls = iter_cls; - GNUNET_PEERINFO_for_all (cfg, - sched, - target, 0, timeout, &lookup_hello_callback, &lhc); -} - - /** * Notify all of our clients about a peer connecting. */ @@ -1653,6 +1576,12 @@ struct CheckHelloValidatedContext */ struct ValidationList *e; + /** + * Context for peerinfo iteration. + * NULL after we are done processing peerinfo's information. + */ + struct GNUNET_PEERINFO_IteratorContext *piter; + }; @@ -1723,6 +1652,7 @@ check_hello_validated (void *cls, first_call = GNUNET_NO; if (chvc->e == NULL) { + chvc->piter = NULL; first_call = GNUNET_YES; chvc->e = GNUNET_malloc (sizeof (struct ValidationList)); GNUNET_assert (GNUNET_OK == @@ -1858,12 +1788,12 @@ process_hello (struct TransportPlugin *plugin, memcpy (chvc->hello, hello, hsize); /* finally, check if HELLO was previously validated (continuation will then schedule actual validation) */ - GNUNET_PEERINFO_for_all (cfg, - sched, - &target, - 0, - HELLO_VERIFICATION_TIMEOUT, - &check_hello_validated, chvc); + chvc->piter = GNUNET_PEERINFO_iterate (cfg, + sched, + &target, + 0, + HELLO_VERIFICATION_TIMEOUT, + &check_hello_validated, chvc); return GNUNET_OK; } @@ -2542,7 +2472,6 @@ create_environment (struct TransportPlugin *plug) plug->env.my_identity = &my_identity; plug->env.cls = plug; plug->env.receive = &plugin_env_receive; - plug->env.lookup = &plugin_env_lookup_address; plug->env.notify_address = &plugin_env_notify_address; plug->env.notify_validation = &plugin_env_notify_validation; 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 @@ -144,25 +144,6 @@ typedef void (*GNUNET_TRANSPORT_AddressCallback) (void *cls, size_t addrlen); -/** - * Function that allows a transport to query the known - * network addresses for a given peer. - * - * @param cls closure - * @param timeout after how long should we time out? - * @param target which peer are we looking for? - * @param iter function to call for each known address - * @param iter_cls closure for iter - */ -typedef void (*GNUNET_TRANSPORT_LookupAddress) (void *cls, - struct GNUNET_TIME_Relative - timeout, - const struct - GNUNET_PeerIdentity * target, - GNUNET_TRANSPORT_AddressCallback - iter, void *iter_cls); - - /** * The transport service will pass a pointer to a struct * of this type as the first and only argument to the @@ -206,11 +187,6 @@ struct GNUNET_TRANSPORT_PluginEnvironment */ GNUNET_TRANSPORT_PluginReceiveCallback receive; - /** - * Address lookup function. - */ - GNUNET_TRANSPORT_LookupAddress lookup; - /** * Function that must be called by each plugin to notify the * transport service about the addresses under which the transport 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 @@ -290,6 +290,12 @@ struct Session */ struct GNUNET_TIME_Absolute last_quota_update; + /** + * Context for our iteration to find HELLOs for this peer. NULL + * after iteration has completed. + */ + struct GNUNET_PEERINFO_IteratorContext *ic; + /** * Address of the other peer if WE initiated the connection * (and hence can be sure what it is), otherwise NULL. @@ -799,6 +805,11 @@ disconnect_session (struct Session *session) else prev->next = session->next; /* clean up state */ + if (session->ic != NULL) + { + GNUNET_PEERINFO_iterate_cancel (session->ic); + session->ic = NULL; + } if (session->transmit_handle != NULL) { GNUNET_CONNECTION_notify_transmit_ready_cancel (session->transmit_handle); @@ -963,6 +974,7 @@ session_try_connect (void *cls, if (peer == NULL) { + session->ic = NULL; /* last call, destroy session if we are still not connected */ if (session->client != NULL) @@ -1106,10 +1118,10 @@ tcp_plugin_send (void *cls, session->expecting_welcome = GNUNET_YES; session->pending_messages = pm; session->service_context = service_context; - GNUNET_PEERINFO_for_all (plugin->env->cfg, - plugin->env->sched, - target, - 0, timeout, &session_try_connect, session); + session->ic = GNUNET_PEERINFO_iterate (plugin->env->cfg, + plugin->env->sched, + target, + 0, timeout, &session_try_connect, session); return; } GNUNET_assert (session != NULL);