#include "platform.h"
#include "gnunet_util_lib.h"
+#include "gnunet_transport_service.h"
#include "gnunet_core_service.h"
#include "gnunet_statistics_service.h"
/**
* Hello message.
*/
- const struct GNUNET_HELLO_Message* hello;
+ struct GNUNET_HELLO_Message* hello;
};
*/
static struct GNUNET_CORE_Handle *core_handle;
+static struct GNUNET_TRANSPORT_Handle *transport_handle;
+
/******************************************************************************/
/***************************** CORE CALLBACKS *********************************/
int priority;
int call_core;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_INFO,
"queue add %s %s towards %s (size %u) on c %p (%s)\n",
GM_f2s (fwd), GM_m2s (type), GMP_2s(peer),
size, c, GMC_2s (c));
NULL, /* Don't notify about all outbound messages */
GNUNET_NO, /* For header-only out notification */
core_handlers); /* Register these handlers */
- if (NULL == core_handle)
+ transport_handle = GNUNET_TRANSPORT_connect (c, &my_full_id,
+ NULL, /* cls */
+ NULL, NULL, NULL); /* Notify callbacks */
+
+ if (NULL == core_handle || NULL == transport_handle)
{
GNUNET_break (0);
GNUNET_SCHEDULER_shutdown ();
return;
}
+
}
/**
GNUNET_CORE_disconnect (core_handle);
core_handle = NULL;
}
+ if (transport_handle != NULL)
+ {
+ GNUNET_TRANSPORT_disconnect (transport_handle);
+ transport_handle = NULL;
+ }
GNUNET_PEER_change_rc (myid, -1);
}
}
+/**
+ * Try to connect to a peer on transport level.
+ *
+ * @param cls Closure (peer).
+ * @param tc TaskContext.
+ */
+static void
+try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct MeshPeer *peer = cls;
+
+ if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
+ return;
+
+ GNUNET_TRANSPORT_try_connect (transport_handle,
+ GNUNET_PEER_resolve2 (peer->id), NULL, NULL);
+}
+
/**
* Try to establish a new connection to this peer (in its tunnel).
* If the peer doesn't have any path to it yet, try to get one.
struct MeshTunnel3 *t;
struct MeshPeerPath *p;
struct MeshConnection *c;
+ struct GNUNET_HELLO_Message *hello;
int rerun_search;
LOG (GNUNET_ERROR_TYPE_DEBUG, "peer_connect towards %s\n", GMP_2s (peer));
+
+ /* If we have a current hello, try to connect using it. */
+ hello = GMP_get_hello (peer);
+ if (NULL != hello)
+ {
+ struct GNUNET_MessageHeader *mh;
+
+ mh = GNUNET_HELLO_get_header (hello);
+ GNUNET_TRANSPORT_offer_hello (transport_handle, mh, try_connect, peer);
+ }
+
t = peer->tunnel;
c = NULL;
rerun_search = GNUNET_NO;
void
GMP_set_hello (struct MeshPeer *peer, const struct GNUNET_HELLO_Message *hello)
{
- struct GNUNET_TIME_Absolute expiration;
- struct GNUNET_TIME_Relative remaining;
+ struct GNUNET_HELLO_Message *old;
+ size_t size;
- if (NULL == peer->hello)
+ old = GMP_get_hello (peer);
+ if (NULL == old)
{
- peer->hello = hello;
+ size = GNUNET_HELLO_size (hello);
+ peer->hello = GNUNET_malloc (size);
+ memcpy (peer->hello, hello, size);
return;
}
-
- expiration = GNUNET_HELLO_get_last_expiration (peer->hello);
- remaining = GNUNET_TIME_absolute_get_remaining (expiration);
- if (0 == remaining.rel_value_us)
+ else
{
- GNUNET_free (peer->hello);
- peer->hello = hello;
+ peer->hello = GNUNET_HELLO_merge (old, hello);
+ GNUNET_free (old);
}
- else
- peer->hello = GNUNET_HELLO_merge (peer->hello, hello);
}
*
* @return Hello message.
*/
-const struct GNUNET_HELLO_Message *
+struct GNUNET_HELLO_Message *
GMP_get_hello (struct MeshPeer *peer)
{
struct GNUNET_TIME_Absolute expiration;
struct GNUNET_TIME_Relative remaining;
+ if (NULL == peer->hello)
+ return NULL;
+
expiration = GNUNET_HELLO_get_last_expiration (peer->hello);
remaining = GNUNET_TIME_absolute_get_remaining (expiration);
if (0 == remaining.rel_value_us)