- sub_system = (char *)&req[1];
- key = sub_system + ss_size;
- value = key + key_size;
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received a store request (size: %lu) for sub system `%s', peer `%s', key `%s'\n",
- value_size,
- sub_system,
- GNUNET_i2s (&req->peer),
- key);
- if(GNUNET_OK == db->store_record(db->cls,
- sub_system,
- &req->peer,
- key,
- value,
- value_size))
- {
- response_type = GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK;
+ num_clients++;
+ GNUNET_SERVICE_client_continue (client);
+}
+
+
+/**
+ * Handle a watch request from client
+ *
+ * @param cls identification of the client
+ * @param hm the actual message
+ */
+static void
+handle_watch (void *cls,
+ const struct StoreKeyHashMessage *hm)
+{
+ struct GNUNET_SERVICE_Client *client = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received a watch request.\n");
+ num_clients--; /* do not count watchers */
+ GNUNET_SERVICE_client_mark_monitor (client);
+ GNUNET_CONTAINER_multihashmap_put (watchers,
+ &hm->keyhash,
+ client,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ GNUNET_SERVICE_client_continue (client);
+}
+
+
+/**
+ * Check an iterate request from client
+ *
+ * @param cls client identification of the client
+ * @param srm the actual message
+ * @return #GNUNET_OK if @a srm is well-formed
+ */
+static int
+check_iterate (void *cls,
+ const struct StoreRecordMessage *srm)
+{
+ struct GNUNET_PEERSTORE_Record *record;
+
+ record = PEERSTORE_parse_record_message (srm);
+ if (NULL == record)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (NULL == record->sub_system)
+ {
+ GNUNET_break (0);
+ PEERSTORE_destroy_record (record);
+ return GNUNET_SYSERR;
+ }
+ PEERSTORE_destroy_record (record);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Handle an iterate request from client
+ *
+ * @param cls identification of the client
+ * @param srm the actual message
+ */
+static void
+handle_iterate (void *cls,
+ const struct StoreRecordMessage *srm)
+{
+ struct GNUNET_SERVICE_Client *client = cls;
+ struct GNUNET_PEERSTORE_Record *record;
+
+ record = PEERSTORE_parse_record_message (srm);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Iterate request: ss `%s', peer `%s', key `%s'\n",
+ record->sub_system,
+ GNUNET_i2s (&record->peer),
+ (NULL == record->key) ? "NULL" : record->key);
+ record->client = client;
+ if (GNUNET_OK !=
+ db->iterate_records (db->cls,
+ record->sub_system,
+ (ntohs (srm->peer_set)) ? &record->peer : NULL,
+ record->key,
+ &record_iterator,
+ record))
+ {
+ GNUNET_break (0);
+ GNUNET_SERVICE_client_drop (client);
+ PEERSTORE_destroy_record (record);
+ }
+}
+
+
+/**
+ * Continuation of store_record called by the peerstore plugin
+ *
+ * @param cls closure
+ * @param success result
+ */
+static void
+store_record_continuation (void *cls,
+ int success)
+{
+ struct GNUNET_PEERSTORE_Record *record = cls;
+
+ if (GNUNET_OK == success)
+ {
+ watch_notifier (record);
+ GNUNET_SERVICE_client_continue (record->client);