diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-03-31 15:35:00 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-03-31 15:35:00 +0000 |
commit | dfe8a19d9d0aebc8711992a99628732dbe674621 (patch) | |
tree | 12f188f126d79ac73f8d46f112b53e34c7e5e677 /src/fs/gnunet-service-fs_pr.c | |
parent | b6f0365dd1cf3fbd6af64500cf9547583989e68b (diff) | |
download | gnunet-dfe8a19d9d0aebc8711992a99628732dbe674621.tar.gz gnunet-dfe8a19d9d0aebc8711992a99628732dbe674621.zip |
fix migration support
Diffstat (limited to 'src/fs/gnunet-service-fs_pr.c')
-rw-r--r-- | src/fs/gnunet-service-fs_pr.c | 81 |
1 files changed, 69 insertions, 12 deletions
diff --git a/src/fs/gnunet-service-fs_pr.c b/src/fs/gnunet-service-fs_pr.c index ed156daf5..f6b31c4e2 100644 --- a/src/fs/gnunet-service-fs_pr.c +++ b/src/fs/gnunet-service-fs_pr.c | |||
@@ -760,6 +760,30 @@ process_reply (void *cls, | |||
760 | 760 | ||
761 | 761 | ||
762 | /** | 762 | /** |
763 | * Context for the 'put_migration_continuation'. | ||
764 | */ | ||
765 | struct PutMigrationContext | ||
766 | { | ||
767 | |||
768 | /** | ||
769 | * Start time for the operation. | ||
770 | */ | ||
771 | struct GNUNET_TIME_Absolute start; | ||
772 | |||
773 | /** | ||
774 | * Request origin. | ||
775 | */ | ||
776 | struct GNUNET_PeerIdentity origin; | ||
777 | |||
778 | /** | ||
779 | * GNUNET_YES if we had a matching request for this block, | ||
780 | * GNUNET_NO if not. | ||
781 | */ | ||
782 | int requested; | ||
783 | }; | ||
784 | |||
785 | |||
786 | /** | ||
763 | * Continuation called to notify client about result of the | 787 | * Continuation called to notify client about result of the |
764 | * operation. | 788 | * operation. |
765 | * | 789 | * |
@@ -772,11 +796,37 @@ put_migration_continuation (void *cls, | |||
772 | int success, | 796 | int success, |
773 | const char *msg) | 797 | const char *msg) |
774 | { | 798 | { |
775 | struct GNUNET_TIME_Absolute *start = cls; | 799 | struct PutMigrationContext *pmc = cls; |
776 | struct GNUNET_TIME_Relative delay; | 800 | struct GNUNET_TIME_Relative delay; |
777 | 801 | struct GNUNET_TIME_Relative block_time; | |
778 | delay = GNUNET_TIME_absolute_get_duration (*start); | 802 | struct GSF_ConnectedPeer *cp; |
779 | GNUNET_free (start); | 803 | struct GSF_PeerPerformanceData *ppd; |
804 | |||
805 | delay = GNUNET_TIME_absolute_get_duration (pmc->start); | ||
806 | cp = GSF_peer_get_ (&pmc->origin); | ||
807 | if ( (GNUNET_OK != success) && | ||
808 | (GNUNET_NO == pmc->requested) ) | ||
809 | { | ||
810 | /* block migration for a bit... */ | ||
811 | if (NULL != cp) | ||
812 | { | ||
813 | ppd = GSF_get_peer_performance_data_ (cp); | ||
814 | ppd->migration_duplication++; | ||
815 | block_time = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
816 | 5 * ppd->migration_duplication + | ||
817 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 5)); | ||
818 | GSF_block_peer_migration_ (cp, block_time); | ||
819 | } | ||
820 | } | ||
821 | else | ||
822 | { | ||
823 | if (NULL != cp) | ||
824 | { | ||
825 | ppd = GSF_get_peer_performance_data_ (cp); | ||
826 | ppd->migration_duplication = 0; /* reset counter */ | ||
827 | } | ||
828 | } | ||
829 | GNUNET_free (pmc); | ||
780 | /* FIXME: should we really update the load value on failure? */ | 830 | /* FIXME: should we really update the load value on failure? */ |
781 | GNUNET_LOAD_update (datastore_put_load, | 831 | GNUNET_LOAD_update (datastore_put_load, |
782 | delay.rel_value); | 832 | delay.rel_value); |
@@ -842,7 +892,7 @@ handle_dht_reply (void *cls, | |||
842 | { | 892 | { |
843 | struct GSF_PendingRequest *pr = cls; | 893 | struct GSF_PendingRequest *pr = cls; |
844 | struct ProcessReplyClosure prq; | 894 | struct ProcessReplyClosure prq; |
845 | struct GNUNET_TIME_Absolute *start; | 895 | struct PutMigrationContext *pmc; |
846 | 896 | ||
847 | memset (&prq, 0, sizeof (prq)); | 897 | memset (&prq, 0, sizeof (prq)); |
848 | prq.data = data; | 898 | prq.data = data; |
@@ -859,8 +909,9 @@ handle_dht_reply (void *cls, | |||
859 | GNUNET_h2s (key), | 909 | GNUNET_h2s (key), |
860 | prq.priority); | 910 | prq.priority); |
861 | #endif | 911 | #endif |
862 | start = GNUNET_malloc (sizeof (struct GNUNET_TIME_Absolute)); | 912 | pmc = GNUNET_malloc (sizeof (struct PutMigrationContext)); |
863 | *start = GNUNET_TIME_absolute_get (); | 913 | pmc->start = GNUNET_TIME_absolute_get (); |
914 | pmc->requested = GNUNET_YES; | ||
864 | GNUNET_DATASTORE_put (GSF_dsh, | 915 | GNUNET_DATASTORE_put (GSF_dsh, |
865 | 0, key, size, data, | 916 | 0, key, size, data, |
866 | type, prq.priority, 1 /* anonymity */, | 917 | type, prq.priority, 1 /* anonymity */, |
@@ -868,7 +919,7 @@ handle_dht_reply (void *cls, | |||
868 | 1 + prq.priority, MAX_DATASTORE_QUEUE, | 919 | 1 + prq.priority, MAX_DATASTORE_QUEUE, |
869 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | 920 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, |
870 | &put_migration_continuation, | 921 | &put_migration_continuation, |
871 | start); | 922 | pmc); |
872 | } | 923 | } |
873 | } | 924 | } |
874 | 925 | ||
@@ -1124,7 +1175,7 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp, | |||
1124 | struct ProcessReplyClosure prq; | 1175 | struct ProcessReplyClosure prq; |
1125 | struct GNUNET_TIME_Relative block_time; | 1176 | struct GNUNET_TIME_Relative block_time; |
1126 | double putl; | 1177 | double putl; |
1127 | struct GNUNET_TIME_Absolute *start; | 1178 | struct PutMigrationContext *pmc; |
1128 | 1179 | ||
1129 | msize = ntohs (message->size); | 1180 | msize = ntohs (message->size); |
1130 | if (msize < sizeof (struct PutMessage)) | 1181 | if (msize < sizeof (struct PutMessage)) |
@@ -1178,8 +1229,11 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp, | |||
1178 | GNUNET_h2s (&query), | 1229 | GNUNET_h2s (&query), |
1179 | prq.priority); | 1230 | prq.priority); |
1180 | #endif | 1231 | #endif |
1181 | start = GNUNET_malloc (sizeof (struct GNUNET_TIME_Absolute)); | 1232 | pmc = GNUNET_malloc (sizeof (struct PutMigrationContext)); |
1182 | *start = GNUNET_TIME_absolute_get (); | 1233 | pmc->start = GNUNET_TIME_absolute_get (); |
1234 | pmc->requested = prq.request_found; | ||
1235 | GNUNET_PEER_resolve (GSF_get_peer_performance_data_ (cp)->pid, | ||
1236 | &pmc->origin); | ||
1183 | GNUNET_DATASTORE_put (GSF_dsh, | 1237 | GNUNET_DATASTORE_put (GSF_dsh, |
1184 | 0, &query, dsize, &put[1], | 1238 | 0, &query, dsize, &put[1], |
1185 | type, prq.priority, 1 /* anonymity */, | 1239 | type, prq.priority, 1 /* anonymity */, |
@@ -1187,7 +1241,7 @@ GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp, | |||
1187 | 1 + prq.priority, MAX_DATASTORE_QUEUE, | 1241 | 1 + prq.priority, MAX_DATASTORE_QUEUE, |
1188 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | 1242 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, |
1189 | &put_migration_continuation, | 1243 | &put_migration_continuation, |
1190 | start); | 1244 | pmc); |
1191 | } | 1245 | } |
1192 | else | 1246 | else |
1193 | { | 1247 | { |
@@ -1232,6 +1286,9 @@ GSF_pending_request_init_ () | |||
1232 | _("Configuration fails to specify `%s', assuming default value."), | 1286 | _("Configuration fails to specify `%s', assuming default value."), |
1233 | "MAX_PENDING_REQUESTS"); | 1287 | "MAX_PENDING_REQUESTS"); |
1234 | } | 1288 | } |
1289 | active_to_migration = GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, | ||
1290 | "FS", | ||
1291 | "CONTENT_CACHING"); | ||
1235 | datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); | 1292 | datastore_put_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE); |
1236 | pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024); | 1293 | pr_map = GNUNET_CONTAINER_multihashmap_create (32 * 1024); |
1237 | requests_by_expiration_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 1294 | requests_by_expiration_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |