aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_conflux_cell.c
blob: bb440d0d0a9b42b235cd408c5472392b335f5527 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Copyright (c) 2023, The Tor Project, Inc. */
/* See LICENSE for licensing information */

/**
 * \file test_conflux_cell.
 * \brief Test conflux cells.
 */

#include "test/test.h"
#include "test/test_helpers.h"
#include "test/log_test_helpers.h"

#include "core/or/conflux_cell.h"
#include "core/or/conflux_st.h"
#include "trunnel/conflux.h"

#include "lib/crypt_ops/crypto_rand.h"

static void
test_link(void *arg)
{
  cell_t cell;
  conflux_cell_link_t link;
  conflux_cell_link_t *decoded_link = NULL;

  (void) arg;

  memset(&link, 0, sizeof(link));

  link.desired_ux = CONFLUX_UX_HIGH_THROUGHPUT;
  link.last_seqno_recv = 0;
  link.last_seqno_sent = 0;
  link.version = 0x01;

  crypto_rand((char *) link.nonce, sizeof(link.nonce));

  ssize_t cell_len = build_link_cell(&link, cell.payload+RELAY_HEADER_SIZE);
  tt_int_op(cell_len, OP_GT, 0);

  decoded_link = conflux_cell_parse_link(&cell, cell_len);
  tt_assert(decoded_link);

  uint8_t buf[RELAY_PAYLOAD_SIZE];
  ssize_t enc_cell_len = build_link_cell(decoded_link, buf);
  tt_int_op(cell_len, OP_EQ, enc_cell_len);

  /* Validate the original link object with the decoded one. */
  tt_mem_op(&link, OP_EQ, decoded_link, sizeof(link));
  tor_free(decoded_link);

 done:
  tor_free(decoded_link);
}

struct testcase_t conflux_cell_tests[] = {
  { "link", test_link, TT_FORK, NULL, NULL },

  END_OF_TESTCASES
};