#include "gnunet_transport_service.h"
#include "gnunet_statistics_service.h"
-#define VERBOSE GNUNET_NO
-#define DEBUG_TRANSMISSION GNUNET_NO
+#define VERBOSE GNUNET_EXTRA_LOGGING
+#define DEBUG_TRANSMISSION GNUNET_EXTRA_LOGGING
#define SYMMETRIC 0
#define ASYMMETRIC_SEND_LIMITED 1
{
struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_CORE_Handle *ch;
+ struct GNUNET_CORE_TransmitHandle *nth;
struct GNUNET_PeerIdentity id;
struct GNUNET_TRANSPORT_Handle *th;
struct GNUNET_MessageHeader *hello;
struct GNUNET_STATISTICS_Handle *stats;
+ struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
int connect_status;
#if START_ARM
struct GNUNET_OS_Process *arm_proc;
uint32_t num;
};
-static void process_hello (void *cls,
- const struct GNUNET_MessageHeader *message);
+static void
+process_hello (void *cls, const struct GNUNET_MessageHeader *message);
static void
terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GNUNET_CORE_Handle *ch;
- GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2);
- GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1);
+ err_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_TRANSPORT_get_hello_cancel (p2.ghh);
+ GNUNET_TRANSPORT_get_hello_cancel (p1.ghh);
+ if (p1.nth != NULL)
+ {
+ GNUNET_CORE_notify_transmit_ready_cancel (p1.nth);
+ p1.nth = NULL;
+ }
ch = p1.ch;
p1.ch = NULL;
GNUNET_CORE_disconnect (ch);
static void
terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ err_task = GNUNET_SCHEDULER_NO_TASK;
+
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase failed!\n");
//GNUNET_break (0);
-
+ if (p1.nth != NULL)
+ {
+ GNUNET_CORE_notify_transmit_ready_cancel (p1.nth);
+ p1.nth = NULL;
+ }
if (measure_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (measure_task);
- GNUNET_TRANSPORT_get_hello_cancel (p1.th, &process_hello, &p1);
- GNUNET_TRANSPORT_get_hello_cancel (p2.th, &process_hello, &p2);
+ GNUNET_TRANSPORT_get_hello_cancel (p1.ghh);
+ GNUNET_TRANSPORT_get_hello_cancel (p2.ghh);
GNUNET_CORE_disconnect (p1.ch);
p1.ch = NULL;
* @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
*/
static int
-print_stat (void *cls,
- const char *subsystem,
- const char *name, uint64_t value, int is_persistent)
+print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
+ int is_persistent)
{
if (cls == &p1)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer1 %50s = %12llu\n", name, (unsigned long long) value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 %50s = %12llu\n", name,
+ (unsigned long long) value);
if (cls == &p2)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer2 %50s = %12llu\n", name, (unsigned long long) value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 %50s = %12llu\n", name,
+ (unsigned long long) value);
return GNUNET_OK;
}
else
ok = 0;
- GNUNET_STATISTICS_get (p1.stats,
- "core",
- "# discarded CORE_SEND requests",
+ GNUNET_STATISTICS_get (p1.stats, "core", "# discarded CORE_SEND requests",
GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
- GNUNET_STATISTICS_get (p1.stats,
- "core",
+ GNUNET_STATISTICS_get (p1.stats, "core",
"# discarded CORE_SEND request bytes",
GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
- GNUNET_STATISTICS_get (p1.stats,
- "core",
+ GNUNET_STATISTICS_get (p1.stats, "core",
"# discarded lower priority CORE_SEND requests",
GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, NULL);
- GNUNET_STATISTICS_get (p1.stats,
- "core",
+ GNUNET_STATISTICS_get (p1.stats, "core",
"# discarded lower priority CORE_SEND request bytes",
GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
- GNUNET_STATISTICS_get (p2.stats,
- "core",
- "# discarded CORE_SEND requests",
+ GNUNET_STATISTICS_get (p2.stats, "core", "# discarded CORE_SEND requests",
GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
- GNUNET_STATISTICS_get (p2.stats,
- "core",
+ GNUNET_STATISTICS_get (p2.stats, "core",
"# discarded CORE_SEND request bytes",
GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
- GNUNET_STATISTICS_get (p2.stats,
- "core",
+ GNUNET_STATISTICS_get (p2.stats, "core",
"# discarded lower priority CORE_SEND requests",
GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
- GNUNET_STATISTICS_get (p2.stats,
- "core",
+ GNUNET_STATISTICS_get (p2.stats, "core",
"# discarded lower priority CORE_SEND request bytes",
GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu kB/s\n",max_quota_out/1024);
*/
GNUNET_SCHEDULER_cancel (err_task);
- GNUNET_SCHEDULER_add_now (&terminate_task, NULL);
+ err_task = GNUNET_SCHEDULER_add_now (&terminate_task, NULL);
}
struct TestMessage hdr;
unsigned int ret;
+ p1.nth = NULL;
GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
if (buf == NULL)
{
if ((p1.ch != NULL) && (p1.connect_status == 1))
GNUNET_break (NULL !=
- GNUNET_CORE_notify_transmit_ready (p1.ch,
- GNUNET_NO,
- 0,
- FAST_TIMEOUT,
- &p2.id,
- MESSAGESIZE,
- &transmit_ready, &p1));
+ (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
+ FAST_TIMEOUT, &p2.id,
+ MESSAGESIZE,
+ &transmit_ready, &p1)));
return 0;
}
GNUNET_assert (tr_n < TOTAL_MSGS);
{
#if DEBUG_TRANSMISSION
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message %u of size %u at offset %u\n",
- tr_n, MESSAGESIZE, ret);
+ "Sending message %u of size %u at offset %u\n", tr_n,
+ MESSAGESIZE, ret);
#endif
hdr.header.size = htons (MESSAGESIZE);
hdr.header.type = htons (MTYPE);
}
while (size - ret >= MESSAGESIZE);
GNUNET_SCHEDULER_cancel (err_task);
- err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &terminate_task_error, NULL);
+ err_task =
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
total_bytes_sent += ret;
return ret;
static void
-connect_notify (void *cls,
- const struct GNUNET_PeerIdentity *peer,
+connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
struct PeerContext *pc = cls;
if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
- return;
+ return; /* loopback */
GNUNET_assert (pc->connect_status == 0);
pc->connect_status = 1;
if (pc == &p1)
#endif
if (err_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (err_task);
- err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &terminate_task_error, NULL);
+ err_task =
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
start_time = GNUNET_TIME_absolute_get ();
running = GNUNET_YES;
measure_task =
GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, &measurement_stop,
NULL);
- GNUNET_break (NULL != GNUNET_CORE_notify_transmit_ready (p1.ch,
- GNUNET_NO,
- 0,
- TIMEOUT,
- &p2.id,
- MESSAGESIZE,
- &transmit_ready,
- &p1));
+ GNUNET_break (NULL !=
+ (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
+ TIMEOUT, &p2.id,
+ MESSAGESIZE,
+ &transmit_ready, &p1)));
}
}
struct PeerContext *pc = cls;
if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
- return;
+ return; /* loopback */
pc->connect_status = 0;
+ if (pc->nth != NULL)
+ {
+ GNUNET_CORE_notify_transmit_ready_cancel (pc->nth);
+ pc->nth = NULL;
+ }
#if DEBUG_TRANSMISSION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection to `%4s' cut\n",
+ GNUNET_i2s (peer));
#endif
}
static int
-inbound_notify (void *cls,
- const struct GNUNET_PeerIdentity *other,
+inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
static int
-outbound_notify (void *cls,
- const struct GNUNET_PeerIdentity *other,
+outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
}
-static size_t transmit_ready (void *cls, size_t size, void *buf);
+static size_t
+transmit_ready (void *cls, size_t size, void *buf);
static int
-process_mtype (void *cls,
- const struct GNUNET_PeerIdentity *peer,
+process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
return GNUNET_SYSERR;
}
#if DEBUG_TRANSMISSION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got message %u of size %u\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n",
ntohl (hdr->num), ntohs (message->size));
#endif
n++;
if (running == GNUNET_YES)
GNUNET_break (NULL !=
- GNUNET_CORE_notify_transmit_ready (p1.ch,
- GNUNET_NO,
- 0,
- FAST_TIMEOUT,
- &p2.id,
+ GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
+ FAST_TIMEOUT, &p2.id,
MESSAGESIZE,
&transmit_ready, &p1));
return GNUNET_OK;
static void
-init_notify (void *cls,
- struct GNUNET_CORE_Handle *server,
- const struct GNUNET_PeerIdentity *my_identity,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
+init_notify (void *cls, struct GNUNET_CORE_Handle *server,
+ const struct GNUNET_PeerIdentity *my_identity)
{
struct PeerContext *p = cls;
GNUNET_i2s (my_identity));
GNUNET_assert (server != NULL);
p->id = *my_identity;
- p->ch = server;
+ GNUNET_assert (p->ch == server);
if (cls == &p1)
{
GNUNET_assert (ok == 2);
OKPP;
/* connect p2 */
- GNUNET_CORE_connect (p2.cfg, 1,
- &p2,
- &init_notify,
- &connect_notify,
- &disconnect_notify,
- NULL,
- &inbound_notify,
- GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
+ p2.ch = GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
+ &disconnect_notify, NULL, &inbound_notify, GNUNET_YES,
+ &outbound_notify, GNUNET_YES, handlers);
}
else
{
"Asking core (1) to connect to peer `%4s'\n",
GNUNET_i2s (&p2.id));
#endif
- GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL);
+ GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
+ GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
}
}
{
p->cfg = GNUNET_CONFIGURATION_create ();
#if START_ARM
- p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
+ p->arm_proc =
+ GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
+ "gnunet-service-arm",
#if VERBOSE
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- "-c", cfgname, NULL);
+ "-c", cfgname, NULL);
#endif
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
p->stats = GNUNET_STATISTICS_create ("core", p->cfg);
GNUNET_assert (p->stats != NULL);
p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
GNUNET_assert (p->th != NULL);
- GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
+ p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
}
static void
-run (void *cls,
- char *const *args,
- const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
+run (void *cls, char *const *args, const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_assert (ok == 1);
OKPP;
- err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &terminate_task_error, NULL);
+ err_task =
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
if (test == SYMMETRIC)
{
setup_peer (&p1, "test_core_quota_peer1.conf");
}
GNUNET_assert (test != -1);
- GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg,
- "CORE",
- "TOTAL_QUOTA_IN",
- ¤t_quota_p1_in));
- GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg,
- "CORE",
- "TOTAL_QUOTA_IN",
- ¤t_quota_p2_in));
- GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg,
- "CORE",
- "TOTAL_QUOTA_OUT",
- ¤t_quota_p1_out));
- GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg,
- "CORE",
- "TOTAL_QUOTA_OUT",
- ¤t_quota_p2_out));
-
- GNUNET_CORE_connect (p1.cfg, 1,
- &p1,
- &init_notify,
- &connect_notify,
- &disconnect_notify,
- NULL,
- &inbound_notify,
- GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
+ GNUNET_assert (GNUNET_SYSERR !=
+ GNUNET_CONFIGURATION_get_value_number (p1.cfg, "CORE",
+ "TOTAL_QUOTA_IN",
+ ¤t_quota_p1_in));
+ GNUNET_assert (GNUNET_SYSERR !=
+ GNUNET_CONFIGURATION_get_value_number (p2.cfg, "CORE",
+ "TOTAL_QUOTA_IN",
+ ¤t_quota_p2_in));
+ GNUNET_assert (GNUNET_SYSERR !=
+ GNUNET_CONFIGURATION_get_value_number (p1.cfg, "CORE",
+ "TOTAL_QUOTA_OUT",
+ ¤t_quota_p1_out));
+ GNUNET_assert (GNUNET_SYSERR !=
+ GNUNET_CONFIGURATION_get_value_number (p2.cfg, "CORE",
+ "TOTAL_QUOTA_OUT",
+ ¤t_quota_p2_out));
+
+ p1.ch = GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
+ &disconnect_notify, NULL, &inbound_notify, GNUNET_YES,
+ &outbound_notify, GNUNET_YES, handlers);
}
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "ARM process %u stopped\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n",
GNUNET_OS_process_get_pid (p->arm_proc));
GNUNET_OS_process_close (p->arm_proc);
p->arm_proc = NULL;
GNUNET_GETOPT_OPTION_END
};
ok = 1;
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-core-quota-compliance", "nohelp", options,
- &run, &ok);
+ GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
+ "test-core-quota-compliance", "nohelp", options, &run,
+ &ok);
stop_arm (&p1);
stop_arm (&p2);
return ok;