#include "gnunet_dht_service.h"
#include "gnunet_statistics_service.h"
-#include "block_mesh.h"
#include "mesh_path.h"
#include "gnunet-service-mesh_dht.h"
#include "gnunet-service-mesh_peer.h"
+#include "gnunet-service-mesh_hello.h"
#define LOG(level, ...) GNUNET_log_from (level,"mesh-dht",__VA_ARGS__)
* to obtain a local peer -> destination path and interning the peer ids.
*
* @return Newly allocated and created path
+ *
+ * FIXME refactor and use build_path_from_peer_ids
*/
static struct MeshPeerPath *
path_build_from_dht (const struct GNUNET_PeerIdentity *get_path,
size_t size, const void *data)
{
struct GMD_search_handle *h = cls;
+ struct GNUNET_HELLO_Message *hello;
struct MeshPeerPath *p;
+ struct MeshPeer *peer;
+ char *s;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Got results!\n");
p = path_build_from_dht (get_path, get_path_length,
put_path, put_path_length);
+ s = path_2s (p);
+ LOG (GNUNET_ERROR_TYPE_INFO, "Got path from DHT: %s\n", s);
+ GNUNET_free_non_null (s);
+ peer = GMP_get_short (p->peers[p->length - 1]);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Got HELLO for %s\n", GMP_2s (peer));
h->callback (h->cls, p);
path_destroy (p);
+ hello = (struct GNUNET_HELLO_Message *) data;
+ GMP_set_hello (peer, hello);
+ GMP_try_connect (peer);
return;
}
static void
announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct PBlock block;
struct GNUNET_HashCode phash;
+ const struct GNUNET_HELLO_Message *hello;
+ size_t size;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
announce_id_task = GNUNET_SCHEDULER_NO_TASK;
return;
}
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Announce ID\n");
/* TODO
* - Set data expiration in function of X
* - Adapt X to churn
*/
- block.id = my_full_id;
- GNUNET_CRYPTO_hash (&my_full_id, sizeof (struct GNUNET_PeerIdentity), &phash);
+ hello = GMH_get_mine ();
+ if (NULL == hello || (size = GNUNET_HELLO_size (hello)) == 0)
+ {
+ /* Peerinfo gave us no hello yet, try again in a second. */
+ announce_id_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &announce_id, cls);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " no hello, waiting!\n");
+ return;
+ }
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Hello %p size: %u\n", hello, size);
+ memset (&phash, 0, sizeof (phash));
+ memcpy (&phash, &my_full_id, sizeof (my_full_id));
GNUNET_DHT_put (dht_handle, /* DHT handle */
&phash, /* Key to use */
dht_replication_level, /* Replication level */
- GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */
- GNUNET_BLOCK_TYPE_MESH_PEER, /* Block type */
- sizeof (block), /* Size of the data */
- (const char *) &block, /* Data itself */
+ GNUNET_DHT_RO_RECORD_ROUTE
+ | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */
+ GNUNET_BLOCK_TYPE_DHT_HELLO, /* Block type */
+ size, /* Size of the data */
+ (const char *) hello, /* Data itself */
GNUNET_TIME_UNIT_FOREVER_ABS, /* Data expiration */
GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */
NULL, /* Continuation */
}
/**
- * Iterator over hash map entries and stop GET requests before disconnecting
+ * Iterator over hash map entries and stop GET requests before disconnecting
* from the DHT.
*
* @param cls Closure (unused)
LOG (GNUNET_ERROR_TYPE_DEBUG,
" Starting DHT GET for peer %s\n", GNUNET_i2s (peer_id));
- GNUNET_CRYPTO_hash (peer_id, sizeof (struct GNUNET_PeerIdentity), &phash);
+ memset (&phash, 0, sizeof (phash));
+ memcpy (&phash, peer_id, sizeof (*peer_id));
h = GNUNET_new (struct GMD_search_handle);
h->peer_id = GNUNET_PEER_intern (peer_id);
h->callback = callback;
h->cls = cls;
h->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */
- GNUNET_BLOCK_TYPE_MESH_PEER, /* type */
+ GNUNET_BLOCK_TYPE_DHT_HELLO, /* type */
&phash, /* key to search */
dht_replication_level, /* replication level */
GNUNET_DHT_RO_RECORD_ROUTE |
h->peer_id, h));
GNUNET_DHT_get_stop (h->dhtget);
GNUNET_free (h);
-}
\ No newline at end of file
+}