aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/test_cadeT.c
blob: 1b74eade2434f254b4a446c1c9d4aaec0f6e5e85 (plain) (blame)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
     This file is part of GNUnet.
     Copyright (C) 2009 GNUnet e.V.

     GNUnet is free software: you can redistribute it and/or modify it
     under the terms of the GNU Affero General Public License as published
     by the Free Software Foundation, either version 3 of the License,
     or (at your option) any later version.

     GNUnet is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     Affero General Public License for more details.

     You should have received a copy of the GNU Affero General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

     SPDX-License-Identifier: AGPL3.0-or-later
 */
/**
 * @file cadet/test_cadeT.c
 * @brief testcase for cadet.c
 * @author xrs
 *
 * Goal:
 *   - test session resumption after a hard channel breakup
 *
 * ToDos:
 *   - setup peer A
 *   - setup peer B
 *   - setup cadet on peer B listening on port 1234
 *   - create a channel from peer A to B
 *   - create method to find out session initiator
 *   - send a message over channel
 *   - check if message was received
 *   - breakup the connection without sending a channel destroy message
 *   - assert tunnel is down
 *   - resume channel (second handshake for tunnel)
 *   - send second message over channel
 *   - check if message was receveived
 *   - end test
 *
 * Questions:
 *   - can we simulate hard breakups with TESTBED?
 *     - yes, with GNUNET_TESTBED_underlay_configure_link 
 *   - how can we test the sublayers of CADET, e.g. connection, tunnel, channel?
 *
 * Development
 *   - red -> green -> refactor (cyclic)
 */
#include "platform.h"
#include "gnunet_testbed_service.h"
#include "cadet.h"

#define REQUESTED_PEERS   2
#define CONFIG            "test_cadet.conf"
#define TESTPROGAM_NAME   "test-cadet-channel-resumption"
#define PORTNAME          "cadet_port"

struct GNUNET_TESTBED_Operation *testbed_to_svc[2];

/**
 * Port name kown by the two peers.
 */
static struct GNUNET_HashCode hashed_portname;

static int test_result = 0;

// FIXME: temp cnt
static int cnt = 0;

/****************************** TEST LOGIC ********************************/

// TBD

/************************** TESBED MANAGEMENT *****************************/

static void
shutdown_task (void *cls)
{
  for (int i=0; i<REQUESTED_PEERS; i++)
    GNUNET_TESTBED_operation_done (testbed_to_svc[i]);
}

static void
disconnect_from_peer (void *cls,
                      void *op_result)
{
  struct GNUNET_CADET_Handle *cadet = op_result;

  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "disconnect_from_cadet ()\n");

  GNUNET_CADET_disconnect (cadet);
}

static void *
setup_initiating_peer (void *cls,
                      const struct GNUNET_CONFIGURATION_Handle *cfg)
{

  struct GNUNET_CADET_Handle *cadet;

  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "setup_initiating_peer()\n");

  cadet = GNUNET_CADET_connect (cfg);

  if (NULL == cadet)
    GNUNET_SCHEDULER_shutdown ();

  return cadet;
}

static void *
handle_port_connects (void *cls,
                      struct GNUNET_CADET_Channel *channel,
                      const struct GNUNET_PeerIdentity *source)
{
  return NULL;
}

static void 
handle_port_disconnects (void *cls, 
                         const struct GNUNET_CADET_Channel *channel)
{
}

static void *
setup_listening_peer (void *cls,
                      const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  struct GNUNET_CADET_Handle *cadet;
  struct GNUNET_CADET_Port *port;

  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "setup_listening_peer()\n");
  
  cadet = GNUNET_CADET_connect (cfg);

  if (NULL == cadet)
    GNUNET_SCHEDULER_shutdown ();

  GNUNET_CRYPTO_hash (PORTNAME, sizeof(PORTNAME), &hashed_portname);
  port = GNUNET_CADET_open_port (cadet, &hashed_portname,
                                 &handle_port_connects,
                                 NULL,
                                 NULL,
                                 &handle_port_disconnects,
                                 NULL);

  return cadet;
}

static void
check_test_readyness (void *cls,
                      struct GNUNET_TESTBED_Operation *op,
                      void *ca_result,
                      const char *emsg)
{
  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "check_test_readyness()\n");

  if (2 == ++cnt)
    GNUNET_SCHEDULER_shutdown ();
}

static void
connect_to_peers (void *cls,
                  struct GNUNET_TESTBED_RunHandle *h,
                  unsigned int num_peers,
                  struct GNUNET_TESTBED_Peer **peers,
                  unsigned int links_succeeded,
                  unsigned int links_failed)
{
  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "connect_to_peers()\n");

  GNUNET_assert (0 == links_failed);


  testbed_to_svc[1] = GNUNET_TESTBED_service_connect (NULL, peers[1],
                                                      "cadet", 
                                                      &check_test_readyness, NULL,
                                                      &setup_listening_peer,
                                                      &disconnect_from_peer, NULL);
  testbed_to_svc[0] = GNUNET_TESTBED_service_connect (NULL, peers[0],
                                                      "cadet", 
                                                      &check_test_readyness, NULL,
                                                      &setup_initiating_peer,
                                                      &disconnect_from_peer, NULL);

  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}

int 
main (int argc, char *argv[])
{
  GNUNET_TESTBED_test_run (TESTPROGAM_NAME,
                           CONFIG,
                           REQUESTED_PEERS, 0LL, NULL, NULL,
                           connect_to_peers, NULL);
  return test_result;
}

/* end of test_template_api.c */