void
GDS_HELLO_init ()
{
- pnc = GNUNET_PEERINFO_notify (GDS_cfg, &process_hello, NULL);
+ pnc = GNUNET_PEERINFO_notify (GDS_cfg, GNUNET_NO, &process_hello, NULL);
peer_to_hello = GNUNET_CONTAINER_multihashmap_create (256, GNUNET_NO);
}
if (daemon_handle_v6 != NULL)
hostlist_task_v6 = prepare_daemon (daemon_handle_v6);
- notify = GNUNET_PEERINFO_notify (cfg, &process_notify, NULL);
+ notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_notify, NULL);
return GNUNET_OK;
}
/**
- * Call a method for each known matching host to get its HELLO.
- * The callback method will be invoked once for each matching
- * host and then finally once with a NULL pointer. After that final
- * invocation, the iterator context must no longer be used.
+ * Call a method for each known matching host. The callback method
+ * will be invoked once for each matching host and then finally once
+ * with a NULL pointer. After that final invocation, the iterator
+ * context must no longer be used.
*
- * Instead of calling this function with 'peer == NULL'
- * it is often better to use 'GNUNET_PEERINFO_notify'.
+ * Instead of calling this function with 'peer == NULL' it is often
+ * better to use 'GNUNET_PEERINFO_notify'.
*
* @param h handle to the peerinfo service
+ * @param include_friend_only include HELLO messages for friends only
* @param peer restrict iteration to this peer only (can be NULL)
* @param timeout how long to wait until timing out
* @param callback the method to call for each peer
* @param callback_cls closure for callback
- * @return NULL on error (in this case, 'callback' is never called!),
- * otherwise an iterator context
+ * @return iterator context
*/
struct GNUNET_PEERINFO_IteratorContext *
GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
+ int include_friend_only,
const struct GNUNET_PeerIdentity *peer,
struct GNUNET_TIME_Relative timeout,
- GNUNET_PEERINFO_Processor callback,
- void *callback_cls);
+ GNUNET_PEERINFO_Processor callback, void *callback_cls);
/**
* Call a method whenever our known information about peers
* changes. Initially calls the given function for all known
- * peers and then only signals changes. Note that it is
- * possible (i.e. on disconnects) that the callback is called
- * twice with the same peer information.
+ * peers and then only signals changes.
+ *
+ * If include_friend_only is set to GNUNET_YES peerinfo will include HELLO
+ * messages which are intended for friend to friend mode and which do not
+ * have to be gossiped. Otherwise these messages are skipped.
*
* @param cfg configuration to use
+ * @param include_friend_only include HELLO messages for friends only
* @param callback the method to call for each peer
* @param callback_cls closure for callback
* @return NULL on error
*/
struct GNUNET_PEERINFO_NotifyContext *
GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ int include_friend_only,
GNUNET_PEERINFO_Processor callback, void *callback_cls);
*/
unsigned int off;
+ /**
+ * Hello was friend only, GNUNET_YES or GNUNET_NO
+ */
+ int friend_only;
+
};
*/
static int be_quiet;
+/**
+ * Option '-f'
+ */
+static int include_friend_only;
+
/**
* Option '-s'
*/
unsigned int i;
GNUNET_CRYPTO_hash_to_enc (&pc->peer.hashPubKey, &enc);
- printf (_("Peer `%s'\n"),
+ printf (_("%sPeer `%s'\n"),
+ (GNUNET_YES == pc->friend_only) ? "F2F: " : "",
(const char *) &enc);
for (i = 0; i < pc->num_addresses; i++)
{
{
struct GNUNET_CRYPTO_HashAsciiEncoded enc;
struct PrintContext *pc;
+ int friend_only;
if (NULL == peer)
{
tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
return;
}
+ friend_only = GNUNET_HELLO_is_friend_only (hello);
if ((GNUNET_YES == be_quiet) || (NULL == hello))
{
GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc);
- printf ("%s\n", (const char *) &enc);
+ printf ("%s%s\n",
+ (GNUNET_YES == friend_only) ? "F2F: " : "",
+ (const char *) &enc);
return;
}
pc = GNUNET_malloc (sizeof (struct PrintContext));
pc_tail,
pc);
pc->peer = *peer;
+ pc->friend_only = friend_only;
GNUNET_HELLO_iterate_addresses (hello,
GNUNET_NO,
&count_address,
{
get_info = GNUNET_NO;
GPI_plugins_load (cfg);
- pic = GNUNET_PEERINFO_iterate (peerinfo, NULL,
+ pic = GNUNET_PEERINFO_iterate (peerinfo, include_friend_only, NULL,
TIMEOUT,
&print_peer_info, NULL);
return;
if (GNUNET_YES == get_uri)
{
GPI_plugins_load (cfg);
- pic = GNUNET_PEERINFO_iterate (peerinfo, &my_peer_identity,
+ pic = GNUNET_PEERINFO_iterate (peerinfo,include_friend_only, &my_peer_identity,
TIMEOUT, &print_my_uri, NULL);
get_uri = GNUNET_NO;
return;
{'q', "quiet", NULL,
gettext_noop ("output only the identity strings"),
0, &GNUNET_GETOPT_set_one, &be_quiet},
+ {'f', "friends", NULL,
+ gettext_noop ("include friend-only information"),
+ 0, &GNUNET_GETOPT_set_one, &include_friend_only},
{'s', "self", NULL,
gettext_noop ("output our own identity only"),
0, &GNUNET_GETOPT_set_one, &get_self},
static struct GNUNET_STATISTICS_Handle *stats;
+
/**
* Notify all clients in the notify list about the
* given host entry changing.
{
const struct ListPeerMessage *lpm;
struct GNUNET_SERVER_TransmitContext *tc;
+ int friend_only;
lpm = (const struct ListPeerMessage *) message;
- GNUNET_break (0 == ntohl (lpm->reserved));
+ friend_only = ntohl (lpm->include_friend_only);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n",
"GET", GNUNET_i2s (&lpm->peer));
tc = GNUNET_SERVER_transmit_context_create (client);
handle_get_all (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
+ const struct ListAllPeersMessage *lapm;
struct GNUNET_SERVER_TransmitContext *tc;
+ int friend_only;
+ lapm = (const struct ListAllPeersMessage *) message;
+ friend_only = ntohl (lapm->include_friend_only);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "GET_ALL");
tc = GNUNET_SERVER_transmit_context_create (client);
GNUNET_CONTAINER_multihashmap_iterate (hostmap, &add_to_tc, tc);
handle_notify (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "NOTIFY");
+ struct NotifyMessage *nm = (struct NotifyMessage *) message;
+ int friend_only;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "NOTIFY");
+ friend_only = ntohl (nm->include_friend_only);
GNUNET_SERVER_client_mark_monitor (client);
GNUNET_SERVER_notification_context_add (notify_list, client);
GNUNET_CONTAINER_multihashmap_iterate (hostmap, &do_notify_entry, client);
{&handle_get, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET,
sizeof (struct ListPeerMessage)},
{&handle_get_all, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL,
- sizeof (struct GNUNET_MessageHeader)},
+ sizeof (struct ListAllPeersMessage)},
{&handle_notify, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY,
- sizeof (struct GNUNET_MessageHeader)},
+ sizeof (struct NotifyMessage)},
{NULL, NULL, 0, 0}
};
char *peerdir;
GNUNET_NETWORK_STRUCT_BEGIN
/**
- * Message requesting a listing of all known peers,
- * possibly restricted to the specified peer identity.
+ * Message requesting a listing of peers,
+ * restricted to the specified peer identity.
*/
struct ListPeerMessage
{
/**
- * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET or
- * GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL.
+ * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET
+ * .
*/
struct GNUNET_MessageHeader header;
/**
- * Always zero.
+ * Include friend only HELLOs and peers in callbacks
*/
- uint32_t reserved GNUNET_PACKED;
+ uint32_t include_friend_only GNUNET_PACKED;
/**
* Restrict to peers with this identity (optional
};
+/**
+ * Message requesting a listing of all peers,
+ * restricted to the specified peer identity.
+ */
+struct ListAllPeersMessage
+{
+ /**
+ * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Include friend only HELLOs and peers in callbacks
+ */
+ uint32_t include_friend_only GNUNET_PACKED;
+
+};
+
+
+/**
+ * Header for all communications.
+ */
+struct NotifyMessage
+{
+ /**
+ * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Include friend only HELLOs and peers in callbacks
+ */
+ uint32_t include_friend_only GNUNET_PACKED;
+
+};
+
/**
* Message used to inform the client about
* better to use 'GNUNET_PEERINFO_notify'.
*
* @param h handle to the peerinfo service
+ * @param include_friend_only include HELLO messages for friends only
* @param peer restrict iteration to this peer only (can be NULL)
* @param timeout how long to wait until timing out
* @param callback the method to call for each peer
*/
struct GNUNET_PEERINFO_IteratorContext *
GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
+ int include_friend_only,
const struct GNUNET_PeerIdentity *peer,
struct GNUNET_TIME_Relative timeout,
GNUNET_PEERINFO_Processor callback, void *callback_cls)
{
- struct GNUNET_MessageHeader *lapm;
+ struct ListAllPeersMessage *lapm;
struct ListPeerMessage *lpm;
struct GNUNET_PEERINFO_IteratorContext *ic;
struct GNUNET_PEERINFO_AddContext *ac;
"Requesting list of peers from PEERINFO service\n");
ac =
GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_AddContext) +
- sizeof (struct GNUNET_MessageHeader));
- ac->size = sizeof (struct GNUNET_MessageHeader);
- lapm = (struct GNUNET_MessageHeader *) &ac[1];
- lapm->size = htons (sizeof (struct GNUNET_MessageHeader));
- lapm->type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL);
+ sizeof (struct ListAllPeersMessage));
+ ac->size = sizeof (struct ListAllPeersMessage);
+ lapm = (struct ListAllPeersMessage *) &ac[1];
+ lapm->header.size = htons (sizeof (struct ListAllPeersMessage));
+ lapm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL);
+ lapm->include_friend_only = htonl (include_friend_only);
}
else
{
lpm = (struct ListPeerMessage *) &ac[1];
lpm->header.size = htons (sizeof (struct ListPeerMessage));
lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET);
+ lpm->include_friend_only = htonl (include_friend_only);
memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity));
ic->have_peer = GNUNET_YES;
ic->peer = *peer;
*/
GNUNET_SCHEDULER_TaskIdentifier task;
+ /**
+ * Include friend only HELLOs in callbacks
+ */
+
+ int include_friend_only;
};
transmit_notify_request (void *cls, size_t size, void *buf)
{
struct GNUNET_PEERINFO_NotifyContext *nc = cls;
- struct GNUNET_MessageHeader hdr;
+ struct NotifyMessage nm;
nc->init = NULL;
if (buf == NULL)
request_notifications (nc);
return 0;
}
- GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
- hdr.size = htons (sizeof (struct GNUNET_MessageHeader));
- hdr.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY);
- memcpy (buf, &hdr, sizeof (struct GNUNET_MessageHeader));
+ GNUNET_assert (size >= sizeof (struct NotifyMessage));
+ nm.header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY);
+ nm.header.size = htons (sizeof (struct NotifyMessage));
+ nm.include_friend_only = htonl (nc->include_friend_only);
+ memcpy (buf, &nm, sizeof (struct NotifyMessage));
receive_notifications (nc);
return sizeof (struct GNUNET_MessageHeader);
}
GNUNET_assert (NULL == nc->init);
nc->init =
GNUNET_CLIENT_notify_transmit_ready (nc->client,
- sizeof (struct GNUNET_MessageHeader),
+ sizeof (struct NotifyMessage),
GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_YES, &transmit_notify_request,
nc);
* changes. Initially calls the given function for all known
* peers and then only signals changes.
*
+ * If include_friend_only is set to GNUNET_YES peerinfo will include HELLO
+ * messages which are intended for friend to friend mode and which do not
+ * have to be gossiped. Otherwise these messages are skipped.
+ *
* @param cfg configuration to use
+ * @param include_friend_only include HELLO messages for friends only
* @param callback the method to call for each peer
* @param callback_cls closure for callback
* @return NULL on error
*/
struct GNUNET_PEERINFO_NotifyContext *
GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ int include_friend_only,
GNUNET_PEERINFO_Processor callback, void *callback_cls)
{
struct GNUNET_PEERINFO_NotifyContext *nc;
nc->client = client;
nc->callback = callback;
nc->callback_cls = callback_cls;
+ nc->include_friend_only = include_friend_only;
request_notifications (nc);
return nc;
}
/* try again */
retries++;
add_peer ();
- ic = GNUNET_PEERINFO_iterate (h, NULL,
+ ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL,
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 15), &process,
cls);
h = GNUNET_PEERINFO_connect (cfg);
GNUNET_assert (NULL != h);
add_peer ();
- ic = GNUNET_PEERINFO_iterate (h, NULL,
+ ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL,
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 15), &process, cls);
}
_("Error in communication with PEERINFO service: %s\n"),
err_msg);
GNUNET_PEERINFO_notify_cancel (peerinfo_notify);
- peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer, NULL);
+ peerinfo_notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_peer, NULL);
return;
}
GNUNET_assert (peer != NULL);
handle = server;
my_identity = *my_id;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id));
- peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer, NULL);
+ peerinfo_notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_peer, NULL);
}
validations_fast_start_threshold, validation_delay.rel_value);
validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE,
GNUNET_NO);
- pnc = GNUNET_PEERINFO_notify (GST_cfg, &process_peerinfo_hello, NULL);
+ pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES, &process_peerinfo_hello, NULL);
}