2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file fs/gnunet-service-fs_cp.c
23 * @brief API to handle 'connected peers'
24 * @author Christian Grothoff
27 #include "gnunet_load_lib.h"
28 #include "gnunet-service-fs.h"
29 #include "gnunet-service-fs_cp.h"
30 #include "gnunet-service-fs_pe.h"
31 #include "gnunet-service-fs_pr.h"
32 #include "gnunet-service-fs_push.h"
35 * How often do we flush trust values to disk?
37 #define TRUST_FLUSH_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
40 * After how long do we discard a reply?
42 #define REPLY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2)
46 * Handle to cancel a transmission request.
48 struct GSF_PeerTransmitHandle
52 * Kept in a doubly-linked list.
54 struct GSF_PeerTransmitHandle *next;
57 * Kept in a doubly-linked list.
59 struct GSF_PeerTransmitHandle *prev;
62 * Handle for an active request for transmission to this
63 * peer, or NULL (if core queue was full).
65 struct GNUNET_CORE_TransmitHandle *cth;
68 * Time when this transmission request was issued.
70 struct GNUNET_TIME_Absolute transmission_request_start_time;
73 * Timeout for this request.
75 struct GNUNET_TIME_Absolute timeout;
78 * Task called on timeout, or 0 for none.
80 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
83 * Function to call to get the actual message.
85 GSF_GetMessageCallback gmc;
88 * Peer this request targets.
90 struct GSF_ConnectedPeer *cp;
98 * Size of the message to be transmitted.
103 * GNUNET_YES if this is a query, GNUNET_NO for content.
108 * Did we get a reservation already?
113 * Priority of this request.
121 * Information per peer and request.
127 * Handle to generic request.
129 struct GSF_PendingRequest *pr;
132 * Handle to specific peer.
134 struct GSF_ConnectedPeer *cp;
137 * Task for asynchronous stopping of this request.
139 GNUNET_SCHEDULER_TaskIdentifier kill_task;
147 struct GSF_ConnectedPeer
151 * Performance data for this peer.
153 struct GSF_PeerPerformanceData ppd;
156 * Time until when we blocked this peer from migrating
159 struct GNUNET_TIME_Absolute last_migration_block;
162 * Task scheduled to revive migration to this peer.
164 GNUNET_SCHEDULER_TaskIdentifier mig_revive_task;
167 * Messages (replies, queries, content migration) we would like to
168 * send to this peer in the near future. Sorted by priority, head.
170 struct GSF_PeerTransmitHandle *pth_head;
173 * Messages (replies, queries, content migration) we would like to
174 * send to this peer in the near future. Sorted by priority, tail.
176 struct GSF_PeerTransmitHandle *pth_tail;
179 * Migration stop message in our queue, or NULL if we have none pending.
181 struct GSF_PeerTransmitHandle *migration_pth;
184 * Context of our GNUNET_CORE_peer_change_preference call (or NULL).
186 struct GNUNET_CORE_InformationRequestContext *irc;
189 * Task scheduled if we need to retry bandwidth reservation later.
191 GNUNET_SCHEDULER_TaskIdentifier irc_delay_task;
194 * Active requests from this neighbour, map of query to 'struct PeerRequest'.
196 struct GNUNET_CONTAINER_MultiHashMap *request_map;
199 * Increase in traffic preference still to be submitted
200 * to the core service for this peer.
202 uint64_t inc_preference;
205 * Trust rating for this peer on disk.
210 * Which offset in "last_p2p_replies" will be updated next?
211 * (we go round-robin).
213 unsigned int last_p2p_replies_woff;
216 * Which offset in "last_client_replies" will be updated next?
217 * (we go round-robin).
219 unsigned int last_client_replies_woff;
222 * Current offset into 'last_request_times' ring buffer.
224 unsigned int last_request_times_off;
227 * GNUNET_YES if we did successfully reserve 32k bandwidth,
236 * Map from peer identities to 'struct GSF_ConnectPeer' entries.
238 static struct GNUNET_CONTAINER_MultiHashMap *cp_map;
241 * Where do we store trust information?
243 static char *trustDirectory;
247 * Get the filename under which we would store the GNUNET_HELLO_Message
248 * for the given host and protocol.
249 * @return filename of the form DIRECTORY/HOSTID
252 get_trust_filename (const struct GNUNET_PeerIdentity *id)
254 struct GNUNET_CRYPTO_HashAsciiEncoded fil;
257 GNUNET_CRYPTO_hash_to_enc (&id->hashPubKey, &fil);
258 GNUNET_asprintf (&fn, "%s%s%s", trustDirectory, DIR_SEPARATOR_STR, &fil);
264 * Find latency information in 'atsi'.
266 * @param atsi performance data
267 * @return connection latency
269 static struct GNUNET_TIME_Relative
270 get_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
273 return GNUNET_TIME_UNIT_SECONDS;
274 while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
275 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) )
277 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
280 /* how can we not have latency data? */
281 return GNUNET_TIME_UNIT_SECONDS;
283 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
284 ntohl (atsi->value));
289 * Update the performance information kept for the given peer.
291 * @param cp peer record to update
292 * @param atsi transport performance data
295 update_atsi (struct GSF_ConnectedPeer *cp,
296 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
298 struct GNUNET_TIME_Relative latency;
300 latency = get_latency (atsi);
301 GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay,
303 /* LATER: merge atsi into cp's performance data (if we ever care...) */
308 * Return the performance data record for the given peer
310 * @param cp peer to query
311 * @return performance data record for the peer
313 struct GSF_PeerPerformanceData *
314 GSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp)
321 * Core is ready to transmit to a peer, get the message.
323 * @param cls the 'struct GSF_PeerTransmitHandle' of the message
324 * @param size number of bytes core is willing to take
325 * @param buf where to copy the message
326 * @return number of bytes copied to buf
329 peer_transmit_ready_cb (void *cls,
337 * Function called by core upon success or failure of our bandwidth reservation request.
339 * @param cls the 'struct GSF_ConnectedPeer' of the peer for which we made the request
340 * @param peer identifies the peer
341 * @param bandwidth_out available amount of outbound bandwidth
342 * @param amount set to the amount that was actually reserved or unreserved;
343 * either the full requested amount or zero (no partial reservations)
344 * @param res_delay if the reservation could not be satisfied (amount was 0), how
345 * long should the client wait until re-trying?
346 * @param preference current traffic preference for the given peer
349 core_reserve_callback (void *cls,
350 const struct GNUNET_PeerIdentity *peer,
351 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
353 struct GNUNET_TIME_Relative res_delay,
354 uint64_t preference);
358 * If ready (bandwidth reserved), try to schedule transmission via
359 * core for the given handle.
361 * @param pth transmission handle to schedule
364 schedule_transmission (struct GSF_PeerTransmitHandle *pth)
366 struct GSF_ConnectedPeer *cp;
367 struct GNUNET_PeerIdentity target;
370 if (NULL != pth->cth)
371 return; /* already done */
373 GNUNET_PEER_resolve (cp->ppd.pid,
375 if ( (GNUNET_YES == pth->is_query) &&
376 (GNUNET_YES != pth->was_reserved) )
378 /* query, need reservation */
379 if (GNUNET_YES != cp->did_reserve)
380 return; /* not ready */
381 cp->did_reserve = GNUNET_NO;
382 /* reservation already done! */
383 pth->was_reserved = GNUNET_YES;
384 ip = cp->inc_preference;
385 cp->inc_preference = 0;
386 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core,
388 GNUNET_TIME_UNIT_FOREVER_REL,
389 GNUNET_BANDWIDTH_VALUE_MAX,
392 &core_reserve_callback,
395 pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core,
398 GNUNET_TIME_absolute_get_remaining (pth->timeout),
401 &peer_transmit_ready_cb,
407 * Core is ready to transmit to a peer, get the message.
409 * @param cls the 'struct GSF_PeerTransmitHandle' of the message
410 * @param size number of bytes core is willing to take
411 * @param buf where to copy the message
412 * @return number of bytes copied to buf
415 peer_transmit_ready_cb (void *cls,
419 struct GSF_PeerTransmitHandle *pth = cls;
420 struct GSF_ConnectedPeer *cp;
424 if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK)
426 GNUNET_SCHEDULER_cancel (pth->timeout_task);
427 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
430 GNUNET_CONTAINER_DLL_remove (cp->pth_head,
433 if (GNUNET_YES == pth->is_query)
435 cp->ppd.last_request_times[(cp->last_request_times_off++) % MAX_QUEUE_PER_PEER] = GNUNET_TIME_absolute_get ();
436 GNUNET_assert (0 < cp->ppd.pending_queries--);
438 else if (GNUNET_NO == pth->is_query)
440 GNUNET_assert (0 < cp->ppd.pending_replies--);
442 GNUNET_LOAD_update (cp->ppd.transmission_delay,
443 GNUNET_TIME_absolute_get_duration (pth->transmission_request_start_time).rel_value);
444 ret = pth->gmc (pth->gmc_cls,
447 for (pth = cp->pth_head; pth != NULL; pth = pth->next)
448 schedule_transmission (pth);
454 * (re)try to reserve bandwidth from the given peer.
456 * @param cls the 'struct GSF_ConnectedPeer' to reserve from
457 * @param tc scheduler context
460 retry_reservation (void *cls,
461 const struct GNUNET_SCHEDULER_TaskContext *tc)
463 struct GSF_ConnectedPeer *cp = cls;
465 struct GNUNET_PeerIdentity target;
467 GNUNET_PEER_resolve (cp->ppd.pid,
469 cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK;
470 ip = cp->inc_preference;
471 cp->inc_preference = 0;
472 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core,
474 GNUNET_TIME_UNIT_FOREVER_REL,
475 GNUNET_BANDWIDTH_VALUE_MAX,
478 &core_reserve_callback,
484 * Function called by core upon success or failure of our bandwidth reservation request.
486 * @param cls the 'struct GSF_ConnectedPeer' of the peer for which we made the request
487 * @param peer identifies the peer
488 * @param bandwidth_out available amount of outbound bandwidth
489 * @param amount set to the amount that was actually reserved or unreserved;
490 * either the full requested amount or zero (no partial reservations)
491 * @param res_delay if the reservation could not be satisfied (amount was 0), how
492 * long should the client wait until re-trying?
493 * @param preference current traffic preference for the given peer
496 core_reserve_callback (void *cls,
497 const struct GNUNET_PeerIdentity *peer,
498 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
500 struct GNUNET_TIME_Relative res_delay,
503 struct GSF_ConnectedPeer *cp = cls;
504 struct GSF_PeerTransmitHandle *pth;
509 cp->irc_delay_task = GNUNET_SCHEDULER_add_delayed (res_delay,
514 cp->did_reserve = GNUNET_YES;
516 if ( (NULL != pth) &&
519 /* reservation success, try transmission now! */
520 pth->cth = GNUNET_CORE_notify_transmit_ready (GSF_core,
523 GNUNET_TIME_absolute_get_remaining (pth->timeout),
526 &peer_transmit_ready_cb,
533 * A peer connected to us. Setup the connected peer
536 * @param peer identity of peer that connected
537 * @param atsi performance data for the connection
538 * @return handle to connected peer entry
540 struct GSF_ConnectedPeer *
541 GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
542 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
544 struct GSF_ConnectedPeer *cp;
548 cp = GNUNET_malloc (sizeof (struct GSF_ConnectedPeer));
549 cp->ppd.pid = GNUNET_PEER_intern (peer);
550 cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO);
551 cp->irc = GNUNET_CORE_peer_change_preference (GSF_core,
553 GNUNET_TIME_UNIT_FOREVER_REL,
554 GNUNET_BANDWIDTH_VALUE_MAX,
557 &core_reserve_callback,
559 fn = get_trust_filename (peer);
560 if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) &&
561 (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust))))
562 cp->disk_trust = cp->ppd.trust = ntohl (trust);
564 cp->request_map = GNUNET_CONTAINER_multihashmap_create (128);
565 GNUNET_break (GNUNET_OK ==
566 GNUNET_CONTAINER_multihashmap_put (cp_map,
569 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
570 update_atsi (cp, atsi);
571 GSF_push_start_ (cp);
577 * It may be time to re-start migrating content to this
578 * peer. Check, and if so, restart migration.
580 * @param cls the 'struct GSF_ConnectedPeer'
581 * @param tc scheduler context
584 revive_migration (void *cls,
585 const struct GNUNET_SCHEDULER_TaskContext *tc)
587 struct GSF_ConnectedPeer *cp = cls;
588 struct GNUNET_TIME_Relative bt;
590 cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK;
591 bt = GNUNET_TIME_absolute_get_remaining (cp->ppd.migration_blocked_until);
592 if (0 != bt.rel_value)
594 /* still time left... */
596 = GNUNET_SCHEDULER_add_delayed (bt,
601 GSF_push_start_ (cp);
606 * Get a handle for a connected peer.
608 * @param peer peer's identity
609 * @return NULL if the peer is not currently connected
611 struct GSF_ConnectedPeer *
612 GSF_peer_get_ (const struct GNUNET_PeerIdentity *peer)
614 return GNUNET_CONTAINER_multihashmap_get (cp_map,
620 * Handle P2P "MIGRATION_STOP" message.
622 * @param cls closure, always NULL
623 * @param other the other peer involved (sender or receiver, NULL
624 * for loopback messages where we are both sender and receiver)
625 * @param message the actual message
626 * @param atsi performance information
627 * @return GNUNET_OK to keep the connection open,
628 * GNUNET_SYSERR to close it (signal serious error)
631 GSF_handle_p2p_migration_stop_ (void *cls,
632 const struct GNUNET_PeerIdentity *other,
633 const struct GNUNET_MessageHeader *message,
634 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
636 struct GSF_ConnectedPeer *cp;
637 const struct MigrationStopMessage *msm;
638 struct GNUNET_TIME_Relative bt;
640 msm = (const struct MigrationStopMessage*) message;
641 cp = GNUNET_CONTAINER_multihashmap_get (cp_map,
648 bt = GNUNET_TIME_relative_ntoh (msm->duration);
649 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
650 _("Migration of content to peer `%s' blocked for %llu ms\n"),
652 (unsigned long long) bt.rel_value);
653 cp->ppd.migration_blocked_until = GNUNET_TIME_relative_to_absolute (bt);
654 if (cp->mig_revive_task == GNUNET_SCHEDULER_NO_TASK)
658 = GNUNET_SCHEDULER_add_delayed (bt,
662 update_atsi (cp, atsi);
668 * Copy reply and free put message.
670 * @param cls the 'struct PutMessage'
671 * @param buf_size number of bytes available in buf
672 * @param buf where to copy the message, NULL on error (peer disconnect)
673 * @return number of bytes copied to 'buf', can be 0 (without indicating an error)
676 copy_reply (void *cls,
680 struct PutMessage *pm = cls;
685 GNUNET_assert (buf_size >= ntohs (pm->header.size));
686 size = ntohs (pm->header.size);
687 memcpy (buf, pm, size);
688 GNUNET_STATISTICS_update (GSF_stats,
689 gettext_noop ("# replies transmitted to other peers"),
696 GNUNET_STATISTICS_update (GSF_stats,
697 gettext_noop ("# replies dropped"),
707 * Free the given client request.
709 * @param cls the client request to free
710 * @param tc task context
713 peer_request_destroy (void *cls,
714 const struct GNUNET_SCHEDULER_TaskContext *tc)
716 struct PeerRequest *peerreq = cls;
717 struct GSF_PendingRequest *pr = peerreq->pr;
718 struct GSF_ConnectedPeer *cp = peerreq->cp;
719 struct GSF_PendingRequestData *prd;
721 peerreq->kill_task = GNUNET_SCHEDULER_NO_TASK;
722 prd = GSF_pending_request_get_data_ (pr);
723 GNUNET_STATISTICS_update (GSF_stats,
724 gettext_noop ("# P2P searches active"),
727 GNUNET_break (GNUNET_OK ==
728 GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
731 GSF_pending_request_cancel_ (pr);
732 GNUNET_free (peerreq);
737 * Handle a reply to a pending request. Also called if a request
738 * expires (then with data == NULL). The handler may be called
739 * many times (depending on the request type), but will not be
740 * called during or after a call to GSF_pending_request_cancel
741 * and will also not be called anymore after a call signalling
744 * @param cls 'struct PeerRequest' this is an answer for
745 * @param eval evaluation of the result
746 * @param pr handle to the original pending request
747 * @param expiration when does 'data' expire?
748 * @param type type of the block
749 * @param data response data, NULL on request expiration
750 * @param data_len number of bytes in data
753 handle_p2p_reply (void *cls,
754 enum GNUNET_BLOCK_EvaluationResult eval,
755 struct GSF_PendingRequest *pr,
756 struct GNUNET_TIME_Absolute expiration,
757 enum GNUNET_BLOCK_Type type,
761 struct PeerRequest *peerreq = cls;
762 struct GSF_ConnectedPeer *cp = peerreq->cp;
763 struct GSF_PendingRequestData *prd;
764 struct PutMessage *pm;
767 GNUNET_assert (data_len < GNUNET_SERVER_MAX_MESSAGE_SIZE);
768 GNUNET_assert (peerreq->pr == pr);
769 prd = GSF_pending_request_get_data_ (pr);
772 GNUNET_STATISTICS_update (GSF_stats,
773 gettext_noop ("# P2P searches active"),
776 GNUNET_break (GNUNET_OK ==
777 GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
780 GNUNET_free (peerreq);
783 GNUNET_break (type != GNUNET_BLOCK_TYPE_ANY);
784 if ( (prd->type != type) &&
785 (prd->type != GNUNET_BLOCK_TYPE_ANY) )
791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
792 "Transmitting result for query `%s' to peer\n",
793 GNUNET_h2s (&prd->query));
795 GNUNET_STATISTICS_update (GSF_stats,
796 gettext_noop ("# replies received for other peers"),
799 msize = sizeof (struct PutMessage) + data_len;
800 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
805 pm = GNUNET_malloc (msize);
806 pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT);
807 pm->header.size = htons (msize);
808 pm->type = htonl (type);
809 pm->expiration = GNUNET_TIME_absolute_hton (expiration);
810 memcpy (&pm[1], data, data_len);
811 (void) GSF_peer_transmit_ (cp, GNUNET_NO,
817 if (eval != GNUNET_BLOCK_EVALUATION_OK_LAST)
819 peerreq->kill_task = GNUNET_SCHEDULER_add_now (&peer_request_destroy,
825 * Increase the host credit by a value.
827 * @param cp which peer to change the trust value on
828 * @param value is the int value by which the
829 * host credit is to be increased or decreased
830 * @returns the actual change in trust (positive or negative)
833 change_host_trust (struct GSF_ConnectedPeer *cp, int value)
837 GNUNET_assert (cp != NULL);
840 if (cp->ppd.trust + value < cp->ppd.trust)
842 value = UINT32_MAX - cp->ppd.trust;
843 cp->ppd.trust = UINT32_MAX;
846 cp->ppd.trust += value;
850 if (cp->ppd.trust < -value)
852 value = -cp->ppd.trust;
856 cp->ppd.trust += value;
863 * We've received a request with the specified priority. Bound it
864 * according to how much we trust the given peer.
866 * @param prio_in requested priority
867 * @param cp the peer making the request
868 * @return effective priority
871 bound_priority (uint32_t prio_in,
872 struct GSF_ConnectedPeer *cp)
874 #define N ((double)128.0)
879 ld = GSF_test_get_load_too_high_ (0);
880 if (ld == GNUNET_SYSERR)
882 GNUNET_STATISTICS_update (GSF_stats,
883 gettext_noop ("# requests done for free (low load)"),
886 return 0; /* excess resources */
888 if (prio_in > INT32_MAX)
890 ret = - change_host_trust (cp, - (int) prio_in);
893 if (ret > GSF_current_priorities + N)
894 rret = GSF_current_priorities + N;
897 GSF_current_priorities
898 = (GSF_current_priorities * (N-1) + rret)/N;
900 if ( (ld == GNUNET_YES) && (ret > 0) )
902 /* try with charging */
903 ld = GSF_test_get_load_too_high_ (ret);
905 if (ld == GNUNET_YES)
907 GNUNET_STATISTICS_update (GSF_stats,
908 gettext_noop ("# request dropped, priority insufficient"),
912 change_host_trust (cp, (int) ret);
913 return -1; /* not enough resources */
917 GNUNET_STATISTICS_update (GSF_stats,
918 gettext_noop ("# requests done for a price (normal load)"),
928 * The priority level imposes a bound on the maximum
929 * value for the ttl that can be requested.
931 * @param ttl_in requested ttl
932 * @param prio given priority
933 * @return ttl_in if ttl_in is below the limit,
934 * otherwise the ttl-limit for the given priority
937 bound_ttl (int32_t ttl_in, uint32_t prio)
939 unsigned long long allowed;
943 allowed = ((unsigned long long) prio) * TTL_DECREMENT / 1000;
944 if (ttl_in > allowed)
946 if (allowed >= (1 << 30))
955 * Handle P2P "QUERY" message. Creates the pending request entry
956 * and sets up all of the data structures to that we will
957 * process replies properly. Does not initiate forwarding or
958 * local database lookups.
960 * @param other the other peer involved (sender or receiver, NULL
961 * for loopback messages where we are both sender and receiver)
962 * @param message the actual message
963 * @return pending request handle, NULL on error
965 struct GSF_PendingRequest *
966 GSF_handle_p2p_query_ (const struct GNUNET_PeerIdentity *other,
967 const struct GNUNET_MessageHeader *message)
969 struct PeerRequest *peerreq;
970 struct GSF_PendingRequest *pr;
971 struct GSF_PendingRequestData *prd;
972 struct GSF_ConnectedPeer *cp;
973 struct GSF_ConnectedPeer *cps;
974 const GNUNET_HashCode *namespace;
975 const struct GNUNET_PeerIdentity *target;
976 enum GSF_PendingRequestOptions options;
978 const struct GetMessage *gm;
980 const GNUNET_HashCode *opt;
983 uint32_t ttl_decrement;
986 enum GNUNET_BLOCK_Type type;
989 msize = ntohs(message->size);
990 if (msize < sizeof (struct GetMessage))
995 gm = (const struct GetMessage*) message;
996 type = ntohl (gm->type);
997 bm = ntohl (gm->hash_bitmap);
1005 if (msize < sizeof (struct GetMessage) + bits * sizeof (GNUNET_HashCode))
1007 GNUNET_break_op (0);
1010 opt = (const GNUNET_HashCode*) &gm[1];
1011 bfsize = msize - sizeof (struct GetMessage) - bits * sizeof (GNUNET_HashCode);
1012 /* bfsize must be power of 2, check! */
1013 if (0 != ( (bfsize - 1) & bfsize))
1015 GNUNET_break_op (0);
1018 GSF_cover_query_count++;
1019 bm = ntohl (gm->hash_bitmap);
1021 cps = GNUNET_CONTAINER_multihashmap_get (cp_map,
1022 &other->hashPubKey);
1025 /* peer must have just disconnected */
1026 GNUNET_STATISTICS_update (GSF_stats,
1027 gettext_noop ("# requests dropped due to initiator not being connected"),
1032 if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO))
1033 cp = GNUNET_CONTAINER_multihashmap_get (cp_map,
1040 if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO))
1041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1042 "Failed to find RETURN-TO peer `%4s' in connection set. Dropping query.\n",
1043 GNUNET_i2s ((const struct GNUNET_PeerIdentity*) &opt[bits-1]));
1046 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1047 "Failed to find peer `%4s' in connection set. Dropping query.\n",
1048 GNUNET_i2s (other));
1050 GNUNET_STATISTICS_update (GSF_stats,
1051 gettext_noop ("# requests dropped due to missing reverse route"),
1056 /* note that we can really only check load here since otherwise
1057 peers could find out that we are overloaded by not being
1058 disconnected after sending us a malformed query... */
1059 priority = bound_priority (ntohl (gm->priority), cps);
1063 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1064 "Dropping query from `%s', this peer is too busy.\n",
1065 GNUNET_i2s (other));
1070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1071 "Received request for `%s' of type %u from peer `%4s' with flags %u\n",
1072 GNUNET_h2s (&gm->query),
1073 (unsigned int) type,
1077 namespace = (0 != (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) ? &opt[bits++] : NULL;
1078 if ( (type == GNUNET_BLOCK_TYPE_FS_SBLOCK) &&
1079 (namespace == NULL) )
1081 GNUNET_break_op (0);
1084 if ( (type != GNUNET_BLOCK_TYPE_FS_SBLOCK) &&
1085 (namespace != NULL) )
1087 GNUNET_break_op (0);
1090 target = (0 != (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? ((const struct GNUNET_PeerIdentity*) &opt[bits++]) : NULL;
1093 if ( (GNUNET_LOAD_get_load (cp->ppd.transmission_delay) > 3 * (1 + priority)) ||
1094 (GNUNET_LOAD_get_average (cp->ppd.transmission_delay) >
1095 GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value * 2 + GNUNET_LOAD_get_average (GSF_rt_entry_lifetime)) )
1097 /* don't have BW to send to peer, or would likely take longer than we have for it,
1098 so at best indirect the query */
1100 options |= GSF_PRO_FORWARD_ONLY;
1101 spid = GNUNET_PEER_intern (other);
1103 ttl = bound_ttl (ntohl (gm->ttl), priority);
1104 /* decrement ttl (always) */
1105 ttl_decrement = 2 * TTL_DECREMENT +
1106 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1109 (((int32_t)(ttl - ttl_decrement)) > 0) )
1112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1113 "Dropping query from `%s' due to TTL underflow (%d - %u).\n",
1118 GNUNET_STATISTICS_update (GSF_stats,
1119 gettext_noop ("# requests dropped due TTL underflow"),
1122 /* integer underflow => drop (should be very rare)! */
1125 ttl -= ttl_decrement;
1127 /* test if the request already exists */
1128 peerreq = GNUNET_CONTAINER_multihashmap_get (cp->request_map,
1130 if (peerreq != NULL)
1133 prd = GSF_pending_request_get_data_ (pr);
1134 if ( (prd->type == type) &&
1135 ( (type != GNUNET_BLOCK_TYPE_FS_SBLOCK) ||
1136 (0 == memcmp (&prd->namespace,
1138 sizeof (GNUNET_HashCode))) ) )
1140 if (prd->ttl.abs_value >= GNUNET_TIME_absolute_get().abs_value + ttl)
1142 /* existing request has higher TTL, drop new one! */
1143 prd->priority += priority;
1145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1146 "Have existing request with higher TTL, dropping new request.\n",
1147 GNUNET_i2s (other));
1149 GNUNET_STATISTICS_update (GSF_stats,
1150 gettext_noop ("# requests dropped due to higher-TTL request"),
1155 /* existing request has lower TTL, drop old one! */
1156 priority += prd->priority;
1157 GSF_pending_request_cancel_ (pr);
1158 GNUNET_assert (GNUNET_YES ==
1159 GNUNET_CONTAINER_multihashmap_remove (cp->request_map,
1162 if (peerreq->kill_task != GNUNET_SCHEDULER_NO_TASK)
1163 GNUNET_SCHEDULER_cancel (peerreq->kill_task);
1164 GNUNET_free (peerreq);
1168 peerreq = GNUNET_malloc (sizeof (struct PeerRequest));
1170 pr = GSF_pending_request_create_ (options,
1175 (bfsize > 0) ? (const char*)&opt[bits] : NULL,
1177 ntohl (gm->filter_mutator),
1179 (uint32_t) priority,
1182 NULL, 0, /* replies_seen */
1186 GNUNET_break (GNUNET_OK ==
1187 GNUNET_CONTAINER_multihashmap_put (cp->request_map,
1190 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
1191 GNUNET_STATISTICS_update (GSF_stats,
1192 gettext_noop ("# P2P searches received"),
1195 GNUNET_STATISTICS_update (GSF_stats,
1196 gettext_noop ("# P2P searches active"),
1204 * Function called if there has been a timeout trying to satisfy
1205 * a transmission request.
1207 * @param cls the 'struct GSF_PeerTransmitHandle' of the request
1208 * @param tc scheduler context
1211 peer_transmit_timeout (void *cls,
1212 const struct GNUNET_SCHEDULER_TaskContext *tc)
1214 struct GSF_PeerTransmitHandle *pth = cls;
1215 struct GSF_ConnectedPeer *cp;
1218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1219 "Timeout trying to transmit to other peer\n");
1221 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1223 GNUNET_CONTAINER_DLL_remove (cp->pth_head,
1226 if (GNUNET_YES == pth->is_query)
1227 GNUNET_assert (0 < cp->ppd.pending_queries--);
1228 else if (GNUNET_NO == pth->is_query)
1229 GNUNET_assert (0 < cp->ppd.pending_replies--);
1230 GNUNET_LOAD_update (cp->ppd.transmission_delay,
1232 pth->gmc (pth->gmc_cls,
1239 * Transmit a message to the given peer as soon as possible.
1240 * If the peer disconnects before the transmission can happen,
1241 * the callback is invoked with a 'NULL' buffer.
1243 * @param cp target peer
1244 * @param is_query is this a query (GNUNET_YES) or content (GNUNET_NO) or neither (GNUNET_SYSERR)
1245 * @param priority how important is this request?
1246 * @param timeout when does this request timeout (call gmc with error)
1247 * @param size number of bytes we would like to send to the peer
1248 * @param gmc function to call to get the message
1249 * @param gmc_cls closure for gmc
1250 * @return handle to cancel request
1252 struct GSF_PeerTransmitHandle *
1253 GSF_peer_transmit_ (struct GSF_ConnectedPeer *cp,
1256 struct GNUNET_TIME_Relative timeout,
1258 GSF_GetMessageCallback gmc,
1261 struct GSF_PeerTransmitHandle *pth;
1262 struct GSF_PeerTransmitHandle *pos;
1263 struct GSF_PeerTransmitHandle *prev;
1265 pth = GNUNET_malloc (sizeof (struct GSF_PeerTransmitHandle));
1266 pth->transmission_request_start_time = GNUNET_TIME_absolute_get ();
1267 pth->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1269 pth->gmc_cls = gmc_cls;
1271 pth->is_query = is_query;
1272 pth->priority = priority;
1274 /* insertion sort (by priority, descending) */
1277 while ( (pos != NULL) &&
1278 (pos->priority > priority) )
1284 GNUNET_CONTAINER_DLL_insert (cp->pth_head,
1288 GNUNET_CONTAINER_DLL_insert_after (cp->pth_head,
1292 if (GNUNET_YES == is_query)
1293 cp->ppd.pending_queries++;
1294 else if (GNUNET_NO == is_query)
1295 cp->ppd.pending_replies++;
1297 pth->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
1298 &peer_transmit_timeout,
1300 schedule_transmission (pth);
1306 * Cancel an earlier request for transmission.
1308 * @param pth request to cancel
1311 GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth)
1313 struct GSF_ConnectedPeer *cp;
1315 if (pth->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1317 GNUNET_SCHEDULER_cancel (pth->timeout_task);
1318 pth->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1320 if (NULL != pth->cth)
1322 GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
1326 GNUNET_CONTAINER_DLL_remove (cp->pth_head,
1329 if (GNUNET_YES == pth->is_query)
1330 GNUNET_assert (0 < cp->ppd.pending_queries--);
1331 else if (GNUNET_NO == pth->is_query)
1332 GNUNET_assert (0 < cp->ppd.pending_replies--);
1338 * Report on receiving a reply; update the performance record of the given peer.
1340 * @param cp responding peer (will be updated)
1341 * @param request_time time at which the original query was transmitted
1342 * @param request_priority priority of the original request
1345 GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp,
1346 struct GNUNET_TIME_Absolute request_time,
1347 uint32_t request_priority)
1349 struct GNUNET_TIME_Relative delay;
1351 delay = GNUNET_TIME_absolute_get_duration (request_time);
1352 cp->ppd.avg_reply_delay.rel_value = (cp->ppd.avg_reply_delay.rel_value * (RUNAVG_DELAY_N-1) + delay.rel_value) / RUNAVG_DELAY_N;
1353 cp->ppd.avg_priority = (cp->ppd.avg_priority * (RUNAVG_DELAY_N-1) + request_priority) / RUNAVG_DELAY_N;
1358 * Report on receiving a reply in response to an initiating client.
1359 * Remember that this peer is good for this client.
1361 * @param cp responding peer (will be updated)
1362 * @param initiator_client local client on responsible for query
1365 GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp,
1366 struct GSF_LocalClient *initiator_client)
1368 cp->ppd.last_client_replies[cp->last_client_replies_woff++ % CS2P_SUCCESS_LIST_SIZE] = initiator_client;
1373 * Report on receiving a reply in response to an initiating peer.
1374 * Remember that this peer is good for this initiating peer.
1376 * @param cp responding peer (will be updated)
1377 * @param initiator_peer other peer responsible for query
1380 GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp,
1381 const struct GSF_ConnectedPeer *initiator_peer)
1383 GNUNET_PEER_change_rc (cp->ppd.last_p2p_replies[cp->last_p2p_replies_woff % P2P_SUCCESS_LIST_SIZE], -1);
1384 cp->ppd.last_p2p_replies[cp->last_p2p_replies_woff++ % P2P_SUCCESS_LIST_SIZE] = initiator_peer->ppd.pid;
1385 GNUNET_PEER_change_rc (initiator_peer->ppd.pid, 1);
1390 * Method called whenever a given peer has a status change.
1392 * @param cls closure
1393 * @param peer peer identity this notification is about
1394 * @param bandwidth_in available amount of inbound bandwidth
1395 * @param bandwidth_out available amount of outbound bandwidth
1396 * @param timeout absolute time when this peer will time out
1397 * unless we see some further activity from it
1398 * @param atsi status information
1401 GSF_peer_status_handler_ (void *cls,
1402 const struct GNUNET_PeerIdentity *peer,
1403 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1404 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
1405 struct GNUNET_TIME_Absolute timeout,
1406 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1408 struct GSF_ConnectedPeer *cp;
1410 cp = GNUNET_CONTAINER_multihashmap_get (cp_map,
1412 GNUNET_assert (NULL != cp);
1413 update_atsi (cp, atsi);
1418 * Cancel all requests associated with the peer.
1421 * @param query hash code of the request
1422 * @param value the 'struct GSF_PendingRequest'
1423 * @return GNUNET_YES (continue to iterate)
1426 cancel_pending_request (void *cls,
1427 const GNUNET_HashCode *query,
1430 struct PeerRequest *peerreq = cls;
1431 struct GSF_PendingRequest *pr = peerreq->pr;
1433 GSF_pending_request_cancel_ (pr);
1434 if (peerreq->kill_task != GNUNET_SCHEDULER_NO_TASK)
1435 GNUNET_SCHEDULER_cancel (peerreq->kill_task);
1436 GNUNET_free (peerreq);
1442 * A peer disconnected from us. Tear down the connected peer
1446 * @param peer identity of peer that connected
1449 GSF_peer_disconnect_handler_ (void *cls,
1450 const struct GNUNET_PeerIdentity *peer)
1452 struct GSF_ConnectedPeer *cp;
1453 struct GSF_PeerTransmitHandle *pth;
1455 cp = GNUNET_CONTAINER_multihashmap_get (cp_map,
1458 return; /* must have been disconnect from core with
1459 'peer' == my_id, ignore */
1460 GNUNET_CONTAINER_multihashmap_remove (cp_map,
1463 if (NULL != cp->migration_pth)
1465 GSF_peer_transmit_cancel_ (cp->migration_pth);
1466 cp->migration_pth = NULL;
1468 if (NULL != cp->irc)
1470 GNUNET_CORE_peer_change_preference_cancel (cp->irc);
1473 if (GNUNET_SCHEDULER_NO_TASK != cp->irc_delay_task)
1475 GNUNET_SCHEDULER_cancel (cp->irc_delay_task);
1476 cp->irc_delay_task = GNUNET_SCHEDULER_NO_TASK;
1478 GNUNET_CONTAINER_multihashmap_iterate (cp->request_map,
1479 &cancel_pending_request,
1481 GNUNET_CONTAINER_multihashmap_destroy (cp->request_map);
1482 cp->request_map = NULL;
1483 GSF_plan_notify_peer_disconnect_ (cp);
1484 GNUNET_LOAD_value_free (cp->ppd.transmission_delay);
1485 GNUNET_PEER_decrement_rcs (cp->ppd.last_p2p_replies, P2P_SUCCESS_LIST_SIZE);
1486 while (NULL != (pth = cp->pth_head))
1488 if (NULL != pth->cth)
1490 GNUNET_CORE_notify_transmit_ready_cancel (pth->cth);
1493 GNUNET_CONTAINER_DLL_remove (cp->pth_head,
1498 GNUNET_PEER_change_rc (cp->ppd.pid, -1);
1499 if (GNUNET_SCHEDULER_NO_TASK != cp->mig_revive_task)
1501 GNUNET_SCHEDULER_cancel (cp->mig_revive_task);
1502 cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK;
1509 * Closure for 'call_iterator'.
1511 struct IterationContext
1514 * Function to call on each entry.
1516 GSF_ConnectedPeerIterator it;
1526 * Function that calls the callback for each peer.
1528 * @param cls the 'struct IterationContext*'
1529 * @param key identity of the peer
1530 * @param value the 'struct GSF_ConnectedPeer*'
1531 * @return GNUNET_YES to continue iteration
1534 call_iterator (void *cls,
1535 const GNUNET_HashCode *key,
1538 struct IterationContext *ic = cls;
1539 struct GSF_ConnectedPeer *cp = value;
1542 (const struct GNUNET_PeerIdentity*) key,
1550 * Iterate over all connected peers.
1552 * @param it function to call for each peer
1553 * @param it_cls closure for it
1556 GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it,
1559 struct IterationContext ic;
1563 GNUNET_CONTAINER_multihashmap_iterate (cp_map,
1570 * Obtain the identity of a connected peer.
1572 * @param cp peer to reserve bandwidth from
1573 * @param id identity to set (written to)
1576 GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp,
1577 struct GNUNET_PeerIdentity *id)
1579 GNUNET_PEER_resolve (cp->ppd.pid,
1585 * Assemble a migration stop message for transmission.
1587 * @param cls the 'struct GSF_ConnectedPeer' to use
1588 * @param size number of bytes we're allowed to write to buf
1589 * @param buf where to copy the message
1590 * @return number of bytes copied to buf
1593 create_migration_stop_message (void *cls,
1597 struct GSF_ConnectedPeer *cp = cls;
1598 struct MigrationStopMessage msm;
1600 cp->migration_pth = NULL;
1603 GNUNET_assert (size >= sizeof (struct MigrationStopMessage));
1604 msm.header.size = htons (sizeof (struct MigrationStopMessage));
1605 msm.header.type = htons (GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP);
1606 msm.reserved = htonl (0);
1607 msm.duration = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (cp->last_migration_block));
1608 memcpy (buf, &msm, sizeof (struct MigrationStopMessage));
1609 return sizeof (struct MigrationStopMessage);
1614 * Ask a peer to stop migrating data to us until the given point
1617 * @param cp peer to ask
1618 * @param block_time until when to block
1621 GSF_block_peer_migration_ (struct GSF_ConnectedPeer *cp,
1622 struct GNUNET_TIME_Relative block_time)
1624 if (GNUNET_TIME_absolute_get_remaining (cp->last_migration_block).rel_value > block_time.rel_value)
1627 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1628 "Migration already blocked for another %llu ms\n",
1629 (unsigned long long) GNUNET_TIME_absolute_get_remaining (cp->last_migration_block).rel_value);
1631 return; /* already blocked */
1634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1635 "Asking to stop migration for %llu ms\n",
1636 (unsigned long long) block_time.rel_value);
1638 cp->last_migration_block = GNUNET_TIME_relative_to_absolute (block_time);
1639 if (cp->migration_pth != NULL)
1640 GSF_peer_transmit_cancel_ (cp->migration_pth);
1642 = GSF_peer_transmit_ (cp,
1645 GNUNET_TIME_UNIT_FOREVER_REL,
1646 sizeof (struct MigrationStopMessage),
1647 &create_migration_stop_message,
1653 * Write host-trust information to a file - flush the buffer entry!
1655 * @param cls closure, not used
1656 * @param key host identity
1657 * @param value the 'struct GSF_ConnectedPeer' to flush
1658 * @return GNUNET_OK to continue iteration
1661 flush_trust (void *cls,
1662 const GNUNET_HashCode *key,
1665 struct GSF_ConnectedPeer *cp = value;
1668 struct GNUNET_PeerIdentity pid;
1670 if (cp->ppd.trust == cp->disk_trust)
1671 return GNUNET_OK; /* unchanged */
1672 GNUNET_PEER_resolve (cp->ppd.pid,
1674 fn = get_trust_filename (&pid);
1675 if (cp->ppd.trust == 0)
1677 if ((0 != UNLINK (fn)) && (errno != ENOENT))
1678 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
1679 GNUNET_ERROR_TYPE_BULK, "unlink", fn);
1683 trust = htonl (cp->ppd.trust);
1684 if (sizeof(uint32_t) == GNUNET_DISK_fn_write (fn, &trust,
1686 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE
1687 | GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_OTHER_READ))
1688 cp->disk_trust = cp->ppd.trust;
1696 * Notify core about a preference we have for the given peer
1697 * (to allocate more resources towards it). The change will
1698 * be communicated the next time we reserve bandwidth with
1699 * core (not instantly).
1701 * @param cp peer to reserve bandwidth from
1702 * @param pref preference change
1705 GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp,
1708 cp->inc_preference += pref;
1713 * Call this method periodically to flush trust information to disk.
1715 * @param cls closure, not used
1716 * @param tc task context, not used
1719 cron_flush_trust (void *cls,
1720 const struct GNUNET_SCHEDULER_TaskContext *tc)
1725 GNUNET_CONTAINER_multihashmap_iterate (cp_map,
1730 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1732 GNUNET_SCHEDULER_add_delayed (TRUST_FLUSH_FREQ,
1739 * Initialize peer management subsystem.
1742 GSF_connected_peer_init_ ()
1744 cp_map = GNUNET_CONTAINER_multihashmap_create (128);
1745 GNUNET_assert (GNUNET_OK ==
1746 GNUNET_CONFIGURATION_get_value_filename (GSF_cfg,
1750 GNUNET_DISK_directory_create (trustDirectory);
1751 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH,
1752 &cron_flush_trust, NULL);
1757 * Iterator to free peer entries.
1759 * @param cls closure, unused
1760 * @param key current key code
1761 * @param value value in the hash map (peer entry)
1762 * @return GNUNET_YES (we should continue to iterate)
1765 clean_peer (void *cls,
1766 const GNUNET_HashCode * key,
1769 GSF_peer_disconnect_handler_ (NULL,
1770 (const struct GNUNET_PeerIdentity*) key);
1776 * Shutdown peer management subsystem.
1779 GSF_connected_peer_done_ ()
1781 cron_flush_trust (NULL, NULL);
1782 GNUNET_CONTAINER_multihashmap_iterate (cp_map,
1785 GNUNET_CONTAINER_multihashmap_destroy (cp_map);
1787 GNUNET_free (trustDirectory);
1788 trustDirectory = NULL;
1793 * Iterator to remove references to LC entry.
1795 * @param cls the 'struct GSF_LocalClient*' to look for
1796 * @param key current key code
1797 * @param value value in the hash map (peer entry)
1798 * @return GNUNET_YES (we should continue to iterate)
1801 clean_local_client (void *cls,
1802 const GNUNET_HashCode * key,
1805 const struct GSF_LocalClient *lc = cls;
1806 struct GSF_ConnectedPeer *cp = value;
1809 for (i=0;i<CS2P_SUCCESS_LIST_SIZE;i++)
1810 if (cp->ppd.last_client_replies[i] == lc)
1811 cp->ppd.last_client_replies[i] = NULL;
1817 * Notification that a local client disconnected. Clean up all of our
1818 * references to the given handle.
1820 * @param lc handle to the local client (henceforth invalid)
1823 GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc)
1826 return; /* already cleaned up */
1827 GNUNET_CONTAINER_multihashmap_iterate (cp_map,
1828 &clean_local_client,
1833 /* end of gnunet-service-fs_cp.c */