+/**
+ * Start monitoring the local DHT service.
+ *
+ * @param handle Handle to the DHT service.
+ * @param type Type of blocks that are of interest.
+ * @param key Key of data of interest, NULL for all.
+ * @param get_cb Callback to process monitored get messages.
+ * @param get_resp_cb Callback to process monitored get response messages.
+ * @param put_cb Callback to process monitored put messages.
+ * @param cb_cls Closure for callbacks.
+ * @return Handle to stop monitoring.
+ */
+struct GNUNET_DHT_MonitorHandle *
+GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle,
+ enum GNUNET_BLOCK_Type type,
+ const struct GNUNET_HashCode *key,
+ GNUNET_DHT_MonitorGetCB get_cb,
+ GNUNET_DHT_MonitorGetRespCB get_resp_cb,
+ GNUNET_DHT_MonitorPutCB put_cb,
+ void *cb_cls)
+{
+ struct GNUNET_DHT_MonitorHandle *mh;
+
+ mh = GNUNET_new (struct GNUNET_DHT_MonitorHandle);
+ mh->get_cb = get_cb;
+ mh->get_resp_cb = get_resp_cb;
+ mh->put_cb = put_cb;
+ mh->cb_cls = cb_cls;
+ mh->type = type;
+ mh->dht_handle = handle;
+ if (NULL != key)
+ {
+ mh->key = GNUNET_new (struct GNUNET_HashCode);
+ *mh->key = *key;
+ }
+ GNUNET_CONTAINER_DLL_insert (handle->monitor_head,
+ handle->monitor_tail,
+ mh);
+ if (NULL != handle->mq)
+ send_monitor_start (mh);
+ return mh;
+}
+
+
+/**
+ * Stop monitoring.
+ *
+ * @param mh The handle to the monitor request returned by monitor_start.
+ *
+ * On return get_handle will no longer be valid, caller must not use again!!!
+ */
+void
+GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *mh)
+{
+ struct GNUNET_DHT_Handle *handle = mh->dht_handle;
+ struct GNUNET_DHT_MonitorStartStopMessage *m;
+ struct GNUNET_MQ_Envelope *env;
+
+ GNUNET_CONTAINER_DLL_remove (handle->monitor_head,
+ handle->monitor_tail,
+ mh);
+ env = GNUNET_MQ_msg (m,
+ GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP);
+ m->type = htonl (mh->type);
+ m->get = htons (NULL != mh->get_cb);
+ m->get_resp = htons(NULL != mh->get_resp_cb);
+ m->put = htons (NULL != mh->put_cb);
+ if (NULL != mh->key)
+ {
+ m->filter_key = htons (1);
+ m->key = *mh->key;
+ }
+ GNUNET_MQ_send (handle->mq,
+ env);
+ GNUNET_free_non_null (mh->key);
+ GNUNET_free (mh);