/**
* Process each hello message received from peerinfo.
*
- * @param cls the 'struct GetUriContext'
- * @param peer identity of the peer
- * @param hello addresses of the peer
- * @param err_msg error message
+ * @param cls Closure (unused).
+ * @param peer Identity of the peer.
+ * @param hello Hello of the peer.
+ * @param err_msg Error message.
*/
static void
got_hello (void *cls, const struct GNUNET_PeerIdentity *id,
{
struct MeshPeer *peer;
- if (NULL == id)
- LOG (GNUNET_ERROR_TYPE_ERROR, "not a valid id\n");
-
+ if (NULL == id || NULL == hello)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " hello with id %p and msg %p\n", id, hello);
+ return;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " hello for %s (%d bytes), expires on %s\n",
+ GNUNET_i2s (id), NULL != hello ? GNUNET_HELLO_size (hello) : -1,
+ GNUNET_STRINGS_absolute_time_to_string (GNUNET_HELLO_get_last_expiration(hello)));
+ if (NULL == hello)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " hello is NULL\n");
+ return;
+ }
peer = GMP_get (id);
GMP_set_hello (peer, hello);
+
+ if (GMP_get_short_id (peer) == myid)
+ {
+ mine = GMP_get_hello (peer);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " updated mine to %p\n", mine);
+ }
}
/******************************** API ***********************************/
/******************************************************************************/
-
+/**
+ * Initialize the hello subsystem.
+ *
+ * @param c Configuration.
+ */
void
GMH_init (const struct GNUNET_CONFIGURATION_Handle *c)
{
- GNUNET_assert (NULL != nc);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "init\n");
+ GNUNET_assert (NULL == nc);
peerinfo = GNUNET_PEERINFO_connect (c);
nc = GNUNET_PEERINFO_notify (c, GNUNET_NO, &got_hello, NULL);
}
+/**
+ * Shut down the hello subsystem.
+ */
void
GMH_shutdown ()
{
}
+/**
+ * Get own hello message.
+ *
+ * @return Own hello message.
+ */
const struct GNUNET_HELLO_Message *
GMH_get_mine (void)
{
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " mine is %p\n", mine);
return mine;
}
+/**
+ * Get another peer's hello message.
+ *
+ * @param id ID of the peer whose hello message is requested.
+ *
+ * @return Hello message, if any (NULL possible).
+ */
const struct GNUNET_HELLO_Message *
GMH_get (const struct GNUNET_PeerIdentity *id)
{
return GMP_get_hello (GMP_get (id));
}
-void
-GMH_2s ()
+
+/**
+ * Convert a hello message to a string.
+ *
+ * @param h Hello message.
+ */
+char *
+GMH_2s (const struct GNUNET_HELLO_Message *h)
{
+ return "hello (TODO)";
}