static char * key_file_p2;
static char * cert_file_p2;
+struct GNUNET_TRANSPORT_TransmitHandle * th;
+
#if VERBOSE
#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
#else
end ()
{
GNUNET_assert (ok == 6);
- GNUNET_SCHEDULER_cancel (die_task);
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ GNUNET_SCHEDULER_cancel (die_task);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Disconnecting from transports!\n");
+ if (th != NULL)
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
+ th = NULL;
+
GNUNET_TRANSPORT_disconnect (p1.th);
GNUNET_TRANSPORT_disconnect (p2.th);
die_task = GNUNET_SCHEDULER_NO_TASK;
stop_arm (struct PeerContext *p)
{
#if START_ARM
- if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- GNUNET_OS_process_wait (p->arm_proc);
- GNUNET_OS_process_close (p->arm_proc);
- p->arm_proc = NULL;
+ if (NULL != p->arm_proc)
+ {
+ if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+ GNUNET_OS_process_wait (p->arm_proc);
+ GNUNET_OS_process_close (p->arm_proc);
+ p->arm_proc = NULL;
+ }
#endif
GNUNET_CONFIGURATION_destroy (p->cfg);
}
+
+
+static void
+exchange_hello_last (void *cls,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct PeerContext *me = cls;
+
+ GNUNET_assert (message != NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Exchanging HELLO of size %d with peer (%s)!\n",
+ (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
+ GNUNET_i2s (&me->id));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
+ message, &me->id));
+ GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL);
+}
+
+
+static void
+exchange_hello (void *cls,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct PeerContext *me = cls;
+
+ GNUNET_assert (message != NULL);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
+ message, &me->id));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Exchanging HELLO of size %d from peer %s!\n",
+ (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
+ GNUNET_i2s (&me->id));
+ GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
+}
+
+
static void
end_badly ()
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
GNUNET_break (0);
+
+ if (th != NULL)
+ {
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
+ th = NULL;
+ }
+ else
+ {
+ GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
+ GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
+ }
+
GNUNET_TRANSPORT_disconnect (p1.th);
GNUNET_TRANSPORT_disconnect (p2.th);
if (GNUNET_SCHEDULER_NO_TASK != tct)
struct PeerContext *p = cls;
struct GNUNET_MessageHeader *hdr;
+ th = NULL;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting message with %u bytes to peer %s\n",
sizeof (struct GNUNET_MessageHeader),
}
-static void
-exchange_hello_last (void *cls,
- const struct GNUNET_MessageHeader *message)
-{
- struct PeerContext *me = cls;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Exchanging HELLO of size %d with peer (%s)!\n",
- (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
- GNUNET_i2s (&me->id));
- GNUNET_assert (message != NULL);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
- message, &me->id));
- GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL);
-}
-
-
-
-static void
-exchange_hello (void *cls,
- const struct GNUNET_MessageHeader *message)
-{
- struct PeerContext *me = cls;
-
- GNUNET_assert (message != NULL);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
- message, &me->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Exchanging HELLO of size %d from peer %s!\n",
- (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
- GNUNET_i2s (&me->id));
- GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
-}
-
-
-
static void
notify_connect (void *cls,
const struct GNUNET_PeerIdentity *peer,
GNUNET_assert (ok >= 2);
OKPP;
OKPP;
- GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_cancel (tct);
+ if (GNUNET_SCHEDULER_NO_TASK != die_task)
+ GNUNET_SCHEDULER_cancel (die_task);
+ if (GNUNET_SCHEDULER_NO_TASK != tct)
+ GNUNET_SCHEDULER_cancel (tct);
tct = GNUNET_SCHEDULER_NO_TASK;
GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT,
&end_badly, NULL);
- GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
+ th = GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
&p2.id,
256, 0, TIMEOUT, ¬ify_ready,
&p1);
GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME"))
GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome);
- GNUNET_DISK_directory_remove (p->servicehome);
+ if (NULL != p->servicehome)
+ GNUNET_DISK_directory_remove (p->servicehome);
#if START_ARM
p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
#endif
- if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME"))
- GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome);
if (is_https)
{
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Asking peers to connect...\n");
+ /* FIXME: 'pX.id' may still be all-zeros here... */
GNUNET_TRANSPORT_try_connect (p2.th,
&p1.id);
GNUNET_TRANSPORT_try_connect (p1.th,
GNUNET_free(cert_file_p2);
}
- if ((p1.servicehome != NULL) && (p2.servicehome != NULL))
- {
+ if (p1.servicehome != NULL)
+ {
GNUNET_DISK_directory_remove (p1.servicehome);
- GNUNET_DISK_directory_remove (p2.servicehome);
GNUNET_free(p1.servicehome);
- GNUNET_free(p2.servicehome);
- }
+ }
+ if (p2.servicehome != NULL)
+ {
+ GNUNET_DISK_directory_remove (p2.servicehome);
+ GNUNET_free(p2.servicehome);
+ }
return ok;
}
main (int argc, char *argv[])
{
int ret;
-#ifdef MINGW
- return GNUNET_SYSERR;
-#endif
GNUNET_log_setup ("test-transport-api",
#if VERBOSE
"`%s' not properly installed, cannot run NAT test!\n",
"gnunet-nat-server");
return 0;
- } GNUNET_free(p1.servicehome);
- GNUNET_free(p2.servicehome);
+ }
}
else if (strstr(argv[0], "udp") != NULL)
{