aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/gnunet-service-datastore.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datastore/gnunet-service-datastore.c')
-rw-r--r--src/datastore/gnunet-service-datastore.c299
1 files changed, 121 insertions, 178 deletions
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c
index c01de5891..8efb706c1 100644
--- a/src/datastore/gnunet-service-datastore.c
+++ b/src/datastore/gnunet-service-datastore.c
@@ -276,8 +276,8 @@ static struct GNUNET_STATISTICS_GetHandle *stat_get;
276 * @param cls not used 276 * @param cls not used
277 * @param tc task context 277 * @param tc task context
278 */ 278 */
279static void 279static void delete_expired (void *cls,
280delete_expired (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 280 const struct GNUNET_SCHEDULER_TaskContext *tc);
281 281
282 282
283/** 283/**
@@ -301,45 +301,38 @@ delete_expired (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
301 * GNUNET_NO to delete the item and continue (if supported) 301 * GNUNET_NO to delete the item and continue (if supported)
302 */ 302 */
303static int 303static int
304expired_processor (void *cls, 304expired_processor (void *cls, const GNUNET_HashCode * key, uint32_t size,
305 const GNUNET_HashCode * key, 305 const void *data, enum GNUNET_BLOCK_Type type,
306 uint32_t size, 306 uint32_t priority, uint32_t anonymity,
307 const void *data,
308 enum GNUNET_BLOCK_Type type,
309 uint32_t priority,
310 uint32_t anonymity,
311 struct GNUNET_TIME_Absolute expiration, uint64_t uid) 307 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
312{ 308{
313 struct GNUNET_TIME_Absolute now; 309 struct GNUNET_TIME_Absolute now;
314 310
315 if (key == NULL) 311 if (key == NULL)
316 { 312 {
317 expired_kill_task 313 expired_kill_task =
318 = GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY, 314 GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY, &delete_expired, NULL);
319 &delete_expired, NULL);
320 return GNUNET_SYSERR; 315 return GNUNET_SYSERR;
321 } 316 }
322 now = GNUNET_TIME_absolute_get (); 317 now = GNUNET_TIME_absolute_get ();
323 if (expiration.abs_value > now.abs_value) 318 if (expiration.abs_value > now.abs_value)
324 { 319 {
325 /* finished processing */ 320 /* finished processing */
326 expired_kill_task 321 expired_kill_task =
327 = GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY, 322 GNUNET_SCHEDULER_add_delayed (MAX_EXPIRE_DELAY, &delete_expired, NULL);
328 &delete_expired, NULL);
329 return GNUNET_SYSERR; 323 return GNUNET_SYSERR;
330 } 324 }
331#if DEBUG_DATASTORE 325#if DEBUG_DATASTORE
332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
333 "Deleting content `%s' of type %u that expired %llu ms ago\n", 327 "Deleting content `%s' of type %u that expired %llu ms ago\n",
334 GNUNET_h2s (key), 328 GNUNET_h2s (key), type,
335 type,
336 (unsigned long long) (now.abs_value - expiration.abs_value)); 329 (unsigned long long) (now.abs_value - expiration.abs_value));
337#endif 330#endif
338 GNUNET_STATISTICS_update (stats, 331 GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes expired"), size,
339 gettext_noop ("# bytes expired"), size, GNUNET_YES); 332 GNUNET_YES);
340 GNUNET_CONTAINER_bloomfilter_remove (filter, key); 333 GNUNET_CONTAINER_bloomfilter_remove (filter, key);
341 expired_kill_task 334 expired_kill_task =
342 = GNUNET_SCHEDULER_add_delayed (MIN_EXPIRE_DELAY, &delete_expired, NULL); 335 GNUNET_SCHEDULER_add_delayed (MIN_EXPIRE_DELAY, &delete_expired, NULL);
343 return GNUNET_NO; 336 return GNUNET_NO;
344} 337}
345 338
@@ -381,13 +374,9 @@ delete_expired (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
381 * GNUNET_NO to delete the item and continue (if supported) 374 * GNUNET_NO to delete the item and continue (if supported)
382 */ 375 */
383static int 376static int
384quota_processor (void *cls, 377quota_processor (void *cls, const GNUNET_HashCode * key, uint32_t size,
385 const GNUNET_HashCode * key, 378 const void *data, enum GNUNET_BLOCK_Type type,
386 uint32_t size, 379 uint32_t priority, uint32_t anonymity,
387 const void *data,
388 enum GNUNET_BLOCK_Type type,
389 uint32_t priority,
390 uint32_t anonymity,
391 struct GNUNET_TIME_Absolute expiration, uint64_t uid) 380 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
392{ 381{
393 unsigned long long *need = cls; 382 unsigned long long *need = cls;
@@ -507,10 +496,10 @@ transmit (struct GNUNET_SERVER_Client *client, struct GNUNET_MessageHeader *msg)
507 tcc->msg = msg; 496 tcc->msg = msg;
508 tcc->client = client; 497 tcc->client = client;
509 if (NULL == 498 if (NULL ==
510 (tcc->th = GNUNET_SERVER_notify_transmit_ready (client, 499 (tcc->th =
511 ntohs (msg->size), 500 GNUNET_SERVER_notify_transmit_ready (client, ntohs (msg->size),
512 GNUNET_TIME_UNIT_FOREVER_REL, 501 GNUNET_TIME_UNIT_FOREVER_REL,
513 &transmit_callback, tcc))) 502 &transmit_callback, tcc)))
514 { 503 {
515 GNUNET_break (0); 504 GNUNET_break (0);
516 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 505 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -572,14 +561,10 @@ transmit_status (struct GNUNET_SERVER_Client *client, int code, const char *msg)
572 * GNUNET_NO to delete the item and continue (if supported) 561 * GNUNET_NO to delete the item and continue (if supported)
573 */ 562 */
574static int 563static int
575transmit_item (void *cls, 564transmit_item (void *cls, const GNUNET_HashCode * key, uint32_t size,
576 const GNUNET_HashCode * key, 565 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
577 uint32_t size, 566 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
578 const void *data, 567 uint64_t uid)
579 enum GNUNET_BLOCK_Type type,
580 uint32_t priority,
581 uint32_t anonymity,
582 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
583{ 568{
584 struct GNUNET_SERVER_Client *client = cls; 569 struct GNUNET_SERVER_Client *client = cls;
585 struct GNUNET_MessageHeader *end; 570 struct GNUNET_MessageHeader *end;
@@ -589,8 +574,8 @@ transmit_item (void *cls,
589 { 574 {
590 /* transmit 'DATA_END' */ 575 /* transmit 'DATA_END' */
591#if DEBUG_DATASTORE 576#if DEBUG_DATASTORE
592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' message\n",
593 "Transmitting `%s' message\n", "DATA_END"); 578 "DATA_END");
594#endif 579#endif
595 end = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader)); 580 end = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
596 end->size = htons (sizeof (struct GNUNET_MessageHeader)); 581 end->size = htons (sizeof (struct GNUNET_MessageHeader));
@@ -618,14 +603,12 @@ transmit_item (void *cls,
618#if DEBUG_DATASTORE 603#if DEBUG_DATASTORE
619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
620 "Transmitting `%s' message for `%s' of type %u with expiration %llu (now: %llu)\n", 605 "Transmitting `%s' message for `%s' of type %u with expiration %llu (now: %llu)\n",
621 "DATA", 606 "DATA", GNUNET_h2s (key), type,
622 GNUNET_h2s (key),
623 type,
624 (unsigned long long) expiration.abs_value, 607 (unsigned long long) expiration.abs_value,
625 (unsigned long long) GNUNET_TIME_absolute_get ().abs_value); 608 (unsigned long long) GNUNET_TIME_absolute_get ().abs_value);
626#endif 609#endif
627 GNUNET_STATISTICS_update (stats, 610 GNUNET_STATISTICS_update (stats, gettext_noop ("# results found"), 1,
628 gettext_noop ("# results found"), 1, GNUNET_NO); 611 GNUNET_NO);
629 transmit (client, &dm->header); 612 transmit (client, &dm->header);
630 GNUNET_SERVER_client_drop (client); 613 GNUNET_SERVER_client_drop (client);
631 return GNUNET_OK; 614 return GNUNET_OK;
@@ -640,8 +623,7 @@ transmit_item (void *cls,
640 * @param message the actual message 623 * @param message the actual message
641 */ 624 */
642static void 625static void
643handle_reserve (void *cls, 626handle_reserve (void *cls, struct GNUNET_SERVER_Client *client,
644 struct GNUNET_SERVER_Client *client,
645 const struct GNUNET_MessageHeader *message) 627 const struct GNUNET_MessageHeader *message)
646{ 628{
647 /** 629 /**
@@ -696,8 +678,8 @@ handle_reserve (void *cls,
696 return; 678 return;
697 } 679 }
698 reserved += req; 680 reserved += req;
699 GNUNET_STATISTICS_set (stats, 681 GNUNET_STATISTICS_set (stats, gettext_noop ("# reserved"), reserved,
700 gettext_noop ("# reserved"), reserved, GNUNET_NO); 682 GNUNET_NO);
701 e = GNUNET_malloc (sizeof (struct ReservationList)); 683 e = GNUNET_malloc (sizeof (struct ReservationList));
702 e->next = reservations; 684 e->next = reservations;
703 reservations = e; 685 reservations = e;
@@ -719,8 +701,7 @@ handle_reserve (void *cls,
719 * @param message the actual message 701 * @param message the actual message
720 */ 702 */
721static void 703static void
722handle_release_reserve (void *cls, 704handle_release_reserve (void *cls, struct GNUNET_SERVER_Client *client,
723 struct GNUNET_SERVER_Client *client,
724 const struct GNUNET_MessageHeader *message) 705 const struct GNUNET_MessageHeader *message)
725{ 706{
726 const struct ReleaseReserveMessage *msg = 707 const struct ReleaseReserveMessage *msg =
@@ -732,8 +713,8 @@ handle_release_reserve (void *cls,
732 unsigned long long rem; 713 unsigned long long rem;
733 714
734#if DEBUG_DATASTORE 715#if DEBUG_DATASTORE
735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request\n",
736 "Processing `%s' request\n", "RELEASE_RESERVE"); 717 "RELEASE_RESERVE");
737#endif 718#endif
738 next = reservations; 719 next = reservations;
739 prev = NULL; 720 prev = NULL;
@@ -751,8 +732,8 @@ handle_release_reserve (void *cls,
751 ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries; 732 ((unsigned long long) GNUNET_DATASTORE_ENTRY_OVERHEAD) * pos->entries;
752 GNUNET_assert (reserved >= rem); 733 GNUNET_assert (reserved >= rem);
753 reserved -= rem; 734 reserved -= rem;
754 GNUNET_STATISTICS_set (stats, 735 GNUNET_STATISTICS_set (stats, gettext_noop ("# reserved"), reserved,
755 gettext_noop ("# reserved"), reserved, GNUNET_NO); 736 GNUNET_NO);
756#if DEBUG_DATASTORE 737#if DEBUG_DATASTORE
757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
758 "Returning %llu remaining reserved bytes to storage pool\n", 739 "Returning %llu remaining reserved bytes to storage pool\n",
@@ -830,20 +811,15 @@ execute_put (struct GNUNET_SERVER_Client *client, const struct DataMessage *dm)
830 811
831 size = ntohl (dm->size); 812 size = ntohl (dm->size);
832 msg = NULL; 813 msg = NULL;
833 ret = plugin->api->put (plugin->api->cls, 814 ret =
834 &dm->key, 815 plugin->api->put (plugin->api->cls, &dm->key, size, &dm[1],
835 size, 816 ntohl (dm->type), ntohl (dm->priority),
836 &dm[1], 817 ntohl (dm->anonymity), ntohl (dm->replication),
837 ntohl (dm->type), 818 GNUNET_TIME_absolute_ntoh (dm->expiration), &msg);
838 ntohl (dm->priority),
839 ntohl (dm->anonymity),
840 ntohl (dm->replication),
841 GNUNET_TIME_absolute_ntoh (dm->expiration), &msg);
842 if (GNUNET_OK == ret) 819 if (GNUNET_OK == ret)
843 { 820 {
844 GNUNET_STATISTICS_update (stats, 821 GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes stored"), size,
845 gettext_noop ("# bytes stored"), 822 GNUNET_YES);
846 size, GNUNET_YES);
847 GNUNET_CONTAINER_bloomfilter_add (filter, &dm->key); 823 GNUNET_CONTAINER_bloomfilter_add (filter, &dm->key);
848#if DEBUG_DATASTORE 824#if DEBUG_DATASTORE
849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 825 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -884,14 +860,10 @@ execute_put (struct GNUNET_SERVER_Client *client, const struct DataMessage *dm)
884 * GNUNET_NO to delete the item 860 * GNUNET_NO to delete the item
885 */ 861 */
886static int 862static int
887check_present (void *cls, 863check_present (void *cls, const GNUNET_HashCode * key, uint32_t size,
888 const GNUNET_HashCode * key, 864 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
889 uint32_t size, 865 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
890 const void *data, 866 uint64_t uid)
891 enum GNUNET_BLOCK_Type type,
892 uint32_t priority,
893 uint32_t anonymity,
894 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
895{ 867{
896 struct PutContext *pc = cls; 868 struct PutContext *pc = cls;
897 const struct DataMessage *dm; 869 const struct DataMessage *dm;
@@ -905,8 +877,9 @@ check_present (void *cls,
905 return GNUNET_OK; 877 return GNUNET_OK;
906 } 878 }
907 if ((GNUNET_BLOCK_TYPE_FS_DBLOCK == type) || 879 if ((GNUNET_BLOCK_TYPE_FS_DBLOCK == type) ||
908 (GNUNET_BLOCK_TYPE_FS_IBLOCK == type) || 880 (GNUNET_BLOCK_TYPE_FS_IBLOCK == type) || ((size == ntohl (dm->size)) &&
909 ((size == ntohl (dm->size)) && (0 == memcmp (&dm[1], data, size)))) 881 (0 ==
882 memcmp (&dm[1], data, size))))
910 { 883 {
911#if DEBUG_MYSQL 884#if DEBUG_MYSQL
912 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -916,8 +889,7 @@ check_present (void *cls,
916 if ((ntohl (dm->priority) > 0) || 889 if ((ntohl (dm->priority) > 0) ||
917 (GNUNET_TIME_absolute_ntoh (dm->expiration).abs_value > 890 (GNUNET_TIME_absolute_ntoh (dm->expiration).abs_value >
918 expiration.abs_value)) 891 expiration.abs_value))
919 plugin->api->update (plugin->api->cls, 892 plugin->api->update (plugin->api->cls, uid,
920 uid,
921 (int32_t) ntohl (dm->priority), 893 (int32_t) ntohl (dm->priority),
922 GNUNET_TIME_absolute_ntoh (dm->expiration), NULL); 894 GNUNET_TIME_absolute_ntoh (dm->expiration), NULL);
923 transmit_status (pc->client, GNUNET_NO, NULL); 895 transmit_status (pc->client, GNUNET_NO, NULL);
@@ -942,8 +914,7 @@ check_present (void *cls,
942 * @param message the actual message 914 * @param message the actual message
943 */ 915 */
944static void 916static void
945handle_put (void *cls, 917handle_put (void *cls, struct GNUNET_SERVER_Client *client,
946 struct GNUNET_SERVER_Client *client,
947 const struct GNUNET_MessageHeader *message) 918 const struct GNUNET_MessageHeader *message)
948{ 919{
949 const struct DataMessage *dm = check_data (message); 920 const struct DataMessage *dm = check_data (message);
@@ -961,8 +932,8 @@ handle_put (void *cls,
961 } 932 }
962#if DEBUG_DATASTORE 933#if DEBUG_DATASTORE
963 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 934 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
964 "Processing `%s' request for `%s' of type %u\n", 935 "Processing `%s' request for `%s' of type %u\n", "PUT",
965 "PUT", GNUNET_h2s (&dm->key), ntohl (dm->type)); 936 GNUNET_h2s (&dm->key), ntohl (dm->type));
966#endif 937#endif
967 rid = ntohl (dm->rid); 938 rid = ntohl (dm->rid);
968 size = ntohl (dm->size); 939 size = ntohl (dm->size);
@@ -979,8 +950,8 @@ handle_put (void *cls,
979 pos->entries--; 950 pos->entries--;
980 pos->amount -= size; 951 pos->amount -= size;
981 reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 952 reserved -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
982 GNUNET_STATISTICS_set (stats, 953 GNUNET_STATISTICS_set (stats, gettext_noop ("# reserved"), reserved,
983 gettext_noop ("# reserved"), reserved, GNUNET_NO); 954 GNUNET_NO);
984 } 955 }
985 } 956 }
986 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key)) 957 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (filter, &dm->key))
@@ -991,10 +962,8 @@ handle_put (void *cls,
991 pc->client = client; 962 pc->client = client;
992 GNUNET_SERVER_client_keep (client); 963 GNUNET_SERVER_client_keep (client);
993 memcpy (&pc[1], dm, size + sizeof (struct DataMessage)); 964 memcpy (&pc[1], dm, size + sizeof (struct DataMessage));
994 plugin->api->get_key (plugin->api->cls, 965 plugin->api->get_key (plugin->api->cls, 0, &dm->key, &vhash,
995 0, 966 ntohl (dm->type), &check_present, pc);
996 &dm->key,
997 &vhash, ntohl (dm->type), &check_present, pc);
998 return; 967 return;
999 } 968 }
1000 execute_put (client, dm); 969 execute_put (client, dm);
@@ -1009,8 +978,7 @@ handle_put (void *cls,
1009 * @param message the actual message 978 * @param message the actual message
1010 */ 979 */
1011static void 980static void
1012handle_get (void *cls, 981handle_get (void *cls, struct GNUNET_SERVER_Client *client,
1013 struct GNUNET_SERVER_Client *client,
1014 const struct GNUNET_MessageHeader *message) 982 const struct GNUNET_MessageHeader *message)
1015{ 983{
1016 const struct GetMessage *msg; 984 const struct GetMessage *msg;
@@ -1027,12 +995,11 @@ handle_get (void *cls,
1027 msg = (const struct GetMessage *) message; 995 msg = (const struct GetMessage *) message;
1028#if DEBUG_DATASTORE 996#if DEBUG_DATASTORE
1029 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 997 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1030 "Processing `%s' request for `%s' of type %u\n", 998 "Processing `%s' request for `%s' of type %u\n", "GET",
1031 "GET", GNUNET_h2s (&msg->key), ntohl (msg->type)); 999 GNUNET_h2s (&msg->key), ntohl (msg->type));
1032#endif 1000#endif
1033 GNUNET_STATISTICS_update (stats, 1001 GNUNET_STATISTICS_update (stats, gettext_noop ("# GET requests received"), 1,
1034 gettext_noop ("# GET requests received"), 1002 GNUNET_NO);
1035 1, GNUNET_NO);
1036 GNUNET_SERVER_client_keep (client); 1003 GNUNET_SERVER_client_keep (client);
1037 if ((size == sizeof (struct GetMessage)) && 1004 if ((size == sizeof (struct GetMessage)) &&
1038 (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key))) 1005 (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key)))
@@ -1051,8 +1018,7 @@ handle_get (void *cls,
1051 0); 1018 0);
1052 return; 1019 return;
1053 } 1020 }
1054 plugin->api->get_key (plugin->api->cls, 1021 plugin->api->get_key (plugin->api->cls, GNUNET_ntohll (msg->offset),
1055 GNUNET_ntohll (msg->offset),
1056 ((size == 1022 ((size ==
1057 sizeof (struct GetMessage)) ? &msg->key : NULL), NULL, 1023 sizeof (struct GetMessage)) ? &msg->key : NULL), NULL,
1058 ntohl (msg->type), &transmit_item, client); 1024 ntohl (msg->type), &transmit_item, client);
@@ -1067,29 +1033,25 @@ handle_get (void *cls,
1067 * @param message the actual message 1033 * @param message the actual message
1068 */ 1034 */
1069static void 1035static void
1070handle_update (void *cls, 1036handle_update (void *cls, struct GNUNET_SERVER_Client *client,
1071 struct GNUNET_SERVER_Client *client,
1072 const struct GNUNET_MessageHeader *message) 1037 const struct GNUNET_MessageHeader *message)
1073{ 1038{
1074 const struct UpdateMessage *msg; 1039 const struct UpdateMessage *msg;
1075 int ret; 1040 int ret;
1076 char *emsg; 1041 char *emsg;
1077 1042
1078 GNUNET_STATISTICS_update (stats, 1043 GNUNET_STATISTICS_update (stats, gettext_noop ("# UPDATE requests received"),
1079 gettext_noop ("# UPDATE requests received"),
1080 1, GNUNET_NO); 1044 1, GNUNET_NO);
1081 msg = (const struct UpdateMessage *) message; 1045 msg = (const struct UpdateMessage *) message;
1082 emsg = NULL; 1046 emsg = NULL;
1083#if DEBUG_DATASTORE 1047#if DEBUG_DATASTORE
1084 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request for %llu\n",
1085 "Processing `%s' request for %llu\n",
1086 "UPDATE", (unsigned long long) GNUNET_ntohll (msg->uid)); 1049 "UPDATE", (unsigned long long) GNUNET_ntohll (msg->uid));
1087#endif 1050#endif
1088 ret = plugin->api->update (plugin->api->cls, 1051 ret =
1089 GNUNET_ntohll (msg->uid), 1052 plugin->api->update (plugin->api->cls, GNUNET_ntohll (msg->uid),
1090 (int32_t) ntohl (msg->priority), 1053 (int32_t) ntohl (msg->priority),
1091 GNUNET_TIME_absolute_ntoh (msg->expiration), 1054 GNUNET_TIME_absolute_ntoh (msg->expiration), &emsg);
1092 &emsg);
1093 transmit_status (client, ret, emsg); 1055 transmit_status (client, ret, emsg);
1094 GNUNET_free_non_null (emsg); 1056 GNUNET_free_non_null (emsg);
1095} 1057}
@@ -1103,13 +1065,12 @@ handle_update (void *cls,
1103 * @param message the actual message 1065 * @param message the actual message
1104 */ 1066 */
1105static void 1067static void
1106handle_get_replication (void *cls, 1068handle_get_replication (void *cls, struct GNUNET_SERVER_Client *client,
1107 struct GNUNET_SERVER_Client *client,
1108 const struct GNUNET_MessageHeader *message) 1069 const struct GNUNET_MessageHeader *message)
1109{ 1070{
1110#if DEBUG_DATASTORE 1071#if DEBUG_DATASTORE
1111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1072 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request\n",
1112 "Processing `%s' request\n", "GET_REPLICATION"); 1073 "GET_REPLICATION");
1113#endif 1074#endif
1114 GNUNET_STATISTICS_update (stats, 1075 GNUNET_STATISTICS_update (stats,
1115 gettext_noop 1076 gettext_noop
@@ -1128,8 +1089,7 @@ handle_get_replication (void *cls,
1128 * @param message the actual message 1089 * @param message the actual message
1129 */ 1090 */
1130static void 1091static void
1131handle_get_zero_anonymity (void *cls, 1092handle_get_zero_anonymity (void *cls, struct GNUNET_SERVER_Client *client,
1132 struct GNUNET_SERVER_Client *client,
1133 const struct GNUNET_MessageHeader *message) 1093 const struct GNUNET_MessageHeader *message)
1134{ 1094{
1135 const struct GetZeroAnonymityMessage *msg = 1095 const struct GetZeroAnonymityMessage *msg =
@@ -1144,8 +1104,8 @@ handle_get_zero_anonymity (void *cls,
1144 return; 1104 return;
1145 } 1105 }
1146#if DEBUG_DATASTORE 1106#if DEBUG_DATASTORE
1147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request\n",
1148 "Processing `%s' request\n", "GET_ZERO_ANONYMITY"); 1108 "GET_ZERO_ANONYMITY");
1149#endif 1109#endif
1150 GNUNET_STATISTICS_update (stats, 1110 GNUNET_STATISTICS_update (stats,
1151 gettext_noop 1111 gettext_noop
@@ -1153,8 +1113,8 @@ handle_get_zero_anonymity (void *cls,
1153 GNUNET_NO); 1113 GNUNET_NO);
1154 GNUNET_SERVER_client_keep (client); 1114 GNUNET_SERVER_client_keep (client);
1155 plugin->api->get_zero_anonymity (plugin->api->cls, 1115 plugin->api->get_zero_anonymity (plugin->api->cls,
1156 GNUNET_ntohll (msg->offset), 1116 GNUNET_ntohll (msg->offset), type,
1157 type, &transmit_item, client); 1117 &transmit_item, client);
1158} 1118}
1159 1119
1160 1120
@@ -1163,13 +1123,9 @@ handle_get_zero_anonymity (void *cls,
1163 * in to be deleted (by returning GNUNET_NO). 1123 * in to be deleted (by returning GNUNET_NO).
1164 */ 1124 */
1165static int 1125static int
1166remove_callback (void *cls, 1126remove_callback (void *cls, const GNUNET_HashCode * key, uint32_t size,
1167 const GNUNET_HashCode * key, 1127 const void *data, enum GNUNET_BLOCK_Type type,
1168 uint32_t size, 1128 uint32_t priority, uint32_t anonymity,
1169 const void *data,
1170 enum GNUNET_BLOCK_Type type,
1171 uint32_t priority,
1172 uint32_t anonymity,
1173 struct GNUNET_TIME_Absolute expiration, uint64_t uid) 1129 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
1174{ 1130{
1175 struct GNUNET_SERVER_Client *client = cls; 1131 struct GNUNET_SERVER_Client *client = cls;
@@ -1207,8 +1163,7 @@ remove_callback (void *cls,
1207 * @param message the actual message 1163 * @param message the actual message
1208 */ 1164 */
1209static void 1165static void
1210handle_remove (void *cls, 1166handle_remove (void *cls, struct GNUNET_SERVER_Client *client,
1211 struct GNUNET_SERVER_Client *client,
1212 const struct GNUNET_MessageHeader *message) 1167 const struct GNUNET_MessageHeader *message)
1213{ 1168{
1214 const struct DataMessage *dm = check_data (message); 1169 const struct DataMessage *dm = check_data (message);
@@ -1222,18 +1177,14 @@ handle_remove (void *cls,
1222 } 1177 }
1223#if DEBUG_DATASTORE 1178#if DEBUG_DATASTORE
1224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1225 "Processing `%s' request for `%s' of type %u\n", 1180 "Processing `%s' request for `%s' of type %u\n", "REMOVE",
1226 "REMOVE", GNUNET_h2s (&dm->key), ntohl (dm->type)); 1181 GNUNET_h2s (&dm->key), ntohl (dm->type));
1227#endif 1182#endif
1228 GNUNET_STATISTICS_update (stats, 1183 GNUNET_STATISTICS_update (stats, gettext_noop ("# REMOVE requests received"),
1229 gettext_noop ("# REMOVE requests received"),
1230 1, GNUNET_NO); 1184 1, GNUNET_NO);
1231 GNUNET_SERVER_client_keep (client); 1185 GNUNET_SERVER_client_keep (client);
1232 GNUNET_CRYPTO_hash (&dm[1], ntohl (dm->size), &vhash); 1186 GNUNET_CRYPTO_hash (&dm[1], ntohl (dm->size), &vhash);
1233 plugin->api->get_key (plugin->api->cls, 1187 plugin->api->get_key (plugin->api->cls, 0, &dm->key, &vhash,
1234 0,
1235 &dm->key,
1236 &vhash,
1237 (enum GNUNET_BLOCK_Type) ntohl (dm->type), 1188 (enum GNUNET_BLOCK_Type) ntohl (dm->type),
1238 &remove_callback, client); 1189 &remove_callback, client);
1239} 1190}
@@ -1247,8 +1198,7 @@ handle_remove (void *cls,
1247 * @param message the actual message 1198 * @param message the actual message
1248 */ 1199 */
1249static void 1200static void
1250handle_drop (void *cls, 1201handle_drop (void *cls, struct GNUNET_SERVER_Client *client,
1251 struct GNUNET_SERVER_Client *client,
1252 const struct GNUNET_MessageHeader *message) 1202 const struct GNUNET_MessageHeader *message)
1253{ 1203{
1254#if DEBUG_DATASTORE 1204#if DEBUG_DATASTORE
@@ -1298,9 +1248,8 @@ disk_utilization_change_cb (void *cls, int delta)
1298 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 1248 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
1299 */ 1249 */
1300static int 1250static int
1301process_stat_in (void *cls, 1251process_stat_in (void *cls, const char *subsystem, const char *name,
1302 const char *subsystem, 1252 uint64_t value, int is_persistent)
1303 const char *name, uint64_t value, int is_persistent)
1304{ 1253{
1305 GNUNET_assert (stats_worked == GNUNET_NO); 1254 GNUNET_assert (stats_worked == GNUNET_NO);
1306 stats_worked = GNUNET_YES; 1255 stats_worked = GNUNET_YES;
@@ -1336,20 +1285,20 @@ load_plugin ()
1336 char *name; 1285 char *name;
1337 1286
1338 if (GNUNET_OK != 1287 if (GNUNET_OK !=
1339 GNUNET_CONFIGURATION_get_value_string (cfg, 1288 GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE",
1340 "DATASTORE", "DATABASE", &name)) 1289 &name))
1341 { 1290 {
1342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1291 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1343 _("No `%s' specified for `%s' in configuration!\n"), 1292 _("No `%s' specified for `%s' in configuration!\n"), "DATABASE",
1344 "DATABASE", "DATASTORE"); 1293 "DATASTORE");
1345 return NULL; 1294 return NULL;
1346 } 1295 }
1347 ret = GNUNET_malloc (sizeof (struct DatastorePlugin)); 1296 ret = GNUNET_malloc (sizeof (struct DatastorePlugin));
1348 ret->env.cfg = cfg; 1297 ret->env.cfg = cfg;
1349 ret->env.duc = &disk_utilization_change_cb; 1298 ret->env.duc = &disk_utilization_change_cb;
1350 ret->env.cls = NULL; 1299 ret->env.cls = NULL;
1351 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1300 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"),
1352 _("Loading `%s' datastore plugin\n"), name); 1301 name);
1353 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); 1302 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
1354 ret->short_name = name; 1303 ret->short_name = name;
1355 ret->lib_name = libname; 1304 ret->lib_name = libname;
@@ -1444,8 +1393,8 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1444 GNUNET_SCHEDULER_cancel (expired_kill_task); 1393 GNUNET_SCHEDULER_cancel (expired_kill_task);
1445 expired_kill_task = GNUNET_SCHEDULER_NO_TASK; 1394 expired_kill_task = GNUNET_SCHEDULER_NO_TASK;
1446 } 1395 }
1447 GNUNET_SCHEDULER_add_continuation (&unload_task, 1396 GNUNET_SCHEDULER_add_continuation (&unload_task, NULL,
1448 NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); 1397 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1449} 1398}
1450 1399
1451 1400
@@ -1486,8 +1435,8 @@ cleanup_reservations (void *cls, struct GNUNET_SERVER_Client *client)
1486 } 1435 }
1487 pos = next; 1436 pos = next;
1488 } 1437 }
1489 GNUNET_STATISTICS_set (stats, 1438 GNUNET_STATISTICS_set (stats, gettext_noop ("# reserved"), reserved,
1490 gettext_noop ("# reserved"), reserved, GNUNET_NO); 1439 GNUNET_NO);
1491} 1440}
1492 1441
1493 1442
@@ -1499,8 +1448,7 @@ cleanup_reservations (void *cls, struct GNUNET_SERVER_Client *client)
1499 * @param c configuration to use 1448 * @param c configuration to use
1500 */ 1449 */
1501static void 1450static void
1502run (void *cls, 1451run (void *cls, struct GNUNET_SERVER_Handle *server,
1503 struct GNUNET_SERVER_Handle *server,
1504 const struct GNUNET_CONFIGURATION_Handle *c) 1452 const struct GNUNET_CONFIGURATION_Handle *c)
1505{ 1453{
1506 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 1454 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -1532,21 +1480,19 @@ run (void *cls,
1532 GNUNET_CONFIGURATION_get_value_number (cfg, "DATASTORE", "QUOTA", &quota)) 1480 GNUNET_CONFIGURATION_get_value_number (cfg, "DATASTORE", "QUOTA", &quota))
1533 { 1481 {
1534 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1482 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1535 _("No `%s' specified for `%s' in configuration!\n"), 1483 _("No `%s' specified for `%s' in configuration!\n"), "QUOTA",
1536 "QUOTA", "DATASTORE"); 1484 "DATASTORE");
1537 return; 1485 return;
1538 } 1486 }
1539 stats = GNUNET_STATISTICS_create ("datastore", cfg); 1487 stats = GNUNET_STATISTICS_create ("datastore", cfg);
1540 GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO); 1488 GNUNET_STATISTICS_set (stats, gettext_noop ("# quota"), quota, GNUNET_NO);
1541 cache_size = quota / 8; /* Or should we make this an option? */ 1489 cache_size = quota / 8; /* Or should we make this an option? */
1542 GNUNET_STATISTICS_set (stats, 1490 GNUNET_STATISTICS_set (stats, gettext_noop ("# cache size"), cache_size,
1543 gettext_noop ("# cache size"), cache_size, GNUNET_NO); 1491 GNUNET_NO);
1544 bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */ 1492 bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
1545 fn = NULL; 1493 fn = NULL;
1546 if ((GNUNET_OK != 1494 if ((GNUNET_OK !=
1547 GNUNET_CONFIGURATION_get_value_filename (cfg, 1495 GNUNET_CONFIGURATION_get_value_filename (cfg, "DATASTORE", "BLOOMFILTER",
1548 "DATASTORE",
1549 "BLOOMFILTER",
1550 &fn)) || 1496 &fn)) ||
1551 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn))) 1497 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)))
1552 { 1498 {
@@ -1584,19 +1530,17 @@ run (void *cls,
1584 } 1530 }
1585 return; 1531 return;
1586 } 1532 }
1587 stat_get = GNUNET_STATISTICS_get (stats, 1533 stat_get =
1588 "datastore", 1534 GNUNET_STATISTICS_get (stats, "datastore", QUOTA_STAT_NAME,
1589 QUOTA_STAT_NAME, 1535 GNUNET_TIME_UNIT_SECONDS, &process_stat_done,
1590 GNUNET_TIME_UNIT_SECONDS, 1536 &process_stat_in, plugin);
1591 &process_stat_done,
1592 &process_stat_in, plugin);
1593 GNUNET_SERVER_disconnect_notify (server, &cleanup_reservations, NULL); 1537 GNUNET_SERVER_disconnect_notify (server, &cleanup_reservations, NULL);
1594 GNUNET_SERVER_add_handlers (server, handlers); 1538 GNUNET_SERVER_add_handlers (server, handlers);
1595 expired_kill_task 1539 expired_kill_task =
1596 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1540 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1597 &delete_expired, NULL); 1541 &delete_expired, NULL);
1598 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1542 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task,
1599 &cleaning_task, NULL); 1543 NULL);
1600} 1544}
1601 1545
1602 1546
@@ -1612,11 +1556,10 @@ main (int argc, char *const *argv)
1612{ 1556{
1613 int ret; 1557 int ret;
1614 1558
1615 ret = (GNUNET_OK == 1559 ret =
1616 GNUNET_SERVICE_run (argc, 1560 (GNUNET_OK ==
1617 argv, 1561 GNUNET_SERVICE_run (argc, argv, "datastore", GNUNET_SERVICE_OPTION_NONE,
1618 "datastore", 1562 &run, NULL)) ? 0 : 1;
1619 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
1620 return ret; 1563 return ret;
1621} 1564}
1622 1565