+
+ env = PEERSTORE_create_record_mq_envelope (record->sub_system,
+ &record->peer,
+ record->key,
+ record->value,
+ record->value_size,
+ record->expiry,
+ 0,
+ GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client),
+ env);
+}
+
+
+/**
+ * Iterator over all watcher clients
+ * to notify them of a new record
+ *
+ * @param cls closure, a `struct GNUNET_PEERSTORE_Record *`
+ * @param key hash of record key
+ * @param value the watcher client, a `struct GNUNET_SERVICE_Client *`
+ * @return #GNUNET_YES to continue iterating
+ */
+static int
+watch_notifier_it (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ struct GNUNET_PEERSTORE_Record *record = cls;
+ struct GNUNET_SERVICE_Client *client = value;
+ struct GNUNET_MQ_Envelope *env;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Found a watcher to update.\n");
+ env = PEERSTORE_create_record_mq_envelope (record->sub_system,
+ &record->peer,
+ record->key,
+ record->value,
+ record->value_size,
+ record->expiry,
+ 0,
+ GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
+ env);
+ return GNUNET_YES;
+}
+
+
+/**
+ * Given a new record, notifies watchers
+ *
+ * @param record changed record to update watchers with
+ */
+static void
+watch_notifier (struct GNUNET_PEERSTORE_Record *record)
+{
+ struct GNUNET_HashCode keyhash;
+
+ PEERSTORE_hash_key (record->sub_system,
+ &record->peer,
+ record->key,
+ &keyhash);
+ GNUNET_CONTAINER_multihashmap_get_multiple (watchers,
+ &keyhash,
+ &watch_notifier_it,
+ record);
+}
+
+
+/**
+ * Handle a watch cancel request from client
+ *
+ * @param cls identification of the client
+ * @param hm the actual message
+ */
+static void
+handle_watch_cancel (void *cls,
+ const struct StoreKeyHashMessage *hm)
+{
+ struct GNUNET_SERVICE_Client *client = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received a watch cancel request.\n");
+ if (GNUNET_OK !=
+ GNUNET_CONTAINER_multihashmap_remove (watchers,
+ &hm->keyhash,
+ client))