diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-03-14 22:40:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-03-14 22:40:04 +0000 |
commit | 4c1791f13283df27338cd877e2087d519aaab05e (patch) | |
tree | b852de95aa307225befc78c54624811f3a79e344 /src/datastore/gnunet-service-datastore.c | |
parent | 165f050555ce4f06380cc26c1dc09235c7b135e6 (diff) | |
download | gnunet-4c1791f13283df27338cd877e2087d519aaab05e.tar.gz gnunet-4c1791f13283df27338cd877e2087d519aaab05e.zip |
-bugfix, adding comments, fixing indent
Diffstat (limited to 'src/datastore/gnunet-service-datastore.c')
-rw-r--r-- | src/datastore/gnunet-service-datastore.c | 141 |
1 files changed, 94 insertions, 47 deletions
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index ba8baf719..4979f4482 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c | |||
@@ -681,7 +681,8 @@ handle_reserve (void *cls, struct GNUNET_SERVER_Client *client, | |||
681 | uint64_t amount; | 681 | uint64_t amount; |
682 | uint32_t entries; | 682 | uint32_t entries; |
683 | 683 | ||
684 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request\n", "RESERVE"); | 684 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
685 | "Processing RESERVE request\n"); | ||
685 | amount = GNUNET_ntohll (msg->amount); | 686 | amount = GNUNET_ntohll (msg->amount); |
686 | entries = ntohl (msg->entries); | 687 | entries = ntohl (msg->entries); |
687 | used = payload + reserved; | 688 | used = payload + reserved; |
@@ -757,8 +758,7 @@ handle_release_reserve (void *cls, | |||
757 | unsigned long long rem; | 758 | unsigned long long rem; |
758 | 759 | ||
759 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 760 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
760 | "Processing `%s' request\n", | 761 | "Processing RELEASE_RESERVE request\n"); |
761 | "RELEASE_RESERVE"); | ||
762 | next = reservations; | 762 | next = reservations; |
763 | prev = NULL; | 763 | prev = NULL; |
764 | while (NULL != (pos = next)) | 764 | while (NULL != (pos = next)) |
@@ -905,6 +905,12 @@ execute_put (struct PutContext *pc) | |||
905 | } | 905 | } |
906 | 906 | ||
907 | 907 | ||
908 | /** | ||
909 | * | ||
910 | * @param cls closure | ||
911 | * @param status #GNUNET_OK or #GNUNET_SYSERR | ||
912 | * @param msg error message on error | ||
913 | */ | ||
908 | static void | 914 | static void |
909 | check_present_continuation (void *cls, | 915 | check_present_continuation (void *cls, |
910 | int status, | 916 | int status, |
@@ -954,10 +960,10 @@ check_present (void *cls, | |||
954 | execute_put (pc); | 960 | execute_put (pc); |
955 | return GNUNET_OK; | 961 | return GNUNET_OK; |
956 | } | 962 | } |
957 | if ((GNUNET_BLOCK_TYPE_FS_DBLOCK == type) || | 963 | if ( (GNUNET_BLOCK_TYPE_FS_DBLOCK == type) || |
958 | (GNUNET_BLOCK_TYPE_FS_IBLOCK == type) || ((size == ntohl (dm->size)) && | 964 | (GNUNET_BLOCK_TYPE_FS_IBLOCK == type) || |
959 | (0 == | 965 | ( (size == ntohl (dm->size)) && |
960 | memcmp (&dm[1], data, size)))) | 966 | (0 == memcmp (&dm[1], data, size)) ) ) |
961 | { | 967 | { |
962 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 968 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
963 | "Result already present in datastore\n"); | 969 | "Result already present in datastore\n"); |
@@ -994,7 +1000,8 @@ check_present (void *cls, | |||
994 | * @param message the actual message | 1000 | * @param message the actual message |
995 | */ | 1001 | */ |
996 | static void | 1002 | static void |
997 | handle_put (void *cls, struct GNUNET_SERVER_Client *client, | 1003 | handle_put (void *cls, |
1004 | struct GNUNET_SERVER_Client *client, | ||
998 | const struct GNUNET_MessageHeader *message) | 1005 | const struct GNUNET_MessageHeader *message) |
999 | { | 1006 | { |
1000 | const struct DataMessage *dm = check_data (message); | 1007 | const struct DataMessage *dm = check_data (message); |
@@ -1011,8 +1018,9 @@ handle_put (void *cls, struct GNUNET_SERVER_Client *client, | |||
1011 | return; | 1018 | return; |
1012 | } | 1019 | } |
1013 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1020 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1014 | "Processing `%s' request for `%s' of type %u\n", "PUT", | 1021 | "Processing PUT request for `%s' of type %u\n", |
1015 | GNUNET_h2s (&dm->key), ntohl (dm->type)); | 1022 | GNUNET_h2s (&dm->key), |
1023 | ntohl (dm->type)); | ||
1016 | rid = ntohl (dm->rid); | 1024 | rid = ntohl (dm->rid); |
1017 | size = ntohl (dm->size); | 1025 | size = ntohl (dm->size); |
1018 | if (rid > 0) | 1026 | if (rid > 0) |
@@ -1063,7 +1071,8 @@ handle_put (void *cls, struct GNUNET_SERVER_Client *client, | |||
1063 | * @param message the actual message | 1071 | * @param message the actual message |
1064 | */ | 1072 | */ |
1065 | static void | 1073 | static void |
1066 | handle_get (void *cls, struct GNUNET_SERVER_Client *client, | 1074 | handle_get (void *cls, |
1075 | struct GNUNET_SERVER_Client *client, | ||
1067 | const struct GNUNET_MessageHeader *message) | 1076 | const struct GNUNET_MessageHeader *message) |
1068 | { | 1077 | { |
1069 | const struct GetMessage *msg; | 1078 | const struct GetMessage *msg; |
@@ -1079,20 +1088,21 @@ handle_get (void *cls, struct GNUNET_SERVER_Client *client, | |||
1079 | } | 1088 | } |
1080 | msg = (const struct GetMessage *) message; | 1089 | msg = (const struct GetMessage *) message; |
1081 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1090 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1082 | "Processing `%s' request for `%s' of type %u\n", "GET", | 1091 | "Processing GET request for `%s' of type %u\n", |
1083 | GNUNET_h2s (&msg->key), ntohl (msg->type)); | 1092 | GNUNET_h2s (&msg->key), |
1093 | ntohl (msg->type)); | ||
1084 | GNUNET_STATISTICS_update (stats, | 1094 | GNUNET_STATISTICS_update (stats, |
1085 | gettext_noop ("# GET requests received"), | 1095 | gettext_noop ("# GET requests received"), |
1086 | 1, | 1096 | 1, |
1087 | GNUNET_NO); | 1097 | GNUNET_NO); |
1088 | GNUNET_SERVER_client_keep (client); | 1098 | GNUNET_SERVER_client_keep (client); |
1089 | if ((size == sizeof (struct GetMessage)) && | 1099 | if ( (size == sizeof (struct GetMessage)) && |
1090 | (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key))) | 1100 | (GNUNET_YES != GNUNET_CONTAINER_bloomfilter_test (filter, &msg->key)) ) |
1091 | { | 1101 | { |
1092 | /* don't bother database... */ | 1102 | /* don't bother database... */ |
1093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1094 | "Empty result set for `%s' request for `%s' (bloomfilter).\n", | 1104 | "Empty result set for GET request for `%s' (bloomfilter).\n", |
1095 | "GET", GNUNET_h2s (&msg->key)); | 1105 | GNUNET_h2s (&msg->key)); |
1096 | GNUNET_STATISTICS_update (stats, | 1106 | GNUNET_STATISTICS_update (stats, |
1097 | gettext_noop | 1107 | gettext_noop |
1098 | ("# requests filtered by bloomfilter"), | 1108 | ("# requests filtered by bloomfilter"), |
@@ -1109,6 +1119,13 @@ handle_get (void *cls, struct GNUNET_SERVER_Client *client, | |||
1109 | } | 1119 | } |
1110 | 1120 | ||
1111 | 1121 | ||
1122 | /** | ||
1123 | * Function called with the result of an update operation. | ||
1124 | * | ||
1125 | * @param cls closure | ||
1126 | * @param status #GNUNET_OK or #GNUNET_SYSERR | ||
1127 | * @param msg error message on error | ||
1128 | */ | ||
1112 | static void | 1129 | static void |
1113 | update_continuation (void *cls, | 1130 | update_continuation (void *cls, |
1114 | int status, | 1131 | int status, |
@@ -1129,7 +1146,8 @@ update_continuation (void *cls, | |||
1129 | * @param message the actual message | 1146 | * @param message the actual message |
1130 | */ | 1147 | */ |
1131 | static void | 1148 | static void |
1132 | handle_update (void *cls, struct GNUNET_SERVER_Client *client, | 1149 | handle_update (void *cls, |
1150 | struct GNUNET_SERVER_Client *client, | ||
1133 | const struct GNUNET_MessageHeader *message) | 1151 | const struct GNUNET_MessageHeader *message) |
1134 | { | 1152 | { |
1135 | const struct UpdateMessage *msg; | 1153 | const struct UpdateMessage *msg; |
@@ -1139,13 +1157,15 @@ handle_update (void *cls, struct GNUNET_SERVER_Client *client, | |||
1139 | 1, | 1157 | 1, |
1140 | GNUNET_NO); | 1158 | GNUNET_NO); |
1141 | msg = (const struct UpdateMessage *) message; | 1159 | msg = (const struct UpdateMessage *) message; |
1142 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' request for %llu\n", | 1160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1143 | "UPDATE", (unsigned long long) GNUNET_ntohll (msg->uid)); | 1161 | "Processing UPDATE request for %llu\n", |
1162 | (unsigned long long) GNUNET_ntohll (msg->uid)); | ||
1144 | GNUNET_SERVER_client_keep (client); | 1163 | GNUNET_SERVER_client_keep (client); |
1145 | plugin->api->update (plugin->api->cls, GNUNET_ntohll (msg->uid), | 1164 | plugin->api->update (plugin->api->cls, |
1165 | GNUNET_ntohll (msg->uid), | ||
1146 | (int32_t) ntohl (msg->priority), | 1166 | (int32_t) ntohl (msg->priority), |
1147 | GNUNET_TIME_absolute_ntoh (msg->expiration), | 1167 | GNUNET_TIME_absolute_ntoh (msg->expiration), |
1148 | update_continuation, client); | 1168 | &update_continuation, client); |
1149 | } | 1169 | } |
1150 | 1170 | ||
1151 | 1171 | ||
@@ -1157,7 +1177,8 @@ handle_update (void *cls, struct GNUNET_SERVER_Client *client, | |||
1157 | * @param message the actual message | 1177 | * @param message the actual message |
1158 | */ | 1178 | */ |
1159 | static void | 1179 | static void |
1160 | handle_get_replication (void *cls, struct GNUNET_SERVER_Client *client, | 1180 | handle_get_replication (void *cls, |
1181 | struct GNUNET_SERVER_Client *client, | ||
1161 | const struct GNUNET_MessageHeader *message) | 1182 | const struct GNUNET_MessageHeader *message) |
1162 | { | 1183 | { |
1163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1168,7 +1189,8 @@ handle_get_replication (void *cls, struct GNUNET_SERVER_Client *client, | |||
1168 | 1, | 1189 | 1, |
1169 | GNUNET_NO); | 1190 | GNUNET_NO); |
1170 | GNUNET_SERVER_client_keep (client); | 1191 | GNUNET_SERVER_client_keep (client); |
1171 | plugin->api->get_replication (plugin->api->cls, &transmit_item, client); | 1192 | plugin->api->get_replication (plugin->api->cls, |
1193 | &transmit_item, client); | ||
1172 | } | 1194 | } |
1173 | 1195 | ||
1174 | 1196 | ||
@@ -1180,7 +1202,8 @@ handle_get_replication (void *cls, struct GNUNET_SERVER_Client *client, | |||
1180 | * @param message the actual message | 1202 | * @param message the actual message |
1181 | */ | 1203 | */ |
1182 | static void | 1204 | static void |
1183 | handle_get_zero_anonymity (void *cls, struct GNUNET_SERVER_Client *client, | 1205 | handle_get_zero_anonymity (void *cls, |
1206 | struct GNUNET_SERVER_Client *client, | ||
1184 | const struct GNUNET_MessageHeader *message) | 1207 | const struct GNUNET_MessageHeader *message) |
1185 | { | 1208 | { |
1186 | const struct GetZeroAnonymityMessage *msg = | 1209 | const struct GetZeroAnonymityMessage *msg = |
@@ -1203,28 +1226,45 @@ handle_get_zero_anonymity (void *cls, struct GNUNET_SERVER_Client *client, | |||
1203 | GNUNET_NO); | 1226 | GNUNET_NO); |
1204 | GNUNET_SERVER_client_keep (client); | 1227 | GNUNET_SERVER_client_keep (client); |
1205 | plugin->api->get_zero_anonymity (plugin->api->cls, | 1228 | plugin->api->get_zero_anonymity (plugin->api->cls, |
1206 | GNUNET_ntohll (msg->offset), type, | 1229 | GNUNET_ntohll (msg->offset), |
1230 | type, | ||
1207 | &transmit_item, client); | 1231 | &transmit_item, client); |
1208 | } | 1232 | } |
1209 | 1233 | ||
1210 | 1234 | ||
1211 | /** | 1235 | /** |
1212 | * Callback function that will cause the item that is passed | 1236 | * Callback function that will cause the item that is passed |
1213 | * in to be deleted (by returning GNUNET_NO). | 1237 | * in to be deleted (by returning #GNUNET_NO). |
1238 | * | ||
1239 | * @param cls closure | ||
1240 | * @param key key for the content | ||
1241 | * @param size number of bytes in data | ||
1242 | * @param data content stored | ||
1243 | * @param type type of the content | ||
1244 | * @param priority priority of the content | ||
1245 | * @param anonymity anonymity-level for the content | ||
1246 | * @param expiration expiration time for the content | ||
1247 | * @param uid unique identifier for the datum | ||
1248 | * @return #GNUNET_OK to keep the item | ||
1249 | * #GNUNET_NO to delete the item | ||
1214 | */ | 1250 | */ |
1215 | static int | 1251 | static int |
1216 | remove_callback (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | 1252 | remove_callback (void *cls, |
1217 | const void *data, enum GNUNET_BLOCK_Type type, | 1253 | const struct GNUNET_HashCode *key, |
1218 | uint32_t priority, uint32_t anonymity, | 1254 | uint32_t size, |
1219 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) | 1255 | const void *data, |
1256 | enum GNUNET_BLOCK_Type type, | ||
1257 | uint32_t priority, | ||
1258 | uint32_t anonymity, | ||
1259 | struct GNUNET_TIME_Absolute expiration, | ||
1260 | uint64_t uid) | ||
1220 | { | 1261 | { |
1221 | struct GNUNET_SERVER_Client *client = cls; | 1262 | struct GNUNET_SERVER_Client *client = cls; |
1222 | 1263 | ||
1223 | if (key == NULL) | 1264 | if (NULL == key) |
1224 | { | 1265 | { |
1225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1226 | "No further matches for `%s' request.\n", | 1267 | "No further matches for REMOVE request.\n"); |
1227 | "REMOVE"); | ||
1228 | transmit_status (client, | 1268 | transmit_status (client, |
1229 | GNUNET_NO, | 1269 | GNUNET_NO, |
1230 | _("Content not found")); | 1270 | _("Content not found")); |
@@ -1232,9 +1272,8 @@ remove_callback (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | |||
1232 | return GNUNET_OK; /* last item */ | 1272 | return GNUNET_OK; /* last item */ |
1233 | } | 1273 | } |
1234 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1235 | "Item %llu matches `%s' request for key `%s' and type %u.\n", | 1275 | "Item %llu matches REMOVE request for key `%s' and type %u.\n", |
1236 | (unsigned long long) uid, | 1276 | (unsigned long long) uid, |
1237 | "REMOVE", | ||
1238 | GNUNET_h2s (key), | 1277 | GNUNET_h2s (key), |
1239 | type); | 1278 | type); |
1240 | GNUNET_STATISTICS_update (stats, | 1279 | GNUNET_STATISTICS_update (stats, |
@@ -1256,26 +1295,34 @@ remove_callback (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | |||
1256 | * @param message the actual message | 1295 | * @param message the actual message |
1257 | */ | 1296 | */ |
1258 | static void | 1297 | static void |
1259 | handle_remove (void *cls, struct GNUNET_SERVER_Client *client, | 1298 | handle_remove (void *cls, |
1299 | struct GNUNET_SERVER_Client *client, | ||
1260 | const struct GNUNET_MessageHeader *message) | 1300 | const struct GNUNET_MessageHeader *message) |
1261 | { | 1301 | { |
1262 | const struct DataMessage *dm = check_data (message); | 1302 | const struct DataMessage *dm = check_data (message); |
1263 | struct GNUNET_HashCode vhash; | 1303 | struct GNUNET_HashCode vhash; |
1264 | 1304 | ||
1265 | if (dm == NULL) | 1305 | if (NULL == dm) |
1266 | { | 1306 | { |
1267 | GNUNET_break (0); | 1307 | GNUNET_break (0); |
1268 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1308 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1269 | return; | 1309 | return; |
1270 | } | 1310 | } |
1271 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1311 | GNUNET_STATISTICS_update (stats, |
1272 | "Processing `%s' request for `%s' of type %u\n", "REMOVE", | 1312 | gettext_noop ("# REMOVE requests received"), |
1273 | GNUNET_h2s (&dm->key), ntohl (dm->type)); | ||
1274 | GNUNET_STATISTICS_update (stats, gettext_noop ("# REMOVE requests received"), | ||
1275 | 1, GNUNET_NO); | 1313 | 1, GNUNET_NO); |
1276 | GNUNET_SERVER_client_keep (client); | 1314 | GNUNET_SERVER_client_keep (client); |
1277 | GNUNET_CRYPTO_hash (&dm[1], ntohl (dm->size), &vhash); | 1315 | GNUNET_CRYPTO_hash (&dm[1], |
1278 | plugin->api->get_key (plugin->api->cls, 0, &dm->key, &vhash, | 1316 | ntohl (dm->size), |
1317 | &vhash); | ||
1318 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1319 | "Processing REMOVE request for `%s' of type %u\n", | ||
1320 | GNUNET_h2s (&dm->key), | ||
1321 | ntohl (dm->type)); | ||
1322 | plugin->api->get_key (plugin->api->cls, | ||
1323 | 0, | ||
1324 | &dm->key, | ||
1325 | &vhash, | ||
1279 | (enum GNUNET_BLOCK_Type) ntohl (dm->type), | 1326 | (enum GNUNET_BLOCK_Type) ntohl (dm->type), |
1280 | &remove_callback, client); | 1327 | &remove_callback, client); |
1281 | } | 1328 | } |
@@ -1289,12 +1336,12 @@ handle_remove (void *cls, struct GNUNET_SERVER_Client *client, | |||
1289 | * @param message the actual message | 1336 | * @param message the actual message |
1290 | */ | 1337 | */ |
1291 | static void | 1338 | static void |
1292 | handle_drop (void *cls, struct GNUNET_SERVER_Client *client, | 1339 | handle_drop (void *cls, |
1340 | struct GNUNET_SERVER_Client *client, | ||
1293 | const struct GNUNET_MessageHeader *message) | 1341 | const struct GNUNET_MessageHeader *message) |
1294 | { | 1342 | { |
1295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1296 | "Processing `%s' request\n", | 1344 | "Processing DROP request\n"); |
1297 | "DROP"); | ||
1298 | do_drop = GNUNET_YES; | 1345 | do_drop = GNUNET_YES; |
1299 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1346 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1300 | } | 1347 | } |