aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fs/fs.h2
-rw-r--r--src/fs/gnunet-service-fs_cp.c51
-rw-r--r--src/fs/gnunet-service-fs_cp.h30
-rw-r--r--src/fs/gnunet-service-fs_pr.c126
-rw-r--r--src/fs/gnunet-service-fs_pr.h12
5 files changed, 120 insertions, 101 deletions
diff --git a/src/fs/fs.h b/src/fs/fs.h
index a9aa7ef74..a5b15dcef 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -2320,7 +2320,7 @@ struct GetMessage
2320 * The number should be in big-endian format when used 2320 * The number should be in big-endian format when used
2321 * for mingling. 2321 * for mingling.
2322 */ 2322 */
2323 int32_t filter_mutator GNUNET_PACKED; 2323 uint32_t filter_mutator GNUNET_PACKED;
2324 2324
2325 /** 2325 /**
2326 * Which of the optional hash codes are present at the end of the 2326 * Which of the optional hash codes are present at the end of the
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
index d88598be7..3ce03be2e 100644
--- a/src/fs/gnunet-service-fs_cp.c
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -981,34 +981,49 @@ GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth)
981 * @param cp responding peer (will be updated) 981 * @param cp responding peer (will be updated)
982 * @param request_time time at which the original query was transmitted 982 * @param request_time time at which the original query was transmitted
983 * @param request_priority priority of the original request 983 * @param request_priority priority of the original request
984 * @param initiator_client local client on responsible for query (or NULL)
985 * @param initiator_peer other peer responsible for query (or NULL)
986 */ 984 */
987void 985void
988GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, 986GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp,
989 struct GNUNET_TIME_Absolute request_time, 987 struct GNUNET_TIME_Absolute request_time,
990 uint32_t request_priority, 988 uint32_t request_priority)
991 const struct GSF_LocalClient *initiator_client,
992 const struct GSF_ConnectedPeer *initiator_peer)
993{ 989{
994 struct GNUNET_TIME_Relative delay; 990 struct GNUNET_TIME_Relative delay;
995 unsigned int i;
996 991
997 delay = GNUNET_TIME_absolute_get_duration (request_time); 992 delay = GNUNET_TIME_absolute_get_duration (request_time);
998 cp->ppd.avg_reply_delay = (cp->ppd.avg_reply_delay * (RUNAVG_DELAY_N-1) + delay.rel_value) / RUNAVG_DELAY_N; 993 cp->ppd.avg_reply_delay = (cp->ppd.avg_reply_delay * (RUNAVG_DELAY_N-1) + delay.rel_value) / RUNAVG_DELAY_N;
999 cp->ppd.avg_priority = (cp->avg_priority * (RUNAVG_DELAY_N-1) + request_priority) / RUNAVG_DELAY_N; 994 cp->ppd.avg_priority = (cp->avg_priority * (RUNAVG_DELAY_N-1) + request_priority) / RUNAVG_DELAY_N;
1000 if (NULL != initiator_client) 995}
1001 { 996
1002 cp->ppd.last_client_replies[cp->last_client_replies_woff++ % CS2P_SUCCESS_LIST_SIZE] = initiator_client; 997
1003 } 998/**
1004 else if (NULL != initiator_peer) 999 * Report on receiving a reply in response to an initiating client.
1005 { 1000 * Remember that this peer is good for this client.
1006 GNUNET_PEER_change_rc (cp->ppd.last_p2p_replies[cp->last_p2p_replies_woff % P2P_SUCCESS_LIST_SIZE], -1); 1001 *
1007 cp->ppd.last_p2p_replies[cp->last_p2p_replies_woff++ % P2P_SUCCESS_LIST_SIZE] = initiator_peer->pid; 1002 * @param cp responding peer (will be updated)
1008 GNUNET_PEER_change_rc (initiator_peer->pid, 1); 1003 * @param initiator_client local client on responsible for query
1009 } 1004 */
1010 else 1005void
1011 GNUNET_break (0); 1006GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp,
1007 const struct GSF_LocalClient *initiator_client)
1008{
1009 cp->ppd.last_client_replies[cp->last_client_replies_woff++ % CS2P_SUCCESS_LIST_SIZE] = initiator_client;
1010}
1011
1012
1013/**
1014 * Report on receiving a reply in response to an initiating peer.
1015 * Remember that this peer is good for this initiating peer.
1016 *
1017 * @param cp responding peer (will be updated)
1018 * @param initiator_peer other peer responsible for query
1019 */
1020void
1021GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp,
1022 const struct GSF_ConnectedPeer *initiator_peer)
1023{
1024 GNUNET_PEER_change_rc (cp->ppd.last_p2p_replies[cp->last_p2p_replies_woff % P2P_SUCCESS_LIST_SIZE], -1);
1025 cp->ppd.last_p2p_replies[cp->last_p2p_replies_woff++ % P2P_SUCCESS_LIST_SIZE] = initiator_peer->pid;
1026 GNUNET_PEER_change_rc (initiator_peer->pid, 1);
1012} 1027}
1013 1028
1014 1029
diff --git a/src/fs/gnunet-service-fs_cp.h b/src/fs/gnunet-service-fs_cp.h
index bc561f792..081a1d5ba 100644
--- a/src/fs/gnunet-service-fs_cp.h
+++ b/src/fs/gnunet-service-fs_cp.h
@@ -204,15 +204,35 @@ GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth);
204 * @param cp responding peer (will be updated) 204 * @param cp responding peer (will be updated)
205 * @param request_time time at which the original query was transmitted 205 * @param request_time time at which the original query was transmitted
206 * @param request_priority priority of the original request 206 * @param request_priority priority of the original request
207 * @param initiator_client local client on responsible for query (or NULL)
208 * @param initiator_peer other peer responsible for query (or NULL)
209 */ 207 */
210void 208void
211GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, 209GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp,
212 struct GNUNET_TIME_Absolute request_time, 210 struct GNUNET_TIME_Absolute request_time,
213 uint32_t request_priority, 211 uint32_t request_priority);
214 const struct GSF_LocalClient *initiator_client, 212
215 const struct GSF_ConnectedPeer *initiator_peer); 213
214/**
215 * Report on receiving a reply in response to an initiating client.
216 * Remember that this peer is good for this client.
217 *
218 * @param cp responding peer (will be updated)
219 * @param initiator_client local client on responsible for query
220 */
221void
222GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp,
223 const struct GSF_LocalClient *initiator_client);
224
225
226/**
227 * Report on receiving a reply in response to an initiating peer.
228 * Remember that this peer is good for this initiating peer.
229 *
230 * @param cp responding peer (will be updated)
231 * @param initiator_peer other peer responsible for query
232 */
233void
234GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp,
235 const struct GSF_ConnectedPeer *initiator_peer);
216 236
217 237
218/** 238/**
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c
index 4dc00f54c..aca63ac94 100644
--- a/src/fs/gnunet-service-fs_pr.c
+++ b/src/fs/gnunet-service-fs_pr.c
@@ -58,6 +58,11 @@ struct GSF_PendingRequest
58 struct GNUNET_CONTAINER_BloomFilter *bf; 58 struct GNUNET_CONTAINER_BloomFilter *bf;
59 59
60 /** 60 /**
61 * Entry for this pending request in the expiration heap, or NULL.
62 */
63 struct GNUNET_CONTAINER_HeapNode *hnode;
64
65 /**
61 * Number of valid entries in the 'replies_seen' array. 66 * Number of valid entries in the 'replies_seen' array.
62 */ 67 */
63 unsigned int replies_seen_count; 68 unsigned int replies_seen_count;
@@ -70,7 +75,7 @@ struct GSF_PendingRequest
70 /** 75 /**
71 * Mingle value we currently use for the bf. 76 * Mingle value we currently use for the bf.
72 */ 77 */
73 int32_t mingle; 78 uint32_t mingle;
74 79
75}; 80};
76 81
@@ -158,8 +163,8 @@ refresh_bloomfilter (struct GSF_PendingRequest *pr)
158 return GNUNET_NO; /* size not changed */ 163 return GNUNET_NO; /* size not changed */
159 if (pr->bf != NULL) 164 if (pr->bf != NULL)
160 GNUNET_CONTAINER_bloomfilter_free (pr->bf); 165 GNUNET_CONTAINER_bloomfilter_free (pr->bf);
161 pr->mingle = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 166 pr->mingle = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
162 UINT32_MAX); 167 UINT32_MAX);
163 pr->bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 168 pr->bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
164 nsize, 169 nsize,
165 BLOOMFILTER_K); 170 BLOOMFILTER_K);
@@ -202,7 +207,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
202 const struct GNUNET_PeerIdentity *target, 207 const struct GNUNET_PeerIdentity *target,
203 const char *bf_data, 208 const char *bf_data,
204 size_t bf_size, 209 size_t bf_size,
205 int32_t mingle, 210 uint32_t mingle,
206 uint32_t anonymity_level, 211 uint32_t anonymity_level,
207 uint32_t priority, 212 uint32_t priority,
208 int32_t ttl, 213 int32_t ttl,
@@ -212,7 +217,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
212 void *rh_cls) 217 void *rh_cls)
213{ 218{
214 struct GSF_PendingRequest *pr; 219 struct GSF_PendingRequest *pr;
215 220 struct GSF_PendingRequest *dpr;
216 221
217 pr = GNUNET_malloc (sizeof (struct GSF_PendingRequest)); 222 pr = GNUNET_malloc (sizeof (struct GSF_PendingRequest));
218 pr->public_data.query = *query; 223 pr->public_data.query = *query;
@@ -228,6 +233,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
228 } 233 }
229 pr->public_data.anonymity_level = anonymity_data; 234 pr->public_data.anonymity_level = anonymity_data;
230 pr->public_data.priority = priority; 235 pr->public_data.priority = priority;
236 pr->public_data.original_priority = priority;
231 pr->public_data.options = options; 237 pr->public_data.options = options;
232 pr->public_data.type = type; 238 pr->public_data.type = type;
233 pr->public_data.start_time = GNUNET_TIME_absolute_get (); 239 pr->public_data.start_time = GNUNET_TIME_absolute_get ();
@@ -265,25 +271,26 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
265 query, 271 query,
266 pr, 272 pr,
267 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 273 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
268 // FIXME: if not a local query, we also need to track the 274 if (0 != (options & GSF_PRO_REQUEST_EXPIRES))
269 // total number of external queries we currently have and
270 // bound it => need an additional heap!
271
272 pr->hnode = GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap,
273 pr,
274 pr->start_time.abs_value + pr->ttl);
275
276
277
278 /* make sure we don't track too many requests */
279 if (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) > max_pending_requests)
280 { 275 {
281 pr = GNUNET_CONTAINER_heap_peek (requests_by_expiration_heap); 276 pr->hnode = GNUNET_CONTAINER_heap_insert (requests_by_expiration_heap,
282 GNUNET_assert (pr != NULL); 277 pr,
283 destroy_pending_request (pr); 278 pr->ttl.abs_value);
279 /* make sure we don't track too many requests */
280 while (GNUNET_CONTAINER_heap_get_size (requests_by_expiration_heap) > max_pending_requests)
281 {
282 dpr = GNUNET_CONTAINER_heap_peek (requests_by_expiration_heap);
283 GNUNET_assert (dpr != NULL);
284 if (pr == dpr)
285 break; /* let the request live briefly... */
286 dpr->rh (dpr->rh_cls,
287 dpr,
288 GNUNET_TIME_UNIT_FOREVER_ABS,
289 NULL, 0,
290 GNUNET_SYSERR);
291 GSF_pending_request_cancel_ (dpr);
292 }
284 } 293 }
285
286
287 return pr; 294 return pr;
288} 295}
289 296
@@ -348,8 +355,8 @@ GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
348 { 355 {
349 /* we're not the initiator, but the initiator did not give us 356 /* we're not the initiator, but the initiator did not give us
350 any bloom-filter, so we need to create one on-the-fly */ 357 any bloom-filter, so we need to create one on-the-fly */
351 pr->mingle = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 358 pr->mingle = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
352 UINT32_MAX); 359 UINT32_MAX);
353 pr->bf = GNUNET_CONTAINER_bloomfilter_init (compute_bloomfilter_size (replies_seen_count), 360 pr->bf = GNUNET_CONTAINER_bloomfilter_init (compute_bloomfilter_size (replies_seen_count),
354 pr->mingle, 361 pr->mingle,
355 BLOOMFILTER_K); 362 BLOOMFILTER_K);
@@ -464,6 +471,9 @@ clean_request (void *cls,
464 GNUNET_free_non_null (pr->replies_seen); 471 GNUNET_free_non_null (pr->replies_seen);
465 if (NULL != pr->bf) 472 if (NULL != pr->bf)
466 GNUNET_CONTAINER_bloomfilter_free (pr->bf); 473 GNUNET_CONTAINER_bloomfilter_free (pr->bf);
474 if (NULL != pr->hnode)
475 GNUNET_CONTAINER_heap_remove_node (requests_by_expiration_heap,
476 pr->hnode);
467 GNUNET_free (pr); 477 GNUNET_free (pr);
468 return GNUNET_YES; 478 return GNUNET_YES;
469} 479}
@@ -517,7 +527,7 @@ struct ProcessReplyClosure
517 /** 527 /**
518 * Who gave us this reply? NULL for local host (or DHT) 528 * Who gave us this reply? NULL for local host (or DHT)
519 */ 529 */
520 struct ConnectedPeer *sender; 530 struct GSF_ConnectedPeer *sender;
521 531
522 /** 532 /**
523 * When the reply expires. 533 * When the reply expires.
@@ -577,41 +587,9 @@ update_request_performance_data (struct ProcessReplyClosure *prq,
577 587
578 if (prq->sender == NULL) 588 if (prq->sender == NULL)
579 return; 589 return;
580 /* FIXME: adapt code to new API... */ 590 GSF_peer_update_performance_ (prq->sender,
581 for (i=0;i<pr->used_targets_off;i++) 591 pr->start_time,
582 if (pr->used_targets[i].pid == prq->sender->pid) 592 prq->priority);
583 break;
584 if (i < pr->used_targets_off)
585 {
586 cur_delay = GNUNET_TIME_absolute_get_duration (pr->used_targets[i].last_request_time);
587 prq->sender->avg_delay.rel_value
588 = (prq->sender->avg_delay.rel_value *
589 (RUNAVG_DELAY_N - 1) + cur_delay.rel_value) / RUNAVG_DELAY_N;
590 prq->sender->avg_priority
591 = (prq->sender->avg_priority *
592 (RUNAVG_DELAY_N - 1) + pr->priority) / (double) RUNAVG_DELAY_N;
593 }
594 if (pr->cp != NULL)
595 {
596 GNUNET_PEER_change_rc (prq->sender->last_p2p_replies
597 [prq->sender->last_p2p_replies_woff % P2P_SUCCESS_LIST_SIZE],
598 -1);
599 GNUNET_PEER_change_rc (pr->cp->pid, 1);
600 prq->sender->last_p2p_replies
601 [(prq->sender->last_p2p_replies_woff++) % P2P_SUCCESS_LIST_SIZE]
602 = pr->cp->pid;
603 }
604 else
605 {
606 if (NULL != prq->sender->last_client_replies
607 [(prq->sender->last_client_replies_woff) % CS2P_SUCCESS_LIST_SIZE])
608 GNUNET_SERVER_client_drop (prq->sender->last_client_replies
609 [(prq->sender->last_client_replies_woff) % CS2P_SUCCESS_LIST_SIZE]);
610 prq->sender->last_client_replies
611 [(prq->sender->last_client_replies_woff++) % CS2P_SUCCESS_LIST_SIZE]
612 = pr->client_request_list->client_list->client;
613 GNUNET_SERVER_client_keep (pr->client_request_list->client_list->client);
614 }
615} 593}
616 594
617 595
@@ -636,6 +614,7 @@ process_reply (void *cls,
636 struct PutMessage *pm; 614 struct PutMessage *pm;
637 struct ConnectedPeer *cp; 615 struct ConnectedPeer *cp;
638 size_t msize; 616 size_t msize;
617 GNUNET_HashCode chash;
639 618
640#if DEBUG_FS 619#if DEBUG_FS
641 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 620 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -661,6 +640,7 @@ process_reply (void *cls,
661 update_request_performance_data (prq, pr); 640 update_request_performance_data (prq, pr);
662 break; 641 break;
663 case GNUNET_BLOCK_EVALUATION_OK_LAST: 642 case GNUNET_BLOCK_EVALUATION_OK_LAST:
643 /* short cut: stop processing early, no BF-update, etc. */
664 update_request_performance_data (prq, pr); 644 update_request_performance_data (prq, pr);
665 GNUNET_LOAD_update (rt_entry_lifetime, 645 GNUNET_LOAD_update (rt_entry_lifetime,
666 GNUNET_TIME_absolute_get_duration (pr->start_time).rel_value); 646 GNUNET_TIME_absolute_get_duration (pr->start_time).rel_value);
@@ -694,18 +674,11 @@ process_reply (void *cls,
694 prq->type); 674 prq->type);
695 return GNUNET_NO; 675 return GNUNET_NO;
696 } 676 }
697 /* FIXME: adapt code to new API! */ 677 /* update bloomfilter */
698 if (pr->client_request_list != NULL) 678 GNUNET_CRYPTO_hash (prq->data,
699 { 679 prq->size,
700 if (pr->replies_seen_size == pr->replies_seen_off) 680 &chash);
701 GNUNET_array_grow (pr->replies_seen, 681 GSF_pending_request_update_ (pr, &chash, 1);
702 pr->replies_seen_size,
703 pr->replies_seen_size * 2 + 4);
704 GNUNET_CRYPTO_hash (prq->data,
705 prq->size,
706 &pr->replies_seen[pr->replies_seen_off++]);
707 refresh_bloomfilter (pr);
708 }
709 if (NULL == prq->sender) 682 if (NULL == prq->sender)
710 { 683 {
711#if DEBUG_FS 684#if DEBUG_FS
@@ -718,11 +691,12 @@ process_reply (void *cls,
718 1, 691 1,
719 GNUNET_NO); 692 GNUNET_NO);
720 } 693 }
721 prq->priority += pr->remaining_priority; 694 prq->priority += pr->public_data.original_priority;
722 pr->remaining_priority = 0; 695 pr->public_data.remaining_priority = 0;
723 pr->results_found++; 696 pr->public_data.original_priority = 0;
697 pr->public_data.results_found++;
724 prq->request_found = GNUNET_YES; 698 prq->request_found = GNUNET_YES;
725 /* finally, pass on to other peers / local clients */ 699 /* finally, pass on to other peer / local client */
726 pr->rh (pr->rh_cls, pr, prq->data, prq->size, GNUNET_YES); 700 pr->rh (pr->rh_cls, pr, prq->data, prq->size, GNUNET_YES);
727 return GNUNET_YES; 701 return GNUNET_YES;
728} 702}
diff --git a/src/fs/gnunet-service-fs_pr.h b/src/fs/gnunet-service-fs_pr.h
index 2cb7cb843..4357565c7 100644
--- a/src/fs/gnunet-service-fs_pr.h
+++ b/src/fs/gnunet-service-fs_pr.h
@@ -112,6 +112,11 @@ struct GSF_PendingRequestData
112 uint32_t priority; 112 uint32_t priority;
113 113
114 /** 114 /**
115 * Priority that this request (originally) had for us.
116 */
117 uint32_t original_priority;
118
119 /**
115 * Options for the request. 120 * Options for the request.
116 */ 121 */
117 enum GSF_PendingRequestOptions options; 122 enum GSF_PendingRequestOptions options;
@@ -122,6 +127,11 @@ struct GSF_PendingRequestData
122 enum GNUNET_BLOCK_Type type; 127 enum GNUNET_BLOCK_Type type;
123 128
124 /** 129 /**
130 * Number of results we have found for this request so far.
131 */
132 unsigned int results_found;
133
134 /**
125 * Is the 'target' value set to a valid peer identity? 135 * Is the 'target' value set to a valid peer identity?
126 */ 136 */
127 int has_target; 137 int has_target;
@@ -182,7 +192,7 @@ GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
182 const struct GNUNET_PeerIdentity *target, 192 const struct GNUNET_PeerIdentity *target,
183 const char *bf_data, 193 const char *bf_data,
184 size_t bf_size, 194 size_t bf_size,
185 int32_t mingle, 195 uint32_t mingle,
186 uint32_t anonymity_level, 196 uint32_t anonymity_level,
187 uint32_t priority, 197 uint32_t priority,
188 int32_t ttl, 198 int32_t ttl,