2019-01-16 18:33:22 +01:00
|
|
|
/* Copyright (c) 2013-2019, The Tor Project, Inc. */
|
2018-12-20 16:21:16 +01:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
#include "core/or/or.h"
|
|
|
|
|
|
|
|
#include "test/test.h"
|
2019-03-08 16:41:43 +01:00
|
|
|
#include "test_helpers.h"
|
2018-12-20 16:21:16 +01:00
|
|
|
#include "test/log_test_helpers.h"
|
|
|
|
|
|
|
|
#define OCIRC_EVENT_PRIVATE
|
|
|
|
#define ORCONN_EVENT_PRIVATE
|
|
|
|
#include "core/or/ocirc_event.h"
|
|
|
|
#include "core/or/orconn_event.h"
|
|
|
|
|
2019-03-08 16:41:43 +01:00
|
|
|
static void
|
|
|
|
send_state(const orconn_state_msg_t *msg_in)
|
|
|
|
{
|
|
|
|
orconn_state_msg_t *msg = tor_malloc(sizeof(*msg));
|
|
|
|
|
|
|
|
*msg = *msg_in;
|
|
|
|
orconn_state_publish(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_status(const orconn_status_msg_t *msg_in)
|
|
|
|
{
|
|
|
|
orconn_status_msg_t *msg = tor_malloc(sizeof(*msg));
|
|
|
|
|
|
|
|
*msg = *msg_in;
|
|
|
|
orconn_status_publish(msg);
|
|
|
|
}
|
|
|
|
|
2018-12-20 16:21:16 +01:00
|
|
|
static void
|
|
|
|
test_btrack_launch(void *arg)
|
|
|
|
{
|
2019-03-08 16:41:43 +01:00
|
|
|
orconn_state_msg_t conn;
|
2018-12-20 16:21:16 +01:00
|
|
|
ocirc_event_msg_t circ;
|
|
|
|
|
|
|
|
(void)arg;
|
2019-03-08 16:41:43 +01:00
|
|
|
conn.gid = 1;
|
|
|
|
conn.chan = 1;
|
|
|
|
conn.proxy_type = PROXY_NONE;
|
|
|
|
conn.state = OR_CONN_STATE_CONNECTING;
|
2018-12-20 16:21:16 +01:00
|
|
|
|
|
|
|
setup_full_capture_of_logs(LOG_DEBUG);
|
2019-03-08 16:41:43 +01:00
|
|
|
send_state(&conn);
|
2018-12-20 16:21:16 +01:00
|
|
|
expect_log_msg_containing("ORCONN gid=1 chan=1 proxy_type=0 state=1");
|
|
|
|
expect_no_log_msg_containing("ORCONN BEST_");
|
|
|
|
teardown_capture_of_logs();
|
|
|
|
|
|
|
|
circ.type = OCIRC_MSGTYPE_CHAN;
|
|
|
|
circ.u.chan.chan = 1;
|
|
|
|
circ.u.chan.onehop = true;
|
|
|
|
|
|
|
|
setup_full_capture_of_logs(LOG_DEBUG);
|
|
|
|
ocirc_event_publish(&circ);
|
|
|
|
expect_log_msg_containing("ORCONN LAUNCH chan=1 onehop=1");
|
|
|
|
expect_log_msg_containing("ORCONN BEST_ANY state -1->1 gid=1");
|
|
|
|
teardown_capture_of_logs();
|
|
|
|
|
2019-03-08 16:41:43 +01:00
|
|
|
conn.gid = 2;
|
|
|
|
conn.chan = 2;
|
2018-12-20 16:21:16 +01:00
|
|
|
|
|
|
|
setup_full_capture_of_logs(LOG_DEBUG);
|
2019-03-08 16:41:43 +01:00
|
|
|
send_state(&conn);
|
2018-12-20 16:21:16 +01:00
|
|
|
expect_log_msg_containing("ORCONN gid=2 chan=2 proxy_type=0 state=1");
|
|
|
|
expect_no_log_msg_containing("ORCONN BEST_");
|
|
|
|
teardown_capture_of_logs();
|
|
|
|
|
|
|
|
circ.u.chan.chan = 2;
|
|
|
|
circ.u.chan.onehop = false;
|
|
|
|
|
|
|
|
setup_full_capture_of_logs(LOG_DEBUG);
|
|
|
|
ocirc_event_publish(&circ);
|
|
|
|
expect_log_msg_containing("ORCONN LAUNCH chan=2 onehop=0");
|
|
|
|
expect_log_msg_containing("ORCONN BEST_AP state -1->1 gid=2");
|
|
|
|
teardown_capture_of_logs();
|
|
|
|
|
|
|
|
done:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_btrack_delete(void *arg)
|
|
|
|
{
|
2019-03-08 16:41:43 +01:00
|
|
|
orconn_state_msg_t state;
|
|
|
|
orconn_status_msg_t status;
|
2018-12-20 16:21:16 +01:00
|
|
|
|
|
|
|
(void)arg;
|
2019-03-08 16:41:43 +01:00
|
|
|
state.gid = 1;
|
|
|
|
state.chan = 1;
|
|
|
|
state.proxy_type = PROXY_NONE;
|
|
|
|
state.state = OR_CONN_STATE_CONNECTING;
|
2018-12-20 16:21:16 +01:00
|
|
|
|
|
|
|
setup_full_capture_of_logs(LOG_DEBUG);
|
2019-03-08 16:41:43 +01:00
|
|
|
send_state(&state);
|
2018-12-20 16:21:16 +01:00
|
|
|
expect_log_msg_containing("ORCONN gid=1 chan=1 proxy_type=0");
|
|
|
|
teardown_capture_of_logs();
|
|
|
|
|
2019-03-08 16:41:43 +01:00
|
|
|
status.gid = 1;
|
|
|
|
status.status = OR_CONN_EVENT_CLOSED;
|
|
|
|
status.reason = 0;
|
2018-12-20 16:21:16 +01:00
|
|
|
|
|
|
|
setup_full_capture_of_logs(LOG_DEBUG);
|
2019-03-08 16:41:43 +01:00
|
|
|
send_status(&status);
|
2018-12-20 16:21:16 +01:00
|
|
|
expect_log_msg_containing("ORCONN DELETE gid=1 status=3 reason=0");
|
|
|
|
teardown_capture_of_logs();
|
|
|
|
|
|
|
|
done:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct testcase_t btrack_tests[] = {
|
2019-03-08 16:41:43 +01:00
|
|
|
{ "launch", test_btrack_launch, TT_FORK, &helper_pubsub_setup, NULL },
|
|
|
|
{ "delete", test_btrack_delete, TT_FORK, &helper_pubsub_setup, NULL },
|
2018-12-20 16:21:16 +01:00
|
|
|
END_OF_TESTCASES
|
|
|
|
};
|