diff options
Diffstat (limited to 'src/fs/gnunet-service-fs_cp.c')
-rw-r--r-- | src/fs/gnunet-service-fs_cp.c | 77 |
1 files changed, 59 insertions, 18 deletions
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c index 3ce03be2e..be041c861 100644 --- a/src/fs/gnunet-service-fs_cp.c +++ b/src/fs/gnunet-service-fs_cp.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet-service-fs.h" | 27 | #include "gnunet-service-fs.h" |
28 | #include "gnunet-service-fs_cp.h" | 28 | #include "gnunet-service-fs_cp.h" |
29 | #include "gnunet-service-fs_push.h" | ||
29 | 30 | ||
30 | /** | 31 | /** |
31 | * How often do we flush trust values to disk? | 32 | * How often do we flush trust values to disk? |
@@ -116,6 +117,11 @@ struct GSF_ConnectedPeer | |||
116 | struct GNUNET_TIME_Absolute last_migration_block; | 117 | struct GNUNET_TIME_Absolute last_migration_block; |
117 | 118 | ||
118 | /** | 119 | /** |
120 | * Task scheduled to revive migration to this peer. | ||
121 | */ | ||
122 | struct GNUNET_SCHEDULER_TaskIdentifier mig_revive_task; | ||
123 | |||
124 | /** | ||
119 | * Messages (replies, queries, content migration) we would like to | 125 | * Messages (replies, queries, content migration) we would like to |
120 | * send to this peer in the near future. Sorted by priority, head. | 126 | * send to this peer in the near future. Sorted by priority, head. |
121 | */ | 127 | */ |
@@ -144,11 +150,6 @@ struct GSF_ConnectedPeer | |||
144 | struct GNUNET_CONTAINER_MulitHashMap *request_map; | 150 | struct GNUNET_CONTAINER_MulitHashMap *request_map; |
145 | 151 | ||
146 | /** | 152 | /** |
147 | * ID of delay task for scheduling transmission. | ||
148 | */ | ||
149 | GNUNET_SCHEDULER_TaskIdentifier delayed_transmission_request_task; // FIXME: used in 'push' (ugh!) | ||
150 | |||
151 | /** | ||
152 | * Increase in traffic preference still to be submitted | 153 | * Increase in traffic preference still to be submitted |
153 | * to the core service for this peer. | 154 | * to the core service for this peer. |
154 | */ | 155 | */ |
@@ -160,11 +161,6 @@ struct GSF_ConnectedPeer | |||
160 | uint32_t disk_trust; | 161 | uint32_t disk_trust; |
161 | 162 | ||
162 | /** | 163 | /** |
163 | * The peer's identity. | ||
164 | */ | ||
165 | GNUNET_PEER_Id pid; | ||
166 | |||
167 | /** | ||
168 | * Which offset in "last_p2p_replies" will be updated next? | 164 | * Which offset in "last_p2p_replies" will be updated next? |
169 | * (we go round-robin). | 165 | * (we go round-robin). |
170 | */ | 166 | */ |
@@ -388,7 +384,7 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, | |||
388 | 384 | ||
389 | cp = GNUNET_malloc (sizeof (struct GSF_ConnectedPeer)); | 385 | cp = GNUNET_malloc (sizeof (struct GSF_ConnectedPeer)); |
390 | cp->transmission_delay = GNUNET_LOAD_value_init (latency); | 386 | cp->transmission_delay = GNUNET_LOAD_value_init (latency); |
391 | cp->pid = GNUNET_PEER_intern (peer); | 387 | cp->ppd.pid = GNUNET_PEER_intern (peer); |
392 | cp->transmission_delay = GNUNET_LOAD_value_init (0); | 388 | cp->transmission_delay = GNUNET_LOAD_value_init (0); |
393 | cp->irc = GNUNET_CORE_peer_change_preference (core, | 389 | cp->irc = GNUNET_CORE_peer_change_preference (core, |
394 | peer, | 390 | peer, |
@@ -411,11 +407,41 @@ GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer, | |||
411 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 407 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
412 | update_atsi (cp, atsi); | 408 | update_atsi (cp, atsi); |
413 | GSF_plan_notify_new_peer_ (cp); | 409 | GSF_plan_notify_new_peer_ (cp); |
410 | GSF_push_start_ (cp); | ||
414 | return cp; | 411 | return cp; |
415 | } | 412 | } |
416 | 413 | ||
417 | 414 | ||
418 | /** | 415 | /** |
416 | * It may be time to re-start migrating content to this | ||
417 | * peer. Check, and if so, restart migration. | ||
418 | * | ||
419 | * @param cls the 'struct GSF_ConnectedPeer' | ||
420 | * @param tc scheduler context | ||
421 | */ | ||
422 | static void | ||
423 | revive_migration (void *cls, | ||
424 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
425 | { | ||
426 | struct GSF_ConnectedPeer *cp = cls; | ||
427 | struct GNUNET_TIME_Relative bt; | ||
428 | |||
429 | cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK; | ||
430 | bt = GNUNET_TIME_absolute_get_remaining (cp->ppd.migration_blocked_until); | ||
431 | if (0 != bt.rel_value) | ||
432 | { | ||
433 | /* still time left... */ | ||
434 | cp->mig_revive_task | ||
435 | = GNUNET_SCHEDULER_add_delayed (bt, | ||
436 | &revive_migration, | ||
437 | cp); | ||
438 | return; | ||
439 | } | ||
440 | GSF_push_start_ (cp); | ||
441 | } | ||
442 | |||
443 | |||
444 | /** | ||
419 | * Handle P2P "MIGRATION_STOP" message. | 445 | * Handle P2P "MIGRATION_STOP" message. |
420 | * | 446 | * |
421 | * @param cls closure, always NULL | 447 | * @param cls closure, always NULL |
@@ -434,6 +460,7 @@ GSF_handle_p2p_migration_stop_ (void *cls, | |||
434 | { | 460 | { |
435 | struct GSF_ConnectedPeer *cp; | 461 | struct GSF_ConnectedPeer *cp; |
436 | const struct MigrationStopMessage *msm; | 462 | const struct MigrationStopMessage *msm; |
463 | struct GNUNET_TIME_Relative bt; | ||
437 | 464 | ||
438 | msm = (const struct MigrationStopMessage*) message; | 465 | msm = (const struct MigrationStopMessage*) message; |
439 | cp = GNUNET_CONTAINER_multihashmap_get (cp_map, | 466 | cp = GNUNET_CONTAINER_multihashmap_get (cp_map, |
@@ -443,7 +470,16 @@ GSF_handle_p2p_migration_stop_ (void *cls, | |||
443 | GNUNET_break (0); | 470 | GNUNET_break (0); |
444 | return GNUNET_OK; | 471 | return GNUNET_OK; |
445 | } | 472 | } |
446 | cp->ppd.migration_blocked_until = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh (msm->duration)); | 473 | bt = GNUNET_TIME_relative_ntoh (msm->duration); |
474 | cp->ppd.migration_blocked_until = GNUNET_TIME_relative_to_absolute (bt); | ||
475 | if (cp->mig_revive_task == GNUNET_SCHEDULER_NO_TASK) | ||
476 | { | ||
477 | GSF_push_stop_ (cp); | ||
478 | cp->mig_revive_task | ||
479 | = GNUNET_SCHEDULER_add_delayed (bt, | ||
480 | &revive_migration, | ||
481 | cp); | ||
482 | } | ||
447 | update_atsi (cp, atsi); | 483 | update_atsi (cp, atsi); |
448 | return GNUNET_OK; | 484 | return GNUNET_OK; |
449 | } | 485 | } |
@@ -880,7 +916,7 @@ GSF_peer_transmit_ (struct GSF_ConnectedPeer *peer, | |||
880 | cp->pth_tail, | 916 | cp->pth_tail, |
881 | prev, | 917 | prev, |
882 | pth); | 918 | pth); |
883 | GNUNET_PEER_resolve (cp->pid, | 919 | GNUNET_PEER_resolve (cp->ppd.pid, |
884 | &target); | 920 | &target); |
885 | if (GNUNET_YES == is_query) | 921 | if (GNUNET_YES == is_query) |
886 | { | 922 | { |
@@ -1022,8 +1058,8 @@ GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, | |||
1022 | const struct GSF_ConnectedPeer *initiator_peer) | 1058 | const struct GSF_ConnectedPeer *initiator_peer) |
1023 | { | 1059 | { |
1024 | GNUNET_PEER_change_rc (cp->ppd.last_p2p_replies[cp->last_p2p_replies_woff % P2P_SUCCESS_LIST_SIZE], -1); | 1060 | 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; | 1061 | cp->ppd.last_p2p_replies[cp->last_p2p_replies_woff++ % P2P_SUCCESS_LIST_SIZE] = initiator_peer->ppd.pid; |
1026 | GNUNET_PEER_change_rc (initiator_peer->pid, 1); | 1062 | GNUNET_PEER_change_rc (initiator_peer->ppd.pid, 1); |
1027 | } | 1063 | } |
1028 | 1064 | ||
1029 | 1065 | ||
@@ -1125,7 +1161,12 @@ GSF_peer_disconnect_handler_ (void *cls, | |||
1125 | pth); | 1161 | pth); |
1126 | GNUNET_free (pth); | 1162 | GNUNET_free (pth); |
1127 | } | 1163 | } |
1128 | GNUNET_PEER_change_rc (cp->pid, -1); | 1164 | GNUNET_PEER_change_rc (cp->ppd.pid, -1); |
1165 | if (GNUNET_SCHEDULER_NO_TASK != cp->mig_revive_task) | ||
1166 | { | ||
1167 | GNUNET_SCHEDULER_cancel (cp->mig_revive_task); | ||
1168 | cp->mig_revive_task = GNUNET_SCHEDULER_NO_TASK; | ||
1169 | } | ||
1129 | GNUNET_free (cp); | 1170 | GNUNET_free (cp); |
1130 | } | 1171 | } |
1131 | 1172 | ||
@@ -1201,7 +1242,7 @@ void | |||
1201 | GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, | 1242 | GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, |
1202 | struct GNUNET_PeerIdentity *id) | 1243 | struct GNUNET_PeerIdentity *id) |
1203 | { | 1244 | { |
1204 | GNUNET_PEER_resolve (cp->pid, | 1245 | GNUNET_PEER_resolve (cp->ppd.pid, |
1205 | &id); | 1246 | &id); |
1206 | } | 1247 | } |
1207 | 1248 | ||
@@ -1281,7 +1322,7 @@ flush_trust (void *cls, | |||
1281 | 1322 | ||
1282 | if (cp->trust == cp->disk_trust) | 1323 | if (cp->trust == cp->disk_trust) |
1283 | return GNUNET_OK; /* unchanged */ | 1324 | return GNUNET_OK; /* unchanged */ |
1284 | GNUNET_PEER_resolve (cp->pid, | 1325 | GNUNET_PEER_resolve (cp->ppd.pid, |
1285 | &pid); | 1326 | &pid); |
1286 | fn = get_trust_filename (&pid); | 1327 | fn = get_trust_filename (&pid); |
1287 | if (cp->trust == 0) | 1328 | if (cp->trust == 0) |