return;
}
hs = GNUNET_HELLO_size (hello);
+#if DEBUG_PEERINFO
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Size of `%s' is %u bytes\n",
+ "HELLO",
+ (unsigned int) GNUNET_HELLO_size (hello));
+#endif
pam = GNUNET_malloc (sizeof (struct PeerAddMessage) + hs);
pam->header.size = htons (hs + sizeof (struct PeerAddMessage));
pam->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_ADD);
"Received information about peer `%s' from peerinfo database\n",
GNUNET_i2s (&im->peer));
#endif
+#if DEBUG_PEERINFO
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Size of `%s' is %u bytes\n",
+ "HELLO",
+ (unsigned int) GNUNET_HELLO_size (hello));
+#endif
ic->callback (ic->callback_cls, &im->peer, hello, ntohl (im->trust));
GNUNET_CLIENT_receive (ic->client,
&info_handler,
#include "gnunet_peerinfo_service.h"
#include "gnunet_program_lib.h"
#include "gnunet_time_lib.h"
+#include "peerinfo.h"
+static struct GNUNET_SCHEDULER_Handle *sched;
+
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+static unsigned int retries;
static int
check_it (void *cls,
}
+static size_t
+address_generator (void *cls, size_t max, void *buf)
+{
+ size_t *agc = cls;
+ size_t ret;
+
+ if (0 == *agc)
+ return 0;
+ ret = GNUNET_HELLO_add_address ("peerinfotest",
+ GNUNET_TIME_relative_to_absolute
+ (GNUNET_TIME_UNIT_HOURS), "Address", *agc,
+ buf, max);
+ (*agc)--;
+ return ret;
+}
+
+
+static void
+add_peer ()
+{
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
+ struct GNUNET_PeerIdentity pid;
+ struct GNUNET_HELLO_Message *h2;
+ size_t agc;
+
+ agc = 2;
+ memset (&pkey, 32, sizeof (pkey));
+ GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey);
+ h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc);
+ GNUNET_PEERINFO_add_peer (cfg, sched, &pid, h2);
+ GNUNET_free (h2);
+
+}
+
+
static void
process (void *cls,
const struct GNUNET_PeerIdentity *peer,
if (peer == NULL)
{
+ if ( (3 == *ok) &&
+ (retries < 5) )
+ {
+ /* try again */
+ retries++;
+ add_peer ();
+ GNUNET_PEERINFO_iterate (cfg,
+ sched,
+ NULL,
+ 0,
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 15),
+ &process, cls);
+ return;
+ }
GNUNET_assert (peer == NULL);
GNUNET_assert (2 == *ok);
GNUNET_assert (trust == 0);
}
-static size_t
-address_generator (void *cls, size_t max, void *buf)
-{
- size_t *agc = cls;
- size_t ret;
-
- if (0 == *agc)
- return 0;
- ret = GNUNET_HELLO_add_address ("peerinfotest",
- GNUNET_TIME_relative_to_absolute
- (GNUNET_TIME_UNIT_HOURS), "Address", *agc,
- buf, max);
- (*agc)--;
- return ret;
-}
-
-
static void
run (void *cls,
- struct GNUNET_SCHEDULER_Handle *sched,
+ struct GNUNET_SCHEDULER_Handle *s,
char *const *args,
const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+ const struct GNUNET_CONFIGURATION_Handle *c)
{
- struct GNUNET_HELLO_Message *hello;
- struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
- size_t agc;
- struct GNUNET_PeerIdentity pid;
-
- memset (&pkey, 32, sizeof (pkey));
- GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey);
- agc = 2;
- hello = GNUNET_HELLO_create (&pkey, &address_generator, &agc);
- GNUNET_assert (hello != NULL);
- GNUNET_PEERINFO_add_peer (cfg, sched, &pid, hello);
+ sched = s;
+ cfg = c;
+ add_peer ();
GNUNET_PEERINFO_iterate (cfg,
sched,
NULL,
0,
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 15), &process, cls);
- GNUNET_free (hello);
}
{
int ret = 0;
+ GNUNET_log_setup ("test_peerinfo_api",
+#if DEBUG_PEERINFO
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
ret = check ();
GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-peerinfo");
return ret;