test_channelpadding.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. #define TOR_CHANNEL_INTERNAL_
  2. #define MAIN_PRIVATE
  3. #define NETWORKSTATUS_PRIVATE
  4. #include "or.h"
  5. #include "test.h"
  6. #include "testsupport.h"
  7. #include "connection.h"
  8. #include "connection_or.h"
  9. #include "channel.h"
  10. #include "channeltls.h"
  11. #include "channelpadding.h"
  12. #include "compat_libevent.h"
  13. #include "config.h"
  14. #include <event2/event.h>
  15. #include "compat_time.h"
  16. #include "main.h"
  17. #include "networkstatus.h"
  18. #include "log_test_helpers.h"
  19. int channelpadding_get_netflow_inactive_timeout_ms(channel_t *chan);
  20. int64_t channelpadding_compute_time_until_pad_for_netflow(channel_t *chan);
  21. int channelpadding_send_disable_command(channel_t*);
  22. int channelpadding_find_timerslot(channel_t *chan);
  23. void test_channelpadding_timers(void *arg);
  24. void test_channelpadding_consensus(void *arg);
  25. void test_channelpadding_negotiation(void *arg);
  26. void test_channelpadding_decide_to_pad_channel(void *arg);
  27. void test_channelpadding_killonehop(void *arg);
  28. void dummy_nop_timer(void);
  29. /* Thing to cast to fake tor_tls_t * to appease assert_connection_ok() */
  30. static int fake_tortls = 0; /* Bleh... */
  31. static int dont_stop_libevent = 0;
  32. // From test_channel.c
  33. channel_t * new_fake_channel(void);
  34. void free_fake_channel(channel_t*);
  35. static int
  36. mock_channel_has_queued_writes(channel_t *chan)
  37. {
  38. (void)chan;
  39. return 0;
  40. }
  41. static int tried_to_write_cell = 0;
  42. static channel_t *relay1_relay2;
  43. static channel_t *relay2_relay1;
  44. static channel_t *relay3_client;
  45. static channel_t *client_relay3;
  46. static int
  47. mock_channel_write_cell_relay2(channel_t *chan, cell_t *cell)
  48. {
  49. (void)chan;
  50. tried_to_write_cell++;
  51. channel_tls_handle_cell(cell, ((channel_tls_t*)relay1_relay2)->conn);
  52. event_base_loopbreak(tor_libevent_get_base());
  53. return 0;
  54. }
  55. static int
  56. mock_channel_write_cell_relay1(channel_t *chan, cell_t *cell)
  57. {
  58. (void)chan;
  59. tried_to_write_cell++;
  60. channel_tls_handle_cell(cell, ((channel_tls_t*)relay2_relay1)->conn);
  61. event_base_loopbreak(tor_libevent_get_base());
  62. return 0;
  63. }
  64. static int
  65. mock_channel_write_cell_relay3(channel_t *chan, cell_t *cell)
  66. {
  67. (void)chan;
  68. tried_to_write_cell++;
  69. channel_tls_handle_cell(cell, ((channel_tls_t*)client_relay3)->conn);
  70. event_base_loopbreak(tor_libevent_get_base());
  71. return 0;
  72. }
  73. static int
  74. mock_channel_write_cell_client(channel_t *chan, cell_t *cell)
  75. {
  76. (void)chan;
  77. tried_to_write_cell++;
  78. channel_tls_handle_cell(cell, ((channel_tls_t*)relay3_client)->conn);
  79. event_base_loopbreak(tor_libevent_get_base());
  80. return 0;
  81. }
  82. static int
  83. mock_channel_write_cell(channel_t *chan, cell_t *cell)
  84. {
  85. tried_to_write_cell++;
  86. channel_tls_handle_cell(cell, ((channel_tls_t*)chan)->conn);
  87. if (!dont_stop_libevent)
  88. event_base_loopbreak(tor_libevent_get_base());
  89. return 0;
  90. }
  91. static void
  92. setup_fake_connection_for_channel(channel_tls_t *chan)
  93. {
  94. or_connection_t *conn = (or_connection_t*)connection_new(CONN_TYPE_OR,
  95. AF_INET);
  96. conn->base_.conn_array_index = smartlist_len(connection_array);
  97. smartlist_add(connection_array, conn);
  98. conn->chan = chan;
  99. chan->conn = conn;
  100. conn->base_.magic = OR_CONNECTION_MAGIC;
  101. conn->base_.state = OR_CONN_STATE_OPEN;
  102. conn->base_.type = CONN_TYPE_OR;
  103. conn->base_.socket_family = AF_INET;
  104. conn->base_.address = tor_strdup("<fake>");
  105. conn->base_.port = 4242;
  106. conn->tls = (tor_tls_t *)((void *)(&fake_tortls));
  107. conn->link_proto = MIN_LINK_PROTO_FOR_CHANNEL_PADDING;
  108. connection_or_set_canonical(conn, 1);
  109. }
  110. static channel_tls_t *
  111. new_fake_channeltls(uint8_t id)
  112. {
  113. channel_tls_t *chan = tor_realloc(new_fake_channel(), sizeof(channel_tls_t));
  114. chan->base_.magic = TLS_CHAN_MAGIC;
  115. setup_fake_connection_for_channel(chan);
  116. chan->base_.channel_usage = CHANNEL_USED_FOR_FULL_CIRCS;
  117. chan->base_.has_queued_writes = mock_channel_has_queued_writes;
  118. chan->base_.write_cell = mock_channel_write_cell;
  119. chan->base_.padding_enabled = 1;
  120. chan->base_.identity_digest[0] = id;
  121. channel_register(&chan->base_);
  122. return chan;
  123. }
  124. static void
  125. free_fake_channeltls(channel_tls_t *chan)
  126. {
  127. channel_unregister(&chan->base_);
  128. tor_free(((channel_tls_t*)chan)->conn->base_.address);
  129. buf_free(((channel_tls_t*)chan)->conn->base_.inbuf);
  130. buf_free(((channel_tls_t*)chan)->conn->base_.outbuf);
  131. tor_free(((channel_tls_t*)chan)->conn);
  132. timer_free(chan->base_.padding_timer);
  133. channel_handle_free(chan->base_.timer_handle);
  134. channel_handles_clear(&chan->base_);
  135. free_fake_channel(&chan->base_);
  136. return;
  137. }
  138. static void
  139. setup_mock_consensus(void)
  140. {
  141. current_md_consensus = current_ns_consensus
  142. = tor_malloc_zero(sizeof(networkstatus_t));
  143. current_md_consensus->net_params = smartlist_new();
  144. current_md_consensus->routerstatus_list = smartlist_new();
  145. channelpadding_new_consensus_params(current_md_consensus);
  146. }
  147. static void
  148. free_mock_consensus(void)
  149. {
  150. SMARTLIST_FOREACH(current_md_consensus->routerstatus_list, void *, r,
  151. tor_free(r));
  152. smartlist_free(current_md_consensus->routerstatus_list);
  153. smartlist_free(current_ns_consensus->net_params);
  154. tor_free(current_ns_consensus);
  155. }
  156. static void
  157. setup_mock_network(void)
  158. {
  159. routerstatus_t *relay;
  160. connection_array = smartlist_new();
  161. relay1_relay2 = (channel_t*)new_fake_channeltls(2);
  162. relay1_relay2->write_cell = mock_channel_write_cell_relay1;
  163. channel_timestamp_active(relay1_relay2);
  164. relay = tor_malloc_zero(sizeof(routerstatus_t));
  165. relay->identity_digest[0] = 1;
  166. smartlist_add(current_md_consensus->routerstatus_list, relay);
  167. relay2_relay1 = (channel_t*)new_fake_channeltls(1);
  168. relay2_relay1->write_cell = mock_channel_write_cell_relay2;
  169. channel_timestamp_active(relay2_relay1);
  170. relay = tor_malloc_zero(sizeof(routerstatus_t));
  171. relay->identity_digest[0] = 2;
  172. smartlist_add(current_md_consensus->routerstatus_list, relay);
  173. relay3_client = (channel_t*)new_fake_channeltls(0);
  174. relay3_client->write_cell = mock_channel_write_cell_relay3;
  175. relay3_client->is_client = 1;
  176. channel_timestamp_active(relay3_client);
  177. relay = tor_malloc_zero(sizeof(routerstatus_t));
  178. relay->identity_digest[0] = 3;
  179. smartlist_add(current_md_consensus->routerstatus_list, relay);
  180. client_relay3 = (channel_t*)new_fake_channeltls(3);
  181. client_relay3->write_cell = mock_channel_write_cell_client;
  182. channel_timestamp_active(client_relay3);
  183. channel_do_open_actions(relay1_relay2);
  184. channel_do_open_actions(relay2_relay1);
  185. channel_do_open_actions(relay3_client);
  186. channel_do_open_actions(client_relay3);
  187. }
  188. static void
  189. free_mock_network(void)
  190. {
  191. free_fake_channeltls((channel_tls_t*)relay1_relay2);
  192. free_fake_channeltls((channel_tls_t*)relay2_relay1);
  193. free_fake_channeltls((channel_tls_t*)relay3_client);
  194. free_fake_channeltls((channel_tls_t*)client_relay3);
  195. smartlist_free(connection_array);
  196. }
  197. static void
  198. dummy_timer_cb(tor_timer_t *t, void *arg, const monotime_t *now_mono)
  199. {
  200. (void)t; (void)arg; (void)now_mono;
  201. event_base_loopbreak(tor_libevent_get_base());
  202. return;
  203. }
  204. // This hack adds a dummy timer so that the libevent base loop
  205. // actually returns when we don't expect any timers to fire. Otherwise,
  206. // the global_timer_event gets scheduled an hour from now, and the
  207. // base loop never returns.
  208. void
  209. dummy_nop_timer(void)
  210. {
  211. tor_timer_t *dummy_timer = timer_new(dummy_timer_cb, NULL);
  212. struct timeval timeout;
  213. timeout.tv_sec = 1;
  214. timeout.tv_usec = 0;
  215. timer_schedule(dummy_timer, &timeout);
  216. event_base_loop(tor_libevent_get_base(), 0);
  217. timer_free(dummy_timer);
  218. }
  219. #define CHANNELPADDING_MAX_TIMERS 25
  220. #define CHANNELS_TO_TEST (CHANNELPADDING_MAX_TIMERS*4)
  221. /**
  222. * Tests to ensure that we handle more than the max number of pending
  223. * timers properly.
  224. */
  225. void
  226. test_channelpadding_timers(void *arg)
  227. {
  228. channelpadding_decision_t decision;
  229. channel_t *chans[CHANNELS_TO_TEST];
  230. (void)arg;
  231. tor_libevent_postfork();
  232. connection_array = smartlist_new();
  233. monotime_init();
  234. timers_initialize();
  235. channelpadding_new_consensus_params(NULL);
  236. for (int i = 0; i < CHANNELS_TO_TEST; i++) {
  237. chans[i] = (channel_t*)new_fake_channeltls(0);
  238. channel_timestamp_active(chans[i]);
  239. }
  240. for (int j = 0; j < 2; j++) {
  241. tried_to_write_cell = 0;
  242. int i = 0;
  243. /* This loop fills our timerslot array with timers of increasing time
  244. * until they fire */
  245. for (; i < CHANNELPADDING_MAX_TIMERS; i++) {
  246. chans[i]->next_padding_time_ms = monotime_coarse_absolute_msec()
  247. + 10 + i*4;
  248. decision = channelpadding_decide_to_pad_channel(chans[i]);
  249. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  250. tt_assert(chans[i]->pending_padding_callback);
  251. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  252. }
  253. /* This loop should add timers to the first position in the timerslot
  254. * array, since its timeout is before all other timers. */
  255. for (; i < CHANNELS_TO_TEST/3; i++) {
  256. chans[i]->next_padding_time_ms = monotime_coarse_absolute_msec() + 1;
  257. decision = channelpadding_decide_to_pad_channel(chans[i]);
  258. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  259. tt_assert(chans[i]->pending_padding_callback);
  260. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  261. }
  262. /* This loop should add timers to our existing lists in a weak
  263. * pseudorandom pattern. It ensures that the lists can grow with multiple
  264. * timers in them. */
  265. for (; i < CHANNELS_TO_TEST/2; i++) {
  266. chans[i]->next_padding_time_ms = monotime_coarse_absolute_msec() + 10 +
  267. i*3 % CHANNELPADDING_MAX_TIMERS;
  268. decision = channelpadding_decide_to_pad_channel(chans[i]);
  269. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  270. tt_assert(chans[i]->pending_padding_callback);
  271. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  272. }
  273. /* This loop should add timers to the last position in the timerslot
  274. * array, since its timeout is after all other timers. */
  275. for (; i < CHANNELS_TO_TEST; i++) {
  276. chans[i]->next_padding_time_ms = monotime_coarse_absolute_msec() + 500 +
  277. i % CHANNELPADDING_MAX_TIMERS;
  278. decision = channelpadding_decide_to_pad_channel(chans[i]);
  279. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  280. tt_assert(chans[i]->pending_padding_callback);
  281. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  282. }
  283. // Wait for the timers and then kill the event loop.
  284. dont_stop_libevent = 1;
  285. dummy_nop_timer();
  286. tt_int_op(tried_to_write_cell, OP_EQ, CHANNELS_TO_TEST);
  287. // Test that we have no pending callbacks and all empty slots now
  288. for (i = 0; i < CHANNELS_TO_TEST; i++) {
  289. tt_assert(!chans[i]->pending_padding_callback);
  290. }
  291. }
  292. done:
  293. for (int i = 0; i < CHANNELS_TO_TEST; i++) {
  294. free_fake_channeltls((channel_tls_t*)chans[i]);
  295. }
  296. smartlist_free(connection_array);
  297. timers_shutdown();
  298. channel_free_all();
  299. return;
  300. }
  301. void
  302. test_channelpadding_killonehop(void *arg)
  303. {
  304. channelpadding_decision_t decision;
  305. (void)arg;
  306. tor_libevent_postfork();
  307. routerstatus_t *relay = tor_malloc_zero(sizeof(routerstatus_t));
  308. monotime_init();
  309. timers_initialize();
  310. setup_mock_consensus();
  311. setup_mock_network();
  312. /* Do we disable padding if tor2webmode or rsos are enabled, and
  313. * the consensus says don't pad? */
  314. /* Ensure we can kill tor2web and rsos padding if we want. */
  315. // First, test that padding works if either is enabled
  316. smartlist_clear(current_md_consensus->net_params);
  317. channelpadding_new_consensus_params(current_md_consensus);
  318. tried_to_write_cell = 0;
  319. get_options_mutable()->Tor2webMode = 1;
  320. client_relay3->next_padding_time_ms = monotime_coarse_absolute_msec() + 100;
  321. decision = channelpadding_decide_to_pad_channel(client_relay3);
  322. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  323. tt_assert(client_relay3->pending_padding_callback);
  324. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  325. decision = channelpadding_decide_to_pad_channel(client_relay3);
  326. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_ALREADY_SCHEDULED);
  327. // Wait for the timer
  328. event_base_loop(tor_libevent_get_base(), 0);
  329. tt_int_op(tried_to_write_cell, OP_EQ, 1);
  330. tt_assert(!client_relay3->pending_padding_callback);
  331. // Then test disabling each via consensus param
  332. smartlist_add(current_md_consensus->net_params,
  333. (void*)"nf_pad_tor2web=0");
  334. channelpadding_new_consensus_params(current_md_consensus);
  335. // Before the client tries to pad, the relay will still pad:
  336. tried_to_write_cell = 0;
  337. relay3_client->next_padding_time_ms = monotime_coarse_absolute_msec() + 100;
  338. get_options_mutable()->ORPort_set = 1;
  339. get_options_mutable()->Tor2webMode = 0;
  340. decision = channelpadding_decide_to_pad_channel(relay3_client);
  341. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  342. tt_assert(relay3_client->pending_padding_callback);
  343. // Wait for the timer
  344. event_base_loop(tor_libevent_get_base(), 0);
  345. tt_int_op(tried_to_write_cell, OP_EQ, 1);
  346. tt_assert(!client_relay3->pending_padding_callback);
  347. // Test client side (it should stop immediately, but send a negotiate)
  348. tried_to_write_cell = 0;
  349. tt_assert(relay3_client->padding_enabled);
  350. tt_assert(client_relay3->padding_enabled);
  351. get_options_mutable()->Tor2webMode = 1;
  352. /* For the relay to recieve the negotiate: */
  353. get_options_mutable()->ORPort_set = 1;
  354. decision = channelpadding_decide_to_pad_channel(client_relay3);
  355. tt_int_op(decision, OP_EQ, CHANNELPADDING_WONTPAD);
  356. tt_int_op(tried_to_write_cell, OP_EQ, 1);
  357. tt_assert(!client_relay3->pending_padding_callback);
  358. tt_assert(!relay3_client->padding_enabled);
  359. // Test relay side (it should have gotten the negotiation to disable)
  360. get_options_mutable()->ORPort_set = 1;
  361. get_options_mutable()->Tor2webMode = 0;
  362. tt_int_op(channelpadding_decide_to_pad_channel(relay3_client), OP_EQ,
  363. CHANNELPADDING_WONTPAD);
  364. tt_assert(!relay3_client->padding_enabled);
  365. /* Repeat for SOS */
  366. // First, test that padding works if either is enabled
  367. smartlist_clear(current_md_consensus->net_params);
  368. channelpadding_new_consensus_params(current_md_consensus);
  369. relay3_client->padding_enabled = 1;
  370. client_relay3->padding_enabled = 1;
  371. tried_to_write_cell = 0;
  372. get_options_mutable()->ORPort_set = 0;
  373. get_options_mutable()->HiddenServiceSingleHopMode = 1;
  374. get_options_mutable()->HiddenServiceNonAnonymousMode = 1;
  375. client_relay3->next_padding_time_ms = monotime_coarse_absolute_msec() + 100;
  376. decision = channelpadding_decide_to_pad_channel(client_relay3);
  377. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  378. tt_assert(client_relay3->pending_padding_callback);
  379. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  380. decision = channelpadding_decide_to_pad_channel(client_relay3);
  381. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_ALREADY_SCHEDULED);
  382. // Wait for the timer
  383. event_base_loop(tor_libevent_get_base(), 0);
  384. tt_int_op(tried_to_write_cell, OP_EQ, 1);
  385. tt_assert(!client_relay3->pending_padding_callback);
  386. // Then test disabling each via consensus param
  387. smartlist_add(current_md_consensus->net_params,
  388. (void*)"nf_pad_single_onion=0");
  389. channelpadding_new_consensus_params(current_md_consensus);
  390. // Before the client tries to pad, the relay will still pad:
  391. tried_to_write_cell = 0;
  392. relay3_client->next_padding_time_ms = monotime_coarse_absolute_msec() + 100;
  393. get_options_mutable()->ORPort_set = 1;
  394. get_options_mutable()->HiddenServiceSingleHopMode = 0;
  395. get_options_mutable()->HiddenServiceNonAnonymousMode = 0;
  396. decision = channelpadding_decide_to_pad_channel(relay3_client);
  397. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  398. tt_assert(relay3_client->pending_padding_callback);
  399. // Wait for the timer
  400. event_base_loop(tor_libevent_get_base(), 0);
  401. tt_int_op(tried_to_write_cell, OP_EQ, 1);
  402. tt_assert(!client_relay3->pending_padding_callback);
  403. // Test client side (it should stop immediately)
  404. get_options_mutable()->HiddenServiceSingleHopMode = 1;
  405. get_options_mutable()->HiddenServiceNonAnonymousMode = 1;
  406. /* For the relay to recieve the negotiate: */
  407. get_options_mutable()->ORPort_set = 1;
  408. decision = channelpadding_decide_to_pad_channel(client_relay3);
  409. tt_int_op(decision, OP_EQ, CHANNELPADDING_WONTPAD);
  410. tt_assert(!client_relay3->pending_padding_callback);
  411. // Test relay side (it should have gotten the negotiation to disable)
  412. get_options_mutable()->ORPort_set = 1;
  413. get_options_mutable()->HiddenServiceSingleHopMode = 0;
  414. get_options_mutable()->HiddenServiceNonAnonymousMode = 0;
  415. tt_int_op(channelpadding_decide_to_pad_channel(relay3_client), OP_EQ,
  416. CHANNELPADDING_WONTPAD);
  417. tt_assert(!relay3_client->padding_enabled);
  418. done:
  419. free_mock_consensus();
  420. free_mock_network();
  421. tor_free(relay);
  422. timers_shutdown();
  423. channel_free_all();
  424. }
  425. void
  426. test_channelpadding_consensus(void *arg)
  427. {
  428. channelpadding_decision_t decision;
  429. or_options_t *options = get_options_mutable();
  430. int64_t val;
  431. (void)arg;
  432. tor_libevent_postfork();
  433. /*
  434. * Params tested:
  435. * nf_pad_before_usage
  436. * nf_pad_relays
  437. * nf_ito_low
  438. * nf_ito_high
  439. *
  440. * Plan:
  441. * 1. Padding can be completely disabled via consensus
  442. * 2. Negotiation can't re-enable consensus-disabled padding
  443. * 3. Negotiation can't increase padding from relays beyond
  444. * consensus defaults
  445. * 4. Relay-to-relay padding can be enabled/disabled in consensus
  446. * 5. Can enable/disable padding before actually using a connection
  447. * 6. Can we control circ and TLS conn lifetime from the consensus?
  448. */
  449. channel_t *chan;
  450. routerstatus_t *relay = tor_malloc_zero(sizeof(routerstatus_t));
  451. monotime_init();
  452. timers_initialize();
  453. connection_array = smartlist_new();
  454. chan = (channel_t*)new_fake_channeltls(0);
  455. channel_timestamp_active(chan);
  456. setup_mock_consensus();
  457. get_options_mutable()->ORPort_set = 1;
  458. /* Test 1: Padding can be completely disabled via consensus */
  459. tried_to_write_cell = 0;
  460. chan->next_padding_time_ms = monotime_coarse_absolute_msec() + 100;
  461. decision = channelpadding_decide_to_pad_channel(chan);
  462. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  463. tt_assert(chan->pending_padding_callback);
  464. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  465. decision = channelpadding_decide_to_pad_channel(chan);
  466. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_ALREADY_SCHEDULED);
  467. // Wait for the timer
  468. event_base_loop(tor_libevent_get_base(), 0);
  469. tt_int_op(tried_to_write_cell, OP_EQ, 1);
  470. tt_assert(!chan->pending_padding_callback);
  471. smartlist_add(current_md_consensus->net_params,
  472. (void*)"nf_ito_low=0");
  473. smartlist_add(current_md_consensus->net_params,
  474. (void*)"nf_ito_high=0");
  475. get_options_mutable()->ConnectionPadding = 1;
  476. channelpadding_new_consensus_params(current_md_consensus);
  477. decision = channelpadding_decide_to_pad_channel(chan);
  478. tt_int_op(decision, OP_EQ, CHANNELPADDING_WONTPAD);
  479. tt_assert(!chan->pending_padding_callback);
  480. val = channelpadding_get_netflow_inactive_timeout_ms(chan);
  481. tt_i64_op(val, OP_EQ, 0);
  482. val = channelpadding_compute_time_until_pad_for_netflow(chan);
  483. tt_i64_op(val, OP_EQ, -2);
  484. /* Test 2: Negotiation can't re-enable consensus-disabled padding */
  485. channelpadding_send_enable_command(chan, 100, 200);
  486. tried_to_write_cell = 0;
  487. decision = channelpadding_decide_to_pad_channel(chan);
  488. tt_int_op(decision, OP_EQ, CHANNELPADDING_WONTPAD);
  489. tt_assert(!chan->pending_padding_callback);
  490. val = channelpadding_get_netflow_inactive_timeout_ms(chan);
  491. tt_i64_op(val, OP_EQ, 0);
  492. val = channelpadding_compute_time_until_pad_for_netflow(chan);
  493. tt_i64_op(val, OP_EQ, -2);
  494. tt_assert(!chan->next_padding_time_ms);
  495. smartlist_clear(current_md_consensus->net_params);
  496. /* Test 3: Negotiation can't increase padding from relays beyond consensus
  497. * values */
  498. smartlist_add(current_md_consensus->net_params,
  499. (void*)"nf_ito_low=100");
  500. smartlist_add(current_md_consensus->net_params,
  501. (void*)"nf_ito_high=200");
  502. channelpadding_new_consensus_params(current_md_consensus);
  503. tried_to_write_cell = 0;
  504. chan->next_padding_time_ms = monotime_coarse_absolute_msec() + 100;
  505. decision = channelpadding_decide_to_pad_channel(chan);
  506. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  507. tt_assert(chan->pending_padding_callback);
  508. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  509. val = channelpadding_get_netflow_inactive_timeout_ms(chan);
  510. tt_i64_op(val, OP_GE, 100);
  511. tt_i64_op(val, OP_LE, 200);
  512. val = channelpadding_compute_time_until_pad_for_netflow(chan);
  513. tt_i64_op(val, OP_LE, 200);
  514. // Wait for the timer
  515. event_base_loop(tor_libevent_get_base(), 0);
  516. tt_int_op(tried_to_write_cell, OP_EQ, 1);
  517. tt_assert(!chan->pending_padding_callback);
  518. smartlist_clear(current_md_consensus->net_params);
  519. smartlist_add(current_md_consensus->net_params,
  520. (void*)"nf_ito_low=1500");
  521. smartlist_add(current_md_consensus->net_params,
  522. (void*)"nf_ito_high=4500");
  523. channelpadding_new_consensus_params(current_md_consensus);
  524. channelpadding_send_enable_command(chan, 100, 200);
  525. tried_to_write_cell = 0;
  526. decision = channelpadding_decide_to_pad_channel(chan);
  527. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADLATER);
  528. tt_assert(!chan->pending_padding_callback);
  529. val = channelpadding_get_netflow_inactive_timeout_ms(chan);
  530. tt_i64_op(val, OP_GE, 1500);
  531. tt_i64_op(val, OP_LE, 4500);
  532. val = channelpadding_compute_time_until_pad_for_netflow(chan);
  533. tt_i64_op(val, OP_LE, 4500);
  534. /* Test 4: Relay-to-relay padding can be enabled/disabled in consensus */
  535. /* Make this channel a relay's channel */
  536. memcpy(relay->identity_digest,
  537. ((channel_tls_t *)chan)->conn->identity_digest, DIGEST_LEN);
  538. smartlist_add(current_md_consensus->routerstatus_list, relay);
  539. tried_to_write_cell = 0;
  540. decision = channelpadding_decide_to_pad_channel(chan);
  541. tt_int_op(decision, OP_EQ, CHANNELPADDING_WONTPAD);
  542. tt_assert(!chan->pending_padding_callback);
  543. smartlist_add(current_md_consensus->net_params,
  544. (void*)"nf_pad_relays=1");
  545. channelpadding_new_consensus_params(current_md_consensus);
  546. decision = channelpadding_decide_to_pad_channel(chan);
  547. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADLATER);
  548. tt_assert(!chan->pending_padding_callback);
  549. val = channelpadding_get_netflow_inactive_timeout_ms(chan);
  550. tt_i64_op(val, OP_GE, 1500);
  551. tt_i64_op(val, OP_LE, 4500);
  552. val = channelpadding_compute_time_until_pad_for_netflow(chan);
  553. tt_i64_op(val, OP_LE, 4500);
  554. /* Test 5: If we disable padding before channel usage, does that work? */
  555. smartlist_add(current_md_consensus->net_params,
  556. (void*)"nf_pad_before_usage=0");
  557. channelpadding_new_consensus_params(current_md_consensus);
  558. tried_to_write_cell = 0;
  559. decision = channelpadding_decide_to_pad_channel(chan);
  560. tt_int_op(decision, OP_EQ, CHANNELPADDING_WONTPAD);
  561. tt_assert(!chan->pending_padding_callback);
  562. /* Test 6: Can we control circ and TLS conn lifetime from the consensus? */
  563. val = channelpadding_get_channel_idle_timeout(NULL, 0);
  564. tt_i64_op(val, OP_GE, 180);
  565. tt_i64_op(val, OP_LE, 180+90);
  566. val = channelpadding_get_channel_idle_timeout(chan, 0);
  567. tt_i64_op(val, OP_GE, 180);
  568. tt_i64_op(val, OP_LE, 180+90);
  569. options->ReducedConnectionPadding = 1;
  570. val = channelpadding_get_channel_idle_timeout(chan, 0);
  571. tt_i64_op(val, OP_GE, 180/2);
  572. tt_i64_op(val, OP_LE, (180+90)/2);
  573. options->ReducedConnectionPadding = 0;
  574. options->ORPort_set = 1;
  575. smartlist_add(current_md_consensus->net_params,
  576. (void*)"nf_conntimeout_relays=600");
  577. channelpadding_new_consensus_params(current_md_consensus);
  578. val = channelpadding_get_channel_idle_timeout(chan, 1);
  579. tt_i64_op(val, OP_GE, 450);
  580. tt_i64_op(val, OP_LE, 750);
  581. val = channelpadding_get_circuits_available_timeout();
  582. tt_i64_op(val, OP_GE, 30*60);
  583. tt_i64_op(val, OP_LE, 30*60*2);
  584. options->ReducedConnectionPadding = 1;
  585. smartlist_add(current_md_consensus->net_params,
  586. (void*)"nf_conntimeout_clients=600");
  587. channelpadding_new_consensus_params(current_md_consensus);
  588. val = channelpadding_get_circuits_available_timeout();
  589. tt_i64_op(val, OP_GE, 600/2);
  590. tt_i64_op(val, OP_LE, 600*2/2);
  591. options->ReducedConnectionPadding = 0;
  592. options->CircuitsAvailableTimeout = 24*60*60;
  593. val = channelpadding_get_circuits_available_timeout();
  594. tt_i64_op(val, OP_GE, 24*60*60);
  595. tt_i64_op(val, OP_LE, 24*60*60*2);
  596. done:
  597. free_mock_consensus();
  598. free_fake_channeltls((channel_tls_t*)chan);
  599. smartlist_free(connection_array);
  600. timers_shutdown();
  601. channel_free_all();
  602. return;
  603. }
  604. void
  605. test_channelpadding_negotiation(void *arg)
  606. {
  607. channelpadding_negotiate_t disable;
  608. cell_t cell;
  609. channelpadding_decision_t decision;
  610. int val;
  611. (void)arg;
  612. /* Plan:
  613. * 1. Clients reject negotiation, relays accept it.
  614. * * Bridges accept negotiation from their clients,
  615. * but not from relays.
  616. * 2. Torrc options can override client-side negotiation
  617. * 3. Test a version issue in channelpadidng cell
  618. * 4. Test channelpadding_reduced_padding
  619. */
  620. monotime_init();
  621. timers_initialize();
  622. setup_mock_consensus();
  623. setup_mock_network();
  624. /* Test case #1: Do the right things ignore negotiation? */
  625. /* relay-to-client case: */
  626. channelpadding_send_disable_command(relay3_client);
  627. tt_assert(client_relay3->padding_enabled);
  628. /* client-to-relay case: */
  629. get_options_mutable()->ORPort_set = 1;
  630. channelpadding_disable_padding_on_channel(client_relay3);
  631. tt_int_op(channelpadding_decide_to_pad_channel(relay3_client), OP_EQ,
  632. CHANNELPADDING_WONTPAD);
  633. tt_assert(!relay3_client->padding_enabled);
  634. relay3_client->padding_enabled = 1;
  635. client_relay3->padding_enabled = 1;
  636. /* Bridge case from relay */
  637. get_options_mutable()->BridgeRelay = 1;
  638. channelpadding_disable_padding_on_channel(relay2_relay1);
  639. tt_assert(relay1_relay2->padding_enabled);
  640. /* Bridge case from client */
  641. channelpadding_disable_padding_on_channel(client_relay3);
  642. tt_assert(!relay3_client->padding_enabled);
  643. tt_int_op(channelpadding_decide_to_pad_channel(relay3_client), OP_EQ,
  644. CHANNELPADDING_WONTPAD);
  645. relay3_client->padding_enabled = 1;
  646. client_relay3->padding_enabled = 1;
  647. get_options_mutable()->BridgeRelay = 0;
  648. get_options_mutable()->ORPort_set = 0;
  649. /* Test case #2: Torrc options */
  650. /* ConnectionPadding auto; Relay doesn't suport us */
  651. ((channel_tls_t*)relay3_client)->conn->link_proto = 4;
  652. relay3_client->padding_enabled = 0;
  653. tried_to_write_cell = 0;
  654. decision = channelpadding_decide_to_pad_channel(relay3_client);
  655. tt_int_op(decision, OP_EQ, CHANNELPADDING_WONTPAD);
  656. tt_assert(!relay3_client->pending_padding_callback);
  657. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  658. ((channel_tls_t*)relay3_client)->conn->link_proto = 5;
  659. relay3_client->padding_enabled = 1;
  660. /* ConnectionPadding 1; Relay doesn't suport us */
  661. get_options_mutable()->ConnectionPadding = 1;
  662. tried_to_write_cell = 0;
  663. decision = channelpadding_decide_to_pad_channel(client_relay3);
  664. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADLATER);
  665. tt_assert(!client_relay3->pending_padding_callback);
  666. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  667. get_options_mutable()->ConnectionPadding = 0;
  668. /* Test case #3: Test a version issue in channelpadding cell */
  669. get_options_mutable()->ORPort_set = 1;
  670. client_relay3->padding_enabled = 1;
  671. relay3_client->padding_enabled = 1;
  672. memset(&cell, 0, sizeof(cell_t));
  673. memset(&disable, 0, sizeof(channelpadding_negotiate_t));
  674. cell.command = CELL_PADDING_NEGOTIATE;
  675. channelpadding_negotiate_set_command(&disable, CHANNELPADDING_COMMAND_STOP);
  676. disable.version = 1;
  677. channelpadding_negotiate_encode(cell.payload, CELL_PAYLOAD_SIZE, &disable);
  678. client_relay3->write_cell(client_relay3, &cell);
  679. tt_assert(relay3_client->padding_enabled);
  680. tt_int_op(channelpadding_update_padding_for_channel(client_relay3, &disable),
  681. OP_EQ, -1);
  682. tt_assert(client_relay3->padding_enabled);
  683. disable.version = 0;
  684. channelpadding_negotiate_encode(cell.payload, CELL_PAYLOAD_SIZE, &disable);
  685. client_relay3->write_cell(client_relay3, &cell);
  686. tt_assert(!relay3_client->padding_enabled);
  687. /* Test case 4: Reducing padding actually reduces it */
  688. relay3_client->padding_enabled = 1;
  689. client_relay3->padding_enabled = 1;
  690. decision = channelpadding_decide_to_pad_channel(relay3_client);
  691. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADLATER);
  692. channelpadding_reduce_padding_on_channel(client_relay3);
  693. tried_to_write_cell = 0;
  694. decision = channelpadding_decide_to_pad_channel(relay3_client);
  695. tt_int_op(decision, OP_EQ, CHANNELPADDING_WONTPAD);
  696. get_options_mutable()->ORPort_set = 0;
  697. decision = channelpadding_decide_to_pad_channel(client_relay3);
  698. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADLATER);
  699. tt_assert(!client_relay3->pending_padding_callback);
  700. val = channelpadding_get_netflow_inactive_timeout_ms(client_relay3);
  701. tt_int_op(val, OP_GE, 9000);
  702. tt_int_op(val, OP_LE, 14000);
  703. int64_t val64 =
  704. channelpadding_compute_time_until_pad_for_netflow(client_relay3);
  705. tt_i64_op(val64, OP_LE, 14000);
  706. done:
  707. free_mock_network();
  708. free_mock_consensus();
  709. timers_shutdown();
  710. channel_free_all();
  711. return;
  712. }
  713. void
  714. test_channelpadding_decide_to_pad_channel(void *arg)
  715. {
  716. channelpadding_decision_t decision;
  717. /**
  718. * Test case plan:
  719. *
  720. * 1. Channel that has "sent a packet" before the timeout.
  721. * + We should decide to pad later
  722. * 2. Channel that has not "sent a packet" before the timeout:
  723. * 2a. Not within 1.1s of the timeout.
  724. * + We should decide to pad later
  725. * 2b. Within 1.1s of the timemout.
  726. * + We should schedule padding
  727. * + We should get feedback that we wrote a cell
  728. * 2c. Within 0.1s of the timeout.
  729. * + We should schedule padding
  730. * + We should get feedback that we wrote a cell
  731. * 2d. Channel that asks to pad while timeout is scheduled
  732. * + We should schedule padding
  733. * + We should get feedback that we wrote a cell
  734. * 2e. 0s of the timeout
  735. * + We should send padding immediately
  736. * + We should get feedback that we wrote a cell
  737. * 2f. <0s of the timeout
  738. * + We should send padding immediately
  739. * + We should get feedback that we wrote a cell
  740. * 3. Channel that sends a packet while timeout is scheduled
  741. * + We should not get feedback that we wrote a cell
  742. * 4. Channel that closes while timeout is scheduled
  743. * + We should not get feedback that we wrote a cell
  744. * 5. Make sure the channel still would work if repaired
  745. * + We should be able to schedule padding and resend
  746. * 6. Channel is not used for full circuits
  747. * 7. Channel that disappears while timeout is scheduled
  748. * + We should not send padding
  749. */
  750. channel_t *chan;
  751. connection_array = smartlist_new();
  752. (void)arg;
  753. tor_libevent_postfork();
  754. monotime_init();
  755. timers_initialize();
  756. setup_full_capture_of_logs(LOG_WARN);
  757. channelpadding_new_consensus_params(NULL);
  758. chan = (channel_t*)new_fake_channeltls(0);
  759. channel_timestamp_active(chan);
  760. /* Test case #1: Channel that has "sent a packet" before the timeout. */
  761. tried_to_write_cell = 0;
  762. decision = channelpadding_decide_to_pad_channel(chan);
  763. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADLATER);
  764. tt_assert(!chan->pending_padding_callback);
  765. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  766. /* Test case #2a: > 1.1s until timeout */
  767. tried_to_write_cell = 0;
  768. chan->next_padding_time_ms = monotime_coarse_absolute_msec() + 1200;
  769. decision = channelpadding_decide_to_pad_channel(chan);
  770. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADLATER);
  771. tt_assert(!chan->pending_padding_callback);
  772. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  773. /* Test case #2b: >= 1.0s until timeout */
  774. tried_to_write_cell = 0;
  775. chan->next_padding_time_ms = monotime_coarse_absolute_msec() + 1000;
  776. decision = channelpadding_decide_to_pad_channel(chan);
  777. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  778. tt_assert(chan->pending_padding_callback);
  779. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  780. // Wait for the timer from case #2b
  781. event_base_loop(tor_libevent_get_base(), 0);
  782. tt_int_op(tried_to_write_cell, OP_EQ, 1);
  783. tt_assert(!chan->pending_padding_callback);
  784. /* Test case #2c: > 0.1s until timeout */
  785. tried_to_write_cell = 0;
  786. chan->next_padding_time_ms = monotime_coarse_absolute_msec() + 100;
  787. decision = channelpadding_decide_to_pad_channel(chan);
  788. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  789. tt_assert(chan->pending_padding_callback);
  790. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  791. /* Test case #2d: Channel that asks to pad while timeout is scheduled */
  792. decision = channelpadding_decide_to_pad_channel(chan);
  793. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_ALREADY_SCHEDULED);
  794. // Wait for the timer
  795. event_base_loop(tor_libevent_get_base(), 0);
  796. tt_int_op(tried_to_write_cell, OP_EQ, 1);
  797. tt_assert(!chan->pending_padding_callback);
  798. /* Test case #2e: 0s until timeout */
  799. tried_to_write_cell = 0;
  800. chan->next_padding_time_ms = monotime_coarse_absolute_msec();
  801. decision = channelpadding_decide_to_pad_channel(chan);
  802. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SENT);
  803. tt_int_op(tried_to_write_cell, OP_EQ, 1);
  804. tt_assert(!chan->pending_padding_callback);
  805. /* Test case #2f: <0s until timeout */
  806. tried_to_write_cell = 0;
  807. chan->next_padding_time_ms = monotime_coarse_absolute_msec() - 100;
  808. decision = channelpadding_decide_to_pad_channel(chan);
  809. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SENT);
  810. tt_int_op(tried_to_write_cell, OP_EQ, 1);
  811. tt_assert(!chan->pending_padding_callback);
  812. /* Test case #3: Channel that sends a packet while timeout is scheduled */
  813. tried_to_write_cell = 0;
  814. chan->next_padding_time_ms = monotime_coarse_absolute_msec() + 100;
  815. decision = channelpadding_decide_to_pad_channel(chan);
  816. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  817. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  818. tt_assert(chan->pending_padding_callback);
  819. // Pretend the channel sent a packet
  820. channel_timestamp_active(chan);
  821. // We don't expect any timer callbacks here. Make a dummy one to be sure.
  822. dummy_nop_timer();
  823. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  824. tt_assert(!chan->pending_padding_callback);
  825. /* Test case #4: Channel that closes while a timeout is scheduled */
  826. tried_to_write_cell = 0;
  827. chan->next_padding_time_ms = monotime_coarse_absolute_msec() + 100;
  828. decision = channelpadding_decide_to_pad_channel(chan);
  829. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  830. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  831. tt_assert(chan->pending_padding_callback);
  832. // Pretend the channel is temporarily down
  833. chan->state = CHANNEL_STATE_MAINT;
  834. // We don't expect any timer callbacks here. Make a dummy one to be sure.
  835. dummy_nop_timer();
  836. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  837. tt_assert(!chan->pending_padding_callback);
  838. chan->state = CHANNEL_STATE_OPEN;
  839. /* Test case #5: Make sure previous test case didn't break everything */
  840. tried_to_write_cell = 0;
  841. chan->next_padding_time_ms = monotime_coarse_absolute_msec() + 100;
  842. decision = channelpadding_decide_to_pad_channel(chan);
  843. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  844. tt_assert(chan->pending_padding_callback);
  845. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  846. // Wait for the timer
  847. event_base_loop(tor_libevent_get_base(), 0);
  848. tt_int_op(tried_to_write_cell, OP_EQ, 1);
  849. tt_assert(!chan->pending_padding_callback);
  850. /* Test case #6. Channel is not used for full circuits */
  851. chan->channel_usage = CHANNEL_USED_NOT_USED_FOR_FULL_CIRCS;
  852. decision = channelpadding_decide_to_pad_channel(chan);
  853. tt_int_op(decision, OP_EQ, CHANNELPADDING_WONTPAD);
  854. tt_assert(!chan->pending_padding_callback);
  855. chan->channel_usage = CHANNEL_USED_FOR_FULL_CIRCS;
  856. /* Test case #7. Channel is closed while timeout is scheduled.
  857. *
  858. * NOTE: This test deliberately breaks the channel callback mechanism.
  859. * It must be last.
  860. */
  861. tried_to_write_cell = 0;
  862. chan->next_padding_time_ms = monotime_coarse_absolute_msec() + 100;
  863. decision = channelpadding_decide_to_pad_channel(chan);
  864. tt_int_op(decision, OP_EQ, CHANNELPADDING_PADDING_SCHEDULED);
  865. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  866. tt_assert(chan->pending_padding_callback);
  867. // Close the connection while the timer is scheduled
  868. free_fake_channeltls((channel_tls_t*)chan);
  869. // We don't expect any timer callbacks here. Make a dummy one to be sure.
  870. dummy_nop_timer();
  871. tt_int_op(tried_to_write_cell, OP_EQ, 0);
  872. done:
  873. smartlist_free(connection_array);
  874. teardown_capture_of_logs();
  875. timers_shutdown();
  876. channel_free_all();
  877. return;
  878. }
  879. #define TEST_CHANNELPADDING(name, flags) \
  880. { #name, test_##name, (flags), NULL, NULL }
  881. struct testcase_t channelpadding_tests[] = {
  882. //TEST_CHANNELPADDING(channelpadding_decide_to_pad_channel, 0),
  883. TEST_CHANNELPADDING(channelpadding_decide_to_pad_channel, TT_FORK),
  884. TEST_CHANNELPADDING(channelpadding_negotiation, TT_FORK),
  885. TEST_CHANNELPADDING(channelpadding_consensus, TT_FORK),
  886. TEST_CHANNELPADDING(channelpadding_killonehop, TT_FORK),
  887. TEST_CHANNELPADDING(channelpadding_timers, TT_FORK),
  888. END_OF_TESTCASES
  889. };