summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2020-06-04 16:22:30 +0200
committert3sserakt <t3ss@posteo.de>2020-06-04 16:22:30 +0200
commit9047571fb5d2398b54900cbdf945a8b0414a9c3f (patch)
tree645c358dad28679877d005009f3a91166cbaa27d
parent75d323bc95c55225226c8e588c65a21fa685fa8c (diff)
fixed test and formattingchannel_destroy
-rw-r--r--src/cadet/gnunet-service-cadet_channel.h14
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c36
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c38
-rw-r--r--src/cadet/test_cadet.c182
4 files changed, 150 insertions, 120 deletions
diff --git a/src/cadet/gnunet-service-cadet_channel.h b/src/cadet/gnunet-service-cadet_channel.h
index 06e1f21ef..7a072f128 100644
--- a/src/cadet/gnunet-service-cadet_channel.h
+++ b/src/cadet/gnunet-service-cadet_channel.h
@@ -59,11 +59,21 @@ GCCH_hash_port (struct GNUNET_HashCode *h_port,
/**
* Check if type of message is the one to drop.
- * @param ch CadetChannel to check for message type to drop.
+ * @param ch CadetChannel to check for message type to drop.
* @param message GNUNET_MessageHeader to compare the type with.
*/
int
-GCCH_is_type_to_drop(struct CadetChannel *ch, const struct GNUNET_MessageHeader *message);
+GCCH_is_type_to_drop (struct CadetChannel *ch, const struct
+ GNUNET_MessageHeader *message);
+
+/**
+ * Check if type of message is the one to drop.
+ * @param ch CadetChannel to assign type to drop.
+ * @param message GNUNET_CADET_RequestDropCadetMessage to get the type from.
+ */
+void
+GCCH_assign_type_to_drop (struct CadetChannel *ch, const struct
+ GNUNET_CADET_RequestDropCadetMessage *message);
/**
* Get the static string for identification of the channel.
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index edf54f03a..1dac9eb1e 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -213,7 +213,7 @@ update_state (struct CadetConnection *cc,
new_state,
cc->mqm_ready,
new_mqm_ready);
-
+
if ((new_state == cc->state) && (new_mqm_ready == cc->mqm_ready))
return; /* no change, nothing to do */
old_ready =
@@ -228,7 +228,7 @@ update_state (struct CadetConnection *cc,
GCT_2s (cc->ct->t),
old_ready,
new_ready);
-
+
if (old_ready != new_ready)
cc->ready_cb (cc->ready_cb_cls, new_ready);
}
@@ -595,19 +595,18 @@ GCC_handle_encrypted (struct CadetConnection *cc,
}
-int
-set_monotime_sig (struct GNUNET_CADET_ConnectionCreateMessage * msg)
+void
+set_monotime_sig (struct GNUNET_CADET_ConnectionCreateMessage *msg)
{
- struct CadetConnectionCreatePS cp = { .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR),
- .purpose.size = htonl (sizeof(cp)),
- .monotonic_time = msg->monotime};
- if (GNUNET_OK != GNUNET_CRYPTO_eddsa_sign (my_private_key, &cp.purpose, &msg->monotime_sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
+ struct CadetConnectionCreatePS cp = { .purpose.purpose = htonl (
+ GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR),
+ .purpose.size = htonl (sizeof(cp)),
+ .monotonic_time = msg->monotime};
+
+ GNUNET_CRYPTO_eddsa_sign (my_private_key, &cp,
+ &msg->monotime_sig);
+
}
/**
@@ -624,7 +623,7 @@ send_create (void *cls)
struct GNUNET_PeerIdentity *pids;
struct GNUNET_MQ_Envelope *env;
struct CadetTunnel *t;
-
+
cc->task = NULL;
GNUNET_assert (GNUNET_YES == cc->mqm_ready);
env =
@@ -637,12 +636,13 @@ send_create (void *cls)
// check for tunnel state and set signed monotime (xrs,t3ss)
t = GCP_get_tunnel (cc->destination, GNUNET_YES);
- if (NULL != t && (GCT_get_estate(t) == CADET_TUNNEL_KEY_UNINITIALIZED) &&
- (GCT_alice_or_betty (GCP_get_id(cc->destination)) == GNUNET_NO))
+ if ((NULL != t)&& (GCT_get_estate (t) == CADET_TUNNEL_KEY_UNINITIALIZED) &&
+ (GCT_alice_or_betty (GCP_get_id (cc->destination)) == GNUNET_NO))
{
create_msg->has_monotime = GNUNET_YES;
- create_msg->monotime = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic(cfg));
- GNUNET_assert (GNUNET_OK == set_monotime_sig(create_msg));
+ create_msg->monotime = GNUNET_TIME_absolute_hton (
+ GNUNET_TIME_absolute_get_monotonic (cfg));
+ set_monotime_sig (create_msg);
}
pids = (struct GNUNET_PeerIdentity *) &create_msg[1];
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index d3e99741f..0ff4d1fb8 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -1555,23 +1555,24 @@ GCP_send_ooo (struct CadetPeer *cp,
/*
* FIXME: comment
*/
-void
+void
GCP_update_monotime (struct CadetPeer *peer)
{
- peer->last_connection_create = GNUNET_TIME_absolute_get_monotonic(cfg);
+ peer->last_connection_create = GNUNET_TIME_absolute_get_monotonic (cfg);
}
/*
* FIXME: comment
*/
-int
-GCP_check_and_update_monotime (struct CadetPeer *peer,
+int
+GCP_check_and_update_monotime (struct CadetPeer *peer,
struct GNUNET_TIME_AbsoluteNBO monotime)
{
- struct GNUNET_TIME_Absolute mt = GNUNET_TIME_absolute_ntoh(monotime);
-
- if (mt.abs_value_us > *(&peer->last_connection_create.abs_value_us)){
+ struct GNUNET_TIME_Absolute mt = GNUNET_TIME_absolute_ntoh (monotime);
+
+ if (mt.abs_value_us > *(&peer->last_connection_create.abs_value_us))
+ {
peer->last_connection_create = mt;
return GNUNET_YES;
}
@@ -1582,20 +1583,23 @@ GCP_check_and_update_monotime (struct CadetPeer *peer,
* FIXME: documentation here
*/
int
-GCP_check_monotime_sig (struct CadetPeer *peer, const struct GNUNET_CADET_ConnectionCreateMessage *msg)
+GCP_check_monotime_sig (struct CadetPeer *peer, const struct
+ GNUNET_CADET_ConnectionCreateMessage *msg)
{
- //struct CadetPeer *peer;
- //const struct GNUNET_CADET_ConnectionCreateMessage *msg;
+ // struct CadetPeer *peer;
+ // const struct GNUNET_CADET_ConnectionCreateMessage *msg;
- struct CadetConnectionCreatePS cp = { .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR),
- .purpose.size = htonl (sizeof(cp)),
- .monotonic_time = msg->monotime};
+ struct CadetConnectionCreatePS cp = { .purpose.purpose = htonl (
+ GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR),
+ .purpose.size = htonl (sizeof(cp)),
+ .monotonic_time = msg->monotime};
if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR,
- &cp.purpose,
- &msg->monotime_sig,
- &peer->pid.public_key))
+ GNUNET_CRYPTO_eddsa_verify (
+ GNUNET_SIGNATURE_PURPOSE_CADET_CONNECTION_INITIATOR,
+ &cp,
+ &msg->monotime_sig,
+ &peer->pid.public_key))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c
index d2fccb229..779d3bc9f 100644
--- a/src/cadet/test_cadet.c
+++ b/src/cadet/test_cadet.c
@@ -265,8 +265,8 @@ static unsigned int msg_dropped;
*/
void
GNUNET_CADET_drop_message (struct GNUNET_MQ_Handle *mq,
- struct GNUNET_CADET_ClientChannelNumber ccn,
- uint16_t type);
+ struct GNUNET_CADET_ClientChannelNumber ccn,
+ uint16_t type);
/******************************************************************************/
@@ -537,20 +537,21 @@ static void
disconnect_handler (void *cls,
const struct GNUNET_CADET_Channel *channel);
-static struct GNUNET_PeerIdentity *
-get_from_p_ids()
+static struct GNUNET_PeerIdentity *
+get_from_p_ids ()
{
if (0 < GNUNET_memcmp (testpeer_id[0], testpeer_id[1]))
{
return testpeer_id[1];
- }else
+ }
+ else
{
- return testpeer_id[0];
+ return testpeer_id[0];
}
}
static struct GNUNET_CADET_Handle *
-get_from_cadets()
+get_from_cadets ()
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "1\n");
@@ -558,23 +559,25 @@ get_from_cadets()
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "standard peer\n");
return cadets_running[0];
- }else
+ }
+ else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "the other peer\n");
return cadets_running[peers_running - 1];
- }
-
+ }
+
}
static unsigned int
-get_peer_nr(int outgoing)
+get_peer_nr (int outgoing)
{
if (0 < GNUNET_memcmp (testpeer_id[0], testpeer_id[1]))
{
return GNUNET_YES == outgoing ? 0 : peers_running - 1;
- }else
+ }
+ else
{
- return GNUNET_YES == outgoing ? peers_running -1 : 0;
+ return GNUNET_YES == outgoing ? peers_running - 1 : 0;
}
}
@@ -597,7 +600,7 @@ reconnect_op (void *cls)
struct CadetTestChannelWrapper *ch;
static struct GNUNET_PeerIdentity *p_id;
static struct GNUNET_CADET_Handle *h1;
-
+
reconnect_task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"reconnecting from line %ld\n",
@@ -609,9 +612,9 @@ reconnect_op (void *cls)
}
ch = GNUNET_new (struct CadetTestChannelWrapper);
- p_id = get_from_p_ids();
- h1 = get_from_cadets();
-
+ p_id = get_from_p_ids ();
+ h1 = get_from_cadets ();
+
outgoing_ch = GNUNET_CADET_channel_create (h1,
ch,
p_id,
@@ -638,16 +641,17 @@ reopen_channel ()
};
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "creating channel again\n");
- p_id = get_from_p_ids();
- h1 = get_from_cadets();
+ p_id = get_from_p_ids ();
+ h1 = get_from_cadets ();
+
ch = GNUNET_new (struct CadetTestChannelWrapper);
outgoing_ch = GNUNET_CADET_channel_create (h1,
- ch,
- p_id,
- &port,
- NULL,
- &disconnect_handler,
- handlers);
+ ch,
+ p_id,
+ &port,
+ NULL,
+ &disconnect_handler,
+ handlers);
ch->ch = outgoing_ch;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Sending second test data (after destroying the channel) on channel %p...\n",
@@ -659,15 +663,16 @@ static void
peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple);
/**
- * We ask the monitoring api for all the peers.
+ * We ask the monitoring api for all the peers.
*/
static void
-get_peers(void *cls)
+get_peers (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "requesting peers info!\n");
- plo = GNUNET_CADET_list_peers (p_cfg[get_peer_nr(GNUNET_YES)], &peers_callback, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "requesting peers info!\n");
+ plo = GNUNET_CADET_list_peers (p_cfg[get_peer_nr (GNUNET_YES)],
+ &peers_callback, NULL);
}
@@ -677,7 +682,7 @@ get_peers(void *cls)
*
* After last peer has been reported, an additional call with NULL is done.
*
- * We check the peer we are interested in, if we have a tunnel. If not, we
+ * We check the peer we are interested in, if we have a tunnel. If not, we
* reopen the channel
*
* @param cls Closure.
@@ -692,13 +697,13 @@ peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
peer = &ple->peer;
-
+
if (NULL == ple)
{
plo = NULL;
return;
}
- p_id = get_from_p_ids();
+ p_id = get_from_p_ids ();
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"ple->peer %s\n",
@@ -706,21 +711,22 @@ peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"p_id %s\n",
GNUNET_i2s_full (p_id));
-
- if (0 == GNUNET_memcmp (&ple->peer, p_id ) && ple->have_tunnel)
+
+ if ((0 == GNUNET_memcmp (&ple->peer, p_id))&& ple->have_tunnel)
{
-
+
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "schedule get_peers again?\n");
- get_peers_task = GNUNET_SCHEDULER_add_now (&get_peers,
- NULL);
-
- }
+ "schedule get_peers again?\n");
+ get_peers_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
+ &get_peers,
+ NULL);
+
+ }
else if (0 == GNUNET_memcmp (&ple->peer, p_id) )
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "reopen channel\n");
+ "reopen channel\n");
reopen_channel ();
@@ -749,14 +755,14 @@ disconnect_handler (void *cls,
ok);
GNUNET_assert (ch_w->ch == channel);
- if ((NULL != disconnect_task) && (DESTROY == test) && (3 == ok))
+ if ((DESTROY == test) && (3 == ok))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Reopen channel task!\n");
if (NULL == get_peers_task)
{
get_peers_task = GNUNET_SCHEDULER_add_now (&get_peers,
- NULL);
+ NULL);
}
return;
}
@@ -834,8 +840,8 @@ send_test_message (struct GNUNET_CADET_Channel *channel)
int size;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending test message on channel %p\n",
- channel);
+ "Sending test message on channel %u\n",
+ channel->ccn.channel_of_client);
size = size_payload;
if (GNUNET_NO == initialized)
{
@@ -1013,7 +1019,7 @@ handle_data (void *cls,
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- " ok: (%d/%d)\n",
+ "handle_data ok: (%d/%d)\n",
ok,
ok_goal);
data = (uint32_t *) &message[1];
@@ -1037,30 +1043,40 @@ handle_data (void *cls,
{
ok++;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- " ok: (%d/%d)\n",
+ "dropping message ok: (%d/%d)\n",
ok,
ok_goal);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "TEST ID 0: %s\n",
- GNUNET_i2s (testpeer_id[0]));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "TEST ID 1: %s\n",
- GNUNET_i2s (testpeer_id[1]));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "TEST ID 0: %s\n",
+ GNUNET_i2s (testpeer_id[0]));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "TEST ID 1: %s\n",
+ GNUNET_i2s (testpeer_id[1]));
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "dropping message\n");
GNUNET_CADET_drop_message (GNUNET_CADET_get_mq (outgoing_ch),
outgoing_ch->ccn,
GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
- GNUNET_CADET_channel_destroy(outgoing_ch);
+ if (NULL != outgoing_ch)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Destroying channel %p...\n",
+ outgoing_ch);
+ GNUNET_CADET_channel_destroy (outgoing_ch);
+ outgoing_ch = NULL;
+ }
}
- else if (4 == ok)
+ else if (5 == ok)
{
- ok++;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- " ok: (%d/%d)\n",
- ok,
- ok_goal);
- // End of DESTROY test.
+ ok++;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "destroy test finished ok: (%d/%d)\n",
+ ok,
+ ok_goal);
+ disconnect_task =
+ GNUNET_SCHEDULER_add_now (&gather_stats_and_exit,
+ (void *) __LINE__);
+ // End of DESTROY test.
}
}
@@ -1147,13 +1163,13 @@ connect_handler (void *cls,
channel);
ok++;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- " ok: (%d/%d)\n",
+ "connect_handler ok: (%d/%d)\n",
ok,
ok_goal);
- if (peer == get_peer_nr(GNUNET_NO))
+ if (peer == get_peer_nr (GNUNET_NO))
{
- if (DESTROY != test && NULL != incoming_ch)
+ if ((DESTROY != test)&&(NULL != incoming_ch))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Duplicate incoming channel for client %lu\n",
@@ -1192,7 +1208,7 @@ connect_handler (void *cls,
&reconnect_op,
(void *) __LINE__);
}
-
+
/* TODO: cannot return channel as-is, in order to unify the data handlers */
ch = GNUNET_new (struct CadetTestChannelWrapper);
@@ -1237,9 +1253,9 @@ start_test (void *cls)
test = SPEED;
}
- p_id = get_from_p_ids();
- h1 = get_from_cadets();
-
+ p_id = get_from_p_ids ();
+ h1 = get_from_cadets ();
+
ch = GNUNET_new (struct CadetTestChannelWrapper);
outgoing_ch = GNUNET_CADET_channel_create (h1,
ch,
@@ -1252,10 +1268,10 @@ start_test (void *cls)
ch->ch = outgoing_ch;
- //if (DESTROY != test)
+ if (DESTROY != test)
disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
- &gather_stats_and_exit,
- (void *) __LINE__);
+ &gather_stats_and_exit,
+ (void *) __LINE__);
if (KEEPALIVE == test)
return; /* Don't send any data. */
@@ -1308,7 +1324,7 @@ pi_cb (void *cls,
return;
}
- if (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit)
+ if (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"ID callback for %ld\n",
@@ -1318,29 +1334,29 @@ pi_cb (void *cls,
"id: %s\n",
GNUNET_i2s (testpeer_id[i]));
}
- else if (GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit)
+ else if (GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"CFG callback for %ld\n",
i);
p_cfg[i] = pinfo->result.cfg;
}
- else
+ else
{
GNUNET_break (0);
}
-
+
peerinfo_task_cnt++;
if (peerinfo_task_cnt < 4)
return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Got all peer information, starting test\n");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "TEST ID 0: %s\n",
- GNUNET_i2s (testpeer_id[0]));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "TEST ID 1: %s\n",
- GNUNET_i2s (testpeer_id[1]));
+ "TEST ID 0: %s\n",
+ GNUNET_i2s (testpeer_id[0]));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "TEST ID 1: %s\n",
+ GNUNET_i2s (testpeer_id[1]));
test_task = GNUNET_SCHEDULER_add_now (&start_test, NULL);
}
@@ -1368,7 +1384,7 @@ tmain (void *cls,
GNUNET_assert (peers_running == peers_requested);
testbed_peers = peers;
cadets_running = cadets;
-
+
disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time,
&disconnect_cadet_peers,
(void *) __LINE__);
@@ -1536,7 +1552,7 @@ main (int argc, char *argv[])
{
test = DESTROY;
test_name = "destroy";
- ok_goal = 5;
+ ok_goal = 6;
short_time = GNUNET_TIME_relative_multiply (short_time, 5);
}
else