diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-05-30 10:28:51 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-05-30 10:28:51 +0200 |
commit | 30fb422df59da0e650eb790933dadbd4bb189658 (patch) | |
tree | b37f7529e275671ce3e640b4064a8945f658d442 /src | |
parent | 0a0ac96d8be21130ccbb885537b0b179b16842e4 (diff) | |
parent | a46fff931d631a176f56547692b16ae32c89299b (diff) | |
download | gnunet-30fb422df59da0e650eb790933dadbd4bb189658.tar.gz gnunet-30fb422df59da0e650eb790933dadbd4bb189658.zip |
Merge branch 'master' of ssh://gnunet.org/gnunet
Diffstat (limited to 'src')
94 files changed, 3684 insertions, 1997 deletions
diff --git a/src/arm/test_arm_api_data.conf b/src/arm/test_arm_api_data.conf index 57799ccc8..b032cc95a 100644 --- a/src/arm/test_arm_api_data.conf +++ b/src/arm/test_arm_api_data.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | 3 | ||
4 | [PATHS] | 4 | [PATHS] |
5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-arm/ | 5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-arm/ |
diff --git a/src/arm/test_gnunet_arm.py.in b/src/arm/test_gnunet_arm.py.in index cdd69251b..10bb58a9c 100644 --- a/src/arm/test_gnunet_arm.py.in +++ b/src/arm/test_gnunet_arm.py.in | |||
@@ -7,100 +7,107 @@ import re | |||
7 | import subprocess | 7 | import subprocess |
8 | import time | 8 | import time |
9 | 9 | ||
10 | # FIXME: There's too much repetition, move generally used parts into reusable modules. | ||
10 | if os.name == "nt": | 11 | if os.name == "nt": |
11 | tmp = os.getenv ("TEMP") | 12 | tmp = os.getenv("TEMP") |
12 | else: | 13 | else: |
13 | tmp = "/tmp" | 14 | tmp = "/tmp" |
14 | 15 | ||
15 | if os.name == 'nt': | 16 | if os.name == 'nt': |
16 | st = 'gnunet-statistics.exe' | 17 | st = 'gnunet-statistics.exe' |
17 | arm = './gnunet-arm.exe' | 18 | arm = './gnunet-arm.exe' |
18 | else: | 19 | else: |
19 | st = 'gnunet-statistics' | 20 | st = 'gnunet-statistics' |
20 | arm = './gnunet-arm' | 21 | arm = './gnunet-arm' |
21 | 22 | ||
22 | run_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr'] | 23 | run_arm = [arm, '-c', 'test_arm_api_data.conf', '--no-stdout', '--no-stderr'] |
23 | debug = os.getenv ('DEBUG') | 24 | debug = os.getenv('DEBUG') |
24 | if debug: | 25 | if debug: |
25 | run_arm += [debug.split (' ')] | 26 | run_arm += [debug.split(' ')] |
26 | 27 | ||
27 | def cleanup (): | 28 | |
28 | shutil.rmtree (os.path.join (tmp, "test-gnunetd-arm"), True) | 29 | def cleanup(): |
29 | 30 | shutil.rmtree(os.path.join(tmp, "test-gnunetd-arm"), True) | |
30 | def sub_run (args, want_stdo = True, want_stde = False, nofail = False): | 31 | |
31 | if want_stdo: | 32 | |
32 | stdo = subprocess.PIPE | 33 | def sub_run(args, want_stdo=True, want_stde=False, nofail=False): |
33 | else: | 34 | if want_stdo: |
34 | stdo = None | 35 | stdo = subprocess.PIPE |
35 | if want_stde: | 36 | else: |
36 | stde = subprocess.PIPE | 37 | stdo = None |
37 | else: | 38 | if want_stde: |
38 | stde = None | 39 | stde = subprocess.PIPE |
39 | p = subprocess.Popen (args, stdout = stdo, stderr = stde) | 40 | else: |
40 | stdo, stde = p.communicate () | 41 | stde = None |
41 | if not nofail: | 42 | p = subprocess.Popen(args, stdout=stdo, stderr=stde) |
42 | if p.returncode != 0: | 43 | stdo, stde = p.communicate() |
43 | sys.exit (p.returncode) | 44 | if not nofail: |
44 | return (p.returncode, stdo, stde) | 45 | if p.returncode != 0: |
45 | 46 | sys.exit(p.returncode) | |
46 | def fail (result): | 47 | return (p.returncode, stdo, stde) |
47 | print (result) | 48 | |
48 | r_arm (['-e'], want_stdo = False) | 49 | |
49 | sys.exit (1) | 50 | def fail(result): |
50 | 51 | print(result) | |
51 | 52 | r_arm(['-e'], want_stdo=False) | |
52 | def end_arm_failer (command, rc, stdo, stde, normal): | 53 | sys.exit(1) |
53 | if normal: | 54 | |
54 | if rc != 0: | 55 | |
55 | fail ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) | 56 | def end_arm_failer(command, rc, stdo, stde, normal): |
56 | else: | 57 | if normal: |
57 | if rc == 0: | 58 | if rc != 0: |
58 | fail ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) | 59 | fail("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) |
59 | 60 | else: | |
60 | def print_only_failer (command, rc, stdo, stde, normal): | 61 | if rc == 0: |
61 | if normal: | 62 | fail("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) |
62 | if rc != 0: | 63 | |
63 | print ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) | 64 | |
64 | sys.exit (1) | 65 | def print_only_failer(command, rc, stdo, stde, normal): |
65 | else: | 66 | if normal: |
66 | if rc == 0: | 67 | if rc != 0: |
67 | print ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) | 68 | print("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) |
68 | sys.exit (1) | 69 | sys.exit(1) |
69 | 70 | else: | |
70 | 71 | if rc == 0: | |
71 | def r_something (to_run, extra_args, failer = None, normal = True, **kw): | 72 | print("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) |
72 | rc, stdo, stde = sub_run (to_run + extra_args, nofail = True, want_stde = True, **kw) | 73 | sys.exit(1) |
73 | if failer is not None: | 74 | |
74 | failer (to_run + extra_args, rc, stdo, stde, normal) | 75 | |
75 | return (rc, stdo, stde) | 76 | def r_something(to_run, extra_args, failer=None, normal=True, **kw): |
76 | 77 | rc, stdo, stde = sub_run(to_run + extra_args, nofail=True, want_stde=True, **kw) | |
77 | def r_arm (extra_args, **kw): | 78 | if failer is not None: |
78 | return r_something (run_arm, extra_args, **kw) | 79 | failer(to_run + extra_args, rc, stdo, stde, normal) |
79 | 80 | return (rc, stdo, stde) | |
80 | cleanup () | 81 | |
81 | 82 | ||
82 | print ("TEST: Bad argument checking...", end='') | 83 | def r_arm(extra_args, **kw): |
83 | r_arm (['-x'], normal = False, failer = print_only_failer) | 84 | return r_something(run_arm, extra_args, **kw) |
84 | print ("PASS") | 85 | |
85 | 86 | ||
86 | print ("TEST: Start ARM...", end='') | 87 | cleanup() |
87 | r_arm (['-s'], failer = print_only_failer) | 88 | |
88 | time.sleep (1) | 89 | print("TEST: Bad argument checking...", end='') |
89 | print ("PASS") | 90 | r_arm(['-x'], normal=False, failer=print_only_failer) |
90 | 91 | print("PASS") | |
91 | print ("TEST: Start another service...", end='') | 92 | |
92 | r_arm (['-i', 'resolver'], failer = end_arm_failer) | 93 | print("TEST: Start ARM...", end='') |
93 | time.sleep (1) | 94 | r_arm(['-s'], failer=print_only_failer) |
94 | print ("PASS") | 95 | time.sleep(1) |
95 | 96 | print("PASS") | |
96 | print ("TEST: Stop a service...", end='') | 97 | |
97 | r_arm (['-k', 'resolver'], failer = end_arm_failer) | 98 | print("TEST: Start another service...", end='') |
98 | time.sleep (1) | 99 | r_arm(['-i', 'resolver'], failer=end_arm_failer) |
99 | print ("PASS") | 100 | time.sleep(1) |
100 | 101 | print("PASS") | |
101 | print ("TEST: Stop ARM...", end='') | 102 | |
102 | r_arm (['-e'], failer = print_only_failer) | 103 | print("TEST: Stop a service...", end='') |
103 | time.sleep (1) | 104 | r_arm(['-k', 'resolver'], failer=end_arm_failer) |
104 | print ("PASS") | 105 | time.sleep(1) |
105 | 106 | print("PASS") | |
106 | cleanup () | 107 | |
108 | print("TEST: Stop ARM...", end='') | ||
109 | r_arm(['-e'], failer=print_only_failer) | ||
110 | time.sleep(1) | ||
111 | print("PASS") | ||
112 | |||
113 | cleanup() | ||
diff --git a/src/ats-tests/template_perf_ats.conf b/src/ats-tests/template_perf_ats.conf index 9d320c3dd..74f608bfb 100644 --- a/src/ats-tests/template_perf_ats.conf +++ b/src/ats-tests/template_perf_ats.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [testbed] | 3 | [testbed] |
4 | # How long should operations wait? | 4 | # How long should operations wait? |
diff --git a/src/ats/test_ats_api.conf b/src/ats/test_ats_api.conf index e0cb495c8..d45e84d18 100644 --- a/src/ats/test_ats_api.conf +++ b/src/ats/test_ats_api.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-ats-api-scheduling/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-ats-api-scheduling/ |
diff --git a/src/ats/test_ats_api_delayed.conf b/src/ats/test_ats_api_delayed.conf index f4d771448..3aac88cf9 100644 --- a/src/ats/test_ats_api_delayed.conf +++ b/src/ats/test_ats_api_delayed.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-ats-api-scheduling/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-ats-api-scheduling/ |
diff --git a/src/ats/test_ats_api_mlp.conf b/src/ats/test_ats_api_mlp.conf index 6a8e24177..d5f05a3c4 100644 --- a/src/ats/test_ats_api_mlp.conf +++ b/src/ats/test_ats_api_mlp.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-ats-mlp/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-ats-mlp/ |
diff --git a/src/ats/test_ats_api_proportional.conf b/src/ats/test_ats_api_proportional.conf index e121c14ea..21f8218ee 100644 --- a/src/ats/test_ats_api_proportional.conf +++ b/src/ats/test_ats_api_proportional.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-ats-proportional/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-ats-proportional/ |
diff --git a/src/ats/test_ats_api_ril.conf b/src/ats/test_ats_api_ril.conf index d6f4f6101..5f5fb006b 100644 --- a/src/ats/test_ats_api_ril.conf +++ b/src/ats/test_ats_api_ril.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-ats-ril/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-ats-ril/ |
diff --git a/src/ats/test_ats_solver_default.conf b/src/ats/test_ats_solver_default.conf index e419c8f35..2d8927abd 100644 --- a/src/ats/test_ats_solver_default.conf +++ b/src/ats/test_ats_solver_default.conf | |||
@@ -1,2 +1,2 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c index 3c142a95c..59f0bfe85 100644 --- a/src/cadet/cadet_api.c +++ b/src/cadet/cadet_api.c | |||
@@ -464,6 +464,10 @@ cadet_mq_send_now (void *cls) | |||
464 | } | 464 | } |
465 | ch->allow_send--; | 465 | ch->allow_send--; |
466 | ch->pending_env = NULL; | 466 | ch->pending_env = NULL; |
467 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
468 | "Sending message on channel %s to CADET, new window size is %u\n", | ||
469 | GNUNET_i2s (&ch->peer), | ||
470 | ch->allow_send); | ||
467 | GNUNET_MQ_send (ch->cadet->mq, | 471 | GNUNET_MQ_send (ch->cadet->mq, |
468 | env); | 472 | env); |
469 | GNUNET_MQ_impl_send_continue (ch->mq); | 473 | GNUNET_MQ_impl_send_continue (ch->mq); |
@@ -781,6 +785,11 @@ handle_local_ack (void *cls, | |||
781 | return; | 785 | return; |
782 | } | 786 | } |
783 | ch->allow_send++; | 787 | ch->allow_send++; |
788 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
789 | "Got an ACK on mq channel %X (peer %s); new window size is %u!\n", | ||
790 | ntohl (ch->ccn.channel_of_client), | ||
791 | GNUNET_i2s (&ch->peer), | ||
792 | ch->allow_send); | ||
784 | if (NULL == ch->pending_env) | 793 | if (NULL == ch->pending_env) |
785 | { | 794 | { |
786 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 795 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -792,9 +801,6 @@ handle_local_ack (void *cls, | |||
792 | } | 801 | } |
793 | if (NULL != ch->mq_cont) | 802 | if (NULL != ch->mq_cont) |
794 | return; /* already working on it! */ | 803 | return; /* already working on it! */ |
795 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
796 | "Got an ACK on mq channel %X, sending pending message!\n", | ||
797 | ntohl (ch->ccn.channel_of_client)); | ||
798 | ch->mq_cont | 804 | ch->mq_cont |
799 | = GNUNET_SCHEDULER_add_now (&cadet_mq_send_now, | 805 | = GNUNET_SCHEDULER_add_now (&cadet_mq_send_now, |
800 | ch); | 806 | ch); |
@@ -992,6 +998,7 @@ check_get_tunnels (void *cls, | |||
992 | { | 998 | { |
993 | size_t esize; | 999 | size_t esize; |
994 | 1000 | ||
1001 | (void) cls; | ||
995 | esize = ntohs (message->size); | 1002 | esize = ntohs (message->size); |
996 | if (sizeof (struct GNUNET_CADET_LocalInfoTunnel) == esize) | 1003 | if (sizeof (struct GNUNET_CADET_LocalInfoTunnel) == esize) |
997 | return GNUNET_OK; | 1004 | return GNUNET_OK; |
@@ -1051,6 +1058,7 @@ check_get_tunnel (void *cls, | |||
1051 | size_t esize; | 1058 | size_t esize; |
1052 | size_t msize; | 1059 | size_t msize; |
1053 | 1060 | ||
1061 | (void) cls; | ||
1054 | /* Verify message sanity */ | 1062 | /* Verify message sanity */ |
1055 | msize = ntohs (msg->header.size); | 1063 | msize = ntohs (msg->header.size); |
1056 | esize = sizeof (struct GNUNET_CADET_LocalInfoTunnel); | 1064 | esize = sizeof (struct GNUNET_CADET_LocalInfoTunnel); |
@@ -1096,7 +1104,6 @@ handle_get_tunnel (void *cls, | |||
1096 | 1104 | ||
1097 | if (NULL == h->info_cb.tunnel_cb) | 1105 | if (NULL == h->info_cb.tunnel_cb) |
1098 | return; | 1106 | return; |
1099 | |||
1100 | ch_n = ntohl (msg->channels); | 1107 | ch_n = ntohl (msg->channels); |
1101 | c_n = ntohl (msg->connections); | 1108 | c_n = ntohl (msg->connections); |
1102 | 1109 | ||
@@ -1191,13 +1198,8 @@ destroy_channel_cb (void *cls, | |||
1191 | /* struct GNUNET_CADET_Handle *handle = cls; */ | 1198 | /* struct GNUNET_CADET_Handle *handle = cls; */ |
1192 | struct GNUNET_CADET_Channel *ch = value; | 1199 | struct GNUNET_CADET_Channel *ch = value; |
1193 | 1200 | ||
1194 | if (ntohl (ch->ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) | 1201 | (void) cls; |
1195 | { | 1202 | (void) cid; |
1196 | GNUNET_break (0); | ||
1197 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1198 | "channel %X not destroyed\n", | ||
1199 | ntohl (ch->ccn.channel_of_client)); | ||
1200 | } | ||
1201 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1203 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1202 | "Destroying channel due to GNUNET_CADET_disconnect()\n"); | 1204 | "Destroying channel due to GNUNET_CADET_disconnect()\n"); |
1203 | destroy_channel (ch); | 1205 | destroy_channel (ch); |
@@ -1222,6 +1224,7 @@ destroy_port_cb (void *cls, | |||
1222 | /* struct GNUNET_CADET_Handle *handle = cls; */ | 1224 | /* struct GNUNET_CADET_Handle *handle = cls; */ |
1223 | struct GNUNET_CADET_Port *port = value; | 1225 | struct GNUNET_CADET_Port *port = value; |
1224 | 1226 | ||
1227 | (void) cls; | ||
1225 | /* This is a warning, the app should have cleanly closed all open ports */ | 1228 | /* This is a warning, the app should have cleanly closed all open ports */ |
1226 | GNUNET_break (0); | 1229 | GNUNET_break (0); |
1227 | GNUNET_CADET_close_port (port); | 1230 | GNUNET_CADET_close_port (port); |
diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h index de0cec5d0..d4a40f9e5 100644 --- a/src/cadet/cadet_protocol.h +++ b/src/cadet/cadet_protocol.h | |||
@@ -28,6 +28,14 @@ | |||
28 | #ifndef CADET_PROTOCOL_H_ | 28 | #ifndef CADET_PROTOCOL_H_ |
29 | #define CADET_PROTOCOL_H_ | 29 | #define CADET_PROTOCOL_H_ |
30 | 30 | ||
31 | /** | ||
32 | * At best, enable when debugging #5328! | ||
33 | */ | ||
34 | #define DEBUG_KX 0 | ||
35 | #if DEBUG_KX | ||
36 | #warning NEVER run this in production! KX debugging is on! | ||
37 | #endif | ||
38 | |||
31 | #include "platform.h" | 39 | #include "platform.h" |
32 | #include "gnunet_util_lib.h" | 40 | #include "gnunet_util_lib.h" |
33 | #include "cadet.h" | 41 | #include "cadet.h" |
@@ -234,6 +242,22 @@ struct GNUNET_CADET_TunnelKeyExchangeMessage | |||
234 | */ | 242 | */ |
235 | struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key; | 243 | struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key; |
236 | 244 | ||
245 | #if DEBUG_KX | ||
246 | /** | ||
247 | * Sender's ephemeral public ECC key encoded in a | ||
248 | * format suitable for network transmission, as created | ||
249 | * using 'gcry_sexp_sprint'. | ||
250 | */ | ||
251 | struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral_key_XXX; // for debugging KX-crypto! | ||
252 | |||
253 | /** | ||
254 | * Sender's ephemeral public ECC key encoded in a | ||
255 | * format suitable for network transmission, as created | ||
256 | * using 'gcry_sexp_sprint'. | ||
257 | */ | ||
258 | struct GNUNET_CRYPTO_EddsaPrivateKey private_key_XXX; // for debugging KX-crypto! | ||
259 | #endif | ||
260 | |||
237 | /** | 261 | /** |
238 | * Sender's next ephemeral public ECC key encoded in a | 262 | * Sender's next ephemeral public ECC key encoded in a |
239 | * format suitable for network transmission, as created | 263 | * format suitable for network transmission, as created |
@@ -256,6 +280,15 @@ struct GNUNET_CADET_TunnelKeyExchangeAuthMessage | |||
256 | */ | 280 | */ |
257 | struct GNUNET_CADET_TunnelKeyExchangeMessage kx; | 281 | struct GNUNET_CADET_TunnelKeyExchangeMessage kx; |
258 | 282 | ||
283 | #if DEBUG_KX | ||
284 | /** | ||
285 | * Received ephemeral public ECC key encoded in a | ||
286 | * format suitable for network transmission, as created | ||
287 | * using 'gcry_sexp_sprint'. | ||
288 | */ | ||
289 | struct GNUNET_CRYPTO_EcdhePublicKey r_ephemeral_key_XXX; // for debugging KX-crypto! | ||
290 | #endif | ||
291 | |||
259 | /** | 292 | /** |
260 | * KDF-proof that sender could compute the 3-DH, used in lieu of a | 293 | * KDF-proof that sender could compute the 3-DH, used in lieu of a |
261 | * signature or payload data. | 294 | * signature or payload data. |
diff --git a/src/cadet/cadet_test_lib.c b/src/cadet/cadet_test_lib.c index 20ef028b2..0efb81ab4 100644 --- a/src/cadet/cadet_test_lib.c +++ b/src/cadet/cadet_test_lib.c | |||
@@ -110,7 +110,7 @@ struct GNUNET_CADET_TEST_AdapterContext | |||
110 | * Port handlers for open ports. | 110 | * Port handlers for open ports. |
111 | */ | 111 | */ |
112 | struct GNUNET_CADET_Port **ports; | 112 | struct GNUNET_CADET_Port **ports; |
113 | 113 | ||
114 | /** | 114 | /** |
115 | * General context. | 115 | * General context. |
116 | */ | 116 | */ |
@@ -135,14 +135,13 @@ cadet_connect_adapter (void *cls, | |||
135 | struct GNUNET_CADET_TEST_AdapterContext *actx = cls; | 135 | struct GNUNET_CADET_TEST_AdapterContext *actx = cls; |
136 | struct GNUNET_CADET_TEST_Context *ctx = actx->ctx; | 136 | struct GNUNET_CADET_TEST_Context *ctx = actx->ctx; |
137 | struct GNUNET_CADET_Handle *h; | 137 | struct GNUNET_CADET_Handle *h; |
138 | unsigned int i; | ||
139 | 138 | ||
140 | h = GNUNET_CADET_connect (cfg); | 139 | h = GNUNET_CADET_connect (cfg); |
141 | if (NULL == ctx->ports) | 140 | if (NULL == ctx->ports) |
142 | return h; | 141 | return h; |
143 | 142 | actx->ports = GNUNET_new_array (ctx->port_count, | |
144 | actx->ports = GNUNET_new_array (ctx->port_count, struct GNUNET_CADET_Port *); | 143 | struct GNUNET_CADET_Port *); |
145 | for (i = 0; i < ctx->port_count; i++) | 144 | for (unsigned int i = 0; i < ctx->port_count; i++) |
146 | { | 145 | { |
147 | actx->ports[i] = GNUNET_CADET_open_port (h, | 146 | actx->ports[i] = GNUNET_CADET_open_port (h, |
148 | ctx->ports[i], | 147 | ctx->ports[i], |
@@ -165,14 +164,14 @@ cadet_connect_adapter (void *cls, | |||
165 | */ | 164 | */ |
166 | static void | 165 | static void |
167 | cadet_disconnect_adapter (void *cls, | 166 | cadet_disconnect_adapter (void *cls, |
168 | void *op_result) | 167 | void *op_result) |
169 | { | 168 | { |
170 | struct GNUNET_CADET_Handle *cadet = op_result; | 169 | struct GNUNET_CADET_Handle *cadet = op_result; |
171 | struct GNUNET_CADET_TEST_AdapterContext *actx = cls; | 170 | struct GNUNET_CADET_TEST_AdapterContext *actx = cls; |
172 | 171 | ||
173 | if (NULL != actx->ports) | 172 | if (NULL != actx->ports) |
174 | { | 173 | { |
175 | for (int i = 0; i < actx->ctx->port_count; i++) | 174 | for (unsigned int i = 0; i < actx->ctx->port_count; i++) |
176 | { | 175 | { |
177 | GNUNET_CADET_close_port (actx->ports[i]); | 176 | GNUNET_CADET_close_port (actx->ports[i]); |
178 | actx->ports[i] = NULL; | 177 | actx->ports[i] = NULL; |
@@ -201,22 +200,24 @@ cadet_connect_cb (void *cls, | |||
201 | const char *emsg) | 200 | const char *emsg) |
202 | { | 201 | { |
203 | struct GNUNET_CADET_TEST_Context *ctx = cls; | 202 | struct GNUNET_CADET_TEST_Context *ctx = cls; |
204 | unsigned int i; | ||
205 | 203 | ||
206 | if (NULL != emsg) | 204 | if (NULL != emsg) |
207 | { | 205 | { |
208 | fprintf (stderr, "Failed to connect to CADET service: %s\n", | 206 | fprintf (stderr, |
207 | "Failed to connect to CADET service: %s\n", | ||
209 | emsg); | 208 | emsg); |
210 | GNUNET_SCHEDULER_shutdown (); | 209 | GNUNET_SCHEDULER_shutdown (); |
211 | return; | 210 | return; |
212 | } | 211 | } |
213 | for (i = 0; i < ctx->num_peers; i++) | 212 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
214 | if (op == ctx->ops[i]) | 213 | if (op == ctx->ops[i]) |
215 | { | 214 | { |
216 | ctx->cadets[i] = ca_result; | 215 | ctx->cadets[i] = ca_result; |
217 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "...cadet %u connected\n", i); | 216 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
217 | "...cadet %u connected\n", | ||
218 | i); | ||
218 | } | 219 | } |
219 | for (i = 0; i < ctx->num_peers; i++) | 220 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
220 | if (NULL == ctx->cadets[i]) | 221 | if (NULL == ctx->cadets[i]) |
221 | return; /* still some CADET connections missing */ | 222 | return; /* still some CADET connections missing */ |
222 | /* all CADET connections ready! */ | 223 | /* all CADET connections ready! */ |
@@ -231,9 +232,7 @@ cadet_connect_cb (void *cls, | |||
231 | void | 232 | void |
232 | GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx) | 233 | GNUNET_CADET_TEST_cleanup (struct GNUNET_CADET_TEST_Context *ctx) |
233 | { | 234 | { |
234 | unsigned int i; | 235 | for (unsigned int i = 0; i < ctx->num_peers; i++) |
235 | |||
236 | for (i = 0; i < ctx->num_peers; i++) | ||
237 | { | 236 | { |
238 | GNUNET_assert (NULL != ctx->ops[i]); | 237 | GNUNET_assert (NULL != ctx->ops[i]); |
239 | GNUNET_TESTBED_operation_done (ctx->ops[i]); | 238 | GNUNET_TESTBED_operation_done (ctx->ops[i]); |
@@ -269,33 +268,37 @@ cadet_test_run (void *cls, | |||
269 | unsigned int links_failed) | 268 | unsigned int links_failed) |
270 | { | 269 | { |
271 | struct GNUNET_CADET_TEST_Context *ctx = cls; | 270 | struct GNUNET_CADET_TEST_Context *ctx = cls; |
272 | unsigned int i; | ||
273 | 271 | ||
274 | if (0 != links_failed) | 272 | if (0 != links_failed) |
275 | { | 273 | { |
276 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Some links failed (%u), ending\n", | 274 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
275 | "Some links failed (%u), ending\n", | ||
277 | links_failed); | 276 | links_failed); |
278 | exit (2); | 277 | exit (2); |
279 | } | 278 | } |
280 | |||
281 | if (num_peers != ctx->num_peers) | 279 | if (num_peers != ctx->num_peers) |
282 | { | 280 | { |
283 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers started %u/%u, ending\n", | 281 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
284 | num_peers, ctx->num_peers); | 282 | "Peers started %u/%u, ending\n", |
283 | num_peers, | ||
284 | ctx->num_peers); | ||
285 | exit (1); | 285 | exit (1); |
286 | } | 286 | } |
287 | |||
288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
289 | "Testbed up, %u peers and %u links\n", | 288 | "Testbed up, %u peers and %u links\n", |
290 | num_peers, links_succeeded); | 289 | num_peers, |
290 | links_succeeded); | ||
291 | ctx->peers = peers; | 291 | ctx->peers = peers; |
292 | for (i = 0; i < num_peers; i++) | 292 | for (unsigned int i = 0; i < num_peers; i++) |
293 | { | 293 | { |
294 | struct GNUNET_CADET_TEST_AdapterContext *newctx; | 294 | struct GNUNET_CADET_TEST_AdapterContext *newctx; |
295 | |||
295 | newctx = GNUNET_new (struct GNUNET_CADET_TEST_AdapterContext); | 296 | newctx = GNUNET_new (struct GNUNET_CADET_TEST_AdapterContext); |
296 | newctx->peer = i; | 297 | newctx->peer = i; |
297 | newctx->ctx = ctx; | 298 | newctx->ctx = ctx; |
298 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to cadet %u\n", i); | 299 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
300 | "Connecting to cadet %u\n", | ||
301 | i); | ||
299 | ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx, | 302 | ctx->ops[i] = GNUNET_TESTBED_service_connect (ctx, |
300 | peers[i], | 303 | peers[i], |
301 | "cadet", | 304 | "cadet", |
@@ -304,7 +307,9 @@ cadet_test_run (void *cls, | |||
304 | &cadet_connect_adapter, | 307 | &cadet_connect_adapter, |
305 | &cadet_disconnect_adapter, | 308 | &cadet_disconnect_adapter, |
306 | newctx); | 309 | newctx); |
307 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "op handle %p\n", ctx->ops[i]); | 310 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
311 | "op handle %p\n", | ||
312 | ctx->ops[i]); | ||
308 | } | 313 | } |
309 | } | 314 | } |
310 | 315 | ||
@@ -340,8 +345,10 @@ GNUNET_CADET_TEST_ruN (const char *testname, | |||
340 | 345 | ||
341 | ctx = GNUNET_new (struct GNUNET_CADET_TEST_Context); | 346 | ctx = GNUNET_new (struct GNUNET_CADET_TEST_Context); |
342 | ctx->num_peers = num_peers; | 347 | ctx->num_peers = num_peers; |
343 | ctx->ops = GNUNET_new_array (num_peers, struct GNUNET_TESTBED_Operation *); | 348 | ctx->ops = GNUNET_new_array (num_peers, |
344 | ctx->cadets = GNUNET_new_array (num_peers, struct GNUNET_CADET_Handle *); | 349 | struct GNUNET_TESTBED_Operation *); |
350 | ctx->cadets = GNUNET_new_array (num_peers, | ||
351 | struct GNUNET_CADET_Handle *); | ||
345 | ctx->app_main = tmain; | 352 | ctx->app_main = tmain; |
346 | ctx->app_main_cls = tmain_cls; | 353 | ctx->app_main_cls = tmain_cls; |
347 | ctx->connects = connects; | 354 | ctx->connects = connects; |
@@ -352,12 +359,12 @@ GNUNET_CADET_TEST_ruN (const char *testname, | |||
352 | ctx->port_count = 0; | 359 | ctx->port_count = 0; |
353 | while (NULL != ctx->ports[ctx->port_count]) | 360 | while (NULL != ctx->ports[ctx->port_count]) |
354 | ctx->port_count++; | 361 | ctx->port_count++; |
355 | |||
356 | GNUNET_TESTBED_test_run (testname, | 362 | GNUNET_TESTBED_test_run (testname, |
357 | cfgfile, | 363 | cfgfile, |
358 | num_peers, | 364 | num_peers, |
359 | 0LL, NULL, NULL, | 365 | 0LL, NULL, NULL, |
360 | &cadet_test_run, ctx); | 366 | &cadet_test_run, |
367 | ctx); | ||
361 | } | 368 | } |
362 | 369 | ||
363 | /* end of cadet_test_lib.c */ | 370 | /* end of cadet_test_lib.c */ |
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c index 20e4c363e..23a4bc247 100644 --- a/src/cadet/gnunet-service-cadet.c +++ b/src/cadet/gnunet-service-cadet.c | |||
@@ -763,6 +763,7 @@ handle_local_data (void *cls, | |||
763 | buf, | 763 | buf, |
764 | payload_size)) | 764 | payload_size)) |
765 | { | 765 | { |
766 | GNUNET_break (0); | ||
766 | GNUNET_SERVICE_client_drop (c->client); | 767 | GNUNET_SERVICE_client_drop (c->client); |
767 | return; | 768 | return; |
768 | } | 769 | } |
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c index 1a2b32be0..2d8d36c6c 100644 --- a/src/cadet/gnunet-service-cadet_channel.c +++ b/src/cadet/gnunet-service-cadet_channel.c | |||
@@ -411,7 +411,7 @@ GCCH_2s (const struct CadetChannel *ch) | |||
411 | 411 | ||
412 | 412 | ||
413 | /** | 413 | /** |
414 | * Hash the @a port and @a initiator and @a listener to | 414 | * Hash the @a port and @a initiator and @a listener to |
415 | * calculate the "challenge" @a h_port we send to the other | 415 | * calculate the "challenge" @a h_port we send to the other |
416 | * peer on #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN. | 416 | * peer on #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN. |
417 | * | 417 | * |
@@ -1186,7 +1186,7 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch, | |||
1186 | port, | 1186 | port, |
1187 | sizeof (struct GNUNET_HashCode))) | 1187 | sizeof (struct GNUNET_HashCode))) |
1188 | { | 1188 | { |
1189 | /* Other peer failed to provide the right port, | 1189 | /* Other peer failed to provide the right port, |
1190 | refuse connection. */ | 1190 | refuse connection. */ |
1191 | GNUNET_break_op (0); | 1191 | GNUNET_break_op (0); |
1192 | return; | 1192 | return; |
@@ -1279,8 +1279,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1279 | uint32_t delta; | 1279 | uint32_t delta; |
1280 | 1280 | ||
1281 | GNUNET_assert (GNUNET_NO == ch->is_loopback); | 1281 | GNUNET_assert (GNUNET_NO == ch->is_loopback); |
1282 | if ( (GNUNET_YES == ch->destroy) && | 1282 | if ( (NULL == ch->owner) && |
1283 | (NULL == ch->owner) && | ||
1284 | (NULL == ch->dest) ) | 1283 | (NULL == ch->dest) ) |
1285 | { | 1284 | { |
1286 | /* This client is gone, but we still have messages to send to | 1285 | /* This client is gone, but we still have messages to send to |
@@ -1290,8 +1289,9 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1290 | "Dropping incoming payload on %s as this end is already closed\n", | 1289 | "Dropping incoming payload on %s as this end is already closed\n", |
1291 | GCCH_2s (ch)); | 1290 | GCCH_2s (ch)); |
1292 | /* send back DESTROY notification to stop further retransmissions! */ | 1291 | /* send back DESTROY notification to stop further retransmissions! */ |
1293 | GCT_send_channel_destroy (ch->t, | 1292 | if (GNUNET_YES == ch->destroy) |
1294 | ch->ctn); | 1293 | GCT_send_channel_destroy (ch->t, |
1294 | ch->ctn); | ||
1295 | return; | 1295 | return; |
1296 | } | 1296 | } |
1297 | payload_size = ntohs (msg->header.size) - sizeof (*msg); | 1297 | payload_size = ntohs (msg->header.size) - sizeof (*msg); |
@@ -1822,7 +1822,7 @@ GCCH_handle_local_data (struct CadetChannel *ch, | |||
1822 | { | 1822 | { |
1823 | struct CadetReliableMessage *crm; | 1823 | struct CadetReliableMessage *crm; |
1824 | 1824 | ||
1825 | if (ch->pending_messages > ch->max_pending_messages) | 1825 | if (ch->pending_messages >= ch->max_pending_messages) |
1826 | { | 1826 | { |
1827 | GNUNET_break (0); | 1827 | GNUNET_break (0); |
1828 | return GNUNET_SYSERR; | 1828 | return GNUNET_SYSERR; |
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index 82ab5cc2c..9ff62b29f 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c | |||
@@ -39,6 +39,13 @@ | |||
39 | 39 | ||
40 | 40 | ||
41 | /** | 41 | /** |
42 | * How long do we wait initially before retransmitting the KX? | ||
43 | * TODO: replace by 2 RTT if/once we have connection-level RTT data! | ||
44 | */ | ||
45 | #define INITIAL_CONNECTION_CREATE_RETRY_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 200) | ||
46 | |||
47 | |||
48 | /** | ||
42 | * All the states a connection can be in. | 49 | * All the states a connection can be in. |
43 | */ | 50 | */ |
44 | enum CadetConnectionState | 51 | enum CadetConnectionState |
@@ -134,6 +141,16 @@ struct CadetConnection | |||
134 | struct GNUNET_TIME_Relative retry_delay; | 141 | struct GNUNET_TIME_Relative retry_delay; |
135 | 142 | ||
136 | /** | 143 | /** |
144 | * Earliest time for re-trying CREATE | ||
145 | */ | ||
146 | struct GNUNET_TIME_Absolute create_at; | ||
147 | |||
148 | /** | ||
149 | * Earliest time for re-trying CREATE_ACK | ||
150 | */ | ||
151 | struct GNUNET_TIME_Absolute create_ack_at; | ||
152 | |||
153 | /** | ||
137 | * Performance metrics for this connection. | 154 | * Performance metrics for this connection. |
138 | */ | 155 | */ |
139 | struct CadetConnectionMetrics metrics; | 156 | struct CadetConnectionMetrics metrics; |
@@ -482,8 +499,9 @@ GCC_latency_observed (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, | |||
482 | 499 | ||
483 | 500 | ||
484 | /** | 501 | /** |
485 | * A #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK was received for this connection, implying | 502 | * A #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK was received for |
486 | * that the end-to-end connection is up. Process it. | 503 | * this connection, implying that the end-to-end connection is up. |
504 | * Process it. | ||
487 | * | 505 | * |
488 | * @param cc the connection that got the ACK. | 506 | * @param cc the connection that got the ACK. |
489 | */ | 507 | */ |
@@ -525,6 +543,11 @@ void | |||
525 | GCC_handle_kx (struct CadetConnection *cc, | 543 | GCC_handle_kx (struct CadetConnection *cc, |
526 | const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg) | 544 | const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg) |
527 | { | 545 | { |
546 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
547 | "Received KX message with ephermal %s on CC %s in state %d\n", | ||
548 | GNUNET_e2s (&msg->ephemeral_key), | ||
549 | GNUNET_sh2s (&cc->cid.connection_of_tunnel), | ||
550 | cc->state); | ||
528 | if (CADET_CONNECTION_SENT == cc->state) | 551 | if (CADET_CONNECTION_SENT == cc->state) |
529 | { | 552 | { |
530 | /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine, | 553 | /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine, |
@@ -549,6 +572,11 @@ void | |||
549 | GCC_handle_kx_auth (struct CadetConnection *cc, | 572 | GCC_handle_kx_auth (struct CadetConnection *cc, |
550 | const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) | 573 | const struct GNUNET_CADET_TunnelKeyExchangeAuthMessage *msg) |
551 | { | 574 | { |
575 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
576 | "Received KX AUTH message with ephermal %s on CC %s in state %d\n", | ||
577 | GNUNET_e2s (&msg->kx.ephemeral_key), | ||
578 | GNUNET_sh2s (&cc->cid.connection_of_tunnel), | ||
579 | cc->state); | ||
552 | if (CADET_CONNECTION_SENT == cc->state) | 580 | if (CADET_CONNECTION_SENT == cc->state) |
553 | { | 581 | { |
554 | /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine, | 582 | /* We didn't get the CADET_CONNECTION_CREATE_ACK, but instead got payload. That's fine, |
@@ -601,25 +629,26 @@ send_create (void *cls) | |||
601 | struct GNUNET_CADET_ConnectionCreateMessage *create_msg; | 629 | struct GNUNET_CADET_ConnectionCreateMessage *create_msg; |
602 | struct GNUNET_PeerIdentity *pids; | 630 | struct GNUNET_PeerIdentity *pids; |
603 | struct GNUNET_MQ_Envelope *env; | 631 | struct GNUNET_MQ_Envelope *env; |
604 | unsigned int path_length; | ||
605 | 632 | ||
606 | cc->task = NULL; | 633 | cc->task = NULL; |
607 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); | 634 | GNUNET_assert (GNUNET_YES == cc->mqm_ready); |
608 | path_length = GCPP_get_length (cc->path); | ||
609 | env = GNUNET_MQ_msg_extra (create_msg, | 635 | env = GNUNET_MQ_msg_extra (create_msg, |
610 | (1 + path_length) * sizeof (struct GNUNET_PeerIdentity), | 636 | (2 + cc->off) * sizeof (struct GNUNET_PeerIdentity), |
611 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); | 637 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); |
612 | create_msg->options = htonl ((uint32_t) cc->options); | 638 | create_msg->options = htonl ((uint32_t) cc->options); |
613 | create_msg->cid = cc->cid; | 639 | create_msg->cid = cc->cid; |
614 | pids = (struct GNUNET_PeerIdentity *) &create_msg[1]; | 640 | pids = (struct GNUNET_PeerIdentity *) &create_msg[1]; |
615 | pids[0] = my_full_id; | 641 | pids[0] = my_full_id; |
616 | for (unsigned int i=0;i<path_length;i++) | 642 | for (unsigned int i=0;i<=cc->off;i++) |
617 | pids[i + 1] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path, | 643 | pids[i + 1] = *GCP_get_id (GCPP_get_peer_at_offset (cc->path, |
618 | i)); | 644 | i)); |
619 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 645 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
620 | "Sending CADET_CONNECTION_CREATE message for %s\n", | 646 | "Sending CADET_CONNECTION_CREATE message for %s with %u hops\n", |
621 | GCC_2s (cc)); | 647 | GCC_2s (cc), |
648 | cc->off + 2); | ||
622 | cc->env = env; | 649 | cc->env = env; |
650 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); | ||
651 | cc->create_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); | ||
623 | update_state (cc, | 652 | update_state (cc, |
624 | CADET_CONNECTION_SENT, | 653 | CADET_CONNECTION_SENT, |
625 | GNUNET_NO); | 654 | GNUNET_NO); |
@@ -641,7 +670,6 @@ send_create_ack (void *cls) | |||
641 | struct GNUNET_MQ_Envelope *env; | 670 | struct GNUNET_MQ_Envelope *env; |
642 | 671 | ||
643 | cc->task = NULL; | 672 | cc->task = NULL; |
644 | GNUNET_assert (CADET_CONNECTION_CREATE_RECEIVED == cc->state); | ||
645 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 673 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
646 | "Sending CONNECTION_CREATE_ACK message for %s\n", | 674 | "Sending CONNECTION_CREATE_ACK message for %s\n", |
647 | GCC_2s (cc)); | 675 | GCC_2s (cc)); |
@@ -650,9 +678,16 @@ send_create_ack (void *cls) | |||
650 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK); | 678 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK); |
651 | ack_msg->cid = cc->cid; | 679 | ack_msg->cid = cc->cid; |
652 | cc->env = env; | 680 | cc->env = env; |
653 | update_state (cc, | 681 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); |
654 | CADET_CONNECTION_READY, | 682 | cc->create_ack_at = GNUNET_TIME_relative_to_absolute (cc->retry_delay); |
655 | GNUNET_NO); | 683 | if (CADET_CONNECTION_CREATE_RECEIVED == cc->state) |
684 | update_state (cc, | ||
685 | CADET_CONNECTION_READY, | ||
686 | GNUNET_NO); | ||
687 | if (CADET_CONNECTION_READY == cc->state) | ||
688 | cc->task = GNUNET_SCHEDULER_add_delayed (keepalive_period, | ||
689 | &send_keepalive, | ||
690 | cc); | ||
656 | GCP_send (cc->mq_man, | 691 | GCP_send (cc->mq_man, |
657 | env); | 692 | env); |
658 | } | 693 | } |
@@ -681,8 +716,9 @@ GCC_handle_duplicate_create (struct CadetConnection *cc) | |||
681 | cc->mqm_ready); | 716 | cc->mqm_ready); |
682 | if (NULL != cc->task) | 717 | if (NULL != cc->task) |
683 | GNUNET_SCHEDULER_cancel (cc->task); | 718 | GNUNET_SCHEDULER_cancel (cc->task); |
684 | cc->task = GNUNET_SCHEDULER_add_now (&send_create_ack, | 719 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_ack_at, |
685 | cc); | 720 | &send_create_ack, |
721 | cc); | ||
686 | } | 722 | } |
687 | else | 723 | else |
688 | { | 724 | { |
@@ -721,7 +757,7 @@ manage_first_hop_mq (void *cls, | |||
721 | update_state (cc, | 757 | update_state (cc, |
722 | CADET_CONNECTION_NEW, | 758 | CADET_CONNECTION_NEW, |
723 | GNUNET_NO); | 759 | GNUNET_NO); |
724 | cc->retry_delay = GNUNET_TIME_UNIT_ZERO; | 760 | cc->retry_delay = INITIAL_CONNECTION_CREATE_RETRY_DELAY; |
725 | if (NULL != cc->task) | 761 | if (NULL != cc->task) |
726 | { | 762 | { |
727 | GNUNET_SCHEDULER_cancel (cc->task); | 763 | GNUNET_SCHEDULER_cancel (cc->task); |
@@ -741,8 +777,9 @@ manage_first_hop_mq (void *cls, | |||
741 | { | 777 | { |
742 | case CADET_CONNECTION_NEW: | 778 | case CADET_CONNECTION_NEW: |
743 | /* Transmit immediately */ | 779 | /* Transmit immediately */ |
744 | cc->task = GNUNET_SCHEDULER_add_now (&send_create, | 780 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, |
745 | cc); | 781 | &send_create, |
782 | cc); | ||
746 | break; | 783 | break; |
747 | case CADET_CONNECTION_SENDING_CREATE: | 784 | case CADET_CONNECTION_SENDING_CREATE: |
748 | /* Should not be possible to be called in this state. */ | 785 | /* Should not be possible to be called in this state. */ |
@@ -750,16 +787,16 @@ manage_first_hop_mq (void *cls, | |||
750 | break; | 787 | break; |
751 | case CADET_CONNECTION_SENT: | 788 | case CADET_CONNECTION_SENT: |
752 | /* Retry a bit later... */ | 789 | /* Retry a bit later... */ |
753 | cc->retry_delay = GNUNET_TIME_STD_BACKOFF (cc->retry_delay); | 790 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_at, |
754 | cc->task = GNUNET_SCHEDULER_add_delayed (cc->retry_delay, | 791 | &send_create, |
755 | &send_create, | 792 | cc); |
756 | cc); | ||
757 | break; | 793 | break; |
758 | case CADET_CONNECTION_CREATE_RECEIVED: | 794 | case CADET_CONNECTION_CREATE_RECEIVED: |
759 | /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */ | 795 | /* We got the 'CREATE' (incoming connection), should send the CREATE_ACK */ |
760 | cc->metrics.age = GNUNET_TIME_absolute_get (); | 796 | cc->metrics.age = GNUNET_TIME_absolute_get (); |
761 | cc->task = GNUNET_SCHEDULER_add_now (&send_create_ack, | 797 | cc->task = GNUNET_SCHEDULER_add_at (cc->create_ack_at, |
762 | cc); | 798 | &send_create_ack, |
799 | cc); | ||
763 | break; | 800 | break; |
764 | case CADET_CONNECTION_READY: | 801 | case CADET_CONNECTION_READY: |
765 | if ( (NULL == cc->keepalive_qe) && | 802 | if ( (NULL == cc->keepalive_qe) && |
@@ -814,6 +851,8 @@ connection_create (struct CadetPeer *destination, | |||
814 | cc->state = init_state; | 851 | cc->state = init_state; |
815 | cc->ct = ct; | 852 | cc->ct = ct; |
816 | cc->cid = *cid; | 853 | cc->cid = *cid; |
854 | cc->retry_delay = GNUNET_TIME_relative_multiply (INITIAL_CONNECTION_CREATE_RETRY_DELAY, | ||
855 | off); | ||
817 | GNUNET_assert (GNUNET_OK == | 856 | GNUNET_assert (GNUNET_OK == |
818 | GNUNET_CONTAINER_multishortmap_put (connections, | 857 | GNUNET_CONTAINER_multishortmap_put (connections, |
819 | &GCC_get_id (cc)->connection_of_tunnel, | 858 | &GCC_get_id (cc)->connection_of_tunnel, |
@@ -824,9 +863,10 @@ connection_create (struct CadetPeer *destination, | |||
824 | cc->path = path; | 863 | cc->path = path; |
825 | cc->off = off; | 864 | cc->off = off; |
826 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 865 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
827 | "Creating %s using path %s\n", | 866 | "Creating %s using path %s (offset: %u)\n", |
828 | GCC_2s (cc), | 867 | GCC_2s (cc), |
829 | GCPP_2s (path)); | 868 | GCPP_2s (path), |
869 | off); | ||
830 | GCPP_add_connection (path, | 870 | GCPP_add_connection (path, |
831 | off, | 871 | off, |
832 | cc); | 872 | cc); |
@@ -834,7 +874,6 @@ connection_create (struct CadetPeer *destination, | |||
834 | GCP_add_connection (GCPP_get_peer_at_offset (path, | 874 | GCP_add_connection (GCPP_get_peer_at_offset (path, |
835 | i), | 875 | i), |
836 | cc); | 876 | cc); |
837 | |||
838 | first_hop = GCPP_get_peer_at_offset (path, | 877 | first_hop = GCPP_get_peer_at_offset (path, |
839 | 0); | 878 | 0); |
840 | cc->mq_man = GCP_request_mq (first_hop, | 879 | cc->mq_man = GCP_request_mq (first_hop, |
@@ -1001,11 +1040,14 @@ GCC_transmit (struct CadetConnection *cc, | |||
1001 | * Obtain the path used by this connection. | 1040 | * Obtain the path used by this connection. |
1002 | * | 1041 | * |
1003 | * @param cc connection | 1042 | * @param cc connection |
1043 | * @param off[out] set to the length of the path we use | ||
1004 | * @return path to @a cc | 1044 | * @return path to @a cc |
1005 | */ | 1045 | */ |
1006 | struct CadetPeerPath * | 1046 | struct CadetPeerPath * |
1007 | GCC_get_path (struct CadetConnection *cc) | 1047 | GCC_get_path (struct CadetConnection *cc, |
1048 | unsigned int *off) | ||
1008 | { | 1049 | { |
1050 | *off = cc->off; | ||
1009 | return cc->path; | 1051 | return cc->path; |
1010 | } | 1052 | } |
1011 | 1053 | ||
diff --git a/src/cadet/gnunet-service-cadet_connection.h b/src/cadet/gnunet-service-cadet_connection.h index fdb184366..1c0475d40 100644 --- a/src/cadet/gnunet-service-cadet_connection.h +++ b/src/cadet/gnunet-service-cadet_connection.h | |||
@@ -300,10 +300,12 @@ GCC_get_ct (struct CadetConnection *cc); | |||
300 | * Obtain the path used by this connection. | 300 | * Obtain the path used by this connection. |
301 | * | 301 | * |
302 | * @param cc connection | 302 | * @param cc connection |
303 | * @param off[out] set to offset in this path where the connection @a cc ends | ||
303 | * @return path to @a cc | 304 | * @return path to @a cc |
304 | */ | 305 | */ |
305 | struct CadetPeerPath * | 306 | struct CadetPeerPath * |
306 | GCC_get_path (struct CadetConnection *cc); | 307 | GCC_get_path (struct CadetConnection *cc, |
308 | unsigned int *off); | ||
307 | 309 | ||
308 | 310 | ||
309 | /** | 311 | /** |
diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c index 84aff1857..65738504e 100644 --- a/src/cadet/gnunet-service-cadet_core.c +++ b/src/cadet/gnunet-service-cadet_core.c | |||
@@ -406,6 +406,28 @@ route_message (struct CadetPeer *prev, | |||
406 | (NULL != dir->env_head) ) | 406 | (NULL != dir->env_head) ) |
407 | discard_buffer (dir, | 407 | discard_buffer (dir, |
408 | dir->env_head); | 408 | dir->env_head); |
409 | /* Check for duplicates */ | ||
410 | for (const struct GNUNET_MQ_Envelope *env = dir->env_head; | ||
411 | NULL != env; | ||
412 | env = GNUNET_MQ_env_next (env)) | ||
413 | { | ||
414 | const struct GNUNET_MessageHeader *hdr = GNUNET_MQ_env_get_msg (env); | ||
415 | |||
416 | if ( (hdr->size == msg->size) && | ||
417 | (0 == memcmp (hdr, | ||
418 | msg, | ||
419 | ntohs (msg->size))) ) | ||
420 | { | ||
421 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
422 | "Received duplicate of message already in buffer, dropping\n"); | ||
423 | GNUNET_STATISTICS_update (stats, | ||
424 | "# messages dropped due to duplicate in buffer", | ||
425 | 1, | ||
426 | GNUNET_NO); | ||
427 | return; | ||
428 | } | ||
429 | } | ||
430 | |||
409 | rung = dir->rung; | 431 | rung = dir->rung; |
410 | if (cur_buffers == max_buffers) | 432 | if (cur_buffers == max_buffers) |
411 | { | 433 | { |
@@ -434,7 +456,7 @@ route_message (struct CadetPeer *prev, | |||
434 | GNUNET_CONTAINER_DLL_remove (rung->rd_head, | 456 | GNUNET_CONTAINER_DLL_remove (rung->rd_head, |
435 | rung->rd_tail, | 457 | rung->rd_tail, |
436 | dir); | 458 | dir); |
437 | /* make 'nxt' point to the next higher rung, creat if necessary */ | 459 | /* make 'nxt' point to the next higher rung, create if necessary */ |
438 | nxt = rung->next; | 460 | nxt = rung->next; |
439 | if ( (NULL == nxt) || | 461 | if ( (NULL == nxt) || |
440 | (rung->rung_off + 1 != nxt->rung_off) ) | 462 | (rung->rung_off + 1 != nxt->rung_off) ) |
@@ -631,7 +653,7 @@ timeout_cb (void *cls) | |||
631 | NULL); | 653 | NULL); |
632 | return; | 654 | return; |
633 | } | 655 | } |
634 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 656 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
635 | "Sending BROKEN due to timeout (%s was last use, %s linger)\n", | 657 | "Sending BROKEN due to timeout (%s was last use, %s linger)\n", |
636 | GNUNET_STRINGS_absolute_time_to_string (r->last_use), | 658 | GNUNET_STRINGS_absolute_time_to_string (r->last_use), |
637 | GNUNET_STRINGS_relative_time_to_string (linger, | 659 | GNUNET_STRINGS_relative_time_to_string (linger, |
@@ -693,7 +715,7 @@ dir_ready_cb (void *cls, | |||
693 | return; | 715 | return; |
694 | } | 716 | } |
695 | odir = (dir == &route->next) ? &route->prev : &route->next; | 717 | odir = (dir == &route->next) ? &route->prev : &route->next; |
696 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 718 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
697 | "Sending BROKEN due to MQ going down\n"); | 719 | "Sending BROKEN due to MQ going down\n"); |
698 | send_broken (&route->next, | 720 | send_broken (&route->next, |
699 | &route->cid, | 721 | &route->cid, |
@@ -781,31 +803,45 @@ handle_connection_create (void *cls, | |||
781 | if (0 == path_length) | 803 | if (0 == path_length) |
782 | { | 804 | { |
783 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 805 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
784 | "Dropping CADET_CONNECTION_CREATE with empty path\n"); | 806 | "Dropping CADET_CONNECTION_CREATE with empty path\n"); |
785 | GNUNET_break_op (0); | 807 | GNUNET_break_op (0); |
786 | return; | 808 | return; |
787 | } | 809 | } |
810 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
811 | "Handling CADET_CONNECTION_CREATE from %s for CID %s with %u hops\n", | ||
812 | GCP_2s (sender), | ||
813 | GNUNET_sh2s (&msg->cid.connection_of_tunnel), | ||
814 | path_length); | ||
788 | /* Check for loops */ | 815 | /* Check for loops */ |
789 | struct GNUNET_CONTAINER_MultiPeerMap *map; | 816 | { |
790 | map = GNUNET_CONTAINER_multipeermap_create (path_length * 2, | 817 | struct GNUNET_CONTAINER_MultiPeerMap *map; |
791 | GNUNET_YES); | 818 | |
792 | GNUNET_assert (NULL != map); | 819 | map = GNUNET_CONTAINER_multipeermap_create (path_length * 2, |
793 | for (off = 0; off < path_length; off++) { | 820 | GNUNET_YES); |
794 | if (GNUNET_SYSERR == | 821 | GNUNET_assert (NULL != map); |
795 | GNUNET_CONTAINER_multipeermap_put (map, | 822 | for (unsigned int i=0;i<path_length;i++) |
796 | &pids[off], | 823 | { |
797 | NULL, | ||
798 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { | ||
799 | /* bogus request */ | ||
800 | GNUNET_CONTAINER_multipeermap_destroy (map); | ||
801 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 824 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
802 | "Dropping CADET_CONNECTION_CREATE with cyclic path\n"); | 825 | "CADET_CONNECTION_CREATE has peer %s at offset %u\n", |
803 | GNUNET_break_op (0); | 826 | GNUNET_i2s (&pids[i]), |
804 | return; | 827 | i); |
828 | if (GNUNET_SYSERR == | ||
829 | GNUNET_CONTAINER_multipeermap_put (map, | ||
830 | &pids[i], | ||
831 | NULL, | ||
832 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
833 | { | ||
834 | /* bogus request */ | ||
835 | GNUNET_CONTAINER_multipeermap_destroy (map); | ||
836 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
837 | "Dropping CADET_CONNECTION_CREATE with cyclic path\n"); | ||
838 | GNUNET_break_op (0); | ||
839 | return; | ||
840 | } | ||
805 | } | 841 | } |
842 | GNUNET_CONTAINER_multipeermap_destroy (map); | ||
806 | } | 843 | } |
807 | GNUNET_CONTAINER_multipeermap_destroy (map); | 844 | /* Initiator is at offset 0, find us */ |
808 | /* Initiator is at offset 0. */ | ||
809 | for (off=1;off<path_length;off++) | 845 | for (off=1;off<path_length;off++) |
810 | if (0 == memcmp (&my_full_id, | 846 | if (0 == memcmp (&my_full_id, |
811 | &pids[off], | 847 | &pids[off], |
@@ -814,7 +850,7 @@ handle_connection_create (void *cls, | |||
814 | if (off == path_length) | 850 | if (off == path_length) |
815 | { | 851 | { |
816 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 852 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
817 | "Dropping CADET_CONNECTION_CREATE without us in the path\n"); | 853 | "Dropping CADET_CONNECTION_CREATE without us in the path\n"); |
818 | GNUNET_break_op (0); | 854 | GNUNET_break_op (0); |
819 | return; | 855 | return; |
820 | } | 856 | } |
@@ -823,14 +859,15 @@ handle_connection_create (void *cls, | |||
823 | GNUNET_NO)) | 859 | GNUNET_NO)) |
824 | { | 860 | { |
825 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 861 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
826 | "Dropping CADET_CONNECTION_CREATE without sender in the path\n"); | 862 | "Dropping CADET_CONNECTION_CREATE without sender at previous hop in the path\n"); |
827 | GNUNET_break_op (0); | 863 | GNUNET_break_op (0); |
828 | return; | 864 | return; |
829 | } | 865 | } |
830 | if (NULL != | 866 | if (NULL != |
831 | get_route (&msg->cid)) | 867 | (route = get_route (&msg->cid))) |
832 | { | 868 | { |
833 | /* Duplicate CREATE, pass it on, previous one might have been lost! */ | 869 | /* Duplicate CREATE, pass it on, previous one might have been lost! */ |
870 | |||
834 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 871 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
835 | "Passing on duplicate CADET_CONNECTION_CREATE message on connection %s\n", | 872 | "Passing on duplicate CADET_CONNECTION_CREATE message on connection %s\n", |
836 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); | 873 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); |
@@ -859,7 +896,7 @@ handle_connection_create (void *cls, | |||
859 | origin = GCP_get (&pids[0], | 896 | origin = GCP_get (&pids[0], |
860 | GNUNET_YES); | 897 | GNUNET_YES); |
861 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 898 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
862 | "Received CADET_CONNECTION_CREATE message from %s for connection %s, building inverse path\n", | 899 | "I am destination for CADET_CONNECTION_CREATE message from %s for connection %s, building inverse path\n", |
863 | GCP_2s (origin), | 900 | GCP_2s (origin), |
864 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); | 901 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); |
865 | path = GCPP_get_path_from_route (path_length - 1, | 902 | path = GCPP_get_path_from_route (path_length - 1, |
@@ -949,6 +986,10 @@ handle_connection_create (void *cls, | |||
949 | 3), | 986 | 3), |
950 | &timeout_cb, | 987 | &timeout_cb, |
951 | NULL); | 988 | NULL); |
989 | /* also pass CREATE message along to next hop */ | ||
990 | route_message (sender, | ||
991 | &msg->cid, | ||
992 | &msg->header); | ||
952 | } | 993 | } |
953 | 994 | ||
954 | 995 | ||
@@ -970,7 +1011,9 @@ handle_connection_create_ack (void *cls, | |||
970 | if (NULL != cc) | 1011 | if (NULL != cc) |
971 | { | 1012 | { |
972 | /* verify ACK came from the right direction */ | 1013 | /* verify ACK came from the right direction */ |
973 | struct CadetPeerPath *path = GCC_get_path (cc); | 1014 | unsigned int len; |
1015 | struct CadetPeerPath *path = GCC_get_path (cc, | ||
1016 | &len); | ||
974 | 1017 | ||
975 | if (peer != | 1018 | if (peer != |
976 | GCPP_get_peer_at_offset (path, | 1019 | GCPP_get_peer_at_offset (path, |
@@ -1014,7 +1057,9 @@ handle_connection_broken (void *cls, | |||
1014 | if (NULL != cc) | 1057 | if (NULL != cc) |
1015 | { | 1058 | { |
1016 | /* verify message came from the right direction */ | 1059 | /* verify message came from the right direction */ |
1017 | struct CadetPeerPath *path = GCC_get_path (cc); | 1060 | unsigned int len; |
1061 | struct CadetPeerPath *path = GCC_get_path (cc, | ||
1062 | &len); | ||
1018 | 1063 | ||
1019 | if (peer != | 1064 | if (peer != |
1020 | GCPP_get_peer_at_offset (path, | 1065 | GCPP_get_peer_at_offset (path, |
@@ -1063,7 +1108,9 @@ handle_connection_destroy (void *cls, | |||
1063 | if (NULL != cc) | 1108 | if (NULL != cc) |
1064 | { | 1109 | { |
1065 | /* verify message came from the right direction */ | 1110 | /* verify message came from the right direction */ |
1066 | struct CadetPeerPath *path = GCC_get_path (cc); | 1111 | unsigned int len; |
1112 | struct CadetPeerPath *path = GCC_get_path (cc, | ||
1113 | &len); | ||
1067 | 1114 | ||
1068 | if (peer != | 1115 | if (peer != |
1069 | GCPP_get_peer_at_offset (path, | 1116 | GCPP_get_peer_at_offset (path, |
@@ -1108,11 +1155,19 @@ handle_tunnel_kx (void *cls, | |||
1108 | struct CadetConnection *cc; | 1155 | struct CadetConnection *cc; |
1109 | 1156 | ||
1110 | /* First, check if message belongs to a connection that ends here. */ | 1157 | /* First, check if message belongs to a connection that ends here. */ |
1158 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1159 | "Routing KX with ephemeral %s on CID %s\n", | ||
1160 | GNUNET_e2s (&msg->ephemeral_key), | ||
1161 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); | ||
1162 | |||
1163 | |||
1111 | cc = GCC_lookup (&msg->cid); | 1164 | cc = GCC_lookup (&msg->cid); |
1112 | if (NULL != cc) | 1165 | if (NULL != cc) |
1113 | { | 1166 | { |
1114 | /* verify message came from the right direction */ | 1167 | /* verify message came from the right direction */ |
1115 | struct CadetPeerPath *path = GCC_get_path (cc); | 1168 | unsigned int len; |
1169 | struct CadetPeerPath *path = GCC_get_path (cc, | ||
1170 | &len); | ||
1116 | 1171 | ||
1117 | if (peer != | 1172 | if (peer != |
1118 | GCPP_get_peer_at_offset (path, | 1173 | GCPP_get_peer_at_offset (path, |
@@ -1152,7 +1207,9 @@ handle_tunnel_kx_auth (void *cls, | |||
1152 | if (NULL != cc) | 1207 | if (NULL != cc) |
1153 | { | 1208 | { |
1154 | /* verify message came from the right direction */ | 1209 | /* verify message came from the right direction */ |
1155 | struct CadetPeerPath *path = GCC_get_path (cc); | 1210 | unsigned int len; |
1211 | struct CadetPeerPath *path = GCC_get_path (cc, | ||
1212 | &len); | ||
1156 | 1213 | ||
1157 | if (peer != | 1214 | if (peer != |
1158 | GCPP_get_peer_at_offset (path, | 1215 | GCPP_get_peer_at_offset (path, |
@@ -1208,7 +1265,9 @@ handle_tunnel_encrypted (void *cls, | |||
1208 | if (NULL != cc) | 1265 | if (NULL != cc) |
1209 | { | 1266 | { |
1210 | /* verify message came from the right direction */ | 1267 | /* verify message came from the right direction */ |
1211 | struct CadetPeerPath *path = GCC_get_path (cc); | 1268 | unsigned int len; |
1269 | struct CadetPeerPath *path = GCC_get_path (cc, | ||
1270 | &len); | ||
1212 | 1271 | ||
1213 | if (peer != | 1272 | if (peer != |
1214 | GCPP_get_peer_at_offset (path, | 1273 | GCPP_get_peer_at_offset (path, |
diff --git a/src/cadet/gnunet-service-cadet_paths.c b/src/cadet/gnunet-service-cadet_paths.c index b443cf9e8..5218d0848 100644 --- a/src/cadet/gnunet-service-cadet_paths.c +++ b/src/cadet/gnunet-service-cadet_paths.c | |||
@@ -146,7 +146,7 @@ GCPP_add_connection (struct CadetPeerPath *path, | |||
146 | struct CadetPeerPathEntry *entry; | 146 | struct CadetPeerPathEntry *entry; |
147 | 147 | ||
148 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 148 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
149 | "Adding connection %s to path %s at offset %u\n", | 149 | "Adding %s to path %s at offset %u\n", |
150 | GCC_2s (cc), | 150 | GCC_2s (cc), |
151 | GCPP_2s (path), | 151 | GCPP_2s (path), |
152 | off); | 152 | off); |
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c index 05555e693..35e2c6148 100644 --- a/src/cadet/gnunet-service-cadet_peer.c +++ b/src/cadet/gnunet-service-cadet_peer.c | |||
@@ -242,12 +242,15 @@ struct CadetPeer | |||
242 | const char * | 242 | const char * |
243 | GCP_2s (const struct CadetPeer *cp) | 243 | GCP_2s (const struct CadetPeer *cp) |
244 | { | 244 | { |
245 | static char buf[32]; | 245 | static char buf[5]; |
246 | 246 | char *ret; | |
247 | GNUNET_snprintf (buf, | 247 | |
248 | sizeof (buf), | 248 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&cp->pid.public_key); |
249 | "P(%s)", | 249 | strncpy (buf, |
250 | GNUNET_i2s (&cp->pid)); | 250 | ret, |
251 | sizeof (buf) - 1); | ||
252 | GNUNET_free (ret); | ||
253 | buf[4] = '\0'; | ||
251 | return buf; | 254 | return buf; |
252 | } | 255 | } |
253 | 256 | ||
@@ -649,6 +652,27 @@ mqm_execute (struct GCP_MessageQueueManager *mqm) | |||
649 | } | 652 | } |
650 | else | 653 | else |
651 | { | 654 | { |
655 | { | ||
656 | const struct GNUNET_MessageHeader *mh; | ||
657 | |||
658 | mh = GNUNET_MQ_env_get_msg (mqm->env); | ||
659 | switch (ntohs (mh->type)) | ||
660 | { | ||
661 | case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX: | ||
662 | { | ||
663 | const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg | ||
664 | = (const struct GNUNET_CADET_TunnelKeyExchangeMessage *) mh; | ||
665 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
666 | "P2P forwarding KX with ephemeral %s to %s on CID %s\n", | ||
667 | GNUNET_e2s (&msg->ephemeral_key), | ||
668 | GCP_2s (cp), | ||
669 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); | ||
670 | } | ||
671 | break; | ||
672 | default: | ||
673 | break; | ||
674 | } | ||
675 | } | ||
652 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 676 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
653 | "Sending to peer %s from MQM %p\n", | 677 | "Sending to peer %s from MQM %p\n", |
654 | GCP_2s (cp), | 678 | GCP_2s (cp), |
@@ -1044,7 +1068,7 @@ GCP_add_connection (struct CadetPeer *cp, | |||
1044 | struct CadetConnection *cc) | 1068 | struct CadetConnection *cc) |
1045 | { | 1069 | { |
1046 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1070 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1047 | "Adding connection %s to peer %s\n", | 1071 | "Adding %s to peer %s\n", |
1048 | GCC_2s (cc), | 1072 | GCC_2s (cc), |
1049 | GCP_2s (cp)); | 1073 | GCP_2s (cp)); |
1050 | GNUNET_assert (GNUNET_OK == | 1074 | GNUNET_assert (GNUNET_OK == |
diff --git a/src/cadet/gnunet-service-cadet_tunnels.c b/src/cadet/gnunet-service-cadet_tunnels.c index 75d454522..dbd84a818 100644 --- a/src/cadet/gnunet-service-cadet_tunnels.c +++ b/src/cadet/gnunet-service-cadet_tunnels.c | |||
@@ -1369,6 +1369,15 @@ send_kx (struct CadetTunnel *t, | |||
1369 | msg->cid = *GCC_get_id (cc); | 1369 | msg->cid = *GCC_get_id (cc); |
1370 | GNUNET_CRYPTO_ecdhe_key_get_public (&ax->kx_0, | 1370 | GNUNET_CRYPTO_ecdhe_key_get_public (&ax->kx_0, |
1371 | &msg->ephemeral_key); | 1371 | &msg->ephemeral_key); |
1372 | #if DEBUG_KX | ||
1373 | msg->ephemeral_key_XXX = ax->kx_0; | ||
1374 | msg->private_key_XXX = *my_private_key; | ||
1375 | #endif | ||
1376 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1377 | "Sending KX message to %s with ephemeral %s on CID %s\n", | ||
1378 | GCT_2s (t), | ||
1379 | GNUNET_e2s (&msg->ephemeral_key), | ||
1380 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); | ||
1372 | GNUNET_CRYPTO_ecdhe_key_get_public (&ax->DHRs, | 1381 | GNUNET_CRYPTO_ecdhe_key_get_public (&ax->DHRs, |
1373 | &msg->ratchet_key); | 1382 | &msg->ratchet_key); |
1374 | mark_connection_unready (ct); | 1383 | mark_connection_unready (ct); |
@@ -1435,6 +1444,17 @@ send_kx_auth (struct CadetTunnel *t, | |||
1435 | &msg->kx.ephemeral_key); | 1444 | &msg->kx.ephemeral_key); |
1436 | GNUNET_CRYPTO_ecdhe_key_get_public (&ax->DHRs, | 1445 | GNUNET_CRYPTO_ecdhe_key_get_public (&ax->DHRs, |
1437 | &msg->kx.ratchet_key); | 1446 | &msg->kx.ratchet_key); |
1447 | #if DEBUG_KX | ||
1448 | msg->kx.ephemeral_key_XXX = ax->kx_0; | ||
1449 | msg->kx.private_key_XXX = *my_private_key; | ||
1450 | msg->r_ephemeral_key_XXX = ax->last_ephemeral; | ||
1451 | #endif | ||
1452 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1453 | "Sending KX_AUTH message to %s with ephemeral %s on CID %s\n", | ||
1454 | GCT_2s (t), | ||
1455 | GNUNET_e2s (&msg->kx.ephemeral_key), | ||
1456 | GNUNET_sh2s (&msg->kx.cid.connection_of_tunnel)); | ||
1457 | |||
1438 | /* Compute authenticator (this is the main difference to #send_kx()) */ | 1458 | /* Compute authenticator (this is the main difference to #send_kx()) */ |
1439 | GNUNET_CRYPTO_hash (&ax->RK, | 1459 | GNUNET_CRYPTO_hash (&ax->RK, |
1440 | sizeof (ax->RK), | 1460 | sizeof (ax->RK), |
@@ -1705,12 +1725,19 @@ GCT_handle_kx (struct CadetTConnection *ct, | |||
1705 | "# KX received", | 1725 | "# KX received", |
1706 | 1, | 1726 | 1, |
1707 | GNUNET_NO); | 1727 | GNUNET_NO); |
1708 | if (GNUNET_YES == alice_or_bob (GCP_get_id (t->destination))) | 1728 | if (GNUNET_YES == |
1729 | alice_or_bob (GCP_get_id (t->destination))) | ||
1709 | { | 1730 | { |
1710 | /* Bob is not allowed to send KX! */ | 1731 | /* Bob is not allowed to send KX! */ |
1711 | GNUNET_break_op (0); | 1732 | GNUNET_break_op (0); |
1712 | return; | 1733 | return; |
1713 | } | 1734 | } |
1735 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1736 | "Received KX message from %s with ephemeral %s from %s on connection %s\n", | ||
1737 | GCT_2s (t), | ||
1738 | GNUNET_e2s (&msg->ephemeral_key), | ||
1739 | GNUNET_i2s (GCP_get_id (t->destination)), | ||
1740 | GCC_2s (ct->cc)); | ||
1714 | #if 1 | 1741 | #if 1 |
1715 | if ( (0 == | 1742 | if ( (0 == |
1716 | memcmp (&t->ax.DHRr, | 1743 | memcmp (&t->ax.DHRr, |
@@ -1823,6 +1850,75 @@ GCT_handle_kx (struct CadetTConnection *ct, | |||
1823 | } | 1850 | } |
1824 | 1851 | ||
1825 | 1852 | ||
1853 | #if DEBUG_KX | ||
1854 | static void | ||
1855 | check_ee (const struct GNUNET_CRYPTO_EcdhePrivateKey *e1, | ||
1856 | const struct GNUNET_CRYPTO_EcdhePrivateKey *e2) | ||
1857 | { | ||
1858 | struct GNUNET_CRYPTO_EcdhePublicKey p1; | ||
1859 | struct GNUNET_CRYPTO_EcdhePublicKey p2; | ||
1860 | struct GNUNET_HashCode hc1; | ||
1861 | struct GNUNET_HashCode hc2; | ||
1862 | |||
1863 | GNUNET_CRYPTO_ecdhe_key_get_public (e1, | ||
1864 | &p1); | ||
1865 | GNUNET_CRYPTO_ecdhe_key_get_public (e2, | ||
1866 | &p2); | ||
1867 | GNUNET_assert (GNUNET_OK == | ||
1868 | GNUNET_CRYPTO_ecc_ecdh (e1, | ||
1869 | &p2, | ||
1870 | &hc1)); | ||
1871 | GNUNET_assert (GNUNET_OK == | ||
1872 | GNUNET_CRYPTO_ecc_ecdh (e2, | ||
1873 | &p1, | ||
1874 | &hc2)); | ||
1875 | GNUNET_break (0 == memcmp (&hc1, | ||
1876 | &hc2, | ||
1877 | sizeof (hc1))); | ||
1878 | } | ||
1879 | |||
1880 | |||
1881 | static void | ||
1882 | check_ed (const struct GNUNET_CRYPTO_EcdhePrivateKey *e1, | ||
1883 | const struct GNUNET_CRYPTO_EddsaPrivateKey *e2) | ||
1884 | { | ||
1885 | struct GNUNET_CRYPTO_EcdhePublicKey p1; | ||
1886 | struct GNUNET_CRYPTO_EddsaPublicKey p2; | ||
1887 | struct GNUNET_HashCode hc1; | ||
1888 | struct GNUNET_HashCode hc2; | ||
1889 | |||
1890 | GNUNET_CRYPTO_ecdhe_key_get_public (e1, | ||
1891 | &p1); | ||
1892 | GNUNET_CRYPTO_eddsa_key_get_public (e2, | ||
1893 | &p2); | ||
1894 | GNUNET_assert (GNUNET_OK == | ||
1895 | GNUNET_CRYPTO_ecdh_eddsa (e1, | ||
1896 | &p2, | ||
1897 | &hc1)); | ||
1898 | GNUNET_assert (GNUNET_OK == | ||
1899 | GNUNET_CRYPTO_eddsa_ecdh (e2, | ||
1900 | &p1, | ||
1901 | &hc2)); | ||
1902 | GNUNET_break (0 == memcmp (&hc1, | ||
1903 | &hc2, | ||
1904 | sizeof (hc1))); | ||
1905 | } | ||
1906 | |||
1907 | |||
1908 | static void | ||
1909 | test_crypto_bug (const struct GNUNET_CRYPTO_EcdhePrivateKey *e1, | ||
1910 | const struct GNUNET_CRYPTO_EcdhePrivateKey *e2, | ||
1911 | const struct GNUNET_CRYPTO_EddsaPrivateKey *d1, | ||
1912 | const struct GNUNET_CRYPTO_EddsaPrivateKey *d2) | ||
1913 | { | ||
1914 | check_ee (e1, e2); | ||
1915 | check_ed (e1, d2); | ||
1916 | check_ed (e2, d1); | ||
1917 | } | ||
1918 | |||
1919 | #endif | ||
1920 | |||
1921 | |||
1826 | /** | 1922 | /** |
1827 | * Handle KX_AUTH message. | 1923 | * Handle KX_AUTH message. |
1828 | * | 1924 | * |
@@ -1852,8 +1948,9 @@ GCT_handle_kx_auth (struct CadetTConnection *ct, | |||
1852 | return; | 1948 | return; |
1853 | } | 1949 | } |
1854 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1950 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1855 | "Handling KX_AUTH message for %s\n", | 1951 | "Handling KX_AUTH message from %s with ephemeral %s\n", |
1856 | GCT_2s (t)); | 1952 | GCT_2s (t), |
1953 | GNUNET_e2s (&msg->kx.ephemeral_key)); | ||
1857 | /* We do everything in ax_tmp until we've checked the authentication | 1954 | /* We do everything in ax_tmp until we've checked the authentication |
1858 | so we don't clobber anything we care about by accident. */ | 1955 | so we don't clobber anything we care about by accident. */ |
1859 | ax_tmp = t->ax; | 1956 | ax_tmp = t->ax; |
@@ -1889,6 +1986,32 @@ GCT_handle_kx_auth (struct CadetTConnection *ct, | |||
1889 | GNUNET_NO); | 1986 | GNUNET_NO); |
1890 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1987 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1891 | "KX AUTH missmatch!\n"); | 1988 | "KX AUTH missmatch!\n"); |
1989 | #if DEBUG_KX | ||
1990 | { | ||
1991 | struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key; | ||
1992 | |||
1993 | GNUNET_CRYPTO_ecdhe_key_get_public (&ax_tmp.kx_0, | ||
1994 | &ephemeral_key); | ||
1995 | if (0 != memcmp (&ephemeral_key, | ||
1996 | &msg->r_ephemeral_key_XXX, | ||
1997 | sizeof (ephemeral_key))) | ||
1998 | { | ||
1999 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
2000 | "My ephemeral is %s!\n", | ||
2001 | GNUNET_e2s (&ephemeral_key)); | ||
2002 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
2003 | "Response is for ephemeral %s!\n", | ||
2004 | GNUNET_e2s (&msg->r_ephemeral_key_XXX)); | ||
2005 | } | ||
2006 | else | ||
2007 | { | ||
2008 | test_crypto_bug (&ax_tmp.kx_0, | ||
2009 | &msg->kx.ephemeral_key_XXX, | ||
2010 | my_private_key, | ||
2011 | &msg->kx.private_key_XXX); | ||
2012 | } | ||
2013 | } | ||
2014 | #endif | ||
1892 | if (NULL == t->kx_task) | 2015 | if (NULL == t->kx_task) |
1893 | t->kx_task | 2016 | t->kx_task |
1894 | = GNUNET_SCHEDULER_add_at (t->next_kx_attempt, | 2017 | = GNUNET_SCHEDULER_add_at (t->next_kx_attempt, |
@@ -2301,6 +2424,8 @@ connection_ready_cb (void *cls, | |||
2301 | /* Do not begin KX if WE have no channels waiting! */ | 2424 | /* Do not begin KX if WE have no channels waiting! */ |
2302 | if (0 == GCT_count_channels (t)) | 2425 | if (0 == GCT_count_channels (t)) |
2303 | return; | 2426 | return; |
2427 | if (0 != GNUNET_TIME_absolute_get_remaining (t->next_kx_attempt).rel_value_us) | ||
2428 | return; /* wait for timeout before retrying */ | ||
2304 | /* We are uninitialized, just transmit immediately, | 2429 | /* We are uninitialized, just transmit immediately, |
2305 | without undue delay. */ | 2430 | without undue delay. */ |
2306 | if (NULL != t->kx_task) | 2431 | if (NULL != t->kx_task) |
@@ -2326,6 +2451,8 @@ connection_ready_cb (void *cls, | |||
2326 | case CADET_TUNNEL_KEY_OK: | 2451 | case CADET_TUNNEL_KEY_OK: |
2327 | if (GNUNET_YES == t->kx_auth_requested) | 2452 | if (GNUNET_YES == t->kx_auth_requested) |
2328 | { | 2453 | { |
2454 | if (0 != GNUNET_TIME_absolute_get_remaining (t->next_kx_attempt).rel_value_us) | ||
2455 | return; /* wait for timeout */ | ||
2329 | if (NULL != t->kx_task) | 2456 | if (NULL != t->kx_task) |
2330 | { | 2457 | { |
2331 | GNUNET_SCHEDULER_cancel (t->kx_task); | 2458 | GNUNET_SCHEDULER_cancel (t->kx_task); |
@@ -2433,15 +2560,21 @@ evaluate_connection (void *cls, | |||
2433 | { | 2560 | { |
2434 | struct EvaluationSummary *es = cls; | 2561 | struct EvaluationSummary *es = cls; |
2435 | struct CadetConnection *cc = ct->cc; | 2562 | struct CadetConnection *cc = ct->cc; |
2436 | struct CadetPeerPath *ps = GCC_get_path (cc); | 2563 | unsigned int ct_length; |
2564 | struct CadetPeerPath *ps; | ||
2437 | const struct CadetConnectionMetrics *metrics; | 2565 | const struct CadetConnectionMetrics *metrics; |
2438 | GNUNET_CONTAINER_HeapCostType ct_desirability; | 2566 | GNUNET_CONTAINER_HeapCostType ct_desirability; |
2439 | struct GNUNET_TIME_Relative uptime; | 2567 | struct GNUNET_TIME_Relative uptime; |
2440 | struct GNUNET_TIME_Relative last_use; | 2568 | struct GNUNET_TIME_Relative last_use; |
2441 | uint32_t ct_length; | ||
2442 | double score; | 2569 | double score; |
2443 | double success_rate; | 2570 | double success_rate; |
2444 | 2571 | ||
2572 | ps = GCC_get_path (cc, | ||
2573 | &ct_length); | ||
2574 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2575 | "Evaluating path %s of existing %s\n", | ||
2576 | GCPP_2s (ps), | ||
2577 | GCC_2s (cc)); | ||
2445 | if (ps == es->path) | 2578 | if (ps == es->path) |
2446 | { | 2579 | { |
2447 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2580 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -2450,8 +2583,39 @@ evaluate_connection (void *cls, | |||
2450 | es->duplicate = GNUNET_YES; | 2583 | es->duplicate = GNUNET_YES; |
2451 | return; | 2584 | return; |
2452 | } | 2585 | } |
2586 | if (NULL != es->path) | ||
2587 | { | ||
2588 | int duplicate = GNUNET_YES; | ||
2589 | |||
2590 | for (unsigned int i=0;i<ct_length;i++) | ||
2591 | { | ||
2592 | GNUNET_assert (GCPP_get_length (es->path) > i); | ||
2593 | if (GCPP_get_peer_at_offset (es->path, | ||
2594 | i) != | ||
2595 | GCPP_get_peer_at_offset (ps, | ||
2596 | i)) | ||
2597 | { | ||
2598 | duplicate = GNUNET_NO; | ||
2599 | break; | ||
2600 | } | ||
2601 | } | ||
2602 | if (GNUNET_YES == duplicate) | ||
2603 | { | ||
2604 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2605 | "Ignoring overlapping path %s.\n", | ||
2606 | GCPP_2s (es->path)); | ||
2607 | es->duplicate = GNUNET_YES; | ||
2608 | return; | ||
2609 | } | ||
2610 | else | ||
2611 | { | ||
2612 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2613 | "Known path %s differs from proposed path\n", | ||
2614 | GCPP_2s (ps)); | ||
2615 | } | ||
2616 | } | ||
2617 | |||
2453 | ct_desirability = GCPP_get_desirability (ps); | 2618 | ct_desirability = GCPP_get_desirability (ps); |
2454 | ct_length = GCPP_get_length (ps); | ||
2455 | metrics = GCC_get_metrics (cc); | 2619 | metrics = GCC_get_metrics (cc); |
2456 | uptime = GNUNET_TIME_absolute_get_duration (metrics->age); | 2620 | uptime = GNUNET_TIME_absolute_get_duration (metrics->age); |
2457 | last_use = GNUNET_TIME_absolute_get_duration (metrics->last_use); | 2621 | last_use = GNUNET_TIME_absolute_get_duration (metrics->last_use); |
@@ -2500,6 +2664,8 @@ consider_path_cb (void *cls, | |||
2500 | struct CadetTConnection *ct; | 2664 | struct CadetTConnection *ct; |
2501 | 2665 | ||
2502 | GNUNET_assert (off < GCPP_get_length (path)); | 2666 | GNUNET_assert (off < GCPP_get_length (path)); |
2667 | GNUNET_assert (GCPP_get_peer_at_offset (path, | ||
2668 | off) == t->destination); | ||
2503 | es.min_length = UINT_MAX; | 2669 | es.min_length = UINT_MAX; |
2504 | es.max_length = 0; | 2670 | es.max_length = 0; |
2505 | es.max_desire = 0; | 2671 | es.max_desire = 0; |
@@ -2509,6 +2675,13 @@ consider_path_cb (void *cls, | |||
2509 | es.worst = NULL; | 2675 | es.worst = NULL; |
2510 | 2676 | ||
2511 | /* Compute evaluation summary over existing connections. */ | 2677 | /* Compute evaluation summary over existing connections. */ |
2678 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2679 | "Evaluating proposed path %s for target %s\n", | ||
2680 | GCPP_2s (path), | ||
2681 | GCT_2s (t)); | ||
2682 | /* FIXME: suspect this does not ACTUALLY iterate | ||
2683 | over all existing paths, otherwise dup detection | ||
2684 | should work!!! */ | ||
2512 | GCT_iterate_connections (t, | 2685 | GCT_iterate_connections (t, |
2513 | &evaluate_connection, | 2686 | &evaluate_connection, |
2514 | &es); | 2687 | &es); |
@@ -2653,9 +2826,10 @@ GCT_consider_path (struct CadetTunnel *t, | |||
2653 | unsigned int off) | 2826 | unsigned int off) |
2654 | { | 2827 | { |
2655 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2828 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2656 | "Considering %s for %s\n", | 2829 | "Considering %s for %s (offset %u)\n", |
2657 | GCPP_2s (p), | 2830 | GCPP_2s (p), |
2658 | GCT_2s (t)); | 2831 | GCT_2s (t), |
2832 | off); | ||
2659 | (void) consider_path_cb (t, | 2833 | (void) consider_path_cb (t, |
2660 | p, | 2834 | p, |
2661 | off); | 2835 | off); |
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c index b9f177652..608136e56 100644 --- a/src/cadet/test_cadet.c +++ b/src/cadet/test_cadet.c | |||
@@ -402,8 +402,11 @@ stats_cont (void *cls, | |||
402 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 402 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
403 | */ | 403 | */ |
404 | static int | 404 | static int |
405 | stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer, | 405 | stats_iterator (void *cls, |
406 | const char *subsystem, const char *name, uint64_t value, | 406 | const struct GNUNET_TESTBED_Peer *peer, |
407 | const char *subsystem, | ||
408 | const char *name, | ||
409 | uint64_t value, | ||
407 | int is_persistent) | 410 | int is_persistent) |
408 | { | 411 | { |
409 | static const char *s_sent = "# keepalives sent"; | 412 | static const char *s_sent = "# keepalives sent"; |
@@ -614,10 +617,9 @@ reschedule_timeout_task (long line) | |||
614 | * #GNUNET_SYSERR to close it (signal serious error). | 617 | * #GNUNET_SYSERR to close it (signal serious error). |
615 | */ | 618 | */ |
616 | static int | 619 | static int |
617 | check_data (void *cls, const struct GNUNET_MessageHeader *message) | 620 | check_data (void *cls, |
621 | const struct GNUNET_MessageHeader *message) | ||
618 | { | 622 | { |
619 | if (sizeof (struct GNUNET_MessageHeader) >= ntohs (message->size)) | ||
620 | return GNUNET_SYSERR; | ||
621 | return GNUNET_OK; /* all is well-formed */ | 623 | return GNUNET_OK; /* all is well-formed */ |
622 | } | 624 | } |
623 | 625 | ||
@@ -646,24 +648,33 @@ handle_data (void *cls, | |||
646 | 648 | ||
647 | if (channel == outgoing_ch) | 649 | if (channel == outgoing_ch) |
648 | { | 650 | { |
649 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Root client got a message.\n"); | 651 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
652 | "Root client got a message.\n"); | ||
650 | } | 653 | } |
651 | else if (channel == incoming_ch) | 654 | else if (channel == incoming_ch) |
652 | { | 655 | { |
653 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Leaf client got a message.\n"); | 656 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
657 | "Leaf client got a message.\n"); | ||
654 | } | 658 | } |
655 | else | 659 | else |
656 | { | 660 | { |
657 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unknown channel %p.\n", channel); | 661 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
662 | "Unknown channel %p.\n", | ||
663 | channel); | ||
658 | GNUNET_assert (0); | 664 | GNUNET_assert (0); |
659 | } | 665 | } |
660 | 666 | ||
661 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: (%d/%d)\n", ok, ok_goal); | 667 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
668 | " ok: (%d/%d)\n", | ||
669 | ok, | ||
670 | ok_goal); | ||
662 | data = (uint32_t *) &message[1]; | 671 | data = (uint32_t *) &message[1]; |
663 | payload = ntohl (*data); | 672 | payload = ntohl (*data); |
664 | if (payload == *counter) | 673 | if (payload == *counter) |
665 | { | 674 | { |
666 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " payload as expected: %u\n", payload); | 675 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
676 | " payload as expected: %u\n", | ||
677 | payload); | ||
667 | } | 678 | } |
668 | else | 679 | else |
669 | { | 680 | { |
@@ -679,7 +690,8 @@ handle_data (void *cls, | |||
679 | if (SPEED == test) | 690 | if (SPEED == test) |
680 | { | 691 | { |
681 | GNUNET_assert (incoming_ch == channel); | 692 | GNUNET_assert (incoming_ch == channel); |
682 | send_next_msg_task = GNUNET_SCHEDULER_add_now (&send_next_msg, NULL); | 693 | send_next_msg_task = GNUNET_SCHEDULER_add_now (&send_next_msg, |
694 | NULL); | ||
683 | return; | 695 | return; |
684 | } | 696 | } |
685 | } | 697 | } |
@@ -740,7 +752,8 @@ handle_data (void *cls, | |||
740 | * received on the @a channel. | 752 | * received on the @a channel. |
741 | */ | 753 | */ |
742 | static void * | 754 | static void * |
743 | connect_handler (void *cls, struct GNUNET_CADET_Channel *channel, | 755 | connect_handler (void *cls, |
756 | struct GNUNET_CADET_Channel *channel, | ||
744 | const struct GNUNET_PeerIdentity *source) | 757 | const struct GNUNET_PeerIdentity *source) |
745 | { | 758 | { |
746 | struct CadetTestChannelWrapper *ch; | 759 | struct CadetTestChannelWrapper *ch; |
@@ -748,15 +761,20 @@ connect_handler (void *cls, struct GNUNET_CADET_Channel *channel, | |||
748 | 761 | ||
749 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 762 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
750 | "Incoming channel from %s to %ld: %p\n", | 763 | "Incoming channel from %s to %ld: %p\n", |
751 | GNUNET_i2s (source), peer, channel); | 764 | GNUNET_i2s (source), |
765 | peer, | ||
766 | channel); | ||
752 | ok++; | 767 | ok++; |
753 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); | 768 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
769 | " ok: %d\n", | ||
770 | ok); | ||
754 | if (peer == peers_requested - 1) | 771 | if (peer == peers_requested - 1) |
755 | { | 772 | { |
756 | if (NULL != incoming_ch) | 773 | if (NULL != incoming_ch) |
757 | { | 774 | { |
758 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 775 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
759 | "Duplicate incoming channel for client %lu\n", (long) cls); | 776 | "Duplicate incoming channel for client %lu\n", |
777 | (long) cls); | ||
760 | GNUNET_assert (0); | 778 | GNUNET_assert (0); |
761 | } | 779 | } |
762 | incoming_ch = channel; | 780 | incoming_ch = channel; |
@@ -764,7 +782,8 @@ connect_handler (void *cls, struct GNUNET_CADET_Channel *channel, | |||
764 | else | 782 | else |
765 | { | 783 | { |
766 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 784 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
767 | "Incoming channel for unexpected peer #%lu\n", (long) cls); | 785 | "Incoming channel for unexpected peer #%lu\n", |
786 | (long) cls); | ||
768 | GNUNET_assert (0); | 787 | GNUNET_assert (0); |
769 | } | 788 | } |
770 | if (NULL != disconnect_task) | 789 | if (NULL != disconnect_task) |
@@ -1003,7 +1022,6 @@ main (int argc, char *argv[]) | |||
1003 | "short_time", | 1022 | "short_time", |
1004 | gettext_noop ("set short timeout"), | 1023 | gettext_noop ("set short timeout"), |
1005 | &short_time), | 1024 | &short_time), |
1006 | |||
1007 | GNUNET_GETOPT_option_uint ('m', | 1025 | GNUNET_GETOPT_option_uint ('m', |
1008 | "messages", | 1026 | "messages", |
1009 | "NUM_MESSAGES", | 1027 | "NUM_MESSAGES", |
diff --git a/src/cadet/test_cadet_flow.c b/src/cadet/test_cadet_flow.c new file mode 100644 index 000000000..554ee1d85 --- /dev/null +++ b/src/cadet/test_cadet_flow.c | |||
@@ -0,0 +1,888 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2011, 2017 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file cadet/test_cadet_flow.c | ||
22 | * @author Bart Polot | ||
23 | * @author Christian Grothoff | ||
24 | * @brief Test for flow control of CADET service | ||
25 | */ | ||
26 | #include <stdio.h> | ||
27 | #include "platform.h" | ||
28 | #include "cadet_test_lib.h" | ||
29 | #include "gnunet_cadet_service.h" | ||
30 | #include "gnunet_statistics_service.h" | ||
31 | #include <gauger.h> | ||
32 | |||
33 | |||
34 | /** | ||
35 | * Ugly workaround to unify data handlers on incoming and outgoing channels. | ||
36 | */ | ||
37 | struct CadetTestChannelWrapper | ||
38 | { | ||
39 | /** | ||
40 | * Channel pointer. | ||
41 | */ | ||
42 | struct GNUNET_CADET_Channel *ch; | ||
43 | }; | ||
44 | |||
45 | /** | ||
46 | * How many messages to send by default. | ||
47 | */ | ||
48 | #define TOTAL_PACKETS_DEFAULT 500 | ||
49 | |||
50 | /** | ||
51 | * How long until we give up on connecting the peers? | ||
52 | */ | ||
53 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | ||
54 | |||
55 | /** | ||
56 | * Time to wait by default for stuff that should be rather fast. | ||
57 | */ | ||
58 | #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) | ||
59 | |||
60 | /** | ||
61 | * How fast do we send messages? | ||
62 | */ | ||
63 | #define SEND_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 10) | ||
64 | |||
65 | |||
66 | /** | ||
67 | * How many packets to send. | ||
68 | */ | ||
69 | static unsigned int total_packets = TOTAL_PACKETS_DEFAULT; | ||
70 | |||
71 | /** | ||
72 | * Time to wait for fast operations. | ||
73 | */ | ||
74 | static struct GNUNET_TIME_Relative short_time; | ||
75 | |||
76 | /** | ||
77 | * Size of each test packet's payload | ||
78 | */ | ||
79 | static size_t size_payload = sizeof (uint32_t); | ||
80 | |||
81 | /** | ||
82 | * Operation to get peer ids. | ||
83 | */ | ||
84 | static struct GNUNET_TESTBED_Operation *t_op[2]; | ||
85 | |||
86 | /** | ||
87 | * Peer ids. | ||
88 | */ | ||
89 | static struct GNUNET_PeerIdentity *p_id[2]; | ||
90 | |||
91 | /** | ||
92 | * Port ID | ||
93 | */ | ||
94 | static struct GNUNET_HashCode port; | ||
95 | |||
96 | /** | ||
97 | * Peer ids counter. | ||
98 | */ | ||
99 | static unsigned int p_ids; | ||
100 | |||
101 | /** | ||
102 | * Is the setup initialized? | ||
103 | */ | ||
104 | static int initialized; | ||
105 | |||
106 | /** | ||
107 | * Number of payload packes sent. | ||
108 | */ | ||
109 | static int data_sent; | ||
110 | |||
111 | /** | ||
112 | * Number of payload packets received. | ||
113 | */ | ||
114 | static int data_received; | ||
115 | |||
116 | /** | ||
117 | * Number of payload packed acknowledgements sent. | ||
118 | */ | ||
119 | static int ack_sent; | ||
120 | |||
121 | /** | ||
122 | * Number of payload packed explicitly (app level) acknowledged. | ||
123 | */ | ||
124 | static int ack_received; | ||
125 | |||
126 | /** | ||
127 | * Total number of peers asked to run. | ||
128 | */ | ||
129 | static unsigned int peers_requested = 2; | ||
130 | |||
131 | /** | ||
132 | * Number of currently running peers (should be same as @c peers_requested). | ||
133 | */ | ||
134 | static unsigned int peers_running; | ||
135 | |||
136 | /** | ||
137 | * Test context (to shut down). | ||
138 | */ | ||
139 | struct GNUNET_CADET_TEST_Context *test_ctx; | ||
140 | |||
141 | /** | ||
142 | * Task called to disconnect peers. | ||
143 | */ | ||
144 | static struct GNUNET_SCHEDULER_Task *disconnect_task; | ||
145 | |||
146 | /** | ||
147 | * Task To perform tests | ||
148 | */ | ||
149 | static struct GNUNET_SCHEDULER_Task *test_task; | ||
150 | |||
151 | /** | ||
152 | * Task runnining #send_next_msg(). | ||
153 | */ | ||
154 | static struct GNUNET_SCHEDULER_Task *send_next_msg_task; | ||
155 | |||
156 | /** | ||
157 | * Cadet handle for the root peer | ||
158 | */ | ||
159 | static struct GNUNET_CADET_Handle *h1; | ||
160 | |||
161 | /** | ||
162 | * Cadet handle for the first leaf peer | ||
163 | */ | ||
164 | static struct GNUNET_CADET_Handle *h2; | ||
165 | |||
166 | /** | ||
167 | * Channel handle for the root peer | ||
168 | */ | ||
169 | static struct GNUNET_CADET_Channel *outgoing_ch; | ||
170 | |||
171 | /** | ||
172 | * Channel handle for the dest peer | ||
173 | */ | ||
174 | static struct GNUNET_CADET_Channel *incoming_ch; | ||
175 | |||
176 | /** | ||
177 | * Time we started the data transmission (after channel has been established | ||
178 | * and initilized). | ||
179 | */ | ||
180 | static struct GNUNET_TIME_Absolute start_time; | ||
181 | |||
182 | /** | ||
183 | * Peers handle. | ||
184 | */ | ||
185 | static struct GNUNET_TESTBED_Peer **testbed_peers; | ||
186 | |||
187 | /** | ||
188 | * Statistics operation handle. | ||
189 | */ | ||
190 | static struct GNUNET_TESTBED_Operation *stats_op; | ||
191 | |||
192 | /** | ||
193 | * Keepalives sent. | ||
194 | */ | ||
195 | static unsigned int ka_sent; | ||
196 | |||
197 | /** | ||
198 | * Keepalives received. | ||
199 | */ | ||
200 | static unsigned int ka_received; | ||
201 | |||
202 | /** | ||
203 | * How many messages were dropped by CADET because of full buffers? | ||
204 | */ | ||
205 | static unsigned int msg_dropped; | ||
206 | |||
207 | |||
208 | /** | ||
209 | * Show the results of the test (banwidth acheived) and log them to GAUGER | ||
210 | */ | ||
211 | static void | ||
212 | show_end_data (void) | ||
213 | { | ||
214 | static struct GNUNET_TIME_Absolute end_time; | ||
215 | static struct GNUNET_TIME_Relative total_time; | ||
216 | |||
217 | end_time = GNUNET_TIME_absolute_get (); | ||
218 | total_time = GNUNET_TIME_absolute_get_difference (start_time, end_time); | ||
219 | FPRINTF (stderr, | ||
220 | "\nResults of test \"%s\"\n", | ||
221 | test_name); | ||
222 | FPRINTF (stderr, | ||
223 | "Test time %s\n", | ||
224 | GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); | ||
225 | FPRINTF (stderr, | ||
226 | "Test bandwidth: %f kb/s\n", | ||
227 | 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms | ||
228 | FPRINTF (stderr, | ||
229 | "Test throughput: %f packets/s\n\n", | ||
230 | total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms | ||
231 | GAUGER ("CADET", | ||
232 | test_name, | ||
233 | total_packets * 1000.0 / (total_time.rel_value_us / 1000), | ||
234 | "packets/s"); | ||
235 | } | ||
236 | |||
237 | |||
238 | /** | ||
239 | * Shut down peergroup, clean up. | ||
240 | * | ||
241 | * @param cls Closure (unused). | ||
242 | * @param tc Task Context. | ||
243 | */ | ||
244 | static void | ||
245 | shutdown_task (void *cls) | ||
246 | { | ||
247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
248 | "Ending test.\n"); | ||
249 | if (NULL != send_next_msg_task) | ||
250 | { | ||
251 | GNUNET_SCHEDULER_cancel (send_next_msg_task); | ||
252 | send_next_msg_task = NULL; | ||
253 | } | ||
254 | if (NULL != test_task) | ||
255 | { | ||
256 | GNUNET_SCHEDULER_cancel (test_task); | ||
257 | test_task = NULL; | ||
258 | } | ||
259 | for (unsigned int i = 0; i < 2; i++) | ||
260 | GNUNET_TESTBED_operation_done (t_op[i]); | ||
261 | if (NULL != outgoing_ch) | ||
262 | { | ||
263 | GNUNET_CADET_channel_destroy (outgoing_ch); | ||
264 | outgoing_ch = NULL; | ||
265 | } | ||
266 | if (NULL != incoming_ch) | ||
267 | { | ||
268 | GNUNET_CADET_channel_destroy (incoming_ch); | ||
269 | incoming_ch = NULL; | ||
270 | } | ||
271 | GNUNET_CADET_TEST_cleanup (test_ctx); | ||
272 | } | ||
273 | |||
274 | |||
275 | /** | ||
276 | * Stats callback. Finish the stats testbed operation and when all stats have | ||
277 | * been iterated, shutdown the test. | ||
278 | * | ||
279 | * @param cls Closure (line number from which termination was requested). | ||
280 | * @param op the operation that has been finished | ||
281 | * @param emsg error message in case the operation has failed; will be NULL if | ||
282 | * operation has executed successfully. | ||
283 | */ | ||
284 | static void | ||
285 | stats_cont (void *cls, | ||
286 | struct GNUNET_TESTBED_Operation *op, | ||
287 | const char *emsg) | ||
288 | { | ||
289 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
290 | "KA sent: %u, KA received: %u\n", | ||
291 | ka_sent, | ||
292 | ka_received); | ||
293 | if ((KEEPALIVE == test) && ((ka_sent < 2) || (ka_sent > ka_received + 1))) | ||
294 | { | ||
295 | GNUNET_break (0); | ||
296 | ok--; | ||
297 | } | ||
298 | GNUNET_TESTBED_operation_done (stats_op); | ||
299 | |||
300 | if (NULL != disconnect_task) | ||
301 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
302 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, | ||
303 | cls); | ||
304 | } | ||
305 | |||
306 | |||
307 | /** | ||
308 | * Process statistic values. | ||
309 | * | ||
310 | * @param cls closure (line number, unused) | ||
311 | * @param peer the peer the statistic belong to | ||
312 | * @param subsystem name of subsystem that created the statistic | ||
313 | * @param name the name of the datum | ||
314 | * @param value the current value | ||
315 | * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not | ||
316 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | ||
317 | */ | ||
318 | static int | ||
319 | stats_iterator (void *cls, | ||
320 | const struct GNUNET_TESTBED_Peer *peer, | ||
321 | const char *subsystem, | ||
322 | const char *name, | ||
323 | uint64_t value, | ||
324 | int is_persistent) | ||
325 | { | ||
326 | static const char *s_sent = "# keepalives sent"; | ||
327 | static const char *s_recv = "# keepalives received"; | ||
328 | static const char *rdrops = "# messages dropped due to full buffer"; | ||
329 | static const char *cdrops = "# messages dropped due to slow client"; | ||
330 | uint32_t i; | ||
331 | |||
332 | i = GNUNET_TESTBED_get_index (peer); | ||
333 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "STATS PEER %u - %s [%s]: %llu\n", i, | ||
334 | subsystem, name, (unsigned long long) value); | ||
335 | if (0 == strncmp (s_sent, name, strlen (s_sent)) && 0 == i) | ||
336 | ka_sent = value; | ||
337 | if (0 == strncmp (s_recv, name, strlen (s_recv)) && peers_requested - 1 == i) | ||
338 | ka_received = value; | ||
339 | if (0 == strncmp (rdrops, name, strlen (rdrops))) | ||
340 | msg_dropped += value; | ||
341 | if (0 == strncmp (cdrops, name, strlen (cdrops))) | ||
342 | msg_dropped += value; | ||
343 | |||
344 | return GNUNET_OK; | ||
345 | } | ||
346 | |||
347 | |||
348 | /** | ||
349 | * Task to gather all statistics. | ||
350 | * | ||
351 | * @param cls Closure (line from which the task was scheduled). | ||
352 | */ | ||
353 | static void | ||
354 | gather_stats_and_exit (void *cls) | ||
355 | { | ||
356 | long l = (long) cls; | ||
357 | |||
358 | disconnect_task = NULL; | ||
359 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
360 | "gathering statistics from line %ld\n", | ||
361 | l); | ||
362 | if (NULL != outgoing_ch) | ||
363 | { | ||
364 | GNUNET_CADET_channel_destroy (outgoing_ch); | ||
365 | outgoing_ch = NULL; | ||
366 | } | ||
367 | stats_op = GNUNET_TESTBED_get_statistics (peers_running, | ||
368 | testbed_peers, | ||
369 | "cadet", | ||
370 | NULL, | ||
371 | &stats_iterator, | ||
372 | stats_cont, | ||
373 | cls); | ||
374 | } | ||
375 | |||
376 | |||
377 | /** | ||
378 | * Abort test: schedule disconnect and shutdown immediately | ||
379 | * | ||
380 | * @param line Line in the code the abort is requested from (__LINE__). | ||
381 | */ | ||
382 | static void | ||
383 | abort_test (long line) | ||
384 | { | ||
385 | if (NULL != disconnect_task) | ||
386 | { | ||
387 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
388 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
389 | "Aborting test from %ld\n", | ||
390 | line); | ||
391 | disconnect_task = | ||
392 | GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, | ||
393 | (void *) line); | ||
394 | } | ||
395 | } | ||
396 | |||
397 | |||
398 | /** | ||
399 | * Send a message on the channel with the appropriate size and payload. | ||
400 | * | ||
401 | * Update the appropriate *_sent counter. | ||
402 | * | ||
403 | * @param channel Channel to send the message on. | ||
404 | */ | ||
405 | static void | ||
406 | send_test_message (struct GNUNET_CADET_Channel *channel) | ||
407 | { | ||
408 | struct GNUNET_MQ_Envelope *env; | ||
409 | struct GNUNET_MessageHeader *msg; | ||
410 | uint32_t *data; | ||
411 | int payload; | ||
412 | int size; | ||
413 | |||
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
415 | "Sending test message on channel %p\n", | ||
416 | channel); | ||
417 | size = size_payload; | ||
418 | if (GNUNET_NO == initialized) | ||
419 | { | ||
420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending INITIALIZER\n"); | ||
421 | size += 1000; | ||
422 | payload = data_sent; | ||
423 | if (SPEED_ACK == test) // FIXME unify SPEED_ACK with an initializer | ||
424 | data_sent++; | ||
425 | } | ||
426 | else if (SPEED == test || SPEED_ACK == test) | ||
427 | { | ||
428 | if (get_target_channel() == channel) | ||
429 | { | ||
430 | payload = ack_sent; | ||
431 | size += ack_sent; | ||
432 | ack_sent++; | ||
433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
434 | "Sending ACK %u [%d bytes]\n", | ||
435 | payload, size); | ||
436 | } | ||
437 | else | ||
438 | { | ||
439 | payload = data_sent; | ||
440 | size += data_sent; | ||
441 | data_sent++; | ||
442 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
443 | "Sending DATA %u [%d bytes]\n", | ||
444 | data_sent, size); | ||
445 | } | ||
446 | } | ||
447 | else if (FORWARD == test) | ||
448 | { | ||
449 | payload = ack_sent; | ||
450 | } | ||
451 | else if (P2P_SIGNAL == test) | ||
452 | { | ||
453 | payload = data_sent; | ||
454 | } | ||
455 | else | ||
456 | { | ||
457 | GNUNET_assert (0); | ||
458 | } | ||
459 | env = GNUNET_MQ_msg_extra (msg, size, GNUNET_MESSAGE_TYPE_DUMMY); | ||
460 | |||
461 | data = (uint32_t *) &msg[1]; | ||
462 | *data = htonl (payload); | ||
463 | GNUNET_MQ_send (GNUNET_CADET_get_mq (channel), env); | ||
464 | } | ||
465 | |||
466 | |||
467 | /** | ||
468 | * Task to request a new data transmission in a SPEED test, without waiting | ||
469 | * for previous messages to be sent/arrrive. | ||
470 | * | ||
471 | * @param cls Closure (unused). | ||
472 | */ | ||
473 | static void | ||
474 | send_next_msg (void *cls) | ||
475 | { | ||
476 | struct GNUNET_CADET_Channel *channel; | ||
477 | |||
478 | send_next_msg_task = NULL; | ||
479 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
480 | "Sending next message: %d\n", | ||
481 | data_sent); | ||
482 | |||
483 | channel = GNUNET_YES == test_backwards ? incoming_ch : outgoing_ch; | ||
484 | GNUNET_assert (NULL != channel); | ||
485 | GNUNET_assert (SPEED == test); | ||
486 | send_test_message (channel); | ||
487 | if (data_sent < total_packets) | ||
488 | { | ||
489 | /* SPEED test: Send all messages as soon as possible */ | ||
490 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
491 | "Scheduling message %d\n", | ||
492 | data_sent + 1); | ||
493 | send_next_msg_task = | ||
494 | GNUNET_SCHEDULER_add_delayed (SEND_INTERVAL, | ||
495 | &send_next_msg, | ||
496 | NULL); | ||
497 | } | ||
498 | } | ||
499 | |||
500 | |||
501 | /** | ||
502 | * Check if payload is sane (size contains payload). | ||
503 | * | ||
504 | * @param cls should match #ch | ||
505 | * @param message The actual message. | ||
506 | * @return #GNUNET_OK to keep the channel open, | ||
507 | * #GNUNET_SYSERR to close it (signal serious error). | ||
508 | */ | ||
509 | static int | ||
510 | check_data (void *cls, | ||
511 | const struct GNUNET_MessageHeader *message) | ||
512 | { | ||
513 | return GNUNET_OK; /* all is well-formed */ | ||
514 | } | ||
515 | |||
516 | |||
517 | /** | ||
518 | * Function is called whenever a message is received. | ||
519 | * | ||
520 | * @param cls closure (set from GNUNET_CADET_connect(), peer number) | ||
521 | * @param message the actual message | ||
522 | */ | ||
523 | static void | ||
524 | handle_data (void *cls, | ||
525 | const struct GNUNET_MessageHeader *message) | ||
526 | { | ||
527 | struct CadetTestChannelWrapper *ch = cls; | ||
528 | struct GNUNET_CADET_Channel *channel = ch->ch; | ||
529 | uint32_t *data; | ||
530 | uint32_t payload; | ||
531 | int *counter; | ||
532 | |||
533 | GNUNET_CADET_receive_done (channel); | ||
534 | counter = get_target_channel () == channel ? &data_received : &ack_received; | ||
535 | if (channel == outgoing_ch) | ||
536 | { | ||
537 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
538 | "Root client got a message.\n"); | ||
539 | } | ||
540 | else if (channel == incoming_ch) | ||
541 | { | ||
542 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
543 | "Leaf client got a message.\n"); | ||
544 | } | ||
545 | else | ||
546 | { | ||
547 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
548 | "Unknown channel %p.\n", | ||
549 | channel); | ||
550 | GNUNET_assert (0); | ||
551 | } | ||
552 | |||
553 | data = (uint32_t *) &message[1]; | ||
554 | payload = ntohl (*data); | ||
555 | if (payload == *counter) | ||
556 | { | ||
557 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
558 | "Payload as expected: %u\n", | ||
559 | payload); | ||
560 | } | ||
561 | else | ||
562 | { | ||
563 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
564 | "Received payload %u, expected: %u\n", | ||
565 | payload, *counter); | ||
566 | } | ||
567 | (*counter)++; | ||
568 | if (get_target_channel () == channel) /* Got "data" */ | ||
569 | { | ||
570 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
571 | " received data %u\n", | ||
572 | data_received); | ||
573 | if (data_received < total_packets) | ||
574 | return; | ||
575 | } | ||
576 | else /* Got "ack" */ | ||
577 | { | ||
578 | if (SPEED_ACK == test || SPEED == test) | ||
579 | { | ||
580 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received); | ||
581 | /* Send more data */ | ||
582 | send_test_message (channel); | ||
583 | if (ack_received < total_packets && SPEED != test) | ||
584 | return; | ||
585 | if (ok == 2 && SPEED == test) | ||
586 | return; | ||
587 | show_end_data (); | ||
588 | } | ||
589 | if (test == P2P_SIGNAL) | ||
590 | { | ||
591 | GNUNET_CADET_channel_destroy (incoming_ch); | ||
592 | incoming_ch = NULL; | ||
593 | } | ||
594 | else | ||
595 | { | ||
596 | GNUNET_CADET_channel_destroy (outgoing_ch); | ||
597 | outgoing_ch = NULL; | ||
598 | } | ||
599 | } | ||
600 | } | ||
601 | |||
602 | |||
603 | /** | ||
604 | * Method called whenever a peer connects to a port in MQ-based CADET. | ||
605 | * | ||
606 | * @param cls Closure from #GNUNET_CADET_open_port (peer # as long). | ||
607 | * @param channel New handle to the channel. | ||
608 | * @param source Peer that started this channel. | ||
609 | * @return Closure for the incoming @a channel. It's given to: | ||
610 | * - The #GNUNET_CADET_DisconnectEventHandler (given to | ||
611 | * #GNUNET_CADET_open_port) when the channel dies. | ||
612 | * - Each the #GNUNET_MQ_MessageCallback handlers for each message | ||
613 | * received on the @a channel. | ||
614 | */ | ||
615 | static void * | ||
616 | connect_handler (void *cls, | ||
617 | struct GNUNET_CADET_Channel *channel, | ||
618 | const struct GNUNET_PeerIdentity *source) | ||
619 | { | ||
620 | struct CadetTestChannelWrapper *ch; | ||
621 | long peer = (long) cls; | ||
622 | |||
623 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
624 | "Incoming channel from %s to %ld: %p\n", | ||
625 | GNUNET_i2s (source), | ||
626 | peer, | ||
627 | channel); | ||
628 | if (peer == peers_requested - 1) | ||
629 | { | ||
630 | if (NULL != incoming_ch) | ||
631 | { | ||
632 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
633 | "Duplicate incoming channel for client %lu\n", | ||
634 | (long) cls); | ||
635 | GNUNET_assert (0); | ||
636 | } | ||
637 | incoming_ch = channel; | ||
638 | } | ||
639 | else | ||
640 | { | ||
641 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
642 | "Incoming channel for unexpected peer #%lu\n", | ||
643 | (long) cls); | ||
644 | GNUNET_assert (0); | ||
645 | } | ||
646 | ch = GNUNET_new (struct CadetTestChannelWrapper); | ||
647 | ch->ch = channel; | ||
648 | |||
649 | return ch; | ||
650 | } | ||
651 | |||
652 | |||
653 | /** | ||
654 | * Function called whenever an MQ-channel is destroyed, even if the destruction | ||
655 | * was requested by #GNUNET_CADET_channel_destroy. | ||
656 | * It must NOT call #GNUNET_CADET_channel_destroy on the channel. | ||
657 | * | ||
658 | * It should clean up any associated state, including cancelling any pending | ||
659 | * transmission on this channel. | ||
660 | * | ||
661 | * @param cls Channel closure (channel wrapper). | ||
662 | * @param channel Connection to the other end (henceforth invalid). | ||
663 | */ | ||
664 | static void | ||
665 | disconnect_handler (void *cls, | ||
666 | const struct GNUNET_CADET_Channel *channel) | ||
667 | { | ||
668 | struct CadetTestChannelWrapper *ch_w = cls; | ||
669 | |||
670 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
671 | "Channel disconnected at %d\n", | ||
672 | ok); | ||
673 | GNUNET_assert (ch_w->ch == channel); | ||
674 | if (channel == incoming_ch) | ||
675 | incoming_ch = NULL; | ||
676 | else if (outgoing_ch == channel) | ||
677 | outgoing_ch = NULL; | ||
678 | else | ||
679 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
680 | "Disconnect on unknown channel %p\n", | ||
681 | channel); | ||
682 | if (NULL != disconnect_task) | ||
683 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
684 | disconnect_task = GNUNET_SCHEDULER_add_now (&gather_stats_and_exit, | ||
685 | (void *) __LINE__); | ||
686 | GNUNET_free (ch_w); | ||
687 | } | ||
688 | |||
689 | |||
690 | /** | ||
691 | * Start the testcase, we know the peers and have handles to CADET. | ||
692 | * | ||
693 | * Testcase continues when the root receives confirmation of connected peers, | ||
694 | * on callback function ch. | ||
695 | * | ||
696 | * @param cls Closure (unused). | ||
697 | */ | ||
698 | static void | ||
699 | start_test (void *cls) | ||
700 | { | ||
701 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
702 | GNUNET_MQ_hd_var_size (data, | ||
703 | GNUNET_MESSAGE_TYPE_DUMMY, | ||
704 | struct GNUNET_MessageHeader, | ||
705 | NULL), | ||
706 | GNUNET_MQ_handler_end () | ||
707 | }; | ||
708 | struct CadetTestChannelWrapper *ch; | ||
709 | enum GNUNET_CADET_ChannelOption flags; | ||
710 | |||
711 | test_task = NULL; | ||
712 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
713 | "In start_test\n"); | ||
714 | start_time = GNUNET_TIME_absolute_get (); | ||
715 | ch = GNUNET_new (struct CadetTestChannelWrapper); | ||
716 | outgoing_ch = GNUNET_CADET_channel_create (h1, | ||
717 | ch, | ||
718 | p_id[1], | ||
719 | &port, | ||
720 | flags, | ||
721 | NULL, | ||
722 | &disconnect_handler, | ||
723 | handlers); | ||
724 | ch->ch = outgoing_ch; | ||
725 | GNUNET_assert (NULL == disconnect_task); | ||
726 | disconnect_task | ||
727 | = GNUNET_SCHEDULER_add_delayed (short_time, | ||
728 | &gather_stats_and_exit, | ||
729 | (void *) __LINE__); | ||
730 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
731 | "Sending data initializer on channel %p...\n", | ||
732 | outgoing_ch); | ||
733 | send_test_message (outgoing_ch); | ||
734 | } | ||
735 | |||
736 | |||
737 | /** | ||
738 | * Callback to be called when the requested peer information is available | ||
739 | * | ||
740 | * @param cls the closure from GNUNET_TESTBED_peer_get_information() | ||
741 | * @param op the operation this callback corresponds to | ||
742 | * @param pinfo the result; will be NULL if the operation has failed | ||
743 | * @param emsg error message if the operation has failed; | ||
744 | * NULL if the operation is successfull | ||
745 | */ | ||
746 | static void | ||
747 | pi_cb (void *cls, | ||
748 | struct GNUNET_TESTBED_Operation *op, | ||
749 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
750 | const char *emsg) | ||
751 | { | ||
752 | long i = (long) cls; | ||
753 | |||
754 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
755 | "ID callback for %ld\n", | ||
756 | i); | ||
757 | if ( (NULL == pinfo) || | ||
758 | (NULL != emsg) ) | ||
759 | { | ||
760 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
761 | "pi_cb: %s\n", | ||
762 | emsg); | ||
763 | abort_test (__LINE__); | ||
764 | return; | ||
765 | } | ||
766 | p_id[i] = pinfo->result.id; | ||
767 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
768 | "id: %s\n", | ||
769 | GNUNET_i2s (p_id[i])); | ||
770 | p_ids++; | ||
771 | if (p_ids < 2) | ||
772 | return; | ||
773 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
774 | "Got all IDs, starting test\n"); | ||
775 | test_task = GNUNET_SCHEDULER_add_now (&start_test, | ||
776 | NULL); | ||
777 | } | ||
778 | |||
779 | |||
780 | /** | ||
781 | * test main: start test when all peers are connected | ||
782 | * | ||
783 | * @param cls Closure. | ||
784 | * @param ctx Argument to give to GNUNET_CADET_TEST_cleanup on test end. | ||
785 | * @param num_peers Number of peers that are running. | ||
786 | * @param peers Array of peers. | ||
787 | * @param cadets Handle to each of the CADETs of the peers. | ||
788 | */ | ||
789 | static void | ||
790 | tmain (void *cls, | ||
791 | struct GNUNET_CADET_TEST_Context *ctx, | ||
792 | unsigned int num_peers, | ||
793 | struct GNUNET_TESTBED_Peer **peers, | ||
794 | struct GNUNET_CADET_Handle **cadets) | ||
795 | { | ||
796 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
797 | "test main\n"); | ||
798 | test_ctx = ctx; | ||
799 | peers_running = num_peers; | ||
800 | GNUNET_assert (peers_running == peers_requested); | ||
801 | testbed_peers = peers; | ||
802 | h1 = cadets[0]; | ||
803 | h2 = cadets[num_peers - 1]; | ||
804 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
805 | NULL); | ||
806 | p_ids = 0; | ||
807 | t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0], | ||
808 | GNUNET_TESTBED_PIT_IDENTITY, | ||
809 | &pi_cb, | ||
810 | (void *) 0L); | ||
811 | t_op[1] = GNUNET_TESTBED_peer_get_information (peers[num_peers - 1], | ||
812 | GNUNET_TESTBED_PIT_IDENTITY, | ||
813 | &pi_cb, | ||
814 | (void *) 1L); | ||
815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
816 | "requested peer ids\n"); | ||
817 | } | ||
818 | |||
819 | |||
820 | /** | ||
821 | * Main: start test | ||
822 | */ | ||
823 | int | ||
824 | main (int argc, | ||
825 | char *argv[]) | ||
826 | { | ||
827 | static const struct GNUNET_HashCode *ports[2]; | ||
828 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
829 | GNUNET_MQ_hd_var_size (data, | ||
830 | GNUNET_MESSAGE_TYPE_DUMMY, | ||
831 | struct GNUNET_MessageHeader, | ||
832 | NULL), | ||
833 | GNUNET_MQ_handler_end () | ||
834 | }; | ||
835 | const char *config_file = "test_cadet.conf"; | ||
836 | char port_id[] = "test port"; | ||
837 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
838 | GNUNET_GETOPT_option_relative_time ('t', | ||
839 | "time", | ||
840 | "short_time", | ||
841 | gettext_noop ("set short timeout"), | ||
842 | &short_time), | ||
843 | GNUNET_GETOPT_option_uint ('m', | ||
844 | "messages", | ||
845 | "NUM_MESSAGES", | ||
846 | gettext_noop ("set number of messages to send"), | ||
847 | &total_packets), | ||
848 | GNUNET_GETOPT_option_uint ('p', | ||
849 | "peers", | ||
850 | "NUM_PEERS", | ||
851 | gettext_noop ("number of peers to launch"), | ||
852 | &peers_requested), | ||
853 | GNUNET_GETOPT_OPTION_END | ||
854 | }; | ||
855 | |||
856 | GNUNET_log_setup ("test-cadet-flow", | ||
857 | "DEBUG", | ||
858 | NULL); | ||
859 | total_packets = TOTAL_PACKETS; | ||
860 | short_time = SHORT_TIME; | ||
861 | if (-1 == GNUNET_GETOPT_run (argv[0], | ||
862 | options, | ||
863 | argc, | ||
864 | argv)) | ||
865 | { | ||
866 | FPRINTF (stderr, | ||
867 | "test failed: problem with CLI parameters\n"); | ||
868 | return 1; | ||
869 | } | ||
870 | GNUNET_CRYPTO_hash (port_id, | ||
871 | sizeof (port_id), | ||
872 | &port); | ||
873 | ports[0] = &port; | ||
874 | ports[1] = NULL; | ||
875 | GNUNET_CADET_TEST_ruN ("test_cadet_flow", | ||
876 | config_file, | ||
877 | peers_requested, | ||
878 | &tmain, | ||
879 | NULL, /* tmain cls */ | ||
880 | &connect_handler, | ||
881 | NULL, | ||
882 | &disconnect_handler, | ||
883 | handlers, | ||
884 | ports); | ||
885 | return 0; | ||
886 | } | ||
887 | |||
888 | /* end of test_cadet_flow.c */ | ||
diff --git a/src/cadet/test_cadet_local_mq.c b/src/cadet/test_cadet_local_mq.c index 3089c7fbb..2ea754743 100644 --- a/src/cadet/test_cadet_local_mq.c +++ b/src/cadet/test_cadet_local_mq.c | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file cadet/test_cadet_local.c | 22 | * @file cadet/test_cadet_local_mq.c |
23 | * @brief test cadet local: test of cadet channels with just one peer | 23 | * @brief test cadet local: test of cadet channels with just one peer |
24 | * @author Bartlomiej Polot | 24 | * @author Bartlomiej Polot |
25 | */ | 25 | */ |
@@ -123,7 +123,9 @@ do_shutdown (void *cls) | |||
123 | static void | 123 | static void |
124 | do_abort (void *cls) | 124 | do_abort (void *cls) |
125 | { | 125 | { |
126 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ABORT from line %ld\n", (long) cls); | 126 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
127 | "ABORT from line %ld\n", | ||
128 | (long) cls); | ||
127 | result = GNUNET_SYSERR; | 129 | result = GNUNET_SYSERR; |
128 | abort_task = NULL; | 130 | abort_task = NULL; |
129 | GNUNET_SCHEDULER_shutdown (); | 131 | GNUNET_SCHEDULER_shutdown (); |
@@ -148,7 +150,8 @@ connected (void *cls, | |||
148 | { | 150 | { |
149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
150 | "connected %s, cls: %p\n", | 152 | "connected %s, cls: %p\n", |
151 | GNUNET_i2s(source), cls); | 153 | GNUNET_i2s(source), |
154 | cls); | ||
152 | return channel; | 155 | return channel; |
153 | } | 156 | } |
154 | 157 | ||
@@ -206,7 +209,8 @@ handle_data_received (void *cls, | |||
206 | static void | 209 | static void |
207 | message_sent (void *cls) | 210 | message_sent (void *cls) |
208 | { | 211 | { |
209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "message sent\n"); | 212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
213 | "message sent\n"); | ||
210 | } | 214 | } |
211 | 215 | ||
212 | 216 | ||
diff --git a/src/consensus/.gitignore b/src/consensus/.gitignore index d49147d17..8050d760e 100644 --- a/src/consensus/.gitignore +++ b/src/consensus/.gitignore | |||
@@ -3,3 +3,4 @@ gnunet-consensus-profiler | |||
3 | gnunet-service-consensus | 3 | gnunet-service-consensus |
4 | test_consensus_api | 4 | test_consensus_api |
5 | resource.log.master | 5 | resource.log.master |
6 | consensus-simulation.py | ||
diff --git a/src/consensus/Makefile.am b/src/consensus/Makefile.am index c0205ee5d..991e36a95 100644 --- a/src/consensus/Makefile.am +++ b/src/consensus/Makefile.am | |||
@@ -27,6 +27,17 @@ libexec_PROGRAMS += \ | |||
27 | gnunet-service-evil-consensus | 27 | gnunet-service-evil-consensus |
28 | endif | 28 | endif |
29 | 29 | ||
30 | do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' | ||
31 | |||
32 | SUFFIXES = .py.in .py | ||
33 | |||
34 | .py.in.py: | ||
35 | $(do_subst) < $< > $@ | ||
36 | chmod +x $@ | ||
37 | |||
38 | check-python-style: | ||
39 | flake8 consensus-simulation.py.in | ||
40 | |||
30 | lib_LTLIBRARIES = \ | 41 | lib_LTLIBRARIES = \ |
31 | libgnunetconsensus.la | 42 | libgnunetconsensus.la |
32 | 43 | ||
@@ -103,5 +114,12 @@ test_consensus_api_LDADD = \ | |||
103 | $(top_builddir)/src/testing/libgnunettesting.la \ | 114 | $(top_builddir)/src/testing/libgnunettesting.la \ |
104 | libgnunetconsensus.la | 115 | libgnunetconsensus.la |
105 | 116 | ||
117 | noinst_SCRIPTS = \ | ||
118 | consensus-simulation.py | ||
119 | |||
120 | CLEANFILES = \ | ||
121 | $(noinst_SCRIPTS) | ||
122 | |||
106 | EXTRA_DIST = \ | 123 | EXTRA_DIST = \ |
107 | test_consensus.conf | 124 | test_consensus.conf \ |
125 | consensus-simulation.py.in | ||
diff --git a/src/consensus/consensus-simulation.py b/src/consensus/consensus-simulation.py deleted file mode 100644 index 542fe0dac..000000000 --- a/src/consensus/consensus-simulation.py +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | #!/usr/bin/python | ||
2 | # This file is part of GNUnet | ||
3 | # (C) 2013 Christian Grothoff (and other contributing authors) | ||
4 | # | ||
5 | # GNUnet is free software; you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License as published | ||
7 | # by the Free Software Foundation; either version 2, or (at your | ||
8 | # option) any later version. | ||
9 | # | ||
10 | # GNUnet is distributed in the hope that it will be useful, but | ||
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | # General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with GNUnet; see the file COPYING. If not, write to the | ||
17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | # Boston, MA 02110-1301, USA. | ||
19 | |||
20 | from __future__ import absolute_import | ||
21 | from __future__ import print_function | ||
22 | import argparse | ||
23 | import random | ||
24 | from math import ceil,log,floor | ||
25 | |||
26 | |||
27 | def bsc(n): | ||
28 | """ count the bits set in n""" | ||
29 | l = n.bit_length() | ||
30 | c = 0 | ||
31 | x = 1 | ||
32 | for _ in range(0, l): | ||
33 | if n & x: | ||
34 | c = c + 1 | ||
35 | x = x << 1 | ||
36 | return c | ||
37 | |||
38 | |||
39 | def simulate(k, n, verbose): | ||
40 | assert k < n | ||
41 | largest_arc = int(2**ceil(log(n, 2))) / 2 | ||
42 | num_ghosts = (2 * largest_arc) - n | ||
43 | if verbose: | ||
44 | print "we have", num_ghosts, "ghost peers" | ||
45 | # n.b. all peers with idx<k are evil | ||
46 | peers = range(n) | ||
47 | info = [1 << x for x in xrange(n)] | ||
48 | def done_p(): | ||
49 | for x in xrange(k, n): | ||
50 | if bsc(info[x]) < n-k: | ||
51 | return False | ||
52 | return True | ||
53 | rounds = 0 | ||
54 | while not done_p(): | ||
55 | if verbose: | ||
56 | print "-- round --" | ||
57 | arc = 1 | ||
58 | while arc <= largest_arc: | ||
59 | if verbose: | ||
60 | print "-- subround --" | ||
61 | new_info = [x for x in info] | ||
62 | for peer_physical in xrange(n): | ||
63 | peer_logical = peers[peer_physical] | ||
64 | peer_type = None | ||
65 | partner_logical = (peer_logical + arc) % n | ||
66 | partner_physical = peers.index(partner_logical) | ||
67 | if peer_physical < k or partner_physical < k: | ||
68 | if verbose: | ||
69 | print "bad peer in connection", peer_physical, "--", partner_physical | ||
70 | continue | ||
71 | if peer_logical & arc == 0: | ||
72 | # we are outgoing | ||
73 | if verbose: | ||
74 | print peer_physical, "connects to", partner_physical | ||
75 | peer_type = "outgoing" | ||
76 | if peer_logical < num_ghosts: | ||
77 | # we have a ghost, check if the peer who connects | ||
78 | # to our ghost is actually outgoing | ||
79 | ghost_partner_logical = (peer_logical - arc) % n | ||
80 | if ghost_partner_logical & arc == 0: | ||
81 | peer_type = peer_type + ", ghost incoming" | ||
82 | new_info[peer_physical] = new_info[peer_physical] | info[peer_physical] | info[partner_physical] | ||
83 | new_info[partner_physical] = new_info[partner_physical] | info[peer_physical] | info[partner_physical] | ||
84 | else: | ||
85 | peer_type = "incoming" | ||
86 | if verbose > 1: | ||
87 | print "type of", str(peer_physical) + ":", peer_type | ||
88 | info = new_info | ||
89 | arc = arc << 1; | ||
90 | rounds = rounds + 1 | ||
91 | random.shuffle(peers) | ||
92 | return rounds | ||
93 | |||
94 | |||
95 | if __name__ == "__main__": | ||
96 | parser = argparse.ArgumentParser() | ||
97 | parser.add_argument("k", metavar="k", type=int, help="#(bad peers)") | ||
98 | parser.add_argument("n", metavar="n", type=int, help="#(all peers)") | ||
99 | parser.add_argument("r", metavar="r", type=int, help="#(rounds)") | ||
100 | parser.add_argument('--verbose', '-v', action='count') | ||
101 | |||
102 | args = parser.parse_args() | ||
103 | sum = 0.0; | ||
104 | for n in xrange (0, args.r): | ||
105 | sum += simulate(args.k, args.n, args.verbose) | ||
106 | printsum / args.r; | ||
107 | |||
108 | |||
diff --git a/src/consensus/consensus-simulation.py.in b/src/consensus/consensus-simulation.py.in new file mode 100644 index 000000000..6629ffaa8 --- /dev/null +++ b/src/consensus/consensus-simulation.py.in | |||
@@ -0,0 +1,110 @@ | |||
1 | #!@PYTHON@ | ||
2 | # This file is part of GNUnet | ||
3 | # (C) 2013, 2018 Christian Grothoff (and other contributing authors) | ||
4 | # | ||
5 | # GNUnet is free software; you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License as published | ||
7 | # by the Free Software Foundation; either version 2, or (at your | ||
8 | # option) any later version. | ||
9 | # | ||
10 | # GNUnet is distributed in the hope that it will be useful, but | ||
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | # General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with GNUnet; see the file COPYING. If not, write to the | ||
17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | # Boston, MA 02110-1301, USA. | ||
19 | |||
20 | from __future__ import absolute_import | ||
21 | from __future__ import print_function | ||
22 | import argparse | ||
23 | import random | ||
24 | from math import ceil, log, floor | ||
25 | from past.builtins import xrange | ||
26 | |||
27 | |||
28 | def bsc(n): | ||
29 | """ count the bits set in n""" | ||
30 | l = n.bit_length() | ||
31 | c = 0 | ||
32 | x = 1 | ||
33 | for _ in range(0, l): | ||
34 | if n & x: | ||
35 | c = c + 1 | ||
36 | x = x << 1 | ||
37 | return c | ||
38 | |||
39 | |||
40 | def simulate(k, n, verbose): | ||
41 | assert k < n | ||
42 | largest_arc = int(2**ceil(log(n, 2))) / 2 | ||
43 | num_ghosts = (2 * largest_arc) - n | ||
44 | if verbose: | ||
45 | print("we have", num_ghosts, "ghost peers") | ||
46 | # n.b. all peers with idx<k are evil | ||
47 | peers = range(n) | ||
48 | # py2-3 compatible, backwards. | ||
49 | # refer to http://python-future.org/compatible_idioms.html#xrange | ||
50 | info = [1 << x for x in xrange(n)] | ||
51 | |||
52 | def done_p(): | ||
53 | for x in xrange(k, n): | ||
54 | if bsc(info[x]) < n-k: | ||
55 | return False | ||
56 | return True | ||
57 | rounds = 0 | ||
58 | while not done_p(): | ||
59 | if verbose: | ||
60 | print("-- round --") | ||
61 | arc = 1 | ||
62 | while arc <= largest_arc: | ||
63 | if verbose: | ||
64 | print("-- subround --") | ||
65 | new_info = [x for x in info] | ||
66 | for peer_physical in xrange(n): | ||
67 | peer_logical = peers[peer_physical] | ||
68 | peer_type = None | ||
69 | partner_logical = (peer_logical + arc) % n | ||
70 | partner_physical = peers.index(partner_logical) | ||
71 | if peer_physical < k or partner_physical < k: | ||
72 | if verbose: | ||
73 | print("bad peer in connection", peer_physical, "--", partner_physical) | ||
74 | continue | ||
75 | if peer_logical & arc == 0: | ||
76 | # we are outgoing | ||
77 | if verbose: | ||
78 | print(peer_physical, "connects to", partner_physical) | ||
79 | peer_type = "outgoing" | ||
80 | if peer_logical < num_ghosts: | ||
81 | # we have a ghost, check if the peer who connects | ||
82 | # to our ghost is actually outgoing | ||
83 | ghost_partner_logical = (peer_logical - arc) % n | ||
84 | if ghost_partner_logical & arc == 0: | ||
85 | peer_type = peer_type + ", ghost incoming" | ||
86 | new_info[peer_physical] = new_info[peer_physical] | info[peer_physical] | info[partner_physical] | ||
87 | new_info[partner_physical] = new_info[partner_physical] | info[peer_physical] | info[partner_physical] | ||
88 | else: | ||
89 | peer_type = "incoming" | ||
90 | if verbose > 1: | ||
91 | print("type of", str(peer_physical) + ":", peer_type) | ||
92 | info = new_info | ||
93 | arc = arc << 1 | ||
94 | rounds = rounds + 1 | ||
95 | random.shuffle(peers) | ||
96 | return rounds | ||
97 | |||
98 | |||
99 | if __name__ == "__main__": | ||
100 | parser = argparse.ArgumentParser() | ||
101 | parser.add_argument("k", metavar="k", type=int, help="#(bad peers)") | ||
102 | parser.add_argument("n", metavar="n", type=int, help="#(all peers)") | ||
103 | parser.add_argument("r", metavar="r", type=int, help="#(rounds)") | ||
104 | parser.add_argument('--verbose', '-v', action='count') | ||
105 | |||
106 | args = parser.parse_args() | ||
107 | sum = 0.0 | ||
108 | for n in xrange(0, args.r): | ||
109 | sum += simulate(args.k, args.n, args.verbose) | ||
110 | print(sum / args.r) | ||
diff --git a/src/conversation/test_conversation.conf b/src/conversation/test_conversation.conf index 87c4b8f07..e77b41003 100644 --- a/src/conversation/test_conversation.conf +++ b/src/conversation/test_conversation.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [conversation] | 3 | [conversation] |
4 | LINE=1 | 4 | LINE=1 |
diff --git a/src/core/test_core_defaults.conf b/src/core/test_core_defaults.conf index 669dd2a9c..7c7dad99e 100644 --- a/src/core/test_core_defaults.conf +++ b/src/core/test_core_defaults.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | 3 | ||
4 | [PATHS] | 4 | [PATHS] |
5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-core/ | 5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-core/ |
diff --git a/src/credential/test_credential_defaults.conf b/src/credential/test_credential_defaults.conf index 328846a10..39f82ad16 100644 --- a/src/credential/test_credential_defaults.conf +++ b/src/credential/test_credential_defaults.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-credential-testing/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-credential-testing/ |
diff --git a/src/datastore/test_defaults.conf b/src/datastore/test_defaults.conf index 67d782f3a..08e630eb0 100644 --- a/src/datastore/test_defaults.conf +++ b/src/datastore/test_defaults.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @inline@ ../../contrib/no_autostart_above_core.conf | 1 | @inline@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
2 | @inline@ ../../contrib/no_forcestart.conf | 2 | @inline@ ../../contrib/conf/gnunet/no_forcestart.conf |
3 | 3 | ||
4 | [datastore] | 4 | [datastore] |
5 | PORT = 22654 | 5 | PORT = 22654 |
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c index 403deb38a..5341e7d61 100644 --- a/src/dht/gnunet_dht_profiler.c +++ b/src/dht/gnunet_dht_profiler.c | |||
@@ -45,7 +45,7 @@ static unsigned int put_probability = 100; | |||
45 | /** | 45 | /** |
46 | * Configuration | 46 | * Configuration |
47 | */ | 47 | */ |
48 | static struct GNUNET_CONFIGURATION_Handle *cfg; | 48 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Name of the file with the hosts to run the test over | 51 | * Name of the file with the hosts to run the test over |
@@ -917,7 +917,7 @@ run (void *cls, | |||
917 | num_peers); | 917 | num_peers); |
918 | return; | 918 | return; |
919 | } | 919 | } |
920 | cfg = GNUNET_CONFIGURATION_dup (config); | 920 | cfg = config; |
921 | event_mask = 0; | 921 | event_mask = 0; |
922 | GNUNET_TESTBED_run (hosts_file, | 922 | GNUNET_TESTBED_run (hosts_file, |
923 | cfg, | 923 | cfg, |
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c index 24f8b21b2..9f2861b50 100644 --- a/src/dht/plugin_block_dht.c +++ b/src/dht/plugin_block_dht.c | |||
@@ -66,7 +66,8 @@ block_plugin_dht_create_group (void *cls, | |||
66 | guard = va_arg (va, const char *); | 66 | guard = va_arg (va, const char *); |
67 | if (0 == strcmp (guard, | 67 | if (0 == strcmp (guard, |
68 | "seen-set-size")) | 68 | "seen-set-size")) |
69 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), | 69 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, |
70 | unsigned int), | ||
70 | BLOOMFILTER_K); | 71 | BLOOMFILTER_K); |
71 | else if (0 == strcmp (guard, | 72 | else if (0 == strcmp (guard, |
72 | "filter-size")) | 73 | "filter-size")) |
@@ -183,14 +184,17 @@ block_plugin_dht_get_key (void *cls, | |||
183 | return GNUNET_SYSERR; | 184 | return GNUNET_SYSERR; |
184 | if (block_size < sizeof (struct GNUNET_MessageHeader)) | 185 | if (block_size < sizeof (struct GNUNET_MessageHeader)) |
185 | { | 186 | { |
186 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "block-dht", | 187 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
187 | _("Block not of type %u\n"), GNUNET_BLOCK_TYPE_DHT_HELLO); | 188 | "block-dht", |
189 | _("Block not of type %u\n"), | ||
190 | GNUNET_BLOCK_TYPE_DHT_HELLO); | ||
188 | return GNUNET_NO; | 191 | return GNUNET_NO; |
189 | } | 192 | } |
190 | msg = block; | 193 | msg = block; |
191 | if (block_size != ntohs (msg->size)) | 194 | if (block_size != ntohs (msg->size)) |
192 | { | 195 | { |
193 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "block-dht", | 196 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
197 | "block-dht", | ||
194 | _("Size mismatch for block\n"), | 198 | _("Size mismatch for block\n"), |
195 | GNUNET_BLOCK_TYPE_DHT_HELLO); | 199 | GNUNET_BLOCK_TYPE_DHT_HELLO); |
196 | return GNUNET_NO; | 200 | return GNUNET_NO; |
@@ -200,7 +204,8 @@ block_plugin_dht_get_key (void *cls, | |||
200 | pid = (struct GNUNET_PeerIdentity *) key; | 204 | pid = (struct GNUNET_PeerIdentity *) key; |
201 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid)) | 205 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid)) |
202 | { | 206 | { |
203 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "block-dht", | 207 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
208 | "block-dht", | ||
204 | _("Block of type %u is malformed\n"), | 209 | _("Block of type %u is malformed\n"), |
205 | GNUNET_BLOCK_TYPE_DHT_HELLO); | 210 | GNUNET_BLOCK_TYPE_DHT_HELLO); |
206 | return GNUNET_NO; | 211 | return GNUNET_NO; |
diff --git a/src/dht/test_dht_2dtorus.conf b/src/dht/test_dht_2dtorus.conf index de138e537..a541e8443 100644 --- a/src/dht/test_dht_2dtorus.conf +++ b/src/dht/test_dht_2dtorus.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/test_dht_2dtorus/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/test_dht_2dtorus/ |
5 | 5 | ||
diff --git a/src/dht/test_dht_api_data.conf b/src/dht/test_dht_api_data.conf index 6f5bf8525..a2c1829c6 100644 --- a/src/dht/test_dht_api_data.conf +++ b/src/dht/test_dht_api_data.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | 3 | ||
4 | [PATHS] | 4 | [PATHS] |
5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-dht-api/ | 5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-dht-api/ |
diff --git a/src/dht/test_dht_api_peer1.conf b/src/dht/test_dht_api_peer1.conf index b563f5096..b4164077f 100644 --- a/src/dht/test_dht_api_peer1.conf +++ b/src/dht/test_dht_api_peer1.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | 3 | ||
4 | [dhtcache] | 4 | [dhtcache] |
5 | QUOTA = 1 MB | 5 | QUOTA = 1 MB |
diff --git a/src/dht/test_dht_line.conf b/src/dht/test_dht_line.conf index 81ce94390..5368b0baf 100644 --- a/src/dht/test_dht_line.conf +++ b/src/dht/test_dht_line.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/test_dht_line/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/test_dht_line/ |
5 | 5 | ||
diff --git a/src/dht/test_dht_monitor.conf b/src/dht/test_dht_monitor.conf index e33563746..c0d457e89 100644 --- a/src/dht/test_dht_monitor.conf +++ b/src/dht/test_dht_monitor.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | 3 | ||
4 | 4 | ||
5 | [dhtcache] | 5 | [dhtcache] |
diff --git a/src/dht/test_dht_multipeer.conf b/src/dht/test_dht_multipeer.conf index 5251883aa..4296d783e 100644 --- a/src/dht/test_dht_multipeer.conf +++ b/src/dht/test_dht_multipeer.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | 3 | ||
4 | [dht] | 4 | [dht] |
5 | AUTOSTART = YES | 5 | AUTOSTART = YES |
diff --git a/src/dht/test_dht_tools.py.in b/src/dht/test_dht_tools.py.in index 2d4ab9adc..05582cbd0 100644 --- a/src/dht/test_dht_tools.py.in +++ b/src/dht/test_dht_tools.py.in | |||
@@ -21,105 +21,113 @@ import subprocess | |||
21 | import time | 21 | import time |
22 | import tempfile | 22 | import tempfile |
23 | 23 | ||
24 | os.environ["PATH"] = "@bindir@" + ":" + os.environ["PATH"]; | 24 | os.environ["PATH"] = "@bindir@" + ":" + os.environ["PATH"] |
25 | 25 | ||
26 | if os.name == "nt": | 26 | if os.name == "nt": |
27 | tmp = os.getenv ("TEMP") | 27 | tmp = os.getenv("TEMP") |
28 | else: | 28 | else: |
29 | tmp = "/tmp" | 29 | tmp = "/tmp" |
30 | 30 | ||
31 | if os.name == 'nt': | 31 | if os.name == 'nt': |
32 | get = './gnunet-dht-get.exe' | 32 | get = './gnunet-dht-get.exe' |
33 | put = './gnunet-dht-put.exe' | 33 | put = './gnunet-dht-put.exe' |
34 | arm = 'gnunet-arm.exe' | 34 | arm = 'gnunet-arm.exe' |
35 | else: | 35 | else: |
36 | get = './gnunet-dht-get' | 36 | get = './gnunet-dht-get' |
37 | put = './gnunet-dht-put' | 37 | put = './gnunet-dht-put' |
38 | arm = 'gnunet-arm' | 38 | arm = 'gnunet-arm' |
39 | 39 | ||
40 | cfgfile = 'test_dht_api_peer1.conf' | 40 | cfgfile = 'test_dht_api_peer1.conf' |
41 | |||
42 | run_get = [get, '-c', cfgfile] | 41 | run_get = [get, '-c', cfgfile] |
43 | run_put = [put, '-c', cfgfile] | 42 | run_put = [put, '-c', cfgfile] |
44 | run_arm = [arm, '-c', cfgfile] | 43 | run_arm = [arm, '-c', cfgfile] |
45 | debug = os.getenv ('DEBUG') | 44 | debug = os.getenv('DEBUG') |
46 | if debug: | 45 | if debug: |
47 | run_arm += [debug.split (' ')] | 46 | run_arm += [debug.split(' ')] |
48 | 47 | ||
49 | def cleanup (exitcode): | 48 | |
50 | sys.exit (exitcode) | 49 | def cleanup(exitcode): |
51 | 50 | sys.exit(exitcode) | |
52 | def sub_run (args, want_stdo = True, want_stde = False, nofail = False): | 51 | |
53 | if want_stdo: | 52 | |
54 | stdo = subprocess.PIPE | 53 | def sub_run(args, want_stdo=True, want_stde=False, nofail=False): |
55 | else: | 54 | if want_stdo: |
56 | stdo = None | 55 | stdo = subprocess.PIPE |
57 | if want_stde: | 56 | else: |
58 | stde = subprocess.PIPE | 57 | stdo = None |
59 | else: | 58 | if want_stde: |
60 | stde = None | 59 | stde = subprocess.PIPE |
61 | p = subprocess.Popen (args, stdout = stdo, stderr = stde) | 60 | else: |
62 | stdo, stde = p.communicate () | 61 | stde = None |
63 | if not nofail: | 62 | p = subprocess.Popen(args, stdout=stdo, stderr=stde) |
64 | if p.returncode != 0: | 63 | stdo, stde = p.communicate() |
65 | sys.exit (p.returncode) | 64 | if not nofail: |
66 | return (p.returncode, stdo, stde) | 65 | if p.returncode != 0: |
67 | 66 | sys.exit(p.returncode) | |
68 | def fail (result): | 67 | return (p.returncode, stdo, stde) |
69 | print (result) | 68 | |
70 | r_arm (['-e'], want_stdo = False) | 69 | |
71 | cleanup (1) | 70 | def fail(result): |
72 | 71 | print(result) | |
73 | def r_something (to_run, extra_args, failer = None, normal = True, **kw): | 72 | r_arm(['-e'], want_stdo=False) |
74 | rc, stdo, stde = sub_run (to_run + extra_args, nofail = True, **kw) | 73 | cleanup(1) |
75 | if failer is not None: | 74 | |
76 | failer (to_run + extra_args, rc, stdo, stde, normal) | 75 | |
77 | return (rc, stdo, stde) | 76 | def r_something(to_run, extra_args, failer=None, normal=True, **kw): |
78 | 77 | rc, stdo, stde = sub_run(to_run + extra_args, nofail=True, **kw) | |
79 | def r_arm (extra_args, **kw): | 78 | if failer is not None: |
80 | return r_something (run_arm, extra_args, **kw) | 79 | failer(to_run + extra_args, rc, stdo, stde, normal) |
81 | 80 | return (rc, stdo, stde) | |
82 | def r_get (extra_args, **kw): | 81 | |
83 | return r_something (run_get, extra_args, **kw) | 82 | |
84 | 83 | def r_arm(extra_args, **kw): | |
85 | def r_put (extra_args, **kw): | 84 | return r_something(run_arm, extra_args, **kw) |
86 | return r_something (run_put, extra_args, **kw) | 85 | |
87 | 86 | ||
88 | def end_arm_failer (command, rc, stdo, stde, normal): | 87 | def r_get(extra_args, **kw): |
89 | if normal: | 88 | return r_something(run_get, extra_args, **kw) |
90 | if rc != 0: | 89 | |
91 | fail ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) | 90 | |
92 | else: | 91 | def r_put(extra_args, **kw): |
93 | if rc == 0: | 92 | return r_something(run_put, extra_args, **kw) |
94 | fail ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) | 93 | |
95 | 94 | ||
96 | def print_only_failer (command, rc, stdo, stde, normal): | 95 | def end_arm_failer(command, rc, stdo, stde, normal): |
97 | if normal: | 96 | if normal: |
98 | if rc != 0: | 97 | if rc != 0: |
99 | print ("FAIL: error running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) | 98 | fail("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) |
100 | cleanup (1) | 99 | else: |
101 | else: | 100 | if rc == 0: |
102 | if rc == 0: | 101 | fail("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) |
103 | print ("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format (command, stdo, stde)) | 102 | |
104 | cleanup (1) | 103 | |
105 | 104 | def print_only_failer(command, rc, stdo, stde, normal): | |
106 | 105 | if normal: | |
107 | print ("TEST: Starting ARM...", end='') | 106 | if rc != 0: |
108 | r_arm (['-s'], failer = end_arm_failer, want_stdo = False, want_stde = False) | 107 | print("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) |
109 | print ("PASS") | 108 | cleanup(1) |
110 | time.sleep (1) | 109 | else: |
111 | 110 | if rc == 0: | |
112 | print ("TEST: Testing put...", end='') | 111 | print("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) |
113 | r_put (['-k', 'testkey', '-d', 'testdata', '-t', '8'], failer = end_arm_failer) | 112 | cleanup(1) |
114 | print ("PASS") | 113 | |
115 | time.sleep (1) | 114 | |
116 | 115 | print("TEST: Starting ARM...", end='') | |
117 | print ("TEST: Testing get...", end='') | 116 | r_arm(['-s'], failer=end_arm_failer, want_stdo=False, want_stde=False) |
118 | rc, stdo, stde = r_get (['-k', 'testkey', '-T', '50 ms', '-t', '8'], want_stdo = True, failer = end_arm_failer) | 117 | print("PASS") |
119 | stdo = stdo.replace ('\r', '').splitlines () | 118 | time.sleep(1) |
119 | |||
120 | print("TEST: Testing put...", end='') | ||
121 | r_put(['-k', 'testkey', '-d', 'testdata', '-t', '8'], failer=end_arm_failer) | ||
122 | print("PASS") | ||
123 | time.sleep(1) | ||
124 | |||
125 | print("TEST: Testing get...", end='') | ||
126 | rc, stdo, stde = r_get(['-k', 'testkey', '-T', '50 ms', '-t', '8'], want_stdo=True, failer=end_arm_failer) | ||
127 | stdo = stdo.replace('\r', '').splitlines() | ||
120 | expect = "Result 0, type 8:\ntestdata".splitlines() | 128 | expect = "Result 0, type 8:\ntestdata".splitlines() |
121 | if len (stdo) != 2 or len (expect) != 2 or stdo[0] != expect[0] or stdo[1] != expect[1]: | 129 | if len(stdo) != 2 or len(expect) != 2 or stdo[0] != expect[0] or stdo[1] != expect[1]: |
122 | fail ("output `{}' differs from expected `{}'".format (stdo, expect)) | 130 | fail("output `{}' differs from expected `{}'".format(stdo, expect)) |
123 | print ("PASS") | 131 | print("PASS") |
124 | 132 | ||
125 | r_arm (['-e', '-d'], failer = print_only_failer) | 133 | r_arm(['-e', '-d'], failer=print_only_failer) |
diff --git a/src/fs/test_fs_defaults.conf b/src/fs/test_fs_defaults.conf index 79344cd66..42661b25d 100644 --- a/src/fs/test_fs_defaults.conf +++ b/src/fs/test_fs_defaults.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/gnunet-test-fs-lib/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/gnunet-test-fs-lib/ |
diff --git a/src/fs/test_gnunet_fs_idx.py.in b/src/fs/test_gnunet_fs_idx.py.in index bd8aa5f7a..a669998fb 100755 --- a/src/fs/test_gnunet_fs_idx.py.in +++ b/src/fs/test_gnunet_fs_idx.py.in | |||
@@ -25,50 +25,50 @@ import re | |||
25 | import shutil | 25 | import shutil |
26 | 26 | ||
27 | srcdir = "../.." | 27 | srcdir = "../.." |
28 | gnunet_pyexpect_dir = os.path.join (srcdir, "contrib") | 28 | gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts") |
29 | if gnunet_pyexpect_dir not in sys.path: | 29 | if gnunet_pyexpect_dir not in sys.path: |
30 | sys.path.append (gnunet_pyexpect_dir) | 30 | sys.path.append(gnunet_pyexpect_dir) |
31 | 31 | ||
32 | from gnunet_pyexpect import pexpect | 32 | from gnunet_pyexpect import pexpect |
33 | 33 | ||
34 | if os.name == 'posix': | 34 | if os.name == 'posix': |
35 | download = './gnunet-download' | 35 | download = './gnunet-download' |
36 | gnunetarm = 'gnunet-arm' | 36 | gnunetarm = 'gnunet-arm' |
37 | publish = './gnunet-publish' | 37 | publish = './gnunet-publish' |
38 | unindex = './gnunet-unindex' | 38 | unindex = './gnunet-unindex' |
39 | elif os.name == 'nt': | 39 | elif os.name == 'nt': |
40 | download = './gnunet-download.exe' | 40 | download = './gnunet-download.exe' |
41 | gnunetarm = 'gnunet-arm.exe' | 41 | gnunetarm = 'gnunet-arm.exe' |
42 | publish = './gnunet-publish.exe' | 42 | publish = './gnunet-publish.exe' |
43 | unindex = './gnunet-unindex.exe' | 43 | unindex = './gnunet-unindex.exe' |
44 | 44 | ||
45 | if os.name == "nt": | 45 | if os.name == "nt": |
46 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-idx"), True) | 46 | shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-idx"), True) |
47 | else: | 47 | else: |
48 | shutil.rmtree ("/tmp/gnunet-test-fs-py-idx", True) | 48 | shutil.rmtree("/tmp/gnunet-test-fs-py-idx", True) |
49 | 49 | ||
50 | arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_fs_idx_data.conf']) | 50 | arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_fs_idx_data.conf']) |
51 | arm.communicate () | 51 | arm.communicate() |
52 | 52 | ||
53 | try: | 53 | try: |
54 | pub = pexpect () | 54 | pub = pexpect() |
55 | 55 | ||
56 | pub.spawn (None, [publish, '-c', 'test_gnunet_fs_idx_data.conf', '-m', "description:Test archive", '-k', 'tst', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 56 | pub.spawn(None, [publish, '-c', 'test_gnunet_fs_idx_data.conf', '-m', "description:Test archive", '-k', 'tst', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
57 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n")) | 57 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n")) |
58 | 58 | ||
59 | down = pexpect () | 59 | down = pexpect() |
60 | down.spawn (None, [download, '-c', 'test_gnunet_fs_idx_data.conf', '-o', 'test_gnunet_fs_rec_data.tar.gz', 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 60 | down.spawn(None, [download, '-c', 'test_gnunet_fs_idx_data.conf', '-o', 'test_gnunet_fs_rec_data.tar.gz', 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
61 | down.expect ("stdout", re.compile (r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n")) | 61 | down.expect("stdout", re.compile(r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n")) |
62 | os.remove ("test_gnunet_fs_rec_data.tar.gz") | 62 | os.remove("test_gnunet_fs_rec_data.tar.gz") |
63 | 63 | ||
64 | un = pexpect () | 64 | un = pexpect() |
65 | un.spawn (None, [unindex, '-c', 'test_gnunet_fs_idx_data.conf', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 65 | un.spawn(None, [unindex, '-c', 'test_gnunet_fs_idx_data.conf', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
66 | un.expect ("stdout", re.compile (r'Unindexing done\.\r?\n')) | 66 | un.expect("stdout", re.compile(r'Unindexing done\.\r?\n')) |
67 | 67 | ||
68 | finally: | 68 | finally: |
69 | arm = subprocess.Popen ([gnunetarm, '-eq', '-c', 'test_gnunet_fs_idx_data.conf']) | 69 | arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_fs_idx_data.conf']) |
70 | arm.communicate () | 70 | arm.communicate() |
71 | if os.name == "nt": | 71 | if os.name == "nt": |
72 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-idx"), True) | 72 | shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-idx"), True) |
73 | else: | 73 | else: |
74 | shutil.rmtree ("/tmp/gnunet-test-fs-py-idx", True) | 74 | shutil.rmtree("/tmp/gnunet-test-fs-py-idx", True) |
diff --git a/src/fs/test_gnunet_fs_psd.py.in b/src/fs/test_gnunet_fs_psd.py.in index 601797c82..4b27b4532 100755 --- a/src/fs/test_gnunet_fs_psd.py.in +++ b/src/fs/test_gnunet_fs_psd.py.in | |||
@@ -29,59 +29,60 @@ except NameError: | |||
29 | # python3.4: | 29 | # python3.4: |
30 | from importlib import reload | 30 | from importlib import reload |
31 | 31 | ||
32 | |||
32 | # Force encoding to utf-8, as this test otherwise fails | 33 | # Force encoding to utf-8, as this test otherwise fails |
33 | # on some systems (see #5094). | 34 | # on some systems (see #5094). |
34 | reload(sys) | 35 | reload(sys) |
35 | sys.setdefaultencoding('utf8') | 36 | sys.setdefaultencoding('utf8') |
36 | 37 | ||
37 | srcdir = "../.." | 38 | srcdir = "../.." |
38 | gnunet_pyexpect_dir = os.path.join (srcdir, "contrib") | 39 | gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts") |
39 | if gnunet_pyexpect_dir not in sys.path: | 40 | if gnunet_pyexpect_dir not in sys.path: |
40 | sys.path.append (gnunet_pyexpect_dir) | 41 | sys.path.append(gnunet_pyexpect_dir) |
41 | 42 | ||
42 | from gnunet_pyexpect import pexpect | 43 | from gnunet_pyexpect import pexpect |
43 | 44 | ||
44 | if os.name == 'posix': | 45 | if os.name == 'posix': |
45 | download = './gnunet-download' | 46 | download = './gnunet-download' |
46 | gnunetarm = 'gnunet-arm' | 47 | gnunetarm = 'gnunet-arm' |
47 | publish = './gnunet-publish' | 48 | publish = './gnunet-publish' |
48 | unindex = './gnunet-unindex' | 49 | unindex = './gnunet-unindex' |
49 | search = './gnunet-search' | 50 | search = './gnunet-search' |
50 | elif os.name == 'nt': | 51 | elif os.name == 'nt': |
51 | download = './gnunet-download.exe' | 52 | download = './gnunet-download.exe' |
52 | gnunetarm = 'gnunet-arm.exe' | 53 | gnunetarm = 'gnunet-arm.exe' |
53 | publish = './gnunet-publish.exe' | 54 | publish = './gnunet-publish.exe' |
54 | unindex = './gnunet-unindex.exe' | 55 | unindex = './gnunet-unindex.exe' |
55 | search = './gnunet-search.exe' | 56 | search = './gnunet-search.exe' |
56 | 57 | ||
57 | if os.name == "nt": | 58 | if os.name == "nt": |
58 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-psd"), True) | 59 | shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-psd"), True) |
59 | else: | 60 | else: |
60 | shutil.rmtree ("/tmp/gnunet-test-fs-py-psd", True) | 61 | shutil.rmtree("/tmp/gnunet-test-fs-py-psd", True) |
61 | 62 | ||
62 | arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_fs_psd_data.conf']) | 63 | arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_fs_psd_data.conf']) |
63 | arm.communicate () | 64 | arm.communicate() |
64 | 65 | ||
65 | # first, basic publish-search-download run | 66 | # first, basic publish-search-download run |
66 | try: | 67 | try: |
67 | pub = pexpect () | 68 | pub = pexpect() |
68 | pub.spawn (None, [publish, '-c', 'test_gnunet_fs_psd_data.conf', '-n', '-m', "description:Test archive", '-k', 'tst', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 69 | pub.spawn(None, [publish, '-c', 'test_gnunet_fs_psd_data.conf', '-n', '-m', "description:Test archive", '-k', 'tst', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
69 | pub.expect ("stdout", re.compile (r"Publishing `.+test_gnunet_fs_rec_data.tgz' done\.\r?\n")) | 70 | pub.expect("stdout", re.compile(r"Publishing `.+test_gnunet_fs_rec_data.tgz' done\.\r?\n")) |
70 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n")) | 71 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n")) |
71 | 72 | ||
72 | s = pexpect () | 73 | s = pexpect() |
73 | s.spawn (None, [search, '-V', '-t', '1000 ms', '-N', '1', '-c', 'test_gnunet_fs_psd_data.conf', 'tst'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 74 | s.spawn(None, [search, '-V', '-t', '1000 ms', '-N', '1', '-c', 'test_gnunet_fs_psd_data.conf', 'tst'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
74 | s.expect ("stdout", re.compile (r'gnunet-download -o "test_gnunet_fs_rec_data.tgz" gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822\r?\n')) | 75 | s.expect("stdout", re.compile(r'gnunet-download -o "test_gnunet_fs_rec_data.tgz" gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822\r?\n')) |
75 | 76 | ||
76 | down = pexpect () | 77 | down = pexpect() |
77 | down.spawn (None, [download, '-c', 'test_gnunet_fs_psd_data.conf', '-o', 'test_gnunet_fs_rec_data.tar.gz', 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 78 | down.spawn(None, [download, '-c', 'test_gnunet_fs_psd_data.conf', '-o', 'test_gnunet_fs_rec_data.tar.gz', 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
78 | down.expect ("stdout", re.compile (r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n")) | 79 | down.expect("stdout", re.compile(r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n")) |
79 | os.remove ("test_gnunet_fs_rec_data.tar.gz") | 80 | os.remove("test_gnunet_fs_rec_data.tar.gz") |
80 | 81 | ||
81 | finally: | 82 | finally: |
82 | arm = subprocess.Popen ([gnunetarm, '-eq', '-c', 'test_gnunet_fs_psd_data.conf']) | 83 | arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_fs_psd_data.conf']) |
83 | arm.communicate () | 84 | arm.communicate() |
84 | if os.name == "nt": | 85 | if os.name == "nt": |
85 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-psd"), True) | 86 | shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-psd"), True) |
86 | else: | 87 | else: |
87 | shutil.rmtree ("/tmp/gnunet-test-fs-py-psd", True) | 88 | shutil.rmtree("/tmp/gnunet-test-fs-py-psd", True) |
diff --git a/src/fs/test_gnunet_fs_rec.py.in b/src/fs/test_gnunet_fs_rec.py.in index 3828a65c9..aa9b7b461 100755 --- a/src/fs/test_gnunet_fs_rec.py.in +++ b/src/fs/test_gnunet_fs_rec.py.in | |||
@@ -27,88 +27,90 @@ import tarfile | |||
27 | import filecmp | 27 | import filecmp |
28 | 28 | ||
29 | srcdir = "../.." | 29 | srcdir = "../.." |
30 | gnunet_pyexpect_dir = os.path.join (srcdir, "contrib") | 30 | gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts") |
31 | if gnunet_pyexpect_dir not in sys.path: | 31 | if gnunet_pyexpect_dir not in sys.path: |
32 | sys.path.append (gnunet_pyexpect_dir) | 32 | sys.path.append(gnunet_pyexpect_dir) |
33 | 33 | ||
34 | from gnunet_pyexpect import pexpect | 34 | from gnunet_pyexpect import pexpect |
35 | from pydiffer import dcdiff | 35 | from pydiffer import dcdiff |
36 | 36 | ||
37 | if os.name == 'posix': | 37 | if os.name == 'posix': |
38 | download = './gnunet-download' | 38 | download = './gnunet-download' |
39 | gnunetarm = 'gnunet-arm' | 39 | gnunetarm = 'gnunet-arm' |
40 | publish = './gnunet-publish' | 40 | publish = './gnunet-publish' |
41 | unindex = './gnunet-unindex' | 41 | unindex = './gnunet-unindex' |
42 | search = './gnunet-search' | 42 | search = './gnunet-search' |
43 | directory = './gnunet-directory' | 43 | directory = './gnunet-directory' |
44 | elif os.name == 'nt': | 44 | elif os.name == 'nt': |
45 | download = './gnunet-download.exe' | 45 | download = './gnunet-download.exe' |
46 | gnunetarm = 'gnunet-arm.exe' | 46 | gnunetarm = 'gnunet-arm.exe' |
47 | publish = './gnunet-publish.exe' | 47 | publish = './gnunet-publish.exe' |
48 | unindex = './gnunet-unindex.exe' | 48 | unindex = './gnunet-unindex.exe' |
49 | search = './gnunet-search.exe' | 49 | search = './gnunet-search.exe' |
50 | directory = './gnunet-directory.exe' | 50 | directory = './gnunet-directory.exe' |
51 | 51 | ||
52 | if os.name == "nt": | 52 | if os.name == "nt": |
53 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-rec"), True) | 53 | shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True) |
54 | else: | 54 | else: |
55 | shutil.rmtree ("/tmp/gnunet-test-fs-py-rec", True) | 55 | shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True) |
56 | 56 | ||
57 | arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_fs_rec_data.conf']) | 57 | arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_fs_rec_data.conf']) |
58 | arm.communicate () | 58 | arm.communicate() |
59 | 59 | ||
60 | # pray that `tar' is in PATH | 60 | # pray that `tar' is in PATH. |
61 | tar = tarfile.open ('test_gnunet_fs_rec_data.tgz') | 61 | # FIXME: Actually we should check for that and output |
62 | tar.extractall () | 62 | # a message if it isn't found. |
63 | tar = tarfile.open('test_gnunet_fs_rec_data.tgz') | ||
64 | tar.extractall() | ||
63 | # first, basic publish-search-download run | 65 | # first, basic publish-search-download run |
64 | try: | 66 | try: |
65 | pub = pexpect () | 67 | pub = pexpect() |
66 | pub.spawn (None, [publish, '-c', 'test_gnunet_fs_rec_data.conf', '-d', '-k', 'testdir', 'dir/'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 68 | pub.spawn(None, [publish, '-c', 'test_gnunet_fs_rec_data.conf', '-d', '-k', 'testdir', 'dir/'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
67 | # Can't say much for publishing, except that the last one is the toplevel directory | 69 | # Can't say much for publishing, except that the last one is the toplevel directory |
68 | pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) | 70 | pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) |
69 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) | 71 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) |
70 | pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) | 72 | pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) |
71 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) | 73 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) |
72 | pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) | 74 | pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) |
73 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) | 75 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) |
74 | pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) | 76 | pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) |
75 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) | 77 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) |
76 | pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) | 78 | pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) |
77 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) | 79 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) |
78 | pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) | 80 | pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) |
79 | pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) | 81 | pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) |
80 | pub.expect ("stdout", re.compile (r"Publishing `.+[\\/]dir[\\/]' done\.\r?\n")) | 82 | pub.expect("stdout", re.compile(r"Publishing `.+[\\/]dir[\\/]' done\.\r?\n")) |
81 | m = pub.expect ("stdout", re.compile (r".+\r?\n")) | 83 | m = pub.expect("stdout", re.compile(r".+\r?\n")) |
82 | if not m: | 84 | if not m: |
83 | sys.exit (3) | 85 | sys.exit(3) |
84 | output = m.string | 86 | output = m.string |
85 | url = output[output.find ("`")+1:output.find("'")] | 87 | url = output[output.find("`")+1:output.find("'")] |
86 | 88 | ||
87 | down = pexpect () | 89 | down = pexpect() |
88 | down.spawn (None, [download, '-c', 'test_gnunet_fs_rec_data.conf', '-R', '-o', 'rdir.gnd', url], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 90 | down.spawn(None, [download, '-c', 'test_gnunet_fs_rec_data.conf', '-R', '-o', 'rdir.gnd', url], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
89 | down.expect ("stdout", re.compile (r"Downloading `rdir.gnd' done (.*).\r?\n")) | 91 | down.expect("stdout", re.compile(r"Downloading `rdir.gnd' done (.*).\r?\n")) |
90 | 92 | ||
91 | d = pexpect () | 93 | d = pexpect() |
92 | d.spawn (None, [directory, '-c', 'test_gnunet_fs_rec_data.conf', 'rdir/a.gnd'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 94 | d.spawn(None, [directory, '-c', 'test_gnunet_fs_rec_data.conf', 'rdir/a.gnd'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
93 | d.expect ("stdout", re.compile (r"Directory `a/' meta data:\r?\n")) | 95 | d.expect("stdout", re.compile(r"Directory `a/' meta data:\r?\n")) |
94 | d.expect ("stdout", re.compile (r"Directory `a/' contents:\r?\n")) | 96 | d.expect("stdout", re.compile(r"Directory `a/' contents:\r?\n")) |
95 | d.expect ("stdout", re.compile (r"COPYING (.*)\r?\n")) | 97 | d.expect("stdout", re.compile(r"COPYING (.*)\r?\n")) |
96 | d.expect ("stdout", re.compile (r"INSTALL (.*)\r?\n")) | 98 | d.expect("stdout", re.compile(r"INSTALL (.*)\r?\n")) |
99 | |||
100 | os.remove("rdir/b.gnd") | ||
101 | os.remove("rdir/a.gnd") | ||
102 | diff = dcdiff('dir', 'rdir') | ||
103 | if len(diff) != 0: | ||
104 | raise Exception("Unexpected difference between source directory and downloaded result:\n{}".format(diff)) | ||
97 | 105 | ||
98 | os.remove ("rdir/b.gnd") | ||
99 | os.remove ("rdir/a.gnd") | ||
100 | diff = dcdiff ('dir', 'rdir') | ||
101 | if len (diff) != 0: | ||
102 | raise Exception ("Unexpected difference between source directory and downloaded result:\n{}".format (diff)) | ||
103 | |||
104 | 106 | ||
105 | finally: | 107 | finally: |
106 | arm = subprocess.Popen ([gnunetarm, '-eq', '-c', 'test_gnunet_fs_rec_data.conf']) | 108 | arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_fs_rec_data.conf']) |
107 | arm.communicate () | 109 | arm.communicate() |
108 | if os.name == "nt": | 110 | if os.name == "nt": |
109 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-rec"), True) | 111 | shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True) |
110 | else: | 112 | else: |
111 | shutil.rmtree ("/tmp/gnunet-test-fs-py-rec", True) | 113 | shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True) |
112 | shutil.rmtree ("dir", True) | 114 | shutil.rmtree("dir", True) |
113 | shutil.rmtree ("rdir", True) | 115 | shutil.rmtree("rdir", True) |
114 | shutil.rmtree ("rdir.gnd", True) | 116 | shutil.rmtree("rdir.gnd", True) |
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index ac11c834e..46642113f 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -264,6 +264,7 @@ check_SCRIPTS = \ | |||
264 | test_gns_txt_lookup.sh\ | 264 | test_gns_txt_lookup.sh\ |
265 | test_gns_mx_lookup.sh \ | 265 | test_gns_mx_lookup.sh \ |
266 | test_gns_gns2dns_lookup.sh \ | 266 | test_gns_gns2dns_lookup.sh \ |
267 | test_gns_gns2dns_cname_lookup.sh \ | ||
267 | test_gns_dht_lookup.sh\ | 268 | test_gns_dht_lookup.sh\ |
268 | test_gns_delegated_lookup.sh \ | 269 | test_gns_delegated_lookup.sh \ |
269 | test_gns_at_lookup.sh\ | 270 | test_gns_at_lookup.sh\ |
diff --git a/src/gns/gnunet-gns-benchmark.c b/src/gns/gnunet-gns-benchmark.c index d5afae9f6..0ab6cefd5 100644 --- a/src/gns/gnunet-gns-benchmark.c +++ b/src/gns/gnunet-gns-benchmark.c | |||
@@ -84,7 +84,7 @@ struct Request | |||
84 | * this struct (optimizing memory consumption by reducing | 84 | * this struct (optimizing memory consumption by reducing |
85 | * total number of allocations). | 85 | * total number of allocations). |
86 | */ | 86 | */ |
87 | char *hostname; | 87 | const char *hostname; |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * While we are fetching the record, the value is set to the | 90 | * While we are fetching the record, the value is set to the |
@@ -176,6 +176,11 @@ static struct GNUNET_TIME_Relative request_delay; | |||
176 | */ | 176 | */ |
177 | static struct GNUNET_TIME_Relative timeout; | 177 | static struct GNUNET_TIME_Relative timeout; |
178 | 178 | ||
179 | /** | ||
180 | * Number of requests we have concurrently active. | ||
181 | */ | ||
182 | static unsigned int active_cnt; | ||
183 | |||
179 | 184 | ||
180 | /** | 185 | /** |
181 | * Free @a req and data structures reachable from it. | 186 | * Free @a req and data structures reachable from it. |
@@ -210,6 +215,10 @@ process_result (void *cls, | |||
210 | (void) gns_tld; | 215 | (void) gns_tld; |
211 | (void) rd_count; | 216 | (void) rd_count; |
212 | (void) rd; | 217 | (void) rd; |
218 | active_cnt--; | ||
219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
220 | "Got response for request `%s'\n", | ||
221 | req->hostname); | ||
213 | req->lr = NULL; | 222 | req->lr = NULL; |
214 | req->latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); | 223 | req->latency = GNUNET_TIME_absolute_get_duration (req->op_start_time); |
215 | GNUNET_CONTAINER_DLL_remove (act_head, | 224 | GNUNET_CONTAINER_DLL_remove (act_head, |
@@ -247,7 +256,11 @@ process_queue (void *cls) | |||
247 | GNUNET_CONTAINER_DLL_remove (act_head, | 256 | GNUNET_CONTAINER_DLL_remove (act_head, |
248 | act_tail, | 257 | act_tail, |
249 | req); | 258 | req); |
259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
260 | "Failing request `%s' due to timeout\n", | ||
261 | req->hostname); | ||
250 | failures[req->cat]++; | 262 | failures[req->cat]++; |
263 | active_cnt--; | ||
251 | free_request (req); | 264 | free_request (req); |
252 | } | 265 | } |
253 | if (NULL == (req = todo_head)) | 266 | if (NULL == (req = todo_head)) |
@@ -273,7 +286,12 @@ process_queue (void *cls) | |||
273 | act_tail, | 286 | act_tail, |
274 | req); | 287 | req); |
275 | lookups[req->cat]++; | 288 | lookups[req->cat]++; |
289 | active_cnt++; | ||
276 | req->op_start_time = GNUNET_TIME_absolute_get (); | 290 | req->op_start_time = GNUNET_TIME_absolute_get (); |
291 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
292 | "Starting request `%s' (%u in parallel)\n", | ||
293 | req->hostname, | ||
294 | active_cnt); | ||
277 | req->lr = GNUNET_GNS_lookup_with_tld (gns, | 295 | req->lr = GNUNET_GNS_lookup_with_tld (gns, |
278 | req->hostname, | 296 | req->hostname, |
279 | GNUNET_GNSRECORD_TYPE_ANY, | 297 | GNUNET_GNSRECORD_TYPE_ANY, |
@@ -439,7 +457,7 @@ queue (const char *hostname, | |||
439 | req = GNUNET_malloc (sizeof (struct Request) + hlen); | 457 | req = GNUNET_malloc (sizeof (struct Request) + hlen); |
440 | req->cat = cat; | 458 | req->cat = cat; |
441 | req->hostname = (char *) &req[1]; | 459 | req->hostname = (char *) &req[1]; |
442 | GNUNET_memcpy (req->hostname, | 460 | GNUNET_memcpy (&req[1], |
443 | hostname, | 461 | hostname, |
444 | hlen); | 462 | hlen); |
445 | GNUNET_CONTAINER_DLL_insert (todo_head, | 463 | GNUNET_CONTAINER_DLL_insert (todo_head, |
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index cffae824d..aaa4aeb0e 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -334,30 +334,43 @@ client_connect_cb (void *cls, | |||
334 | * @param rd the record data | 334 | * @param rd the record data |
335 | */ | 335 | */ |
336 | static void | 336 | static void |
337 | send_lookup_response (void* cls, | 337 | send_lookup_response (void *cls, |
338 | uint32_t rd_count, | 338 | uint32_t rd_count, |
339 | const struct GNUNET_GNSRECORD_Data *rd) | 339 | const struct GNUNET_GNSRECORD_Data *rd) |
340 | { | 340 | { |
341 | struct ClientLookupHandle *clh = cls; | 341 | struct ClientLookupHandle *clh = cls; |
342 | struct GnsClient *gc = clh->gc; | 342 | struct GnsClient *gc = clh->gc; |
343 | struct GNUNET_MQ_Envelope *env; | 343 | struct GNUNET_MQ_Envelope *env; |
344 | struct LookupResultMessage *rmsg; | 344 | struct LookupResultMessage *rmsg; |
345 | size_t len; | 345 | ssize_t len; |
346 | 346 | ||
347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
348 | "Sending LOOKUP_RESULT message with %u results\n", | 348 | "Sending LOOKUP_RESULT message with %u results\n", |
349 | (unsigned int) rd_count); | 349 | (unsigned int) rd_count); |
350 | len = GNUNET_GNSRECORD_records_get_size (rd_count, | 350 | len = GNUNET_GNSRECORD_records_get_size (rd_count, |
351 | rd); | 351 | rd); |
352 | if (len < 0) | ||
353 | { | ||
354 | GNUNET_break (0); | ||
355 | GNUNET_SERVICE_client_drop (gc->client); | ||
356 | return; | ||
357 | } | ||
358 | if (len > UINT16_MAX - sizeof (*rmsg)) | ||
359 | { | ||
360 | GNUNET_break (0); | ||
361 | GNUNET_SERVICE_client_drop (gc->client); | ||
362 | return; | ||
363 | } | ||
352 | env = GNUNET_MQ_msg_extra (rmsg, | 364 | env = GNUNET_MQ_msg_extra (rmsg, |
353 | len, | 365 | len, |
354 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT); | 366 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT); |
355 | rmsg->id = clh->request_id; | 367 | rmsg->id = clh->request_id; |
356 | rmsg->rd_count = htonl (rd_count); | 368 | rmsg->rd_count = htonl (rd_count); |
357 | GNUNET_GNSRECORD_records_serialize (rd_count, | 369 | GNUNET_assert (len == |
358 | rd, | 370 | GNUNET_GNSRECORD_records_serialize (rd_count, |
359 | len, | 371 | rd, |
360 | (char*) &rmsg[1]); | 372 | len, |
373 | (char*) &rmsg[1])); | ||
361 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (gc->client), | 374 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (gc->client), |
362 | env); | 375 | env); |
363 | GNUNET_CONTAINER_DLL_remove (gc->clh_head, | 376 | GNUNET_CONTAINER_DLL_remove (gc->clh_head, |
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 542085910..8b20f2ae3 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -151,16 +151,6 @@ struct AuthorityChain | |||
151 | char *label; | 151 | char *label; |
152 | 152 | ||
153 | /** | 153 | /** |
154 | * label/name suggested for shortening to the authority | ||
155 | */ | ||
156 | char *suggested_shortening_label; | ||
157 | |||
158 | /** | ||
159 | * Do we already try to shorten this authority? | ||
160 | */ | ||
161 | int shortening_started; | ||
162 | |||
163 | /** | ||
164 | * #GNUNET_YES if the authority was a GNS authority, | 154 | * #GNUNET_YES if the authority was a GNS authority, |
165 | * #GNUNET_NO if the authority was a DNS authority. | 155 | * #GNUNET_NO if the authority was a DNS authority. |
166 | */ | 156 | */ |
@@ -290,7 +280,7 @@ struct VpnContext | |||
290 | /** | 280 | /** |
291 | * Number of bytes in @e rd_data. | 281 | * Number of bytes in @e rd_data. |
292 | */ | 282 | */ |
293 | size_t rd_data_size; | 283 | ssize_t rd_data_size; |
294 | }; | 284 | }; |
295 | 285 | ||
296 | 286 | ||
@@ -946,35 +936,45 @@ dns_result_parser (void *cls, | |||
946 | if ( (p->num_answers > 0) && | 936 | if ( (p->num_answers > 0) && |
947 | (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) && | 937 | (GNUNET_DNSPARSER_TYPE_CNAME == p->answers[0].type) && |
948 | (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) ) | 938 | (GNUNET_DNSPARSER_TYPE_CNAME != rh->record_type) ) |
949 | { | 939 | { |
950 | int af; | 940 | int af; |
951 | 941 | ||
952 | GNUNET_free (rh->name); | 942 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
953 | rh->name = GNUNET_strdup (p->answers[0].data.hostname); | 943 | "Got CNAME `%s' from DNS for `%s'\n", |
954 | rh->name_resolution_pos = strlen (rh->name); | 944 | p->answers[0].data.hostname, |
955 | switch (rh->record_type) | 945 | rh->name); |
956 | { | 946 | if (NULL != rh->std_resolve) |
957 | case GNUNET_DNSPARSER_TYPE_A: | 947 | { |
958 | af = AF_INET; | 948 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
959 | break; | 949 | "Multiple CNAME results from DNS resolving `%s'! Not really allowed...\n", |
960 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
961 | af = AF_INET6; | ||
962 | break; | ||
963 | default: | ||
964 | af = AF_UNSPEC; | ||
965 | break; | ||
966 | } | ||
967 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
968 | "Doing standard DNS lookup for `%s'\n", | ||
969 | rh->name); | 950 | rh->name); |
970 | rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name, | 951 | GNUNET_RESOLVER_request_cancel (rh->std_resolve); |
971 | af, | 952 | } |
972 | DNS_LOOKUP_TIMEOUT, | 953 | GNUNET_free (rh->name); |
973 | &handle_dns_result, | 954 | rh->name = GNUNET_strdup (p->answers[0].data.hostname); |
974 | rh); | 955 | rh->name_resolution_pos = strlen (rh->name); |
975 | GNUNET_DNSPARSER_free_packet (p); | 956 | switch (rh->record_type) |
976 | return; | 957 | { |
958 | case GNUNET_DNSPARSER_TYPE_A: | ||
959 | af = AF_INET; | ||
960 | break; | ||
961 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
962 | af = AF_INET6; | ||
963 | break; | ||
964 | default: | ||
965 | af = AF_UNSPEC; | ||
966 | break; | ||
977 | } | 967 | } |
968 | rh->std_resolve = GNUNET_RESOLVER_ip_get (rh->name, | ||
969 | af, | ||
970 | DNS_LOOKUP_TIMEOUT, | ||
971 | &handle_dns_result, | ||
972 | rh); | ||
973 | GNUNET_DNSPARSER_free_packet (p); | ||
974 | GNUNET_DNSSTUB_resolve_cancel (rh->dns_request); | ||
975 | rh->dns_request = NULL; | ||
976 | return; | ||
977 | } | ||
978 | 978 | ||
979 | /* convert from (parsed) DNS to (binary) GNS format! */ | 979 | /* convert from (parsed) DNS to (binary) GNS format! */ |
980 | rd_count = p->num_answers + p->num_authority_records + p->num_additional_records; | 980 | rd_count = p->num_answers + p->num_authority_records + p->num_additional_records; |
@@ -1112,6 +1112,8 @@ dns_result_parser (void *cls, | |||
1112 | rh->proc (rh->proc_cls, | 1112 | rh->proc (rh->proc_cls, |
1113 | rd_count - skip, | 1113 | rd_count - skip, |
1114 | rd); | 1114 | rd); |
1115 | GNUNET_DNSSTUB_resolve_cancel (rh->dns_request); | ||
1116 | rh->dns_request = NULL; | ||
1115 | } | 1117 | } |
1116 | GNUNET_DNSPARSER_free_packet (p); | 1118 | GNUNET_DNSPARSER_free_packet (p); |
1117 | if (NULL != rh->task_id) | 1119 | if (NULL != rh->task_id) |
@@ -1235,8 +1237,6 @@ handle_gns_cname_result (struct GNS_ResolverHandle *rh, | |||
1235 | ac->gns_authority = GNUNET_YES; | 1237 | ac->gns_authority = GNUNET_YES; |
1236 | ac->authority_info.gns_authority = rh->ac_tail->authority_info.gns_authority; | 1238 | ac->authority_info.gns_authority = rh->ac_tail->authority_info.gns_authority; |
1237 | ac->label = resolver_lookup_get_next_label (rh); | 1239 | ac->label = resolver_lookup_get_next_label (rh); |
1238 | ac->suggested_shortening_label = NULL; | ||
1239 | ac->shortening_started = GNUNET_NO; | ||
1240 | /* add AC to tail */ | 1240 | /* add AC to tail */ |
1241 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | 1241 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, |
1242 | rh->ac_tail, | 1242 | rh->ac_tail, |
@@ -1245,6 +1245,17 @@ handle_gns_cname_result (struct GNS_ResolverHandle *rh, | |||
1245 | rh); | 1245 | rh); |
1246 | return; | 1246 | return; |
1247 | } | 1247 | } |
1248 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1249 | "Got CNAME `%s' from GNS for `%s'\n", | ||
1250 | cname, | ||
1251 | rh->name); | ||
1252 | if (NULL != rh->std_resolve) | ||
1253 | { | ||
1254 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1255 | "Multiple CNAME results from GNS resolving `%s'! Not really allowed...\n", | ||
1256 | rh->name); | ||
1257 | GNUNET_RESOLVER_request_cancel (rh->std_resolve); | ||
1258 | } | ||
1248 | /* name is absolute, go to DNS */ | 1259 | /* name is absolute, go to DNS */ |
1249 | GNUNET_free (rh->name); | 1260 | GNUNET_free (rh->name); |
1250 | rh->name = GNUNET_strdup (cname); | 1261 | rh->name = GNUNET_strdup (cname); |
@@ -1312,7 +1323,7 @@ vpn_allocation_cb (void *cls, | |||
1312 | vpn_ctx->vpn_request = NULL; | 1323 | vpn_ctx->vpn_request = NULL; |
1313 | rh->vpn_ctx = NULL; | 1324 | rh->vpn_ctx = NULL; |
1314 | GNUNET_assert (GNUNET_OK == | 1325 | GNUNET_assert (GNUNET_OK == |
1315 | GNUNET_GNSRECORD_records_deserialize (vpn_ctx->rd_data_size, | 1326 | GNUNET_GNSRECORD_records_deserialize ((size_t) vpn_ctx->rd_data_size, |
1316 | vpn_ctx->rd_data, | 1327 | vpn_ctx->rd_data, |
1317 | vpn_ctx->rd_count, | 1328 | vpn_ctx->rd_count, |
1318 | rd)); | 1329 | rd)); |
@@ -1601,8 +1612,6 @@ recursive_pkey_resolution (struct GNS_ResolverHandle *rh, | |||
1601 | ac = GNUNET_new (struct AuthorityChain); | 1612 | ac = GNUNET_new (struct AuthorityChain); |
1602 | ac->rh = rh; | 1613 | ac->rh = rh; |
1603 | ac->gns_authority = GNUNET_YES; | 1614 | ac->gns_authority = GNUNET_YES; |
1604 | ac->suggested_shortening_label = NULL; | ||
1605 | ac->shortening_started = GNUNET_NO; | ||
1606 | GNUNET_memcpy (&ac->authority_info.gns_authority, | 1615 | GNUNET_memcpy (&ac->authority_info.gns_authority, |
1607 | rd->data, | 1616 | rd->data, |
1608 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 1617 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); |
@@ -1649,6 +1658,8 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh, | |||
1649 | size_t off; | 1658 | size_t off; |
1650 | struct Gns2DnsPending *gp; | 1659 | struct Gns2DnsPending *gp; |
1651 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; | 1660 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; |
1661 | struct sockaddr_in v4; | ||
1662 | struct sockaddr_in6 v6; | ||
1652 | 1663 | ||
1653 | if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type) | 1664 | if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type) |
1654 | continue; | 1665 | continue; |
@@ -1690,10 +1701,16 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh, | |||
1690 | } | 1701 | } |
1691 | 1702 | ||
1692 | /* check if 'ip' is already an IPv4/IPv6 address */ | 1703 | /* check if 'ip' is already an IPv4/IPv6 address */ |
1693 | if (GNUNET_OK == | 1704 | if ( (1 == inet_pton (AF_INET, |
1694 | GNUNET_DNSSTUB_add_dns_ip (ac->authority_info.dns_authority.dns_handle, | 1705 | ip, |
1695 | ip)) | 1706 | &v4)) || |
1707 | (1 == inet_pton (AF_INET6, | ||
1708 | ip, | ||
1709 | &v6)) ) | ||
1696 | { | 1710 | { |
1711 | GNUNET_break (GNUNET_OK == | ||
1712 | GNUNET_DNSSTUB_add_dns_ip (ac->authority_info.dns_authority.dns_handle, | ||
1713 | ip)); | ||
1697 | ac->authority_info.dns_authority.found = GNUNET_YES; | 1714 | ac->authority_info.dns_authority.found = GNUNET_YES; |
1698 | GNUNET_free (ip); | 1715 | GNUNET_free (ip); |
1699 | continue; | 1716 | continue; |
@@ -1798,7 +1815,6 @@ handle_gns_resolution_result (void *cls, | |||
1798 | const struct GNUNET_GNSRECORD_Data *rd) | 1815 | const struct GNUNET_GNSRECORD_Data *rd) |
1799 | { | 1816 | { |
1800 | struct GNS_ResolverHandle *rh = cls; | 1817 | struct GNS_ResolverHandle *rh = cls; |
1801 | struct AuthorityChain *shorten_ac; | ||
1802 | char *cname; | 1818 | char *cname; |
1803 | struct VpnContext *vpn_ctx; | 1819 | struct VpnContext *vpn_ctx; |
1804 | const struct GNUNET_TUN_GnsVpnRecord *vpn; | 1820 | const struct GNUNET_TUN_GnsVpnRecord *vpn; |
@@ -1889,13 +1905,20 @@ handle_gns_resolution_result (void *cls, | |||
1889 | vpn_ctx->rh = rh; | 1905 | vpn_ctx->rh = rh; |
1890 | vpn_ctx->rd_data_size = GNUNET_GNSRECORD_records_get_size (rd_count, | 1906 | vpn_ctx->rd_data_size = GNUNET_GNSRECORD_records_get_size (rd_count, |
1891 | rd); | 1907 | rd); |
1892 | vpn_ctx->rd_data = GNUNET_malloc (vpn_ctx->rd_data_size); | 1908 | if (vpn_ctx->rd_data_size < 0) |
1909 | { | ||
1910 | GNUNET_break_op (0); | ||
1911 | GNUNET_free (vpn_ctx); | ||
1912 | fail_resolution (rh); | ||
1913 | return; | ||
1914 | } | ||
1915 | vpn_ctx->rd_data = GNUNET_malloc ((size_t) vpn_ctx->rd_data_size); | ||
1893 | vpn_ctx->rd_count = rd_count; | 1916 | vpn_ctx->rd_count = rd_count; |
1894 | GNUNET_assert (vpn_ctx->rd_data_size == | 1917 | GNUNET_assert (vpn_ctx->rd_data_size == |
1895 | (size_t) GNUNET_GNSRECORD_records_serialize (rd_count, | 1918 | GNUNET_GNSRECORD_records_serialize (rd_count, |
1896 | rd, | 1919 | rd, |
1897 | vpn_ctx->rd_data_size, | 1920 | (size_t) vpn_ctx->rd_data_size, |
1898 | vpn_ctx->rd_data)); | 1921 | vpn_ctx->rd_data)); |
1899 | vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle, | 1922 | vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle, |
1900 | af, | 1923 | af, |
1901 | ntohs (vpn->proto), | 1924 | ntohs (vpn->proto), |
@@ -1928,7 +1951,6 @@ handle_gns_resolution_result (void *cls, | |||
1928 | using 'scratch' array for memory allocations */ | 1951 | using 'scratch' array for memory allocations */ |
1929 | scratch_off = 0; | 1952 | scratch_off = 0; |
1930 | rd_off = 0; | 1953 | rd_off = 0; |
1931 | shorten_ac = rh->ac_tail; | ||
1932 | for (unsigned int i=0;i<rd_count;i++) | 1954 | for (unsigned int i=0;i<rd_count;i++) |
1933 | { | 1955 | { |
1934 | GNUNET_assert (rd_off <= i); | 1956 | GNUNET_assert (rd_off <= i); |
@@ -2106,8 +2128,6 @@ handle_gns_resolution_result (void *cls, | |||
2106 | GNUNET_break_op (0); | 2128 | GNUNET_break_op (0); |
2107 | break; | 2129 | break; |
2108 | } | 2130 | } |
2109 | if (NULL == shorten_ac->suggested_shortening_label) | ||
2110 | shorten_ac->suggested_shortening_label = GNUNET_strdup (nick); | ||
2111 | break; | 2131 | break; |
2112 | } | 2132 | } |
2113 | case GNUNET_GNSRECORD_TYPE_PKEY: | 2133 | case GNUNET_GNSRECORD_TYPE_PKEY: |
@@ -2133,8 +2153,6 @@ handle_gns_resolution_result (void *cls, | |||
2133 | ac->gns_authority = GNUNET_YES; | 2153 | ac->gns_authority = GNUNET_YES; |
2134 | ac->authority_info.gns_authority = pub; | 2154 | ac->authority_info.gns_authority = pub; |
2135 | ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT); | 2155 | ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT); |
2136 | ac->suggested_shortening_label = NULL; | ||
2137 | ac->shortening_started = GNUNET_NO; | ||
2138 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | 2156 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, |
2139 | rh->ac_tail, | 2157 | rh->ac_tail, |
2140 | ac); | 2158 | ac); |
@@ -2386,7 +2404,8 @@ start_dht_request (struct GNS_ResolverHandle *rh, | |||
2386 | if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) > max_allowed_background_queries) | 2404 | if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) > max_allowed_background_queries) |
2387 | { | 2405 | { |
2388 | /* fail longest-standing DHT request */ | 2406 | /* fail longest-standing DHT request */ |
2389 | rx = GNUNET_CONTAINER_heap_peek (dht_lookup_heap); | 2407 | rx = GNUNET_CONTAINER_heap_remove_root (dht_lookup_heap); |
2408 | rx->dht_heap_node = NULL; | ||
2390 | GNUNET_assert (NULL != rx); | 2409 | GNUNET_assert (NULL != rx); |
2391 | fail_resolution (rx); | 2410 | fail_resolution (rx); |
2392 | } | 2411 | } |
@@ -2656,7 +2675,6 @@ start_resolver_lookup (void *cls) | |||
2656 | ac = GNUNET_new (struct AuthorityChain); | 2675 | ac = GNUNET_new (struct AuthorityChain); |
2657 | ac->rh = rh; | 2676 | ac->rh = rh; |
2658 | ac->label = resolver_lookup_get_next_label (rh); | 2677 | ac->label = resolver_lookup_get_next_label (rh); |
2659 | ac->suggested_shortening_label = NULL; | ||
2660 | if (NULL == ac->label) | 2678 | if (NULL == ac->label) |
2661 | /* name was just the "TLD", so we default to label | 2679 | /* name was just the "TLD", so we default to label |
2662 | #GNUNET_GNS_EMPTY_LABEL_AT */ | 2680 | #GNUNET_GNS_EMPTY_LABEL_AT */ |
@@ -2770,7 +2788,6 @@ GNS_resolver_lookup_cancel (struct GNS_ResolverHandle *rh) | |||
2770 | GNUNET_DNSSTUB_stop (ac->authority_info.dns_authority.dns_handle); | 2788 | GNUNET_DNSSTUB_stop (ac->authority_info.dns_authority.dns_handle); |
2771 | } | 2789 | } |
2772 | GNUNET_free (ac->label); | 2790 | GNUNET_free (ac->label); |
2773 | GNUNET_free_non_null (ac->suggested_shortening_label); | ||
2774 | GNUNET_free (ac); | 2791 | GNUNET_free (ac); |
2775 | } | 2792 | } |
2776 | if (NULL != rh->task_id) | 2793 | if (NULL != rh->task_id) |
diff --git a/src/gns/test_gns_defaults.conf b/src/gns/test_gns_defaults.conf index 261dab6ed..01825fafe 100644 --- a/src/gns/test_gns_defaults.conf +++ b/src/gns/test_gns_defaults.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-gns-testing/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-gns-testing/ |
diff --git a/src/gns/test_gns_gns2dns_cname_lookup.sh b/src/gns/test_gns_gns2dns_cname_lookup.sh new file mode 100755 index 000000000..32e730d4c --- /dev/null +++ b/src/gns/test_gns_gns2dns_cname_lookup.sh | |||
@@ -0,0 +1,89 @@ | |||
1 | #!/bin/bash | ||
2 | trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT | ||
3 | |||
4 | LOCATION=$(which gnunet-config) | ||
5 | if [ -z $LOCATION ] | ||
6 | then | ||
7 | LOCATION="gnunet-config" | ||
8 | fi | ||
9 | $LOCATION --version 1> /dev/null | ||
10 | if test $? != 0 | ||
11 | then | ||
12 | echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX" | ||
13 | exit 77 | ||
14 | fi | ||
15 | |||
16 | rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` | ||
17 | # IP address of 'www.gnunet.org' | ||
18 | TEST_IP="131.159.74.67" | ||
19 | # IPv6 address of 'gnunet.org' | ||
20 | TEST_IP6="2001:4ca0:2001:42:225:90ff:fe6b:d60" | ||
21 | |||
22 | # main label used during resolution | ||
23 | TEST_RECORD_NAME="homepage" | ||
24 | |||
25 | XNS=ns.joker.com | ||
26 | |||
27 | if ! nslookup gnunet.org a.$XNS &> /dev/null | ||
28 | then | ||
29 | echo "Cannot reach DNS, skipping test" | ||
30 | exit 77 | ||
31 | fi | ||
32 | |||
33 | # helper record for pointing to the DNS resolver | ||
34 | TEST_RESOLVER_LABEL="resolver" | ||
35 | # GNS2DNS record value: delegate to DNS domain 'gnunet.org' | ||
36 | # using the TEST_RESOLVER_LABEL DNS server for resolution | ||
37 | TEST_RECORD_GNS2DNS1="gnunet.org@a.$XNS" | ||
38 | TEST_RECORD_GNS2DNS2="gnunet.org@b.$XNS" | ||
39 | TEST_RECORD_GNS2DNS3="gnunet.org@c.$XNS" | ||
40 | |||
41 | MY_EGO="myego" | ||
42 | # various names we will use for resolution | ||
43 | TEST_DOMAIN="www.${TEST_RECORD_NAME}.$MY_EGO" | ||
44 | |||
45 | gnunet-arm -s -c test_gns_lookup.conf | ||
46 | gnunet-identity -C $MY_EGO -c test_gns_lookup.conf | ||
47 | |||
48 | # set IP address for DNS resolver for resolving in gnunet.org domain | ||
49 | # map '$TEST_RECORD_NAME.$MY_EGO' to 'gnunet.org' in DNS | ||
50 | gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS1 -e never -c test_gns_lookup.conf | ||
51 | gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS2 -e never -c test_gns_lookup.conf | ||
52 | gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS3 -e never -c test_gns_lookup.conf | ||
53 | |||
54 | which timeout &> /dev/null && DO_TIMEOUT="timeout 15" | ||
55 | |||
56 | echo "EGOs:" | ||
57 | gnunet-identity -d | ||
58 | |||
59 | # lookup 'www.gnunet.org', IPv4 | ||
60 | RES_IP=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t A -c test_gns_lookup.conf` | ||
61 | # lookup 'www.gnunet.org', IPv6 | ||
62 | RES_IP6=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t AAAA -c test_gns_lookup.conf` | ||
63 | |||
64 | # clean up | ||
65 | gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS1 -e never -c test_gns_lookup.conf | ||
66 | gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS2 -e never -c test_gns_lookup.conf | ||
67 | gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V $TEST_RECORD_GNS2DNS3 -e never -c test_gns_lookup.conf | ||
68 | gnunet-identity -D $MY_EGO -c test_gns_lookup.conf | ||
69 | gnunet-arm -e -c test_gns_lookup.conf | ||
70 | rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME` | ||
71 | |||
72 | ret=0 | ||
73 | if [ "$RES_IP" == "$TEST_IP" ] | ||
74 | then | ||
75 | echo "PASS: Resolved $TEST_DOMAIN to $RES_IP." | ||
76 | else | ||
77 | echo "Failed to resolve to proper IP for $TEST_DOMAIN, got $RES_IP, wanted $TEST_IP." | ||
78 | ret=1 | ||
79 | fi | ||
80 | |||
81 | if [ "$RES_IP6" == "$TEST_IP6" ] | ||
82 | then | ||
83 | echo "PASS: Resolved $TEST_DOMAIN to $RES_IP6." | ||
84 | else | ||
85 | echo "Failed to resolve to proper IP for $TEST_DOMAIN, got $RES_IP6, wanted $TEST_IP6." | ||
86 | ret=1 | ||
87 | fi | ||
88 | |||
89 | exit $ret | ||
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c index 6d59a545a..6d3887392 100644 --- a/src/gnsrecord/gnsrecord_crypto.c +++ b/src/gnsrecord/gnsrecord_crypto.c | |||
@@ -87,9 +87,8 @@ block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
87 | const struct GNUNET_GNSRECORD_Data *rd, | 87 | const struct GNUNET_GNSRECORD_Data *rd, |
88 | unsigned int rd_count) | 88 | unsigned int rd_count) |
89 | { | 89 | { |
90 | size_t payload_len = GNUNET_GNSRECORD_records_get_size (rd_count, | 90 | ssize_t payload_len = GNUNET_GNSRECORD_records_get_size (rd_count, |
91 | rd); | 91 | rd); |
92 | char payload[sizeof (uint32_t) + payload_len]; | ||
93 | struct GNUNET_GNSRECORD_Block *block; | 92 | struct GNUNET_GNSRECORD_Block *block; |
94 | struct GNUNET_CRYPTO_EcdsaPrivateKey *dkey; | 93 | struct GNUNET_CRYPTO_EcdsaPrivateKey *dkey; |
95 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 94 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
@@ -98,8 +97,16 @@ block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
98 | uint32_t rd_count_nbo; | 97 | uint32_t rd_count_nbo; |
99 | struct GNUNET_TIME_Absolute now; | 98 | struct GNUNET_TIME_Absolute now; |
100 | 99 | ||
100 | if (payload_len < 0) | ||
101 | { | ||
102 | GNUNET_break (0); | ||
103 | return NULL; | ||
104 | } | ||
101 | if (payload_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE) | 105 | if (payload_len > GNUNET_GNSRECORD_MAX_BLOCK_SIZE) |
106 | { | ||
107 | GNUNET_break (0); | ||
102 | return NULL; | 108 | return NULL; |
109 | } | ||
103 | /* convert relative to absolute times */ | 110 | /* convert relative to absolute times */ |
104 | now = GNUNET_TIME_absolute_get (); | 111 | now = GNUNET_TIME_absolute_get (); |
105 | for (unsigned int i=0;i<rd_count;i++) | 112 | for (unsigned int i=0;i<rd_count;i++) |
@@ -117,39 +124,43 @@ block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
117 | } | 124 | } |
118 | /* serialize */ | 125 | /* serialize */ |
119 | rd_count_nbo = htonl (rd_count); | 126 | rd_count_nbo = htonl (rd_count); |
120 | GNUNET_memcpy (payload, | 127 | { |
121 | &rd_count_nbo, | 128 | char payload[sizeof (uint32_t) + payload_len]; |
122 | sizeof (uint32_t)); | 129 | |
123 | GNUNET_assert (payload_len == | 130 | GNUNET_memcpy (payload, |
124 | GNUNET_GNSRECORD_records_serialize (rd_count, | 131 | &rd_count_nbo, |
125 | rdc, | 132 | sizeof (uint32_t)); |
126 | payload_len, | 133 | GNUNET_assert (payload_len == |
127 | &payload[sizeof (uint32_t)])); | 134 | GNUNET_GNSRECORD_records_serialize (rd_count, |
128 | block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block) + | 135 | rdc, |
129 | sizeof (uint32_t) + | 136 | payload_len, |
130 | payload_len); | 137 | &payload[sizeof (uint32_t)])); |
131 | block->purpose.size = htonl (sizeof (uint32_t) + | 138 | block = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Block) + |
132 | payload_len + | 139 | sizeof (uint32_t) + |
133 | sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + | 140 | payload_len); |
134 | sizeof (struct GNUNET_TIME_AbsoluteNBO)); | 141 | block->purpose.size = htonl (sizeof (uint32_t) + |
135 | block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | 142 | payload_len + |
136 | block->expiration_time = GNUNET_TIME_absolute_hton (expire); | 143 | sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + |
137 | /* encrypt and sign */ | 144 | sizeof (struct GNUNET_TIME_AbsoluteNBO)); |
138 | dkey = GNUNET_CRYPTO_ecdsa_private_key_derive (key, | 145 | block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); |
139 | label, | 146 | block->expiration_time = GNUNET_TIME_absolute_hton (expire); |
140 | "gns"); | 147 | /* encrypt and sign */ |
141 | GNUNET_CRYPTO_ecdsa_key_get_public (dkey, | 148 | dkey = GNUNET_CRYPTO_ecdsa_private_key_derive (key, |
142 | &block->derived_key); | 149 | label, |
143 | derive_block_aes_key (&iv, | 150 | "gns"); |
144 | &skey, | 151 | GNUNET_CRYPTO_ecdsa_key_get_public (dkey, |
145 | label, | 152 | &block->derived_key); |
146 | pkey); | 153 | derive_block_aes_key (&iv, |
147 | GNUNET_break (payload_len + sizeof (uint32_t) == | 154 | &skey, |
148 | GNUNET_CRYPTO_symmetric_encrypt (payload, | 155 | label, |
149 | payload_len + sizeof (uint32_t), | 156 | pkey); |
150 | &skey, | 157 | GNUNET_break (payload_len + sizeof (uint32_t) == |
151 | &iv, | 158 | GNUNET_CRYPTO_symmetric_encrypt (payload, |
152 | &block[1])); | 159 | payload_len + sizeof (uint32_t), |
160 | &skey, | ||
161 | &iv, | ||
162 | &block[1])); | ||
163 | } | ||
153 | if (GNUNET_OK != | 164 | if (GNUNET_OK != |
154 | GNUNET_CRYPTO_ecdsa_sign (dkey, | 165 | GNUNET_CRYPTO_ecdsa_sign (dkey, |
155 | &block->purpose, | 166 | &block->purpose, |
diff --git a/src/gnsrecord/gnsrecord_serialization.c b/src/gnsrecord/gnsrecord_serialization.c index 1db27464f..77118ab94 100644 --- a/src/gnsrecord/gnsrecord_serialization.c +++ b/src/gnsrecord/gnsrecord_serialization.c | |||
@@ -37,6 +37,12 @@ | |||
37 | 37 | ||
38 | #define LOG(kind,...) GNUNET_log_from (kind, "gnsrecord",__VA_ARGS__) | 38 | #define LOG(kind,...) GNUNET_log_from (kind, "gnsrecord",__VA_ARGS__) |
39 | 39 | ||
40 | /** | ||
41 | * Set to 1 to check that all records are well-formed (can be converted | ||
42 | * to string) during serialization/deserialization. | ||
43 | */ | ||
44 | #define DEBUG_GNSRECORDS 0 | ||
45 | |||
40 | GNUNET_NETWORK_STRUCT_BEGIN | 46 | GNUNET_NETWORK_STRUCT_BEGIN |
41 | 47 | ||
42 | 48 | ||
@@ -78,9 +84,9 @@ GNUNET_NETWORK_STRUCT_END | |||
78 | * | 84 | * |
79 | * @param rd_count number of records in the rd array | 85 | * @param rd_count number of records in the rd array |
80 | * @param rd array of #GNUNET_GNSRECORD_Data with @a rd_count elements | 86 | * @param rd array of #GNUNET_GNSRECORD_Data with @a rd_count elements |
81 | * @return the required size to serialize | 87 | * @return the required size to serialize, -1 on error |
82 | */ | 88 | */ |
83 | size_t | 89 | ssize_t |
84 | GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, | 90 | GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, |
85 | const struct GNUNET_GNSRECORD_Data *rd) | 91 | const struct GNUNET_GNSRECORD_Data *rd) |
86 | { | 92 | { |
@@ -89,10 +95,34 @@ GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, | |||
89 | ret = sizeof (struct NetworkRecord) * rd_count; | 95 | ret = sizeof (struct NetworkRecord) * rd_count; |
90 | for (unsigned int i=0;i<rd_count;i++) | 96 | for (unsigned int i=0;i<rd_count;i++) |
91 | { | 97 | { |
92 | GNUNET_assert ((ret + rd[i].data_size) >= ret); | 98 | if ((ret + rd[i].data_size) < ret) |
99 | { | ||
100 | GNUNET_break (0); | ||
101 | return -1; | ||
102 | } | ||
93 | ret += rd[i].data_size; | 103 | ret += rd[i].data_size; |
104 | #if DEBUG_GNSRECORDS | ||
105 | { | ||
106 | char *str; | ||
107 | |||
108 | str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | ||
109 | rd[i].data, | ||
110 | rd[i].data_size); | ||
111 | if (NULL == str) | ||
112 | { | ||
113 | GNUNET_break_op (0); | ||
114 | return -1; | ||
115 | } | ||
116 | GNUNET_free (str); | ||
117 | } | ||
118 | #endif | ||
119 | } | ||
120 | if (ret > SSIZE_MAX) | ||
121 | { | ||
122 | GNUNET_break (0); | ||
123 | return -1; | ||
94 | } | 124 | } |
95 | return ret; | 125 | return (ssize_t) ret; |
96 | } | 126 | } |
97 | 127 | ||
98 | 128 | ||
@@ -126,7 +156,8 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, | |||
126 | rec.data_size = htonl ((uint32_t) rd[i].data_size); | 156 | rec.data_size = htonl ((uint32_t) rd[i].data_size); |
127 | rec.record_type = htonl (rd[i].record_type); | 157 | rec.record_type = htonl (rd[i].record_type); |
128 | rec.flags = htonl (rd[i].flags); | 158 | rec.flags = htonl (rd[i].flags); |
129 | if (off + sizeof (rec) > dest_size) | 159 | if ( (off + sizeof (rec) > dest_size) || |
160 | (off + sizeof (rec) < off) ) | ||
130 | { | 161 | { |
131 | GNUNET_break (0); | 162 | GNUNET_break (0); |
132 | return -1; | 163 | return -1; |
@@ -135,7 +166,8 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, | |||
135 | &rec, | 166 | &rec, |
136 | sizeof (rec)); | 167 | sizeof (rec)); |
137 | off += sizeof (rec); | 168 | off += sizeof (rec); |
138 | if (off + rd[i].data_size > dest_size) | 169 | if ( (off + rd[i].data_size > dest_size) || |
170 | (off + rd[i].data_size < off) ) | ||
139 | { | 171 | { |
140 | GNUNET_break (0); | 172 | GNUNET_break (0); |
141 | return -1; | 173 | return -1; |
@@ -144,7 +176,7 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, | |||
144 | rd[i].data, | 176 | rd[i].data, |
145 | rd[i].data_size); | 177 | rd[i].data_size); |
146 | off += rd[i].data_size; | 178 | off += rd[i].data_size; |
147 | #if GNUNET_EXTRA_LOGGING | 179 | #if DEBUG_GNSRECORDS |
148 | { | 180 | { |
149 | char *str; | 181 | char *str; |
150 | 182 | ||
@@ -154,7 +186,7 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, | |||
154 | if (NULL == str) | 186 | if (NULL == str) |
155 | { | 187 | { |
156 | GNUNET_break_op (0); | 188 | GNUNET_break_op (0); |
157 | return GNUNET_SYSERR; | 189 | return -1; |
158 | } | 190 | } |
159 | GNUNET_free (str); | 191 | GNUNET_free (str); |
160 | } | 192 | } |
@@ -185,7 +217,8 @@ GNUNET_GNSRECORD_records_deserialize (size_t len, | |||
185 | off = 0; | 217 | off = 0; |
186 | for (unsigned int i=0;i<rd_count;i++) | 218 | for (unsigned int i=0;i<rd_count;i++) |
187 | { | 219 | { |
188 | if (off + sizeof (rec) > len) | 220 | if ( (off + sizeof (rec) > len) || |
221 | (off + sizeof (rec) < off) ) | ||
189 | { | 222 | { |
190 | GNUNET_break_op (0); | 223 | GNUNET_break_op (0); |
191 | return GNUNET_SYSERR; | 224 | return GNUNET_SYSERR; |
@@ -198,7 +231,8 @@ GNUNET_GNSRECORD_records_deserialize (size_t len, | |||
198 | dest[i].record_type = ntohl (rec.record_type); | 231 | dest[i].record_type = ntohl (rec.record_type); |
199 | dest[i].flags = ntohl (rec.flags); | 232 | dest[i].flags = ntohl (rec.flags); |
200 | off += sizeof (rec); | 233 | off += sizeof (rec); |
201 | if (off + dest[i].data_size > len) | 234 | if ( (off + dest[i].data_size > len) || |
235 | (off + dest[i].data_size < off) ) | ||
202 | { | 236 | { |
203 | GNUNET_break_op (0); | 237 | GNUNET_break_op (0); |
204 | return GNUNET_SYSERR; | 238 | return GNUNET_SYSERR; |
diff --git a/src/hostlist/test_hostlist_defaults.conf b/src/hostlist/test_hostlist_defaults.conf index 64e9acd51..dcd2790b0 100644 --- a/src/hostlist/test_hostlist_defaults.conf +++ b/src/hostlist/test_hostlist_defaults.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | 3 | ||
4 | [PATHS] | 4 | [PATHS] |
5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-hostlist/ | 5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-hostlist/ |
diff --git a/src/identity-provider/test_idp_defaults.conf b/src/identity-provider/test_idp_defaults.conf index d7de3ce12..a9a197dea 100644 --- a/src/identity-provider/test_idp_defaults.conf +++ b/src/identity-provider/test_idp_defaults.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-idp-testing/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-idp-testing/ |
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h index 38346ada3..56dadef3a 100644 --- a/src/include/gnunet_gnsrecord_lib.h +++ b/src/include/gnunet_gnsrecord_lib.h | |||
@@ -411,9 +411,9 @@ GNUNET_GNSRECORD_number_to_typename (uint32_t type); | |||
411 | * | 411 | * |
412 | * @param rd_count number of records in the @a rd array | 412 | * @param rd_count number of records in the @a rd array |
413 | * @param rd array of #GNUNET_GNSRECORD_Data with @a rd_count elements | 413 | * @param rd array of #GNUNET_GNSRECORD_Data with @a rd_count elements |
414 | * @return the required size to serialize | 414 | * @return the required size to serialize, -1 on error |
415 | */ | 415 | */ |
416 | size_t | 416 | ssize_t |
417 | GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, | 417 | GNUNET_GNSRECORD_records_get_size (unsigned int rd_count, |
418 | const struct GNUNET_GNSRECORD_Data *rd); | 418 | const struct GNUNET_GNSRECORD_Data *rd); |
419 | 419 | ||
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h index ecee1b223..fe699c48f 100644 --- a/src/include/gnunet_mq_lib.h +++ b/src/include/gnunet_mq_lib.h | |||
@@ -135,6 +135,26 @@ struct GNUNET_MQ_Envelope; | |||
135 | 135 | ||
136 | 136 | ||
137 | /** | 137 | /** |
138 | * Obtain message contained in envelope. | ||
139 | * | ||
140 | * @param env the envelope | ||
141 | * @return message contained in the envelope | ||
142 | */ | ||
143 | const struct GNUNET_MessageHeader * | ||
144 | GNUNET_MQ_env_get_msg (const struct GNUNET_MQ_Envelope *env); | ||
145 | |||
146 | |||
147 | /** | ||
148 | * Return next envelope in queue. | ||
149 | * | ||
150 | * @param env a queued envelope | ||
151 | * @return next one, or NULL | ||
152 | */ | ||
153 | const struct GNUNET_MQ_Envelope * | ||
154 | GNUNET_MQ_env_next (const struct GNUNET_MQ_Envelope *env); | ||
155 | |||
156 | |||
157 | /** | ||
138 | * Implementation of the #GNUNET_MQ_msg_nested_mh macro. | 158 | * Implementation of the #GNUNET_MQ_msg_nested_mh macro. |
139 | * | 159 | * |
140 | * @param mhp pointer to the message header pointer that will be changed to allocate at | 160 | * @param mhp pointer to the message header pointer that will be changed to allocate at |
diff --git a/src/integration-tests/confs/test_defaults.conf b/src/integration-tests/confs/test_defaults.conf index 1be582650..39020515f 100644 --- a/src/integration-tests/confs/test_defaults.conf +++ b/src/integration-tests/confs/test_defaults.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ ../../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../../contrib/conf/gnunet/no_forcestart.conf |
2 | @INLINE@ ../../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | 3 | ||
4 | [fs] | 4 | [fs] |
5 | FORCESTART = YES | 5 | FORCESTART = YES |
diff --git a/src/integration-tests/gnunet_testing.py.in b/src/integration-tests/gnunet_testing.py.in index cc3e18b06..d18f2b9f8 100644 --- a/src/integration-tests/gnunet_testing.py.in +++ b/src/integration-tests/gnunet_testing.py.in | |||
@@ -1,6 +1,6 @@ | |||
1 | #!@PYTHON@ | 1 | #!@PYTHON@ |
2 | # This file is part of GNUnet. | 2 | # This file is part of GNUnet. |
3 | # (C) 2010, 2017 Christian Grothoff (and other contributing authors) | 3 | # (C) 2010, 2017, 2018 Christian Grothoff (and other contributing authors) |
4 | # | 4 | # |
5 | # GNUnet is free software; you can redistribute it and/or modify | 5 | # GNUnet is free software; you can redistribute it and/or modify |
6 | # it under the terms of the GNU General Public License as published | 6 | # it under the terms of the GNU General Public License as published |
@@ -25,86 +25,99 @@ import shutil | |||
25 | import time | 25 | import time |
26 | from gnunet_pyexpect import pexpect | 26 | from gnunet_pyexpect import pexpect |
27 | 27 | ||
28 | |||
28 | class Check: | 29 | class Check: |
29 | def __init__(self, test): | 30 | def __init__(self, test): |
30 | self.fulfilled = False | 31 | self.fulfilled = False |
31 | self.conditions = list() | 32 | self.conditions = list() |
32 | self.test = test | 33 | self.test = test |
33 | def add (self, condition): | 34 | |
35 | def add(self, condition): | ||
34 | self.conditions.append(condition) | 36 | self.conditions.append(condition) |
35 | def run (self): | 37 | |
38 | def run(self): | ||
36 | fulfilled = True | 39 | fulfilled = True |
37 | pos = 0 | 40 | pos = 0 |
38 | neg = 0 | 41 | neg = 0 |
39 | for c in self.conditions: | 42 | for c in self.conditions: |
40 | if (False == c.check ()): | 43 | if (False == c.check()): |
41 | fulfilled = False | 44 | fulfilled = False |
42 | neg += 1 | 45 | neg += 1 |
43 | else: | 46 | else: |
44 | pos += 1 | 47 | pos += 1 |
45 | return fulfilled | 48 | return fulfilled |
46 | def run_blocking (self, timeout, pos_cont, neg_cont): | 49 | |
47 | execs = 0; | 50 | def run_blocking(self, timeout, pos_cont, neg_cont): |
51 | execs = 0 | ||
48 | res = False | 52 | res = False |
49 | while ((False == res) and (execs < timeout)): | 53 | while ((False == res) and (execs < timeout)): |
50 | res = self.run() | 54 | res = self.run() |
51 | time.sleep(1) | 55 | time.sleep(1) |
52 | execs += 1 | 56 | execs += 1 |
53 | if ((False == res) and (execs >= timeout)): | 57 | if ((False == res) and (execs >= timeout)): |
54 | print(('Check had timeout after ' +str(timeout)+ ' seconds')) | 58 | print(('Check had timeout after ' + str(timeout) + ' seconds')) |
55 | neg_cont (self) | 59 | neg_cont(self) |
56 | elif ((False == res) and (execs < timeout)): | 60 | elif ((False == res) and (execs < timeout)): |
57 | if (None != neg_cont): | 61 | if (None != neg_cont): |
58 | neg_cont (self) | 62 | neg_cont(self) |
59 | else: | 63 | else: |
60 | if (None != pos_cont): | 64 | if (None != pos_cont): |
61 | pos_cont (self) | 65 | pos_cont(self) |
62 | return res | 66 | return res |
63 | def run_once (self, pos_cont, neg_cont): | 67 | |
64 | execs = 0; | 68 | def run_once(self, pos_cont, neg_cont): |
69 | execs = 0 | ||
65 | res = False | 70 | res = False |
66 | res = self.run() | 71 | res = self.run() |
67 | if ((res == False) and (neg_cont != None)): | 72 | if ((res == False) and (neg_cont != None)): |
68 | neg_cont (self) | 73 | neg_cont(self) |
69 | if ((res == True) and (pos_cont != None)): | 74 | if ((res == True) and (pos_cont != None)): |
70 | pos_cont (self) | 75 | pos_cont(self) |
71 | return res | 76 | return res |
72 | def evaluate (self, failed_only): | 77 | |
78 | def evaluate(self, failed_only): | ||
73 | pos = 0 | 79 | pos = 0 |
74 | neg = 0 | 80 | neg = 0 |
75 | for c in self.conditions: | 81 | for c in self.conditions: |
76 | if (False == c.evaluate (failed_only)): | 82 | if (False == c.evaluate(failed_only)): |
77 | neg += 1 | 83 | neg += 1 |
78 | else: | 84 | else: |
79 | pos += 1 | 85 | pos += 1 |
80 | print((str(pos) +' out of '+ str (pos+neg) + ' conditions fulfilled')) | 86 | print((str(pos) + ' out of ' + str(pos+neg) + ' conditions fulfilled')) |
81 | return self.fulfilled | 87 | return self.fulfilled |
82 | def reset (self): | 88 | |
83 | self.fulfilled = False | 89 | def reset(self): |
84 | for c in self.conditions: | 90 | self.fulfilled = False |
85 | c.fulfilled = False | 91 | for c in self.conditions: |
86 | 92 | c.fulfilled = False | |
93 | |||
94 | |||
87 | class Condition: | 95 | class Condition: |
88 | def __init__(self): | 96 | def __init__(self): |
89 | self.fulfilled = False | 97 | self.fulfilled = False |
90 | self.type = 'generic' | 98 | self.type = 'generic' |
99 | |||
91 | def __init__(self, type): | 100 | def __init__(self, type): |
92 | self.fulfilled = False | 101 | self.fulfilled = False |
93 | self.type = type | 102 | self.type = type |
103 | |||
94 | def check(self): | 104 | def check(self): |
95 | return False; | 105 | return False |
96 | def evaluate (self, failed_only): | 106 | |
107 | def evaluate(self, failed_only): | ||
97 | if ((self.fulfilled == False) and (failed_only == True)): | 108 | if ((self.fulfilled == False) and (failed_only == True)): |
98 | print(str(self.type) + 'condition for was ' + str(self.fulfilled)) | 109 | print(str(self.type) + 'condition for was ' + str(self.fulfilled)) |
99 | elif (failed_only == False): | 110 | elif (failed_only == False): |
100 | print(str(self.type) + 'condition for was ' + str(self.fulfilled)) | 111 | print(str(self.type) + 'condition for was ' + str(self.fulfilled)) |
101 | return self.fulfilled | 112 | return self.fulfilled |
113 | |||
102 | 114 | ||
103 | class FileExistCondition (Condition): | 115 | class FileExistCondition(Condition): |
104 | def __init__(self, file): | 116 | def __init__(self, file): |
105 | self.fulfilled = False | 117 | self.fulfilled = False |
106 | self.type = 'file' | 118 | self.type = 'file' |
107 | self.file = file | 119 | self.file = file |
120 | |||
108 | def check(self): | 121 | def check(self): |
109 | if (self.fulfilled == False): | 122 | if (self.fulfilled == False): |
110 | res = os.path.isfile(self.file) | 123 | res = os.path.isfile(self.file) |
@@ -115,25 +128,28 @@ class FileExistCondition (Condition): | |||
115 | return False | 128 | return False |
116 | else: | 129 | else: |
117 | return True | 130 | return True |
118 | def evaluate (self, failed_only): | 131 | |
132 | def evaluate(self, failed_only): | ||
119 | if ((self.fulfilled == False) and (failed_only == True)): | 133 | if ((self.fulfilled == False) and (failed_only == True)): |
120 | print(str(self.type) + 'condition for file '+self.file+' was ' + str(self.fulfilled)) | 134 | print(str(self.type) + 'condition for file '+self.file+' was ' + str(self.fulfilled)) |
121 | elif (failed_only == False): | 135 | elif (failed_only == False): |
122 | print(str(self.type) + 'condition for file '+self.file+' was ' + str(self.fulfilled)) | 136 | print(str(self.type) + 'condition for file '+self.file+' was ' + str(self.fulfilled)) |
123 | return self.fulfilled | 137 | return self.fulfilled |
124 | 138 | ||
139 | |||
125 | class StatisticsCondition (Condition): | 140 | class StatisticsCondition (Condition): |
126 | def __init__(self, peer, subsystem, name, value): | 141 | def __init__(self, peer, subsystem, name, value): |
127 | self.fulfilled = False | 142 | self.fulfilled = False |
128 | self.type = 'statistics' | 143 | self.type = 'statistics' |
129 | self.peer = peer; | 144 | self.peer = peer |
130 | self.subsystem = subsystem; | 145 | self.subsystem = subsystem |
131 | self.name = name; | 146 | self.name = name |
132 | self.value = value; | 147 | self.value = value |
133 | self.result = -1; | 148 | self.result = -1 |
149 | |||
134 | def check(self): | 150 | def check(self): |
135 | if (self.fulfilled == False): | 151 | if (self.fulfilled == False): |
136 | self.result = self.peer.get_statistics_value (self.subsystem, self.name) | 152 | self.result = self.peer.get_statistics_value(self.subsystem, self.name) |
137 | if (str(self.result) == str(self.value)): | 153 | if (str(self.result) == str(self.value)): |
138 | self.fulfilled = True | 154 | self.fulfilled = True |
139 | return True | 155 | return True |
@@ -141,38 +157,41 @@ class StatisticsCondition (Condition): | |||
141 | return False | 157 | return False |
142 | else: | 158 | else: |
143 | return True | 159 | return True |
144 | def evaluate (self, failed_only): | 160 | |
161 | def evaluate(self, failed_only): | ||
145 | if (self.result == -1): | 162 | if (self.result == -1): |
146 | res = 'NaN' | 163 | res = 'NaN' |
147 | else: | 164 | else: |
148 | res = str(self.result) | 165 | res = str(self.result) |
149 | if (self.fulfilled == False): | 166 | if (self.fulfilled == False): |
150 | fail = " FAIL!" | 167 | fail = " FAIL!" |
151 | op = " != " | 168 | op = " != " |
152 | else: | 169 | else: |
153 | fail = "" | 170 | fail = "" |
154 | op = " == " | 171 | op = " == " |
155 | if (((self.fulfilled == False) and (failed_only == True)) or (failed_only == False)): | 172 | if (((self.fulfilled == False) and (failed_only == True)) or (failed_only == False)): |
156 | print(self.peer.id[:4] + " " +self.peer.cfg + " " + str(self.type) + ' condition in subsystem "' + self.subsystem.ljust(12) +'" : "' + self.name.ljust(30) +'" : (expected/real value) ' + str(self.value) + op + res + fail) | 173 | print(self.peer.id[:4] + " " + self.peer.cfg + " " + str(self.type) + ' condition in subsystem "' + self.subsystem.ljust(12) + '" : "' + self.name.ljust(30) + '" : (expected/real value) ' + str(self.value) + op + res + fail) |
157 | return self.fulfilled | 174 | return self.fulfilled |
158 | 175 | ||
159 | # Specify two statistic values and check if they are equal | 176 | |
177 | # Specify two statistic values and check if they are equal | ||
160 | class EqualStatisticsCondition (Condition): | 178 | class EqualStatisticsCondition (Condition): |
161 | def __init__(self, peer, subsystem, name, peer2, subsystem2, name2): | 179 | def __init__(self, peer, subsystem, name, peer2, subsystem2, name2): |
162 | self.fulfilled = False | 180 | self.fulfilled = False |
163 | self.type = 'equalstatistics' | 181 | self.type = 'equalstatistics' |
164 | self.peer = peer; | 182 | self.peer = peer |
165 | self.subsystem = subsystem; | 183 | self.subsystem = subsystem |
166 | self.name = name; | 184 | self.name = name |
167 | self.result = -1; | 185 | self.result = -1 |
168 | self.peer2 = peer2; | 186 | self.peer2 = peer2 |
169 | self.subsystem2 = subsystem2; | 187 | self.subsystem2 = subsystem2 |
170 | self.name2 = name2; | 188 | self.name2 = name2 |
171 | self.result2 = -1; | 189 | self.result2 = -1 |
190 | |||
172 | def check(self): | 191 | def check(self): |
173 | if (self.fulfilled == False): | 192 | if (self.fulfilled == False): |
174 | self.result = self.peer.get_statistics_value (self.subsystem, self.name); | 193 | self.result = self.peer.get_statistics_value(self.subsystem, self.name) |
175 | self.result2 = self.peer2.get_statistics_value (self.subsystem2, self.name2); | 194 | self.result2 = self.peer2.get_statistics_value(self.subsystem2, self.name2) |
176 | if (str(self.result) == str(self.result2)): | 195 | if (str(self.result) == str(self.result2)): |
177 | self.fulfilled = True | 196 | self.fulfilled = True |
178 | return True | 197 | return True |
@@ -180,7 +199,8 @@ class EqualStatisticsCondition (Condition): | |||
180 | return False | 199 | return False |
181 | else: | 200 | else: |
182 | return True | 201 | return True |
183 | def evaluate (self, failed_only): | 202 | |
203 | def evaluate(self, failed_only): | ||
184 | if (self.result == -1): | 204 | if (self.result == -1): |
185 | res = 'NaN' | 205 | res = 'NaN' |
186 | else: | 206 | else: |
@@ -188,27 +208,28 @@ class EqualStatisticsCondition (Condition): | |||
188 | if (self.result2 == -1): | 208 | if (self.result2 == -1): |
189 | res2 = 'NaN' | 209 | res2 = 'NaN' |
190 | else: | 210 | else: |
191 | res2 = str(self.result2) | 211 | res2 = str(self.result2) |
192 | if (self.fulfilled == False): | 212 | if (self.fulfilled == False): |
193 | fail = " FAIL!" | 213 | fail = " FAIL!" |
194 | op = " != " | 214 | op = " != " |
195 | else: | 215 | else: |
196 | fail = "" | 216 | fail = "" |
197 | op = " == " | 217 | op = " == " |
198 | if (((self.fulfilled == False) and (failed_only == True)) or (failed_only == False)): | 218 | if (((self.fulfilled == False) and (failed_only == True)) or (failed_only == False)): |
199 | print(self.peer.id[:4] + ' "' + self.subsystem.ljust(12) + '" "' + self.name.ljust(30) + '" == ' + str(self.result) +" " + self.peer2.id[:4] + ' "' + self.subsystem2.ljust(12) + '" '+ self.name2.ljust(30) + '" ' + str(self.result2)) | 219 | print(self.peer.id[:4] + ' "' + self.subsystem.ljust(12) + '" "' + self.name.ljust(30) + '" == ' + str(self.result) + " " + self.peer2.id[:4] + ' "' + self.subsystem2.ljust(12) + '" ' + self.name2.ljust(30) + '" ' + str(self.result2)) |
200 | return self.fulfilled | 220 | return self.fulfilled |
201 | 221 | ||
222 | |||
202 | class Test: | 223 | class Test: |
203 | def __init__(self, testname, verbose): | 224 | def __init__(self, testname, verbose): |
204 | self.peers = list() | 225 | self.peers = list() |
205 | self.verbose = verbose; | 226 | self.verbose = verbose |
206 | self.name = testname; | 227 | self.name = testname |
207 | srcdir = "../.." | 228 | srcdir = "../.." |
208 | gnunet_pyexpect_dir = os.path.join (srcdir, "contrib") | 229 | gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts") |
209 | if gnunet_pyexpect_dir not in sys.path: | 230 | if gnunet_pyexpect_dir not in sys.path: |
210 | sys.path.append (gnunet_pyexpect_dir) | 231 | sys.path.append(gnunet_pyexpect_dir) |
211 | self.gnunetarm = '' | 232 | self.gnunetarm = '' |
212 | self.gnunetstatistics = '' | 233 | self.gnunetstatistics = '' |
213 | if os.name == 'posix': | 234 | if os.name == 'posix': |
214 | self.gnunetarm = 'gnunet-arm' | 235 | self.gnunetarm = 'gnunet-arm' |
@@ -217,17 +238,20 @@ class Test: | |||
217 | elif os.name == 'nt': | 238 | elif os.name == 'nt': |
218 | self.gnunetarm = 'gnunet-arm.exe' | 239 | self.gnunetarm = 'gnunet-arm.exe' |
219 | self.gnunetstatistics = 'gnunet-statistics.exe' | 240 | self.gnunetstatistics = 'gnunet-statistics.exe' |
220 | self.gnunetpeerinfo = 'gnunet-peerinfo.exe' | 241 | self.gnunetpeerinfo = 'gnunet-peerinfo.exe' |
221 | if os.name == "nt": | 242 | if os.name == "nt": |
222 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), testname), True) | 243 | shutil.rmtree(os.path.join(os.getenv("TEMP"), testname), True) |
223 | else: | 244 | else: |
224 | shutil.rmtree ("/tmp/" + testname, True) | 245 | shutil.rmtree("/tmp/" + testname, True) |
225 | def add_peer (self, peer): | 246 | |
247 | def add_peer(self, peer): | ||
226 | self.peers.append(peer) | 248 | self.peers.append(peer) |
227 | def p (self, msg): | 249 | |
250 | def p(self, msg): | ||
228 | if (self.verbose == True): | 251 | if (self.verbose == True): |
229 | print(msg) | 252 | print(msg) |
230 | 253 | ||
254 | |||
231 | class Peer: | 255 | class Peer: |
232 | def __init__(self, test, cfg_file): | 256 | def __init__(self, test, cfg_file): |
233 | if (False == os.path.isfile(cfg_file)): | 257 | if (False == os.path.isfile(cfg_file)): |
@@ -235,53 +259,57 @@ class Peer: | |||
235 | self.id = "<NaN>" | 259 | self.id = "<NaN>" |
236 | self.test = test | 260 | self.test = test |
237 | self.started = False | 261 | self.started = False |
238 | self.cfg = cfg_file | 262 | self.cfg = cfg_file |
263 | |||
239 | def __del__(self): | 264 | def __del__(self): |
240 | if (self.started == True): | 265 | if (self.started == True): |
241 | print('ERROR! Peer using cfg ' + self.cfg + ' was not stopped') | 266 | print('ERROR! Peer using cfg ' + self.cfg + ' was not stopped') |
242 | ret = self.stop () | 267 | ret = self.stop() |
243 | if (False == ret): | 268 | if (False == ret): |
244 | print('ERROR! Peer using cfg ' + self.cfg + ' could not be stopped') | 269 | print('ERROR! Peer using cfg ' + self.cfg + ' could not be stopped') |
245 | self.started = False | 270 | self.started = False |
246 | return ret | 271 | return ret |
247 | else: | 272 | else: |
248 | return False | 273 | return False |
249 | def start (self): | 274 | |
250 | self.test.p ("Starting peer using cfg " + self.cfg) | 275 | def start(self): |
276 | self.test.p("Starting peer using cfg " + self.cfg) | ||
251 | try: | 277 | try: |
252 | server = subprocess.Popen ([self.test.gnunetarm, '-sq', '-c', self.cfg]) | 278 | server = subprocess.Popen([self.test.gnunetarm, '-sq', '-c', self.cfg]) |
253 | server.communicate () | 279 | server.communicate() |
254 | except OSError: | 280 | except OSError: |
255 | print("Can not start peer") | 281 | print("Can not start peer") |
256 | self.started = False | 282 | self.started = False |
257 | return False | 283 | return False |
258 | self.started = True; | 284 | self.started = True |
259 | test = '' | 285 | test = '' |
260 | try: | 286 | try: |
261 | server = pexpect () | 287 | server = pexpect() |
262 | server.spawn (None, [self.test.gnunetpeerinfo, '-c', self.cfg ,'-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 288 | server.spawn(None, [self.test.gnunetpeerinfo, '-c', self.cfg, '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
263 | test = server.read("stdout", 1024) | 289 | test = server.read("stdout", 1024) |
264 | except OSError: | 290 | except OSError: |
265 | print("Can not get peer identity") | 291 | print("Can not get peer identity") |
266 | test = (test.split('`')[1]) | 292 | test = (test.split('`')[1]) |
267 | self.id = test.split('\'')[0] | 293 | self.id = test.split('\'')[0] |
268 | return True | 294 | return True |
269 | def stop (self): | 295 | |
296 | def stop(self): | ||
270 | if (self.started == False): | 297 | if (self.started == False): |
271 | return False | 298 | return False |
272 | self.test.p ("Stopping peer using cfg " + self.cfg) | 299 | self.test.p("Stopping peer using cfg " + self.cfg) |
273 | try: | 300 | try: |
274 | server = subprocess.Popen ([self.test.gnunetarm, '-eq', '-c', self.cfg]) | 301 | server = subprocess.Popen([self.test.gnunetarm, '-eq', '-c', self.cfg]) |
275 | server.communicate () | 302 | server.communicate() |
276 | except OSError: | 303 | except OSError: |
277 | print("Can not stop peer") | 304 | print("Can not stop peer") |
278 | return False | 305 | return False |
279 | self.started = False | 306 | self.started = False |
280 | return True; | 307 | return True |
281 | def get_statistics_value (self, subsystem, name): | 308 | |
282 | server = pexpect () | 309 | def get_statistics_value(self, subsystem, name): |
283 | server.spawn (None, [self.test.gnunetstatistics, '-c', self.cfg ,'-q','-n', name, '-s', subsystem ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 310 | server = pexpect() |
284 | #server.expect ("stdout", re.compile (r"")) | 311 | server.spawn(None, [self.test.gnunetstatistics, '-c', self.cfg, '-q', '-n', name, '-s', subsystem], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
312 | # server.expect ("stdout", re.compile (r"")) | ||
285 | test = server.read("stdout", 10240) | 313 | test = server.read("stdout", 10240) |
286 | tests = test.partition('\n') | 314 | tests = test.partition('\n') |
287 | # On W32 GNUnet outputs with \r\n, rather than \n | 315 | # On W32 GNUnet outputs with \r\n, rather than \n |
@@ -292,4 +320,3 @@ class Peer: | |||
292 | return tests | 320 | return tests |
293 | else: | 321 | else: |
294 | return -1 | 322 | return -1 |
295 | |||
diff --git a/src/integration-tests/test_integration_bootstrap_and_connect.py.in b/src/integration-tests/test_integration_bootstrap_and_connect.py.in index 01e36f81c..2a7768c6a 100755 --- a/src/integration-tests/test_integration_bootstrap_and_connect.py.in +++ b/src/integration-tests/test_integration_bootstrap_and_connect.py.in | |||
@@ -17,7 +17,7 @@ | |||
17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | # Boston, MA 02110-1301, USA. | 18 | # Boston, MA 02110-1301, USA. |
19 | # | 19 | # |
20 | # | 20 | # |
21 | import signal | 21 | import signal |
22 | import sys | 22 | import sys |
23 | import os | 23 | import os |
@@ -29,177 +29,183 @@ from gnunet_testing import Peer | |||
29 | from gnunet_testing import Test | 29 | from gnunet_testing import Test |
30 | from gnunet_testing import Check | 30 | from gnunet_testing import Check |
31 | from gnunet_testing import Condition | 31 | from gnunet_testing import Condition |
32 | from gnunet_testing import * | 32 | from gnunet_testing import * |
33 | 33 | ||
34 | 34 | ||
35 | # | 35 | # |
36 | # This test tests if a fresh peer bootstraps from a hostlist server and then | 36 | # This test tests if a fresh peer bootstraps from a hostlist server and then |
37 | # successfully connects to the server | 37 | # successfully connects to the server |
38 | # | 38 | # |
39 | # Conditions for successful exit: | 39 | # Conditions for successful exit: |
40 | # Both peers have 1 connected peer in transport, core, topology, fs | 40 | # Both peers have 1 connected peer in transport, core, topology, fs |
41 | 41 | ||
42 | # | 42 | # |
43 | # This test tests if a fresh peer bootstraps from a hostlist server and then | 43 | # This test tests if a fresh peer bootstraps from a hostlist server and then |
44 | # successfully connects to the server | 44 | # successfully connects to the server |
45 | # | 45 | # |
46 | # Conditions for successful exit: | 46 | # Conditions for successful exit: |
47 | # Both peers have 1 connected peer in transport, core, topology, fs | 47 | # Both peers have 1 connected peer in transport, core, topology, fs |
48 | 48 | ||
49 | #definitions | 49 | # definitions |
50 | 50 | ||
51 | testname = "test_integration_bootstrap_and_connect" | 51 | testname = "test_integration_bootstrap_and_connect" |
52 | verbose = False | 52 | verbose = False |
53 | check_timeout = 180 | 53 | check_timeout = 180 |
54 | 54 | ||
55 | if os.name == "nt": | 55 | if os.name == "nt": |
56 | tmp = os.getenv ("TEMP") | 56 | tmp = os.getenv("TEMP") |
57 | signals = [signal.SIGTERM, signal.SIGINT] | 57 | signals = [signal.SIGTERM, signal.SIGINT] |
58 | else: | 58 | else: |
59 | tmp = "/tmp" | 59 | tmp = "/tmp" |
60 | signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] | 60 | signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] |
61 | 61 | ||
62 | def cleanup_onerror (function, path, excinfo): | 62 | |
63 | import stat | 63 | def cleanup_onerror(function, path, excinfo): |
64 | if not os.path.exists (path): | 64 | import stat |
65 | pass | 65 | if not os.path.exists(path): |
66 | elif not os.access(path, os.W_OK): | 66 | pass |
67 | # Is the error an access error ? | 67 | elif not os.access(path, os.W_OK): |
68 | os.chmod (path, stat.S_IWUSR) | 68 | # Is the error an access error ? |
69 | function (path) | 69 | os.chmod(path, stat.S_IWUSR) |
70 | else: | 70 | function(path) |
71 | raise | 71 | else: |
72 | 72 | raise | |
73 | def cleanup (): | 73 | |
74 | |||
75 | def cleanup(): | ||
74 | retries = 10 | 76 | retries = 10 |
75 | path = os.path.join (tmp, "c_bootstrap_server") | 77 | path = os.path.join(tmp, "c_bootstrap_server") |
76 | test.p ("Removing " + path) | 78 | test.p("Removing " + path) |
77 | while ((os.path.exists(path)) and (retries > 0)): | 79 | while ((os.path.exists(path)) and (retries > 0)): |
78 | shutil.rmtree ((path), False, cleanup_onerror) | 80 | shutil.rmtree((path), False, cleanup_onerror) |
79 | time.sleep (1) | 81 | time.sleep(1) |
80 | retries -= 1 | 82 | retries -= 1 |
81 | if (os.path.exists(path)): | 83 | if (os.path.exists(path)): |
82 | test.p ("Failed to remove " + path) | 84 | test.p("Failed to remove " + path) |
83 | 85 | ||
84 | |||
85 | retries = 10 | 86 | retries = 10 |
86 | path = os.path.join (tmp, "c_no_nat_client") | 87 | path = os.path.join(tmp, "c_no_nat_client") |
87 | test.p ("Removing " + path) | 88 | test.p("Removing " + path) |
88 | while ((os.path.exists(path)) and (retries > 0)): | 89 | while ((os.path.exists(path)) and (retries > 0)): |
89 | shutil.rmtree ((path), False, cleanup_onerror) | 90 | shutil.rmtree((path), False, cleanup_onerror) |
90 | time.sleep (1) | 91 | time.sleep(1) |
91 | retries -= 1 | 92 | retries -= 1 |
92 | if (os.path.exists(path)): | 93 | if (os.path.exists(path)): |
93 | test.p ("Failed to remove " + path) | 94 | test.p("Failed to remove " + path) |
94 | 95 | ||
95 | def success_cont (check): | 96 | |
97 | def success_cont(check): | ||
96 | global success | 98 | global success |
97 | success = True; | 99 | success = True |
98 | print('Peers connected successfully') | 100 | print('Peers connected successfully') |
99 | 101 | ||
100 | def fail_cont (check): | 102 | |
101 | global success | 103 | def fail_cont(check): |
102 | success = False; | 104 | global success |
105 | success = False | ||
103 | print('Peers did not connect') | 106 | print('Peers did not connect') |
104 | check.evaluate(True) | 107 | check.evaluate(True) |
105 | 108 | ||
106 | def check (): | 109 | |
107 | check = Check (test) | 110 | def check(): |
108 | check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) | 111 | check = Check(test) |
109 | check.add (StatisticsCondition (client, 'core', '# peers connected',1)) | 112 | check.add(StatisticsCondition(client, 'transport', '# peers connected', 1)) |
110 | check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) | 113 | check.add(StatisticsCondition(client, 'core', '# peers connected', 1)) |
111 | check.add (StatisticsCondition (client, 'dht', '# peers connected',1)) | 114 | check.add(StatisticsCondition(client, 'topology', '# peers connected', 1)) |
112 | check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) | 115 | check.add(StatisticsCondition(client, 'dht', '# peers connected', 1)) |
113 | 116 | check.add(StatisticsCondition(client, 'fs', '# peers connected', 1)) | |
114 | check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) | 117 | |
115 | check.add (StatisticsCondition (server, 'core', '# peers connected',1)) | 118 | check.add(StatisticsCondition(server, 'transport', '# peers connected', 1)) |
116 | check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) | 119 | check.add(StatisticsCondition(server, 'core', '# peers connected', 1)) |
117 | check.add (StatisticsCondition (server, 'dht', '# peers connected',1)) | 120 | check.add(StatisticsCondition(server, 'topology', '# peers connected', 1)) |
118 | check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) | 121 | check.add(StatisticsCondition(server, 'dht', '# peers connected', 1)) |
119 | 122 | check.add(StatisticsCondition(server, 'fs', '# peers connected', 1)) | |
120 | check.run_blocking (check_timeout, success_cont, fail_cont) | 123 | |
121 | 124 | check.run_blocking(check_timeout, success_cont, fail_cont) | |
122 | # | 125 | |
126 | # | ||
123 | # Test execution | 127 | # Test execution |
124 | # | 128 | # |
125 | 129 | ||
126 | def SigHandler(signum = None, frame = None): | 130 | |
127 | global success | 131 | def SigHandler(signum=None, frame=None): |
128 | global server | 132 | global success |
129 | global client | 133 | global server |
130 | 134 | global client | |
131 | print('Test was aborted!') | 135 | |
132 | if (None != server): | 136 | print('Test was aborted!') |
133 | server.stop () | 137 | if (None != server): |
134 | if (None != client): | 138 | server.stop() |
135 | client.stop () | 139 | if (None != client): |
136 | cleanup () | 140 | client.stop() |
137 | sys.exit(success) | 141 | cleanup() |
138 | 142 | sys.exit(success) | |
139 | def run (): | 143 | |
140 | global success | 144 | |
141 | global test | 145 | def run(): |
142 | global server | 146 | global success |
143 | global client | 147 | global test |
144 | 148 | global server | |
145 | server = None | 149 | global client |
146 | client = None | 150 | |
147 | success = False | 151 | server = None |
148 | 152 | client = None | |
149 | for sig in signals: | 153 | success = False |
150 | signal.signal(sig, SigHandler) | 154 | |
151 | 155 | for sig in signals: | |
152 | test = Test ('test_integration_bootstrap_and_connect.py', verbose) | 156 | signal.signal(sig, SigHandler) |
153 | cleanup () | 157 | |
154 | 158 | test = Test('test_integration_bootstrap_and_connect.py', verbose) | |
155 | server = Peer(test, './confs/c_bootstrap_server.conf'); | 159 | cleanup() |
156 | client = Peer(test, './confs/c_no_nat_client.conf'); | 160 | |
157 | 161 | server = Peer(test, './confs/c_bootstrap_server.conf') | |
158 | if (True != server.start()): | 162 | client = Peer(test, './confs/c_no_nat_client.conf') |
159 | print('Failed to start server') | 163 | |
160 | if (None != server): | 164 | if (True != server.start()): |
161 | server.stop () | 165 | print('Failed to start server') |
162 | if (None != server): | 166 | if (None != server): |
163 | client.stop () | 167 | server.stop() |
164 | cleanup () | 168 | if (None != server): |
165 | sys.exit(success) | 169 | client.stop() |
166 | 170 | cleanup() | |
167 | # Give the server time to start | 171 | sys.exit(success) |
168 | time.sleep(5) | 172 | |
169 | 173 | # Give the server time to start | |
170 | if (True != client.start()): | 174 | time.sleep(5) |
171 | print('Failed to start client') | 175 | |
172 | if (None != server): | 176 | if (True != client.start()): |
173 | server.stop () | 177 | print('Failed to start client') |
174 | if (None != server): | 178 | if (None != server): |
175 | client.stop () | 179 | server.stop() |
176 | cleanup () | 180 | if (None != server): |
177 | sys.exit(success) | 181 | client.stop() |
178 | 182 | cleanup() | |
179 | if ((client.started == True) and (server.started == True)): | 183 | sys.exit(success) |
180 | test.p ('Peers started, running check') | 184 | |
181 | time.sleep(5) | 185 | if ((client.started == True) and (server.started == True)): |
182 | check () | 186 | test.p('Peers started, running check') |
183 | server.stop () | 187 | time.sleep(5) |
184 | client.stop () | 188 | check() |
185 | 189 | server.stop() | |
186 | cleanup () | 190 | client.stop() |
187 | 191 | ||
188 | if (success == False): | 192 | cleanup() |
189 | print ('Test failed') | 193 | |
190 | return False | 194 | if (success == False): |
191 | else: | 195 | print('Test failed') |
192 | return True | 196 | return False |
197 | else: | ||
198 | return True | ||
199 | |||
193 | 200 | ||
194 | try: | 201 | try: |
195 | run () | 202 | run() |
196 | except (KeyboardInterrupt, SystemExit): | 203 | except (KeyboardInterrupt, SystemExit): |
197 | print('Test interrupted') | 204 | print('Test interrupted') |
198 | server.stop () | 205 | server.stop() |
199 | client.stop () | 206 | client.stop() |
200 | cleanup () | 207 | cleanup() |
201 | if (success == False): | 208 | if (success == False): |
202 | sys.exit(1) | 209 | sys.exit(1) |
203 | else: | 210 | else: |
204 | sys.exit(0) | 211 | sys.exit(0) |
205 | |||
diff --git a/src/integration-tests/test_integration_clique.py.in b/src/integration-tests/test_integration_clique.py.in index f8b60f33d..b4c53da58 100755 --- a/src/integration-tests/test_integration_clique.py.in +++ b/src/integration-tests/test_integration_clique.py.in | |||
@@ -17,13 +17,13 @@ | |||
17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | # Boston, MA 02110-1301, USA. | 18 | # Boston, MA 02110-1301, USA. |
19 | # | 19 | # |
20 | # | ||
21 | # | 20 | # |
22 | # This test starts 3 peers (nated, server, no nat)and expects bootstrap | 21 | # |
22 | # This test starts 3 peers (nated, server, no nat)and expects bootstrap | ||
23 | # and a connected clique | 23 | # and a connected clique |
24 | # | 24 | # |
25 | # Conditions for successful exit: | 25 | # Conditions for successful exit: |
26 | # Both peers have 2 connected peers in transport, core, topology, fs and dht | 26 | # Both peers have 2 connected peers in transport, core, topology, fs and dht |
27 | 27 | ||
28 | import sys | 28 | import sys |
29 | import signal | 29 | import signal |
@@ -36,192 +36,195 @@ from gnunet_testing import Peer | |||
36 | from gnunet_testing import Test | 36 | from gnunet_testing import Test |
37 | from gnunet_testing import Check | 37 | from gnunet_testing import Check |
38 | from gnunet_testing import Condition | 38 | from gnunet_testing import Condition |
39 | from gnunet_testing import * | 39 | from gnunet_testing import * |
40 | 40 | ||
41 | if os.name == "nt": | 41 | if os.name == "nt": |
42 | tmp = os.getenv ("TEMP") | 42 | tmp = os.getenv("TEMP") |
43 | else: | 43 | else: |
44 | tmp = "/tmp" | 44 | tmp = "/tmp" |
45 | 45 | ||
46 | #definitions | 46 | # definitions |
47 | 47 | ||
48 | testname = "test_integration_clique" | 48 | testname = "test_integration_clique" |
49 | verbose = True | 49 | verbose = True |
50 | check_timeout = 180 | 50 | check_timeout = 180 |
51 | 51 | ||
52 | def cleanup_onerror (function, path, excinfo): | 52 | |
53 | import stat | 53 | def cleanup_onerror(function, path, excinfo): |
54 | if not os.path.exists (path): | 54 | import stat |
55 | pass | 55 | if not os.path.exists(path): |
56 | elif not os.access(path, os.W_OK): | 56 | pass |
57 | # Is the error an access error ? | 57 | elif not os.access(path, os.W_OK): |
58 | os.chmod (path, stat.S_IWUSR) | 58 | # Is the error an access error ? |
59 | function (path) | 59 | os.chmod(path, stat.S_IWUSR) |
60 | else: | 60 | function(path) |
61 | raise | 61 | else: |
62 | 62 | raise | |
63 | def cleanup (): | 63 | |
64 | |||
65 | def cleanup(): | ||
64 | retries = 10 | 66 | retries = 10 |
65 | path = os.path.join (tmp, "c_bootstrap_server") | 67 | path = os.path.join(tmp, "c_bootstrap_server") |
66 | test.p ("Removing " + path) | 68 | test.p("Removing " + path) |
67 | while ((os.path.exists(path)) and (retries > 0)): | 69 | while ((os.path.exists(path)) and (retries > 0)): |
68 | shutil.rmtree ((path), False, cleanup_onerror) | 70 | shutil.rmtree((path), False, cleanup_onerror) |
69 | time.sleep (1) | 71 | time.sleep(1) |
70 | retries -= 1 | 72 | retries -= 1 |
71 | if (os.path.exists(path)): | 73 | if (os.path.exists(path)): |
72 | test.p ("Failed to remove " + path) | 74 | test.p("Failed to remove " + path) |
73 | retries = 10 | 75 | retries = 10 |
74 | path = os.path.join (tmp, "c_no_nat_client") | 76 | path = os.path.join(tmp, "c_no_nat_client") |
75 | test.p ("Removing " + path) | 77 | test.p("Removing " + path) |
76 | while ((os.path.exists(path)) and (retries > 0)): | 78 | while ((os.path.exists(path)) and (retries > 0)): |
77 | shutil.rmtree ((path), False, cleanup_onerror) | 79 | shutil.rmtree((path), False, cleanup_onerror) |
78 | time.sleep (1) | 80 | time.sleep(1) |
79 | retries -= 1 | 81 | retries -= 1 |
80 | if (os.path.exists(path)): | 82 | if (os.path.exists(path)): |
81 | test.p ("Failed to remove " + path) | 83 | test.p("Failed to remove " + path) |
82 | retries = 10 | 84 | retries = 10 |
83 | path = os.path.join (tmp, "c_nat_client") | 85 | path = os.path.join(tmp, "c_nat_client") |
84 | test.p ("Removing " + path) | 86 | test.p("Removing " + path) |
85 | while ((os.path.exists(path)) and (retries > 0)): | 87 | while ((os.path.exists(path)) and (retries > 0)): |
86 | shutil.rmtree ((path), False, cleanup_onerror) | 88 | shutil.rmtree((path), False, cleanup_onerror) |
87 | time.sleep (1) | 89 | time.sleep(1) |
88 | retries -= 1 | 90 | retries -= 1 |
89 | if (os.path.exists(path)): | 91 | if (os.path.exists(path)): |
90 | test.p ("Failed to remove " + path) | 92 | test.p("Failed to remove " + path) |
91 | 93 | ||
92 | 94 | ||
93 | def success_cont (check): | 95 | def success_cont(check): |
94 | global success | 96 | global success |
95 | success = True; | 97 | success = True |
96 | print('Connected clique successfully') | 98 | print('Connected clique successfully') |
97 | 99 | ||
98 | def fail_cont (check): | 100 | |
99 | global success | 101 | def fail_cont(check): |
100 | success= False; | 102 | global success |
103 | success = False | ||
101 | check.evaluate(True) | 104 | check.evaluate(True) |
102 | print('Failed to connect clique') | 105 | print('Failed to connect clique') |
103 | 106 | ||
104 | def check_connect (): | 107 | |
105 | check = Check (test) | 108 | def check_connect(): |
106 | check.add (StatisticsCondition (client, 'transport', '# peers connected',2)) | 109 | check = Check(test) |
107 | check.add (StatisticsCondition (client, 'core', '# peers connected',2)) | 110 | check.add(StatisticsCondition(client, 'transport', '# peers connected', 2)) |
108 | check.add (StatisticsCondition (client, 'topology', '# peers connected',2)) | 111 | check.add(StatisticsCondition(client, 'core', '# peers connected', 2)) |
109 | check.add (StatisticsCondition (client, 'dht', '# peers connected',2)) | 112 | check.add(StatisticsCondition(client, 'topology', '# peers connected', 2)) |
110 | check.add (StatisticsCondition (client, 'fs', '# peers connected',2)) | 113 | check.add(StatisticsCondition(client, 'dht', '# peers connected', 2)) |
111 | 114 | check.add(StatisticsCondition(client, 'fs', '# peers connected', 2)) | |
112 | check.add (StatisticsCondition (client_nat, 'transport', '# peers connected',2)) | 115 | |
113 | check.add (StatisticsCondition (client_nat, 'core', '# peers connected',2)) | 116 | check.add(StatisticsCondition(client_nat, 'transport', '# peers connected', 2)) |
114 | check.add (StatisticsCondition (client_nat, 'topology', '# peers connected',2)) | 117 | check.add(StatisticsCondition(client_nat, 'core', '# peers connected', 2)) |
115 | check.add (StatisticsCondition (client_nat, 'dht', '# peers connected',2)) | 118 | check.add(StatisticsCondition(client_nat, 'topology', '# peers connected', 2)) |
116 | check.add (StatisticsCondition (client_nat, 'fs', '# peers connected',2)) | 119 | check.add(StatisticsCondition(client_nat, 'dht', '# peers connected', 2)) |
117 | 120 | check.add(StatisticsCondition(client_nat, 'fs', '# peers connected', 2)) | |
118 | check.add (StatisticsCondition (server, 'transport', '# peers connected',2)) | 121 | |
119 | check.add (StatisticsCondition (server, 'core', '# peers connected',2)) | 122 | check.add(StatisticsCondition(server, 'transport', '# peers connected', 2)) |
120 | check.add (StatisticsCondition (server, 'topology', '# peers connected',2)) | 123 | check.add(StatisticsCondition(server, 'core', '# peers connected', 2)) |
121 | check.add (StatisticsCondition (server, 'dht', '# peers connected',2)) | 124 | check.add(StatisticsCondition(server, 'topology', '# peers connected', 2)) |
122 | check.add (StatisticsCondition (server, 'fs', '# peers connected',2)) | 125 | check.add(StatisticsCondition(server, 'dht', '# peers connected', 2)) |
123 | 126 | check.add(StatisticsCondition(server, 'fs', '# peers connected', 2)) | |
124 | check.run_blocking (check_timeout, success_cont, fail_cont) | 127 | |
125 | 128 | check.run_blocking(check_timeout, success_cont, fail_cont) | |
126 | # | 129 | |
130 | # | ||
127 | # Test execution | 131 | # Test execution |
128 | # | 132 | # |
129 | 133 | ||
130 | def SigHandler(signum = None, frame = None): | 134 | |
131 | global success | 135 | def SigHandler(signum=None, frame=None): |
132 | global server | 136 | global success |
133 | global client | 137 | global server |
134 | global client_nat | 138 | global client |
135 | 139 | global client_nat | |
136 | print('Test was aborted!') | 140 | |
137 | if (None != server): | 141 | print('Test was aborted!') |
138 | server.stop () | 142 | if (None != server): |
139 | if (None != client): | 143 | server.stop() |
140 | client.stop () | 144 | if (None != client): |
141 | if (None != client_nat): | 145 | client.stop() |
142 | client_nat.stop () | 146 | if (None != client_nat): |
143 | cleanup () | 147 | client_nat.stop() |
144 | sys.exit(success) | 148 | cleanup() |
145 | 149 | sys.exit(success) | |
146 | def run (): | 150 | |
147 | global success | 151 | |
148 | global test | 152 | def run(): |
149 | global server | 153 | global success |
150 | global client | 154 | global test |
151 | global client_nat | 155 | global server |
152 | 156 | global client | |
153 | success = False | 157 | global client_nat |
154 | server = None | 158 | |
155 | client = None | 159 | success = False |
156 | client_nat = None | 160 | server = None |
157 | test = Test ('test_integration_clique', verbose) | 161 | client = None |
158 | cleanup () | 162 | client_nat = None |
159 | 163 | test = Test('test_integration_clique', verbose) | |
160 | server = Peer(test, './confs/c_bootstrap_server.conf'); | 164 | cleanup() |
161 | if (True != server.start()): | 165 | |
162 | print('Failed to start server') | 166 | server = Peer(test, './confs/c_bootstrap_server.conf') |
163 | if (None != server): | 167 | if (True != server.start()): |
164 | server.stop () | 168 | print('Failed to start server') |
165 | cleanup () | 169 | if (None != server): |
166 | sys.exit(success) | 170 | server.stop() |
167 | 171 | cleanup() | |
168 | # Server has to settle down | 172 | sys.exit(success) |
169 | time.sleep(5) | 173 | |
170 | 174 | # Server has to settle down | |
171 | client = Peer(test, './confs/c_no_nat_client.conf'); | 175 | time.sleep(5) |
172 | if (True != client.start()): | 176 | |
173 | print('Failed to start client') | 177 | client = Peer(test, './confs/c_no_nat_client.conf') |
174 | if (None != server): | 178 | if (True != client.start()): |
175 | server.stop () | 179 | print('Failed to start client') |
176 | if (None != client): | 180 | if (None != server): |
177 | client.stop () | 181 | server.stop() |
178 | cleanup () | 182 | if (None != client): |
179 | sys.exit(success) | 183 | client.stop() |
180 | 184 | cleanup() | |
181 | # Server has to settle down | 185 | sys.exit(success) |
182 | time.sleep(5) | 186 | |
183 | 187 | # Server has to settle down | |
184 | 188 | time.sleep(5) | |
185 | client_nat = Peer(test, './confs/c_nat_client.conf'); | 189 | |
186 | if (True != client_nat.start()): | 190 | client_nat = Peer(test, './confs/c_nat_client.conf') |
187 | print('Failed to start client_nat') | 191 | if (True != client_nat.start()): |
188 | if (None != server): | 192 | print('Failed to start client_nat') |
189 | server.stop () | 193 | if (None != server): |
190 | if (None != client): | 194 | server.stop() |
191 | client.stop () | 195 | if (None != client): |
192 | if (None != client_nat): | 196 | client.stop() |
193 | client_nat.stop () | 197 | if (None != client_nat): |
194 | cleanup () | 198 | client_nat.stop() |
195 | sys.exit(success) | 199 | cleanup() |
196 | 200 | sys.exit(success) | |
197 | if ((client.started == True) and (client_nat.started == True) and (server.started == True)): | 201 | |
198 | test.p ('Peers started, running check') | 202 | if ((client.started == True) and (client_nat.started == True) and (server.started == True)): |
199 | check_connect () | 203 | test.p('Peers started, running check') |
200 | 204 | check_connect() | |
201 | server.stop () | 205 | |
202 | client.stop () | 206 | server.stop() |
203 | client_nat.stop () | 207 | client.stop() |
204 | 208 | client_nat.stop() | |
205 | cleanup () | 209 | |
206 | 210 | cleanup() | |
207 | if (success == False): | 211 | |
208 | print ('Test failed') | 212 | if (success == False): |
209 | return False | 213 | print('Test failed') |
210 | else: | 214 | return False |
211 | return True | 215 | else: |
212 | 216 | return True | |
213 | 217 | ||
218 | |||
214 | try: | 219 | try: |
215 | run () | 220 | run() |
216 | except (KeyboardInterrupt, SystemExit): | 221 | except (KeyboardInterrupt, SystemExit): |
217 | print('Test interrupted') | 222 | print('Test interrupted') |
218 | server.stop () | 223 | server.stop() |
219 | client.stop () | 224 | client.stop() |
220 | client_nat.stop () | 225 | client_nat.stop() |
221 | cleanup () | 226 | cleanup() |
222 | if (success == False): | 227 | if (success == False): |
223 | sys.exit(1) | 228 | sys.exit(1) |
224 | else: | 229 | else: |
225 | sys.exit(0) | 230 | sys.exit(0) |
226 | |||
227 | |||
diff --git a/src/integration-tests/test_integration_disconnect_nat.py.in b/src/integration-tests/test_integration_disconnect_nat.py.in index 611255a09..12c268bd6 100755 --- a/src/integration-tests/test_integration_disconnect_nat.py.in +++ b/src/integration-tests/test_integration_disconnect_nat.py.in | |||
@@ -17,7 +17,7 @@ | |||
17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | # Boston, MA 02110-1301, USA. | 18 | # Boston, MA 02110-1301, USA. |
19 | # | 19 | # |
20 | # | 20 | # |
21 | import sys | 21 | import sys |
22 | import signal | 22 | import signal |
23 | import os | 23 | import os |
@@ -29,8 +29,8 @@ from gnunet_testing import Peer | |||
29 | from gnunet_testing import Test | 29 | from gnunet_testing import Test |
30 | from gnunet_testing import Check | 30 | from gnunet_testing import Check |
31 | from gnunet_testing import Condition | 31 | from gnunet_testing import Condition |
32 | from gnunet_testing import * | 32 | from gnunet_testing import * |
33 | 33 | ||
34 | 34 | ||
35 | # | 35 | # |
36 | # This test tests if a fresh peer bootstraps from a hostlist server and then | 36 | # This test tests if a fresh peer bootstraps from a hostlist server and then |
@@ -40,173 +40,175 @@ from gnunet_testing import * | |||
40 | # Conditions for successful exit: | 40 | # Conditions for successful exit: |
41 | # Client peer has 0 connected peer in transport, core, topology, dht, fs | 41 | # Client peer has 0 connected peer in transport, core, topology, dht, fs |
42 | 42 | ||
43 | #definitions | 43 | # definitions |
44 | 44 | ||
45 | testname = "test_integration_disconnect" | 45 | testname = "test_integration_disconnect" |
46 | verbose = True | 46 | verbose = True |
47 | check_timeout = 180 | 47 | check_timeout = 180 |
48 | 48 | ||
49 | if os.name == "nt": | 49 | if os.name == "nt": |
50 | tmp = os.getenv ("TEMP") | 50 | tmp = os.getenv("TEMP") |
51 | signals = [signal.SIGTERM, signal.SIGINT] | 51 | signals = [signal.SIGTERM, signal.SIGINT] |
52 | else: | 52 | else: |
53 | tmp = "/tmp" | 53 | tmp = "/tmp" |
54 | signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] | 54 | signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] |
55 | 55 | ||
56 | def cleanup_onerror (function, path, excinfo): | 56 | |
57 | import stat | 57 | def cleanup_onerror(function, path, excinfo): |
58 | if not os.path.exists (path): | 58 | import stat |
59 | pass | 59 | if not os.path.exists(path): |
60 | elif not os.access(path, os.W_OK): | 60 | pass |
61 | # Is the error an access error ? | 61 | elif not os.access(path, os.W_OK): |
62 | os.chmod (path, stat.S_IWUSR) | 62 | # Is the error an access error ? |
63 | function (path) | 63 | os.chmod(path, stat.S_IWUSR) |
64 | else: | 64 | function(path) |
65 | raise | 65 | else: |
66 | 66 | raise | |
67 | def cleanup (): | 67 | |
68 | shutil.rmtree (os.path.join (tmp, "c_bootstrap_server"), False, cleanup_onerror) | 68 | |
69 | shutil.rmtree (os.path.join (tmp, "c_nat_client"), False, cleanup_onerror) | 69 | def cleanup(): |
70 | 70 | shutil.rmtree(os.path.join(tmp, "c_bootstrap_server"), False, cleanup_onerror) | |
71 | 71 | shutil.rmtree(os.path.join(tmp, "c_nat_client"), False, cleanup_onerror) | |
72 | def success_disconnect_cont (check): | 72 | |
73 | print('Peers disconnected successfully') | 73 | |
74 | global success | 74 | def success_disconnect_cont(check): |
75 | success = True; | 75 | print('Peers disconnected successfully') |
76 | 76 | global success | |
77 | 77 | success = True | |
78 | def fail_disconnect_cont (check): | 78 | |
79 | global success | 79 | |
80 | success = False; | 80 | def fail_disconnect_cont(check): |
81 | print('Peers failed to disconnect') | 81 | global success |
82 | check.evaluate(True) | 82 | success = False; |
83 | 83 | print('Peers failed to disconnect') | |
84 | def check_disconnect (): | 84 | check.evaluate(True) |
85 | global server | 85 | |
86 | global nat_client | 86 | |
87 | test.p ('Shutting down nat client') | 87 | def check_disconnect(): |
88 | nat_client.stop () | 88 | global server |
89 | check = Check (test) | 89 | global nat_client |
90 | check.add (StatisticsCondition (server, 'transport', '# peers connected',0)) | 90 | test.p('Shutting down nat client') |
91 | check.add (StatisticsCondition (server, 'core', '# peers connected',0)) | 91 | nat_client.stop() |
92 | check.add (StatisticsCondition (server, 'topology', '# peers connected',0)) | 92 | check = Check(test) |
93 | check.add (StatisticsCondition (server, 'dht', '# peers connected',0)) | 93 | check.add(StatisticsCondition(server, 'transport', '# peers connected', 0)) |
94 | check.add (StatisticsCondition (server, 'fs', '# peers connected',0)) | 94 | check.add(StatisticsCondition(server, 'core', '# peers connected', 0)) |
95 | check.run_blocking (check_timeout, success_disconnect_cont, fail_disconnect_cont) | 95 | check.add(StatisticsCondition(server, 'topology', '# peers connected', 0)) |
96 | 96 | check.add(StatisticsCondition(server, 'dht', '# peers connected', 0)) | |
97 | 97 | check.add(StatisticsCondition(server, 'fs', '# peers connected', 0)) | |
98 | def success_connect_cont (check): | 98 | check.run_blocking(check_timeout, success_disconnect_cont, fail_disconnect_cont) |
99 | print('Peers connected successfully') | 99 | |
100 | check_disconnect () | 100 | |
101 | 101 | def success_connect_cont(check): | |
102 | 102 | print('Peers connected successfully') | |
103 | def fail_connect_cont (check): | 103 | check_disconnect() |
104 | global success | 104 | |
105 | success= False | 105 | |
106 | print('Peers failed to connected!') | 106 | def fail_connect_cont(check): |
107 | check.evaluate(True) | 107 | global success |
108 | 108 | success = False | |
109 | 109 | print('Peers failed to connected!') | |
110 | def check_connect (): | 110 | check.evaluate(True) |
111 | global server | 111 | |
112 | global nat_client | 112 | |
113 | check = Check (test) | 113 | def check_connect(): |
114 | check.add (StatisticsCondition (nat_client, 'transport', '# peers connected',1)) | 114 | global server |
115 | check.add (StatisticsCondition (nat_client, 'core', '# peers connected',1)) | 115 | global nat_client |
116 | check.add (StatisticsCondition (nat_client, 'topology', '# peers connected',1)) | 116 | check = Check(test) |
117 | check.add (StatisticsCondition (nat_client, 'dht', '# peers connected',1)) | 117 | check.add(StatisticsCondition(nat_client, 'transport', '# peers connected', 1)) |
118 | check.add (StatisticsCondition (nat_client, 'fs', '# peers connected',1)) | 118 | check.add(StatisticsCondition(nat_client, 'core', '# peers connected', 1)) |
119 | 119 | check.add(StatisticsCondition(nat_client, 'topology', '# peers connected', 1)) | |
120 | check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) | 120 | check.add(StatisticsCondition(nat_client, 'dht', '# peers connected', 1)) |
121 | check.add (StatisticsCondition (server, 'core', '# peers connected',1)) | 121 | check.add(StatisticsCondition(nat_client, 'fs', '# peers connected', 1)) |
122 | check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) | 122 | |
123 | check.add (StatisticsCondition (server, 'dht', '# peers connected',1)) | 123 | check.add(StatisticsCondition(server, 'transport', '# peers connected', 1)) |
124 | check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) | 124 | check.add(StatisticsCondition(server, 'core', '# peers connected', 1)) |
125 | 125 | check.add(StatisticsCondition(server, 'topology', '# peers connected', 1)) | |
126 | check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont) | 126 | check.add(StatisticsCondition(server, 'dht', '# peers connected', 1)) |
127 | 127 | check.add(StatisticsCondition(server, 'fs', '# peers connected', 1)) | |
128 | # | 128 | |
129 | check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont) | ||
130 | |||
131 | |||
132 | # | ||
129 | # Test execution | 133 | # Test execution |
130 | # | 134 | # |
131 | 135 | ||
132 | def SigHandler(signum = None, frame = None): | 136 | def SigHandler(signum=None, frame=None): |
133 | global success | 137 | global success |
134 | global server | 138 | global server |
135 | global nat_client | 139 | global nat_client |
136 | 140 | ||
137 | print('Test was aborted!') | 141 | print('Test was aborted!') |
138 | if (None != server): | 142 | if (None != server): |
139 | server.stop () | 143 | server.stop() |
140 | if (None != nat_client): | 144 | if (None != nat_client): |
141 | nat_client.stop () | 145 | nat_client.stop() |
142 | cleanup () | 146 | cleanup() |
143 | sys.exit(success) | 147 | sys.exit(success) |
144 | 148 | ||
145 | def run (): | 149 | |
146 | global success | 150 | def run(): |
147 | global test | 151 | global success |
148 | global server | 152 | global test |
149 | global nat_client | 153 | global server |
150 | 154 | global nat_client | |
151 | server = None | 155 | |
152 | nat_client = None | 156 | server = None |
153 | success = False | 157 | nat_client = None |
154 | 158 | success = False | |
155 | for sig in signals: | 159 | |
156 | signal.signal(sig, SigHandler) | 160 | for sig in signals: |
157 | 161 | signal.signal(sig, SigHandler) | |
158 | test = Test ('test_integration_bootstrap_and_connect.py', verbose) | 162 | |
159 | cleanup () | 163 | test = Test('test_integration_bootstrap_and_connect.py', verbose) |
160 | 164 | cleanup() | |
161 | server = Peer(test, './confs/c_bootstrap_server.conf'); | 165 | |
162 | nat_client = Peer(test, './confs/c_nat_client.conf'); | 166 | server = Peer(test, './confs/c_bootstrap_server.conf') |
163 | 167 | nat_client = Peer(test, './confs/c_nat_client.conf') | |
164 | if (True != server.start()): | 168 | |
165 | print('Failed to start server') | 169 | if (True != server.start()): |
166 | if (None != server): | 170 | print('Failed to start server') |
167 | server.stop () | 171 | if (None != server): |
168 | cleanup () | 172 | server.stop() |
169 | sys.exit(success) | 173 | cleanup() |
170 | 174 | sys.exit(success) | |
171 | # Give the server time to start | 175 | |
172 | time.sleep(5) | 176 | # Give the server time to start |
173 | 177 | time.sleep(5) | |
174 | if (True != nat_client.start()): | 178 | |
175 | print('Failed to start nat_client') | 179 | if (True != nat_client.start()): |
176 | if (None != server): | 180 | print('Failed to start nat_client') |
177 | server.stop () | 181 | if (None != server): |
178 | if (None != nat_client): | 182 | server.stop() |
179 | nat_client.stop () | 183 | if (None != nat_client): |
180 | cleanup () | 184 | nat_client.stop() |
181 | sys.exit(success) | 185 | cleanup() |
182 | 186 | sys.exit(success) | |
183 | if ((nat_client.started == True) and (server.started == True)): | 187 | |
184 | test.p ('Peers started, running check') | 188 | if ((nat_client.started == True) and (server.started == True)): |
185 | time.sleep(5) | 189 | test.p('Peers started, running check') |
186 | check_connect () | 190 | time.sleep(5) |
187 | server.stop () | 191 | check_connect() |
188 | nat_client.stop () | 192 | server.stop() |
189 | 193 | nat_client.stop() | |
190 | cleanup () | 194 | |
191 | 195 | cleanup() | |
192 | if (success == False): | 196 | |
193 | print ('Test failed') | 197 | if (success == False): |
194 | return False | 198 | print('Test failed') |
195 | else: | 199 | return False |
196 | return True | 200 | else: |
201 | return True | ||
202 | |||
197 | 203 | ||
198 | try: | 204 | try: |
199 | run () | 205 | run() |
200 | except (KeyboardInterrupt, SystemExit): | 206 | except(KeyboardInterrupt, SystemExit): |
201 | print('Test interrupted') | 207 | print('Test interrupted') |
202 | server.stop () | 208 | server.stop() |
203 | nat_client.stop () | 209 | nat_client.stop() |
204 | cleanup () | 210 | cleanup() |
205 | if (success == False): | 211 | if (success == False): |
206 | sys.exit(1) | 212 | sys.exit(1) |
207 | else: | 213 | else: |
208 | sys.exit(0) | 214 | sys.exit(0) |
209 | |||
210 | |||
211 | |||
212 | |||
diff --git a/src/integration-tests/test_integration_reconnect_nat.py.in b/src/integration-tests/test_integration_reconnect_nat.py.in index 78c75c335..81cff7833 100755 --- a/src/integration-tests/test_integration_reconnect_nat.py.in +++ b/src/integration-tests/test_integration_reconnect_nat.py.in | |||
@@ -17,7 +17,7 @@ | |||
17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | # Boston, MA 02110-1301, USA. | 18 | # Boston, MA 02110-1301, USA. |
19 | # | 19 | # |
20 | # | 20 | # |
21 | import sys | 21 | import sys |
22 | import os | 22 | import os |
23 | import subprocess | 23 | import subprocess |
@@ -29,18 +29,18 @@ from gnunet_testing import Peer | |||
29 | from gnunet_testing import Test | 29 | from gnunet_testing import Test |
30 | from gnunet_testing import Check | 30 | from gnunet_testing import Check |
31 | from gnunet_testing import Condition | 31 | from gnunet_testing import Condition |
32 | from gnunet_testing import * | 32 | from gnunet_testing import * |
33 | 33 | ||
34 | 34 | ||
35 | # | 35 | # |
36 | # This test tests if a fresh peer bootstraps from a hostlist server and then | 36 | # This test tests if a fresh peer bootstraps from a hostlist server and then |
37 | # successfully connects to the server. When both peers are connected | 37 | # successfully connects to the server. When both peers are connected |
38 | # in transport, core, topology, fs, botth peers are shutdown and restarted | 38 | # in transport, core, topology, fs, botth peers are shutdown and restarted |
39 | # | 39 | # |
40 | # Conditions for successful exit: | 40 | # Conditions for successful exit: |
41 | # Both peers have 1 connected peer in transport, core, topology, fs after restart | 41 | # Both peers have 1 connected peer in transport, core, topology, fs after restart |
42 | 42 | ||
43 | #definitions | 43 | # definitions |
44 | 44 | ||
45 | 45 | ||
46 | testname = "test_integration_restart" | 46 | testname = "test_integration_restart" |
@@ -48,191 +48,190 @@ verbose = True | |||
48 | check_timeout = 180 | 48 | check_timeout = 180 |
49 | 49 | ||
50 | if os.name == "nt": | 50 | if os.name == "nt": |
51 | tmp = os.getenv ("TEMP") | 51 | tmp = os.getenv("TEMP") |
52 | signals = [signal.SIGTERM, signal.SIGINT] | 52 | signals = [signal.SIGTERM, signal.SIGINT] |
53 | else: | 53 | else: |
54 | tmp = "/tmp" | 54 | tmp = "/tmp" |
55 | signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] | 55 | signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] |
56 | 56 | ||
57 | def cleanup_onerror (function, path, excinfo): | 57 | |
58 | import stat | 58 | def cleanup_onerror(function, path, excinfo): |
59 | if not os.path.exists (path): | 59 | import stat |
60 | pass | 60 | if not os.path.exists(path): |
61 | elif not os.access(path, os.W_OK): | 61 | pass |
62 | # Is the error an access error ? | 62 | elif not os.access(path, os.W_OK): |
63 | os.chmod (path, stat.S_IWUSR) | 63 | # Is the error an access error ? |
64 | function (path) | 64 | os.chmod(path, stat.S_IWUSR) |
65 | else: | 65 | function(path) |
66 | raise | 66 | else: |
67 | 67 | raise | |
68 | def cleanup (): | 68 | |
69 | |||
70 | def cleanup(): | ||
69 | retries = 10 | 71 | retries = 10 |
70 | path = os.path.join (tmp, "c_bootstrap_server") | 72 | path = os.path.join(tmp, "c_bootstrap_server") |
71 | test.p ("Removing " + path) | 73 | test.p("Removing " + path) |
72 | while ((os.path.exists(path)) and (retries > 0)): | 74 | while ((os.path.exists(path)) and (retries > 0)): |
73 | shutil.rmtree ((path), False, cleanup_onerror) | 75 | shutil.rmtree((path), False, cleanup_onerror) |
74 | time.sleep (1) | 76 | time.sleep(1) |
75 | retries -= 1 | 77 | retries -= 1 |
76 | if (os.path.exists(path)): | 78 | if (os.path.exists(path)): |
77 | test.p ("Failed to remove " + path) | 79 | test.p("Failed to remove " + path) |
78 | 80 | ||
79 | |||
80 | retries = 10 | 81 | retries = 10 |
81 | path = os.path.join (tmp, "c_nat_client") | 82 | path = os.path.join(tmp, "c_nat_client") |
82 | test.p ("Removing " + path) | 83 | test.p("Removing " + path) |
83 | while ((os.path.exists(path)) and (retries > 0)): | 84 | while((os.path.exists(path)) and(retries > 0)): |
84 | shutil.rmtree ((path), False, cleanup_onerror) | 85 | shutil.rmtree((path), False, cleanup_onerror) |
85 | time.sleep (1) | 86 | time.sleep(1) |
86 | retries -= 1 | 87 | retries -= 1 |
87 | if (os.path.exists(path)): | 88 | if (os.path.exists(path)): |
88 | test.p ("Failed to remove " + path) | 89 | test.p("Failed to remove " + path) |
89 | 90 | ||
90 | def success_restart_cont (check): | 91 | |
91 | global success | 92 | def success_restart_cont(check): |
92 | print('Peers connected successfully after restart') | 93 | global success |
93 | server.stop () | 94 | print('Peers connected successfully after restart') |
94 | client.stop () | 95 | server.stop() |
95 | success = True; | 96 | client.stop() |
96 | 97 | success = True | |
97 | 98 | ||
98 | def fail_restart_cont (check): | 99 | |
99 | global success | 100 | def fail_restart_cont(check): |
100 | success = False; | 101 | global success |
101 | print('Peers failed to connect after restart') | 102 | success = False |
102 | check.evaluate(True) | 103 | print('Peers failed to connect after restart') |
103 | 104 | check.evaluate(True) | |
104 | 105 | ||
105 | def success_connect_cont (check): | 106 | |
106 | print('Peers connected successfully') | 107 | def success_connect_cont(check): |
107 | server.stop () | 108 | print('Peers connected successfully') |
108 | client.stop () | 109 | server.stop() |
109 | 110 | client.stop() | |
110 | time.sleep(5) | 111 | |
111 | 112 | time.sleep(5) | |
112 | test.p ('Restarting client & server') | 113 | |
113 | server.start () | 114 | test.p('Restarting client & server') |
114 | client.start () | 115 | server.start() |
115 | 116 | client.start() | |
116 | check = Check (test) | 117 | |
117 | check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) | 118 | check = Check(test) |
118 | check.add (StatisticsCondition (client, 'core', '# peers connected',1)) | 119 | check.add(StatisticsCondition(client, 'transport', '# peers connected', 1)) |
119 | check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) | 120 | check.add(StatisticsCondition(client, 'core', '# peers connected', 1)) |
120 | check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) | 121 | check.add(StatisticsCondition(client, 'topology', '# peers connected', 1)) |
121 | 122 | check.add(StatisticsCondition(client, 'fs', '# peers connected', 1)) | |
122 | check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) | 123 | |
123 | check.add (StatisticsCondition (server, 'core', '# peers connected',1)) | 124 | check.add(StatisticsCondition(server, 'transport', '# peers connected', 1)) |
124 | check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) | 125 | check.add(StatisticsCondition(server, 'core', '# peers connected', 1)) |
125 | check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) | 126 | check.add(StatisticsCondition(server, 'topology', '# peers connected', 1)) |
126 | 127 | check.add(StatisticsCondition(server, 'fs', '# peers connected', 1)) | |
127 | check.run_blocking (check_timeout, success_restart_cont, fail_restart_cont) | 128 | |
128 | 129 | check.run_blocking(check_timeout, success_restart_cont, fail_restart_cont) | |
129 | 130 | ||
130 | def fail_connect_cont (check): | 131 | |
131 | global success | 132 | def fail_connect_cont(check): |
132 | success= False; | 133 | global success |
133 | print('Peers failed to connect') | 134 | success = False |
134 | check.evaluate(True) | 135 | print('Peers failed to connect') |
135 | 136 | check.evaluate(True) | |
136 | 137 | ||
137 | def check_connect (): | 138 | |
138 | check = Check (test) | 139 | def check_connect(): |
139 | check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) | 140 | check = Check(test) |
140 | check.add (StatisticsCondition (client, 'core', '# peers connected',1)) | 141 | check.add(StatisticsCondition(client, 'transport', '# peers connected', 1)) |
141 | check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) | 142 | check.add(StatisticsCondition(client, 'core', '# peers connected', 1)) |
142 | check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) | 143 | check.add(StatisticsCondition(client, 'topology', '# peers connected', 1)) |
143 | 144 | check.add(StatisticsCondition(client, 'fs', '# peers connected', 1)) | |
144 | check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) | 145 | |
145 | check.add (StatisticsCondition (server, 'core', '# peers connected',1)) | 146 | check.add(StatisticsCondition(server, 'transport', '# peers connected', 1)) |
146 | check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) | 147 | check.add(StatisticsCondition(server, 'core', '# peers connected', 1)) |
147 | check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) | 148 | check.add(StatisticsCondition(server, 'topology', '# peers connected', 1)) |
148 | 149 | check.add(StatisticsCondition(server, 'fs', '# peers connected', 1)) | |
149 | check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont) | 150 | |
150 | 151 | check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont) | |
151 | # | 152 | |
153 | # | ||
152 | # Test execution | 154 | # Test execution |
153 | # | 155 | # |
154 | 156 | ||
155 | 157 | ||
156 | def SigHandler(signum = None, frame = None): | 158 | def SigHandler(signum=None, frame=None): |
157 | global success | 159 | global success |
158 | global server | 160 | global server |
159 | global client | 161 | global client |
160 | 162 | ||
161 | print('Test was aborted!') | 163 | print('Test was aborted!') |
162 | if (None != server): | 164 | if (None != server): |
163 | server.stop () | 165 | server.stop() |
164 | if (None != client): | 166 | if (None != client): |
165 | client.stop () | 167 | client.stop() |
166 | cleanup () | 168 | cleanup() |
167 | sys.exit(success) | 169 | sys.exit(success) |
168 | 170 | ||
169 | def run (): | 171 | |
170 | global success | 172 | def run(): |
171 | global test | 173 | global success |
172 | global server | 174 | global test |
173 | global client | 175 | global server |
174 | 176 | global client | |
175 | success = False | 177 | |
176 | server = None | 178 | success = False |
177 | client = None | 179 | server = None |
178 | 180 | client = None | |
179 | for sig in signals: | 181 | |
180 | signal.signal(sig, SigHandler) | 182 | for sig in signals: |
181 | 183 | signal.signal(sig, SigHandler) | |
182 | 184 | ||
183 | test = Test ('test_integration_disconnect', verbose) | 185 | test = Test('test_integration_disconnect', verbose) |
184 | cleanup () | 186 | cleanup() |
185 | server = Peer(test, './confs/c_bootstrap_server.conf'); | 187 | server = Peer(test, './confs/c_bootstrap_server.conf') |
186 | server.start(); | 188 | server.start() |
187 | 189 | ||
188 | client = Peer(test, './confs/c_nat_client.conf'); | 190 | client = Peer(test, './confs/c_nat_client.conf') |
189 | client.start(); | 191 | client.start() |
190 | 192 | ||
191 | 193 | if (True != server.start()): | |
192 | if (True != server.start()): | 194 | print('Failed to start server') |
193 | print('Failed to start server') | 195 | if (None != server): |
194 | if (None != server): | 196 | server.stop() |
195 | server.stop () | 197 | if (None != server): |
196 | if (None != server): | 198 | client.stop() |
197 | client.stop () | 199 | cleanup() |
198 | cleanup () | 200 | sys.exit(success) |
199 | sys.exit(success) | 201 | |
200 | 202 | # Give the server time to start | |
201 | # Give the server time to start | 203 | time.sleep(5) |
202 | time.sleep(5) | 204 | |
203 | 205 | if (True != client.start()): | |
204 | if (True != client.start()): | 206 | print('Failed to start client') |
205 | print('Failed to start client') | 207 | if (None != server): |
206 | if (None != server): | 208 | server.stop() |
207 | server.stop () | 209 | if (None != server): |
208 | if (None != server): | 210 | client.stop() |
209 | client.stop () | 211 | cleanup() |
210 | cleanup () | 212 | sys.exit(success) |
211 | sys.exit(success) | 213 | |
212 | 214 | check_connect() | |
213 | check_connect () | 215 | |
214 | 216 | server.stop() | |
215 | server.stop () | 217 | client.stop() |
216 | client.stop () | 218 | cleanup() |
217 | cleanup () | 219 | |
218 | 220 | if (success == False): | |
219 | if (success == False): | 221 | print('Test failed') |
220 | print ('Test failed') | 222 | return True |
221 | return True | 223 | else: |
222 | else: | 224 | return False |
223 | return False | 225 | |
224 | 226 | ||
225 | |||
226 | try: | 227 | try: |
227 | run () | 228 | run() |
228 | except (KeyboardInterrupt, SystemExit): | 229 | except(KeyboardInterrupt, SystemExit): |
229 | print('Test interrupted') | 230 | print('Test interrupted') |
230 | server.stop () | 231 | server.stop() |
231 | client.stop () | 232 | client.stop() |
232 | cleanup () | 233 | cleanup() |
233 | if (success == False): | 234 | if (success == False): |
234 | sys.exit(1) | 235 | sys.exit(1) |
235 | else: | 236 | else: |
236 | sys.exit(0) | 237 | sys.exit(0) |
237 | |||
238 | |||
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 753ee79d1..83a7ee349 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -641,14 +641,6 @@ get_existing_record (void *cls, | |||
641 | ret = 1; | 641 | ret = 1; |
642 | test_finished (); | 642 | test_finished (); |
643 | return; | 643 | return; |
644 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: | ||
645 | fprintf (stderr, | ||
646 | _("A %s record exists already under `%s', no other records can be added.\n"), | ||
647 | "GNS2DNS", | ||
648 | rec_name); | ||
649 | ret = 1; | ||
650 | test_finished (); | ||
651 | return; | ||
652 | } | 644 | } |
653 | } | 645 | } |
654 | switch (type) | 646 | switch (type) |
@@ -678,16 +670,16 @@ get_existing_record (void *cls, | |||
678 | } | 670 | } |
679 | break; | 671 | break; |
680 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: | 672 | case GNUNET_GNSRECORD_TYPE_GNS2DNS: |
681 | if (0 != rd_count) | 673 | for (unsigned int i=0;i<rd_count;i++) |
682 | { | 674 | if (GNUNET_GNSRECORD_TYPE_GNS2DNS != rd[i].record_type) |
683 | fprintf (stderr, | 675 | { |
684 | _("Records already exist under `%s', cannot add `%s' record.\n"), | 676 | fprintf (stderr, |
685 | rec_name, | 677 | _("Non-GNS2DNS records already exist under `%s', cannot add GNS2DNS record.\n"), |
686 | "GNS2DNS"); | 678 | rec_name); |
687 | ret = 1; | 679 | ret = 1; |
688 | test_finished (); | 680 | test_finished (); |
689 | return; | 681 | return; |
690 | } | 682 | } |
691 | break; | 683 | break; |
692 | } | 684 | } |
693 | memset (rdn, | 685 | memset (rdn, |
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 8e88558de..2044010df 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -278,12 +278,6 @@ struct StoreActivity | |||
278 | const struct RecordStoreMessage *rsm; | 278 | const struct RecordStoreMessage *rsm; |
279 | 279 | ||
280 | /** | 280 | /** |
281 | * Array of record data to store (without NICK unless this is about | ||
282 | * #GNUNET_GNS_EMPTY_LABEL_AT). Length is in @e rd_count. | ||
283 | */ | ||
284 | struct GNUNET_GNSRECORD_Data *rd; | ||
285 | |||
286 | /** | ||
287 | * Next zone monitor that still needs to be notified about this PUT. | 281 | * Next zone monitor that still needs to be notified about this PUT. |
288 | */ | 282 | */ |
289 | struct ZoneMonitor *zm_pos; | 283 | struct ZoneMonitor *zm_pos; |
@@ -293,11 +287,6 @@ struct StoreActivity | |||
293 | */ | 287 | */ |
294 | char *conv_name; | 288 | char *conv_name; |
295 | 289 | ||
296 | /** | ||
297 | * How many records do we try to store? | ||
298 | */ | ||
299 | unsigned int rd_count; | ||
300 | |||
301 | }; | 290 | }; |
302 | 291 | ||
303 | 292 | ||
@@ -436,9 +425,6 @@ free_store_activity (struct StoreActivity *sa) | |||
436 | GNUNET_CONTAINER_DLL_remove (sa_head, | 425 | GNUNET_CONTAINER_DLL_remove (sa_head, |
437 | sa_tail, | 426 | sa_tail, |
438 | sa); | 427 | sa); |
439 | GNUNET_array_grow (sa->rd, | ||
440 | sa->rd_count, | ||
441 | 0); | ||
442 | GNUNET_free (sa->conv_name); | 428 | GNUNET_free (sa->conv_name); |
443 | GNUNET_free (sa); | 429 | GNUNET_free (sa); |
444 | } | 430 | } |
@@ -551,6 +537,7 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd, | |||
551 | size_t req; | 537 | size_t req; |
552 | char *data; | 538 | char *data; |
553 | size_t data_offset; | 539 | size_t data_offset; |
540 | struct GNUNET_GNSRECORD_Data *target; | ||
554 | 541 | ||
555 | (*rdc_res) = 1 + rd2_length; | 542 | (*rdc_res) = 1 + rd2_length; |
556 | if (0 == 1 + rd2_length) | 543 | if (0 == 1 + rd2_length) |
@@ -560,38 +547,52 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd, | |||
560 | return; | 547 | return; |
561 | } | 548 | } |
562 | req = sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd->data_size; | 549 | req = sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd->data_size; |
563 | for (unsigned int c=0; c< rd2_length; c++) | 550 | for (unsigned int i=0; i<rd2_length; i++) |
564 | req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size; | 551 | { |
565 | (*rd_res) = GNUNET_malloc (req); | 552 | const struct GNUNET_GNSRECORD_Data *orig = &rd2[i]; |
566 | data = (char *) &(*rd_res)[1 + rd2_length]; | 553 | |
554 | if (req + sizeof (struct GNUNET_GNSRECORD_Data) + orig->data_size < req) | ||
555 | { | ||
556 | GNUNET_break (0); | ||
557 | (*rd_res) = NULL; | ||
558 | return; | ||
559 | } | ||
560 | req += sizeof (struct GNUNET_GNSRECORD_Data) + orig->data_size; | ||
561 | } | ||
562 | target = GNUNET_malloc (req); | ||
563 | (*rd_res) = target; | ||
564 | data = (char *) &target[1 + rd2_length]; | ||
567 | data_offset = 0; | 565 | data_offset = 0; |
568 | latest_expiration = 0; | 566 | latest_expiration = 0; |
569 | for (unsigned int c=0; c< rd2_length; c++) | 567 | for (unsigned int i=0;i<rd2_length;i++) |
570 | { | 568 | { |
571 | if (0 != (rd2[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | 569 | const struct GNUNET_GNSRECORD_Data *orig = &rd2[i]; |
570 | |||
571 | if (0 != (orig->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | ||
572 | { | 572 | { |
573 | if ((GNUNET_TIME_absolute_get().abs_value_us + rd2[c].expiration_time) > | 573 | if ((GNUNET_TIME_absolute_get().abs_value_us + orig->expiration_time) > |
574 | latest_expiration) | 574 | latest_expiration) |
575 | latest_expiration = rd2[c].expiration_time; | 575 | latest_expiration = orig->expiration_time; |
576 | } | 576 | } |
577 | else if (rd2[c].expiration_time > latest_expiration) | 577 | else if (orig->expiration_time > latest_expiration) |
578 | latest_expiration = rd2[c].expiration_time; | 578 | latest_expiration = orig->expiration_time; |
579 | (*rd_res)[c] = rd2[c]; | 579 | target[i] = *orig; |
580 | (*rd_res)[c].data = (void *) &data[data_offset]; | 580 | target[i].data = (void *) &data[data_offset]; |
581 | GNUNET_memcpy (&data[data_offset], | 581 | GNUNET_memcpy (&data[data_offset], |
582 | rd2[c].data, | 582 | orig->data, |
583 | rd2[c].data_size); | 583 | orig->data_size); |
584 | data_offset += (*rd_res)[c].data_size; | 584 | data_offset += orig->data_size; |
585 | } | 585 | } |
586 | /* append nick */ | 586 | /* append nick */ |
587 | (*rd_res)[rd2_length] = *nick_rd; | 587 | target[rd2_length] = *nick_rd; |
588 | (*rd_res)[rd2_length].expiration_time = latest_expiration; | 588 | target[rd2_length].expiration_time = latest_expiration; |
589 | (*rd_res)[rd2_length].data = (void *) &data[data_offset]; | 589 | target[rd2_length].data = (void *) &data[data_offset]; |
590 | GNUNET_memcpy ((void *) (*rd_res)[rd2_length].data, | 590 | GNUNET_memcpy (&data[data_offset], |
591 | nick_rd->data, | 591 | nick_rd->data, |
592 | nick_rd->data_size); | 592 | nick_rd->data_size); |
593 | data_offset += (*rd_res)[rd2_length].data_size; | 593 | data_offset += nick_rd->data_size; |
594 | GNUNET_assert (req == (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset); | 594 | GNUNET_assert (req == |
595 | (sizeof (struct GNUNET_GNSRECORD_Data)) * (*rdc_res) + data_offset); | ||
595 | } | 596 | } |
596 | 597 | ||
597 | 598 | ||
@@ -620,11 +621,16 @@ send_lookup_response (struct NamestoreClient *nc, | |||
620 | struct GNUNET_GNSRECORD_Data *res; | 621 | struct GNUNET_GNSRECORD_Data *res; |
621 | unsigned int res_count; | 622 | unsigned int res_count; |
622 | size_t name_len; | 623 | size_t name_len; |
623 | size_t rd_ser_len; | 624 | ssize_t rd_ser_len; |
624 | char *name_tmp; | 625 | char *name_tmp; |
625 | char *rd_ser; | 626 | char *rd_ser; |
626 | 627 | ||
627 | nick = get_nick_record (zone_key); | 628 | nick = get_nick_record (zone_key); |
629 | |||
630 | GNUNET_assert (-1 != | ||
631 | GNUNET_GNSRECORD_records_get_size (rd_count, | ||
632 | rd)); | ||
633 | |||
628 | if ( (NULL != nick) && | 634 | if ( (NULL != nick) && |
629 | (0 != strcmp (name, | 635 | (0 != strcmp (name, |
630 | GNUNET_GNS_EMPTY_LABEL_AT))) | 636 | GNUNET_GNS_EMPTY_LABEL_AT))) |
@@ -643,26 +649,44 @@ send_lookup_response (struct NamestoreClient *nc, | |||
643 | res = (struct GNUNET_GNSRECORD_Data *) rd; | 649 | res = (struct GNUNET_GNSRECORD_Data *) rd; |
644 | } | 650 | } |
645 | 651 | ||
652 | GNUNET_assert (-1 != | ||
653 | GNUNET_GNSRECORD_records_get_size (res_count, | ||
654 | res)); | ||
655 | |||
656 | |||
646 | name_len = strlen (name) + 1; | 657 | name_len = strlen (name) + 1; |
647 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, | 658 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, |
648 | res); | 659 | res); |
660 | if (rd_ser_len < 0) | ||
661 | { | ||
662 | GNUNET_break (0); | ||
663 | GNUNET_SERVICE_client_drop (nc->client); | ||
664 | return; | ||
665 | } | ||
666 | if (rd_ser_len >= UINT16_MAX - name_len - sizeof (*zir_msg)) | ||
667 | { | ||
668 | GNUNET_break (0); | ||
669 | GNUNET_SERVICE_client_drop (nc->client); | ||
670 | return; | ||
671 | } | ||
649 | env = GNUNET_MQ_msg_extra (zir_msg, | 672 | env = GNUNET_MQ_msg_extra (zir_msg, |
650 | name_len + rd_ser_len, | 673 | name_len + rd_ser_len, |
651 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); | 674 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); |
652 | zir_msg->gns_header.r_id = htonl (request_id); | 675 | zir_msg->gns_header.r_id = htonl (request_id); |
653 | zir_msg->name_len = htons (name_len); | 676 | zir_msg->name_len = htons (name_len); |
654 | zir_msg->rd_count = htons (res_count); | 677 | zir_msg->rd_count = htons (res_count); |
655 | zir_msg->rd_len = htons (rd_ser_len); | 678 | zir_msg->rd_len = htons ((uint16_t) rd_ser_len); |
656 | zir_msg->private_key = *zone_key; | 679 | zir_msg->private_key = *zone_key; |
657 | name_tmp = (char *) &zir_msg[1]; | 680 | name_tmp = (char *) &zir_msg[1]; |
658 | GNUNET_memcpy (name_tmp, | 681 | GNUNET_memcpy (name_tmp, |
659 | name, | 682 | name, |
660 | name_len); | 683 | name_len); |
661 | rd_ser = &name_tmp[name_len]; | 684 | rd_ser = &name_tmp[name_len]; |
662 | GNUNET_GNSRECORD_records_serialize (res_count, | 685 | GNUNET_assert (rd_ser_len == |
663 | res, | 686 | GNUNET_GNSRECORD_records_serialize (res_count, |
664 | rd_ser_len, | 687 | res, |
665 | rd_ser); | 688 | rd_ser_len, |
689 | rd_ser)); | ||
666 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 690 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
667 | "Sending RECORD_RESULT message with %u records\n", | 691 | "Sending RECORD_RESULT message with %u records\n", |
668 | res_count); | 692 | res_count); |
@@ -865,72 +889,70 @@ static void | |||
865 | continue_store_activity (struct StoreActivity *sa) | 889 | continue_store_activity (struct StoreActivity *sa) |
866 | { | 890 | { |
867 | const struct RecordStoreMessage *rp_msg = sa->rsm; | 891 | const struct RecordStoreMessage *rp_msg = sa->rsm; |
892 | unsigned int rd_count; | ||
893 | size_t name_len; | ||
894 | size_t rd_ser_len; | ||
895 | uint32_t rid; | ||
896 | const char *name_tmp; | ||
897 | const char *rd_ser; | ||
868 | 898 | ||
869 | for (struct ZoneMonitor *zm = sa->zm_pos; | 899 | rid = ntohl (rp_msg->gns_header.r_id); |
870 | NULL != zm; | 900 | name_len = ntohs (rp_msg->name_len); |
871 | zm = sa->zm_pos) | 901 | rd_count = ntohs (rp_msg->rd_count); |
872 | { | 902 | rd_ser_len = ntohs (rp_msg->rd_len); |
873 | if ( (0 != memcmp (&rp_msg->private_key, | 903 | name_tmp = (const char *) &rp_msg[1]; |
874 | &zm->zone, | 904 | rd_ser = &name_tmp[name_len]; |
875 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) && | ||
876 | (0 != memcmp (&zm->zone, | ||
877 | &zero, | ||
878 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ) | ||
879 | sa->zm_pos = zm->next; /* not interesting to this monitor */ | ||
880 | if (zm->limit == zm->iteration_cnt) | ||
881 | { | ||
882 | zm->sa_waiting = GNUNET_YES; | ||
883 | zm->sa_waiting_start = GNUNET_TIME_absolute_get (); | ||
884 | if (NULL != zm->sa_wait_warning) | ||
885 | GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); | ||
886 | zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY, | ||
887 | &warn_monitor_slow, | ||
888 | zm); | ||
889 | return; /* blocked on zone monitor */ | ||
890 | } | ||
891 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
892 | "Notifying monitor about changes under label `%s'\n", | ||
893 | sa->conv_name); | ||
894 | zm->limit--; | ||
895 | send_lookup_response (zm->nc, | ||
896 | 0, | ||
897 | &rp_msg->private_key, | ||
898 | sa->conv_name, | ||
899 | sa->rd_count, | ||
900 | sa->rd); | ||
901 | sa->zm_pos = zm->next; | ||
902 | } | ||
903 | /* great, done with the monitors, unpack (again) for refresh_block operation */ | ||
904 | { | 905 | { |
905 | size_t name_len; | 906 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)]; |
906 | size_t rd_ser_len; | 907 | |
907 | uint32_t rid; | 908 | /* We did this before, must succeed again */ |
908 | const char *name_tmp; | 909 | GNUNET_assert (GNUNET_OK == |
909 | const char *rd_ser; | 910 | GNUNET_GNSRECORD_records_deserialize (rd_ser_len, |
910 | unsigned int rd_count; | 911 | rd_ser, |
911 | 912 | rd_count, | |
912 | rid = ntohl (rp_msg->gns_header.r_id); | 913 | rd)); |
913 | name_len = ntohs (rp_msg->name_len); | 914 | |
914 | rd_count = ntohs (rp_msg->rd_count); | 915 | for (struct ZoneMonitor *zm = sa->zm_pos; |
915 | rd_ser_len = ntohs (rp_msg->rd_len); | 916 | NULL != zm; |
916 | name_tmp = (const char *) &rp_msg[1]; | 917 | zm = sa->zm_pos) |
917 | rd_ser = &name_tmp[name_len]; | ||
918 | { | 918 | { |
919 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 919 | if ( (0 != memcmp (&rp_msg->private_key, |
920 | 920 | &zm->zone, | |
921 | /* We did this before, must succeed again */ | 921 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) && |
922 | GNUNET_assert (GNUNET_OK == | 922 | (0 != memcmp (&zm->zone, |
923 | GNUNET_GNSRECORD_records_deserialize (rd_ser_len, | 923 | &zero, |
924 | rd_ser, | 924 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ) |
925 | rd_count, | 925 | sa->zm_pos = zm->next; /* not interesting to this monitor */ |
926 | rd)); | 926 | if (zm->limit == zm->iteration_cnt) |
927 | refresh_block (sa->nc, | 927 | { |
928 | rid, | 928 | zm->sa_waiting = GNUNET_YES; |
929 | &rp_msg->private_key, | 929 | zm->sa_waiting_start = GNUNET_TIME_absolute_get (); |
930 | sa->conv_name, | 930 | if (NULL != zm->sa_wait_warning) |
931 | rd_count, | 931 | GNUNET_SCHEDULER_cancel (zm->sa_wait_warning); |
932 | rd); | 932 | zm->sa_wait_warning = GNUNET_SCHEDULER_add_delayed (MONITOR_STALL_WARN_DELAY, |
933 | &warn_monitor_slow, | ||
934 | zm); | ||
935 | return; /* blocked on zone monitor */ | ||
936 | } | ||
937 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
938 | "Notifying monitor about changes under label `%s'\n", | ||
939 | sa->conv_name); | ||
940 | zm->limit--; | ||
941 | send_lookup_response (zm->nc, | ||
942 | 0, | ||
943 | &rp_msg->private_key, | ||
944 | sa->conv_name, | ||
945 | rd_count, | ||
946 | rd); | ||
947 | sa->zm_pos = zm->next; | ||
933 | } | 948 | } |
949 | /* great, done with the monitors, unpack (again) for refresh_block operation */ | ||
950 | refresh_block (sa->nc, | ||
951 | rid, | ||
952 | &rp_msg->private_key, | ||
953 | sa->conv_name, | ||
954 | rd_count, | ||
955 | rd); | ||
934 | } | 956 | } |
935 | GNUNET_SERVICE_client_continue (sa->nc->client); | 957 | GNUNET_SERVICE_client_continue (sa->nc->client); |
936 | free_store_activity (sa); | 958 | free_store_activity (sa); |
@@ -1073,12 +1095,13 @@ struct RecordLookupContext | |||
1073 | /** | 1095 | /** |
1074 | * FIXME. | 1096 | * FIXME. |
1075 | */ | 1097 | */ |
1076 | size_t rd_ser_len; | 1098 | ssize_t rd_ser_len; |
1077 | }; | 1099 | }; |
1078 | 1100 | ||
1079 | 1101 | ||
1080 | /** | 1102 | /** |
1081 | * FIXME. | 1103 | * FIXME. |
1104 | * | ||
1082 | * @param seq sequence number of the record | 1105 | * @param seq sequence number of the record |
1083 | */ | 1106 | */ |
1084 | static void | 1107 | static void |
@@ -1090,60 +1113,93 @@ lookup_it (void *cls, | |||
1090 | const struct GNUNET_GNSRECORD_Data *rd) | 1113 | const struct GNUNET_GNSRECORD_Data *rd) |
1091 | { | 1114 | { |
1092 | struct RecordLookupContext *rlc = cls; | 1115 | struct RecordLookupContext *rlc = cls; |
1093 | struct GNUNET_GNSRECORD_Data *rd_res; | ||
1094 | unsigned int rdc_res; | ||
1095 | 1116 | ||
1096 | (void) private_key; | 1117 | (void) private_key; |
1097 | (void) seq; | 1118 | (void) seq; |
1098 | if (0 == strcmp (label, | 1119 | if (0 != strcmp (label, |
1099 | rlc->label)) | 1120 | rlc->label)) |
1121 | return; | ||
1122 | rlc->found = GNUNET_YES; | ||
1123 | if (0 == rd_count) | ||
1100 | { | 1124 | { |
1101 | rlc->found = GNUNET_YES; | 1125 | rlc->rd_ser_len = 0; |
1102 | if (0 != rd_count) | 1126 | rlc->res_rd_count = 0; |
1127 | rlc->res_rd = NULL; | ||
1128 | return; | ||
1129 | } | ||
1130 | if ( (NULL != rlc->nick) && | ||
1131 | (0 != strcmp (label, | ||
1132 | GNUNET_GNS_EMPTY_LABEL_AT)) ) | ||
1133 | { | ||
1134 | /* Merge */ | ||
1135 | struct GNUNET_GNSRECORD_Data *rd_res; | ||
1136 | unsigned int rdc_res; | ||
1137 | |||
1138 | rd_res = NULL; | ||
1139 | rdc_res = 0; | ||
1140 | rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; | ||
1141 | merge_with_nick_records (rlc->nick, | ||
1142 | rd_count, | ||
1143 | rd, | ||
1144 | &rdc_res, | ||
1145 | &rd_res); | ||
1146 | rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res, | ||
1147 | rd_res); | ||
1148 | if (rlc->rd_ser_len < 0) | ||
1103 | { | 1149 | { |
1104 | if ( (NULL != rlc->nick) && | 1150 | GNUNET_break (0); |
1105 | (0 != strcmp (label, | 1151 | GNUNET_free (rd_res); |
1106 | GNUNET_GNS_EMPTY_LABEL_AT)) ) | 1152 | rlc->found = GNUNET_NO; |
1107 | { | 1153 | rlc->rd_ser_len = 0; |
1108 | /* Merge */ | 1154 | return; |
1109 | rd_res = NULL; | 1155 | } |
1110 | rdc_res = 0; | 1156 | rlc->res_rd_count = rdc_res; |
1111 | rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; | 1157 | rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len); |
1112 | merge_with_nick_records (rlc->nick, | 1158 | if (rlc->rd_ser_len != |
1113 | rd_count, | ||
1114 | rd, | ||
1115 | &rdc_res, | ||
1116 | &rd_res); | ||
1117 | rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res, | ||
1118 | rd_res); | ||
1119 | rlc->res_rd_count = rdc_res; | ||
1120 | rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len); | ||
1121 | GNUNET_GNSRECORD_records_serialize (rdc_res, | 1159 | GNUNET_GNSRECORD_records_serialize (rdc_res, |
1122 | rd_res, | 1160 | rd_res, |
1123 | rlc->rd_ser_len, | 1161 | rlc->rd_ser_len, |
1124 | rlc->res_rd); | 1162 | rlc->res_rd)) |
1125 | 1163 | { | |
1126 | GNUNET_free (rd_res); | 1164 | GNUNET_break (0); |
1127 | GNUNET_free (rlc->nick); | 1165 | GNUNET_free (rlc->res_rd); |
1128 | rlc->nick = NULL; | 1166 | rlc->res_rd = NULL; |
1129 | } | 1167 | rlc->res_rd_count = 0; |
1130 | else | 1168 | rlc->rd_ser_len = 0; |
1131 | { | 1169 | GNUNET_free (rd_res); |
1132 | rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, | 1170 | rlc->found = GNUNET_NO; |
1133 | rd); | 1171 | return; |
1134 | rlc->res_rd_count = rd_count; | 1172 | } |
1135 | rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len); | 1173 | GNUNET_free (rd_res); |
1174 | GNUNET_free (rlc->nick); | ||
1175 | rlc->nick = NULL; | ||
1176 | } | ||
1177 | else | ||
1178 | { | ||
1179 | rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, | ||
1180 | rd); | ||
1181 | if (rlc->rd_ser_len < 0) | ||
1182 | { | ||
1183 | GNUNET_break (0); | ||
1184 | rlc->found = GNUNET_NO; | ||
1185 | rlc->rd_ser_len = 0; | ||
1186 | return; | ||
1187 | } | ||
1188 | rlc->res_rd_count = rd_count; | ||
1189 | rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len); | ||
1190 | if (rlc->rd_ser_len != | ||
1136 | GNUNET_GNSRECORD_records_serialize (rd_count, | 1191 | GNUNET_GNSRECORD_records_serialize (rd_count, |
1137 | rd, | 1192 | rd, |
1138 | rlc->rd_ser_len, | 1193 | rlc->rd_ser_len, |
1139 | rlc->res_rd); | 1194 | rlc->res_rd)) |
1140 | } | ||
1141 | } | ||
1142 | else | ||
1143 | { | 1195 | { |
1144 | rlc->rd_ser_len = 0; | 1196 | GNUNET_break (0); |
1145 | rlc->res_rd_count = 0; | 1197 | GNUNET_free (rlc->res_rd); |
1146 | rlc->res_rd = NULL; | 1198 | rlc->res_rd = NULL; |
1199 | rlc->res_rd_count = 0; | ||
1200 | rlc->rd_ser_len = 0; | ||
1201 | rlc->found = GNUNET_NO; | ||
1202 | return; | ||
1147 | } | 1203 | } |
1148 | } | 1204 | } |
1149 | } | 1205 | } |
@@ -1331,8 +1387,6 @@ handle_record_store (void *cls, | |||
1331 | rd_ser = &name_tmp[name_len]; | 1387 | rd_ser = &name_tmp[name_len]; |
1332 | { | 1388 | { |
1333 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)]; | 1389 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)]; |
1334 | struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)]; | ||
1335 | unsigned int rd_clean_off; | ||
1336 | 1390 | ||
1337 | if (GNUNET_OK != | 1391 | if (GNUNET_OK != |
1338 | GNUNET_GNSRECORD_records_deserialize (rd_ser_len, | 1392 | GNUNET_GNSRECORD_records_deserialize (rd_ser_len, |
@@ -1381,6 +1435,9 @@ handle_record_store (void *cls, | |||
1381 | { | 1435 | { |
1382 | /* remove "NICK" records, unless this is for the | 1436 | /* remove "NICK" records, unless this is for the |
1383 | #GNUNET_GNS_EMPTY_LABEL_AT label */ | 1437 | #GNUNET_GNS_EMPTY_LABEL_AT label */ |
1438 | struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)]; | ||
1439 | unsigned int rd_clean_off; | ||
1440 | |||
1384 | rd_clean_off = 0; | 1441 | rd_clean_off = 0; |
1385 | for (unsigned int i=0;i<rd_count;i++) | 1442 | for (unsigned int i=0;i<rd_count;i++) |
1386 | { | 1443 | { |
@@ -1420,12 +1477,6 @@ handle_record_store (void *cls, | |||
1420 | ntohs (rp_msg->gns_header.header.size)); | 1477 | ntohs (rp_msg->gns_header.header.size)); |
1421 | sa->zm_pos = monitor_head; | 1478 | sa->zm_pos = monitor_head; |
1422 | sa->conv_name = conv_name; | 1479 | sa->conv_name = conv_name; |
1423 | GNUNET_array_grow (sa->rd, | ||
1424 | sa->rd_count, | ||
1425 | rd_clean_off); | ||
1426 | GNUNET_memcpy (sa->rd, | ||
1427 | rd_clean, | ||
1428 | sizeof (struct GNUNET_GNSRECORD_Data) * rd_clean_off); | ||
1429 | continue_store_activity (sa); | 1480 | continue_store_activity (sa); |
1430 | } | 1481 | } |
1431 | } | 1482 | } |
@@ -1479,7 +1530,7 @@ handle_zone_to_name_it (void *cls, | |||
1479 | struct ZoneToNameResponseMessage *ztnr_msg; | 1530 | struct ZoneToNameResponseMessage *ztnr_msg; |
1480 | int16_t res; | 1531 | int16_t res; |
1481 | size_t name_len; | 1532 | size_t name_len; |
1482 | size_t rd_ser_len; | 1533 | ssize_t rd_ser_len; |
1483 | size_t msg_size; | 1534 | size_t msg_size; |
1484 | char *name_tmp; | 1535 | char *name_tmp; |
1485 | char *rd_tmp; | 1536 | char *rd_tmp; |
@@ -1490,7 +1541,14 @@ handle_zone_to_name_it (void *cls, | |||
1490 | name); | 1541 | name); |
1491 | res = GNUNET_YES; | 1542 | res = GNUNET_YES; |
1492 | name_len = (NULL == name) ? 0 : strlen (name) + 1; | 1543 | name_len = (NULL == name) ? 0 : strlen (name) + 1; |
1493 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); | 1544 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, |
1545 | rd); | ||
1546 | if (rd_ser_len < 0) | ||
1547 | { | ||
1548 | GNUNET_break (0); | ||
1549 | ztn_ctx->success = GNUNET_SYSERR; | ||
1550 | return; | ||
1551 | } | ||
1494 | msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len; | 1552 | msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len; |
1495 | if (msg_size >= GNUNET_MAX_MESSAGE_SIZE) | 1553 | if (msg_size >= GNUNET_MAX_MESSAGE_SIZE) |
1496 | { | 1554 | { |
@@ -1513,10 +1571,11 @@ handle_zone_to_name_it (void *cls, | |||
1513 | name, | 1571 | name, |
1514 | name_len); | 1572 | name_len); |
1515 | rd_tmp = &name_tmp[name_len]; | 1573 | rd_tmp = &name_tmp[name_len]; |
1516 | GNUNET_GNSRECORD_records_serialize (rd_count, | 1574 | GNUNET_assert (rd_ser_len == |
1517 | rd, | 1575 | GNUNET_GNSRECORD_records_serialize (rd_count, |
1518 | rd_ser_len, | 1576 | rd, |
1519 | rd_tmp); | 1577 | rd_ser_len, |
1578 | rd_tmp)); | ||
1520 | ztn_ctx->success = GNUNET_OK; | 1579 | ztn_ctx->success = GNUNET_OK; |
1521 | GNUNET_MQ_send (ztn_ctx->nc->mq, | 1580 | GNUNET_MQ_send (ztn_ctx->nc->mq, |
1522 | env); | 1581 | env); |
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c index b394178a6..44c9fe89e 100644 --- a/src/namestore/gnunet-zoneimport.c +++ b/src/namestore/gnunet-zoneimport.c | |||
@@ -1494,6 +1494,16 @@ do_shutdown (void *cls) | |||
1494 | 1494 | ||
1495 | 1495 | ||
1496 | /** | 1496 | /** |
1497 | * Iterate over all of the zones we care about and see which records | ||
1498 | * we may need to re-fetch when. | ||
1499 | * | ||
1500 | * @param cls NULL | ||
1501 | */ | ||
1502 | static void | ||
1503 | iterate_zones (void *cls); | ||
1504 | |||
1505 | |||
1506 | /** | ||
1497 | * Function called if #GNUNET_NAMESTORE_records_lookup() failed. | 1507 | * Function called if #GNUNET_NAMESTORE_records_lookup() failed. |
1498 | * Just logs an error. | 1508 | * Just logs an error. |
1499 | * | 1509 | * |
@@ -1507,6 +1517,9 @@ ns_lookup_error_cb (void *cls) | |||
1507 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1517 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1508 | "Failed to load data from namestore for zone `%s'\n", | 1518 | "Failed to load data from namestore for zone `%s'\n", |
1509 | zone->domain); | 1519 | zone->domain); |
1520 | zone_it = NULL; | ||
1521 | ns_iterator_trigger_next = 0; | ||
1522 | iterate_zones (NULL); | ||
1510 | } | 1523 | } |
1511 | 1524 | ||
1512 | 1525 | ||
@@ -1842,7 +1855,7 @@ process_stdin (void *cls) | |||
1842 | delta = GNUNET_TIME_absolute_get_duration (last); | 1855 | delta = GNUNET_TIME_absolute_get_duration (last); |
1843 | last = GNUNET_TIME_absolute_get (); | 1856 | last = GNUNET_TIME_absolute_get (); |
1844 | fprintf (stderr, | 1857 | fprintf (stderr, |
1845 | "Read 10000 domain names in %s\n", | 1858 | "Read 100000 domain names in %s\n", |
1846 | GNUNET_STRINGS_relative_time_to_string (delta, | 1859 | GNUNET_STRINGS_relative_time_to_string (delta, |
1847 | GNUNET_YES)); | 1860 | GNUNET_YES)); |
1848 | GNUNET_STATISTICS_set (stats, | 1861 | GNUNET_STATISTICS_set (stats, |
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 57bf8f81b..f2aaa43c8 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -1033,7 +1033,7 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
1033 | struct GNUNET_MQ_Envelope *env; | 1033 | struct GNUNET_MQ_Envelope *env; |
1034 | char *name_tmp; | 1034 | char *name_tmp; |
1035 | char *rd_ser; | 1035 | char *rd_ser; |
1036 | size_t rd_ser_len; | 1036 | ssize_t rd_ser_len; |
1037 | size_t name_len; | 1037 | size_t name_len; |
1038 | uint32_t rid; | 1038 | uint32_t rid; |
1039 | struct RecordStoreMessage *msg; | 1039 | struct RecordStoreMessage *msg; |
@@ -1045,6 +1045,18 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
1045 | GNUNET_break (0); | 1045 | GNUNET_break (0); |
1046 | return NULL; | 1046 | return NULL; |
1047 | } | 1047 | } |
1048 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, | ||
1049 | rd); | ||
1050 | if (rd_ser_len < 0) | ||
1051 | { | ||
1052 | GNUNET_break (0); | ||
1053 | return NULL; | ||
1054 | } | ||
1055 | if (rd_ser_len > UINT16_MAX) | ||
1056 | { | ||
1057 | GNUNET_break (0); | ||
1058 | return NULL; | ||
1059 | } | ||
1048 | rid = get_op_id (h); | 1060 | rid = get_op_id (h); |
1049 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); | 1061 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); |
1050 | qe->h = h; | 1062 | qe->h = h; |
@@ -1056,8 +1068,6 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
1056 | qe); | 1068 | qe); |
1057 | 1069 | ||
1058 | /* setup msg */ | 1070 | /* setup msg */ |
1059 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, | ||
1060 | rd); | ||
1061 | env = GNUNET_MQ_msg_extra (msg, | 1071 | env = GNUNET_MQ_msg_extra (msg, |
1062 | name_len + rd_ser_len, | 1072 | name_len + rd_ser_len, |
1063 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE); | 1073 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE); |
@@ -1077,8 +1087,10 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
1077 | rd, | 1087 | rd, |
1078 | rd_ser_len, | 1088 | rd_ser_len, |
1079 | rd_ser); | 1089 | rd_ser); |
1080 | if (0 > sret) | 1090 | if ( (0 > sret) || |
1091 | (sret != rd_ser_len) ) | ||
1081 | { | 1092 | { |
1093 | GNUNET_break (0); | ||
1082 | GNUNET_free (env); | 1094 | GNUNET_free (env); |
1083 | return NULL; | 1095 | return NULL; |
1084 | } | 1096 | } |
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c index 9ba90833b..16780ad0c 100644 --- a/src/namestore/namestore_api_monitor.c +++ b/src/namestore/namestore_api_monitor.c | |||
@@ -144,6 +144,11 @@ check_result (void *cls, | |||
144 | rd_len = ntohs (lrm->rd_len); | 144 | rd_len = ntohs (lrm->rd_len); |
145 | rd_count = ntohs (lrm->rd_count); | 145 | rd_count = ntohs (lrm->rd_count); |
146 | name_len = ntohs (lrm->name_len); | 146 | name_len = ntohs (lrm->name_len); |
147 | if (name_len > MAX_NAME_LEN) | ||
148 | { | ||
149 | GNUNET_break (0); | ||
150 | return GNUNET_SYSERR; | ||
151 | } | ||
147 | exp_lrm_len = sizeof (struct RecordResultMessage) + name_len + rd_len; | 152 | exp_lrm_len = sizeof (struct RecordResultMessage) + name_len + rd_len; |
148 | if (lrm_len != exp_lrm_len) | 153 | if (lrm_len != exp_lrm_len) |
149 | { | 154 | { |
@@ -156,7 +161,7 @@ check_result (void *cls, | |||
156 | return GNUNET_SYSERR; | 161 | return GNUNET_SYSERR; |
157 | } | 162 | } |
158 | name_tmp = (const char *) &lrm[1]; | 163 | name_tmp = (const char *) &lrm[1]; |
159 | if ((name_tmp[name_len -1] != '\0') || (name_len > MAX_NAME_LEN)) | 164 | if (name_tmp[name_len -1] != '\0') |
160 | { | 165 | { |
161 | GNUNET_break (0); | 166 | GNUNET_break (0); |
162 | return GNUNET_SYSERR; | 167 | return GNUNET_SYSERR; |
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c index 35d8424b4..95edb9d87 100644 --- a/src/namestore/plugin_namestore_flat.c +++ b/src/namestore/plugin_namestore_flat.c | |||
@@ -301,7 +301,7 @@ store_and_free_entries (void *cls, | |||
301 | char *line; | 301 | char *line; |
302 | char *zone_private_key; | 302 | char *zone_private_key; |
303 | char *record_data_b64; | 303 | char *record_data_b64; |
304 | size_t data_size; | 304 | ssize_t data_size; |
305 | 305 | ||
306 | (void) key; | 306 | (void) key; |
307 | GNUNET_STRINGS_base64_encode ((char*)entry->private_key, | 307 | GNUNET_STRINGS_base64_encode ((char*)entry->private_key, |
@@ -309,6 +309,18 @@ store_and_free_entries (void *cls, | |||
309 | &zone_private_key); | 309 | &zone_private_key); |
310 | data_size = GNUNET_GNSRECORD_records_get_size (entry->record_count, | 310 | data_size = GNUNET_GNSRECORD_records_get_size (entry->record_count, |
311 | entry->record_data); | 311 | entry->record_data); |
312 | if (data_size < 0) | ||
313 | { | ||
314 | GNUNET_break (0); | ||
315 | GNUNET_free (zone_private_key); | ||
316 | return GNUNET_SYSERR; | ||
317 | } | ||
318 | if (data_size >= UINT16_MAX) | ||
319 | { | ||
320 | GNUNET_break (0); | ||
321 | GNUNET_free (zone_private_key); | ||
322 | return GNUNET_SYSERR; | ||
323 | } | ||
312 | { | 324 | { |
313 | char data[data_size]; | 325 | char data[data_size]; |
314 | ssize_t ret; | 326 | ssize_t ret; |
@@ -318,7 +330,7 @@ store_and_free_entries (void *cls, | |||
318 | data_size, | 330 | data_size, |
319 | data); | 331 | data); |
320 | if ( (ret < 0) || | 332 | if ( (ret < 0) || |
321 | (data_size != (size_t) ret) ) | 333 | (data_size != ret) ) |
322 | { | 334 | { |
323 | GNUNET_break (0); | 335 | GNUNET_break (0); |
324 | GNUNET_free (zone_private_key); | 336 | GNUNET_free (zone_private_key); |
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index d7907b1a6..09fdd760f 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c | |||
@@ -220,7 +220,7 @@ namestore_postgres_store_records (void *cls, | |||
220 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 220 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
221 | uint64_t rvalue; | 221 | uint64_t rvalue; |
222 | uint32_t rd_count32 = (uint32_t) rd_count; | 222 | uint32_t rd_count32 = (uint32_t) rd_count; |
223 | size_t data_size; | 223 | ssize_t data_size; |
224 | 224 | ||
225 | memset (&pkey, | 225 | memset (&pkey, |
226 | 0, | 226 | 0, |
@@ -238,7 +238,12 @@ namestore_postgres_store_records (void *cls, | |||
238 | UINT64_MAX); | 238 | UINT64_MAX); |
239 | data_size = GNUNET_GNSRECORD_records_get_size (rd_count, | 239 | data_size = GNUNET_GNSRECORD_records_get_size (rd_count, |
240 | rd); | 240 | rd); |
241 | if (data_size > 64 * 65536) | 241 | if (data_size < 0) |
242 | { | ||
243 | GNUNET_break (0); | ||
244 | return GNUNET_SYSERR; | ||
245 | } | ||
246 | if (data_size >= UINT16_MAX) | ||
242 | { | 247 | { |
243 | GNUNET_break (0); | 248 | GNUNET_break (0); |
244 | return GNUNET_SYSERR; | 249 | return GNUNET_SYSERR; |
@@ -287,7 +292,7 @@ namestore_postgres_store_records (void *cls, | |||
287 | data_size, | 292 | data_size, |
288 | data); | 293 | data); |
289 | if ( (ret < 0) || | 294 | if ( (ret < 0) || |
290 | (data_size != (size_t) ret) ) | 295 | (data_size != ret) ) |
291 | { | 296 | { |
292 | GNUNET_break (0); | 297 | GNUNET_break (0); |
293 | return GNUNET_SYSERR; | 298 | return GNUNET_SYSERR; |
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index 34e548613..81391ce8a 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c | |||
@@ -313,7 +313,7 @@ namestore_sqlite_store_records (void *cls, | |||
313 | int n; | 313 | int n; |
314 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 314 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
315 | uint64_t rvalue; | 315 | uint64_t rvalue; |
316 | size_t data_size; | 316 | ssize_t data_size; |
317 | 317 | ||
318 | memset (&pkey, | 318 | memset (&pkey, |
319 | 0, | 319 | 0, |
@@ -332,6 +332,11 @@ namestore_sqlite_store_records (void *cls, | |||
332 | UINT64_MAX); | 332 | UINT64_MAX); |
333 | data_size = GNUNET_GNSRECORD_records_get_size (rd_count, | 333 | data_size = GNUNET_GNSRECORD_records_get_size (rd_count, |
334 | rd); | 334 | rd); |
335 | if (data_size < 0) | ||
336 | { | ||
337 | GNUNET_break (0); | ||
338 | return GNUNET_SYSERR; | ||
339 | } | ||
335 | if (data_size > 64 * 65536) | 340 | if (data_size > 64 * 65536) |
336 | { | 341 | { |
337 | GNUNET_break (0); | 342 | GNUNET_break (0); |
@@ -352,7 +357,7 @@ namestore_sqlite_store_records (void *cls, | |||
352 | data_size, | 357 | data_size, |
353 | data); | 358 | data); |
354 | if ( (ret < 0) || | 359 | if ( (ret < 0) || |
355 | (data_size != (size_t) ret) ) | 360 | (data_size != ret) ) |
356 | { | 361 | { |
357 | GNUNET_break (0); | 362 | GNUNET_break (0); |
358 | return GNUNET_SYSERR; | 363 | return GNUNET_SYSERR; |
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf index 07409ea2b..5e96eab7c 100644 --- a/src/namestore/test_namestore_api.conf +++ b/src/namestore/test_namestore_api.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | 3 | ||
4 | [PATHS] | 4 | [PATHS] |
5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-namestore/ | 5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-namestore/ |
diff --git a/src/peerinfo-tool/test_gnunet_peerinfo.py.in b/src/peerinfo-tool/test_gnunet_peerinfo.py.in index 3207c2c2f..fb5941121 100755 --- a/src/peerinfo-tool/test_gnunet_peerinfo.py.in +++ b/src/peerinfo-tool/test_gnunet_peerinfo.py.in | |||
@@ -1,6 +1,6 @@ | |||
1 | #!@PYTHON@ | 1 | #!@PYTHON@ |
2 | # This file is part of GNUnet. | 2 | # This file is part of GNUnet. |
3 | # (C) 2010 Christian Grothoff (and other contributing authors) | 3 | # (C) 2010, 2018 Christian Grothoff (and other contributing authors) |
4 | # | 4 | # |
5 | # GNUnet is free software; you can redistribute it and/or modify | 5 | # GNUnet is free software; you can redistribute it and/or modify |
6 | # it under the terms of the GNU General Public License as published | 6 | # it under the terms of the GNU General Public License as published |
@@ -26,70 +26,70 @@ import shutil | |||
26 | import time | 26 | import time |
27 | 27 | ||
28 | srcdir = "../.." | 28 | srcdir = "../.." |
29 | gnunet_pyexpect_dir = os.path.join (srcdir, "contrib") | 29 | gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts") |
30 | if gnunet_pyexpect_dir not in sys.path: | 30 | if gnunet_pyexpect_dir not in sys.path: |
31 | sys.path.append (gnunet_pyexpect_dir) | 31 | sys.path.append(gnunet_pyexpect_dir) |
32 | 32 | ||
33 | from gnunet_pyexpect import pexpect | 33 | from gnunet_pyexpect import pexpect |
34 | 34 | ||
35 | if os.name == 'posix': | 35 | if os.name == 'posix': |
36 | peerinfo = './gnunet-peerinfo' | 36 | peerinfo = './gnunet-peerinfo' |
37 | gnunetarm = 'gnunet-arm' | 37 | gnunetarm = 'gnunet-arm' |
38 | gnunettesting = 'gnunet-testing' | 38 | gnunettesting = 'gnunet-testing' |
39 | elif os.name == 'nt': | 39 | elif os.name == 'nt': |
40 | peerinfo = './gnunet-peerinfo.exe' | 40 | peerinfo = './gnunet-peerinfo.exe' |
41 | gnunetarm = 'gnunet-arm.exe' | 41 | gnunetarm = 'gnunet-arm.exe' |
42 | gnunettesting = 'gnunet-testing.exe' | 42 | gnunettesting = 'gnunet-testing.exe' |
43 | 43 | ||
44 | pinfo = pexpect () | 44 | pinfo = pexpect() |
45 | 45 | ||
46 | 46 | ||
47 | if os.name == "nt": | 47 | if os.name == "nt": |
48 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-peerinfo"), True) | 48 | shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True) |
49 | else: | 49 | else: |
50 | shutil.rmtree ("/tmp/gnunet-test-peerinfo", True) | 50 | shutil.rmtree("/tmp/gnunet-test-peerinfo", True) |
51 | 51 | ||
52 | # create hostkey via testing lib | 52 | # create hostkey via testing lib # FIXME: The /tmp/ location needs to be adjusted to the TMP variable! |
53 | hkk = subprocess.Popen ([gnunettesting, '-n', '1', '-c', 'test_gnunet_peerinfo_data.conf', '-k', '/tmp/gnunet-test-peerinfo/.hostkey']) | 53 | hkk = subprocess.Popen([gnunettesting, '-n', '1', '-c', 'test_gnunet_peerinfo_data.conf', '-k', '/tmp/gnunet-test-peerinfo/.hostkey']) |
54 | hkk.communicate () | 54 | hkk.communicate() |
55 | 55 | ||
56 | arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_peerinfo_data.conf']) | 56 | arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_peerinfo_data.conf']) |
57 | arm.communicate () | 57 | arm.communicate() |
58 | 58 | ||
59 | try: | 59 | try: |
60 | pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 60 | pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
61 | pinfo.expect ("stdout", re.compile (r'I am peer `.*\'.\r?\n')) | 61 | pinfo.expect("stdout", re.compile(r'I am peer `.*\'.\r?\n')) |
62 | 62 | ||
63 | pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 63 | pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
64 | pinfo.expect ("stdout", re.compile (r'....................................................\r?\n')) | 64 | pinfo.expect("stdout", re.compile(r'....................................................\r?\n')) |
65 | 65 | ||
66 | pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', 'invalid'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 66 | pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', 'invalid'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
67 | pinfo.expect ("stdout", re.compile (r'Invalid command line argument `invalid\'\r?\n')) | 67 | pinfo.expect("stdout", re.compile(r'Invalid command line argument `invalid\'\r?\n')) |
68 | 68 | ||
69 | arm = subprocess.Popen ([gnunetarm, '-q', '-i', 'transport', '-c', 'test_gnunet_peerinfo_data.conf']) | 69 | arm = subprocess.Popen([gnunetarm, '-q', '-i', 'transport', '-c', 'test_gnunet_peerinfo_data.conf']) |
70 | arm.communicate () | 70 | arm.communicate() |
71 | time.sleep (1) | 71 | time.sleep(1) |
72 | 72 | ||
73 | pinfo.spawn (None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 73 | pinfo.spawn(None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
74 | pinfo.expect ("stdout", re.compile ("Peer `.*'\r?\n")) | 74 | pinfo.expect("stdout", re.compile("Peer `.*'\r?\n")) |
75 | m = pinfo.expect ("stdout", re.compile ("\s.*:24357\r?\n")) | 75 | m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n")) |
76 | while len (m.group (0)) > 0: | 76 | while len(m.group(0)) > 0: |
77 | m = pinfo.expect ("stdout", re.compile ("(\s.*:24357\r?\n|\r?\n|)")) | 77 | m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)")) |
78 | 78 | ||
79 | pinfo.spawn (None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf', '-n'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 79 | pinfo.spawn(None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf', '-n'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
80 | pinfo.expect ("stdout", re.compile ("Peer `.*'\r?\n")) | 80 | pinfo.expect("stdout", re.compile("Peer `.*'\r?\n")) |
81 | m = pinfo.expect ("stdout", re.compile ("\s.*:24357\r?\n")) | 81 | m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n")) |
82 | while len (m.group (0)) > 0: | 82 | while len(m.group(0)) > 0: |
83 | m = pinfo.expect ("stdout", re.compile ("(\s.*:24357\r?\n|\r?\n|)")) | 83 | m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)")) |
84 | 84 | ||
85 | pinfo.spawn (None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 85 | pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
86 | pid = pinfo.read ("stdout") | 86 | pid = pinfo.read("stdout") |
87 | pid.strip () | 87 | pid.strip() |
88 | 88 | ||
89 | finally: | 89 | finally: |
90 | arm = subprocess.Popen ([gnunetarm, '-eq', '-c', 'test_gnunet_peerinfo_data.conf']) | 90 | arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_peerinfo_data.conf']) |
91 | arm.communicate () | 91 | arm.communicate() |
92 | if os.name == "nt": | 92 | if os.name == "nt": |
93 | shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-peerinfo"), True) | 93 | shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True) |
94 | else: | 94 | else: |
95 | shutil.rmtree ("/tmp/gnunet-test-peerinfo", True) | 95 | shutil.rmtree("/tmp/gnunet-test-peerinfo", True) |
diff --git a/src/peerinfo-tool/test_gnunet_peerinfo_data.conf b/src/peerinfo-tool/test_gnunet_peerinfo_data.conf index 32b096809..d18d3cf96 100644 --- a/src/peerinfo-tool/test_gnunet_peerinfo_data.conf +++ b/src/peerinfo-tool/test_gnunet_peerinfo_data.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/gnunet-test-peerinfo/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/gnunet-test-peerinfo/ |
diff --git a/src/psyc/test_psyc.conf b/src/psyc/test_psyc.conf index 836255163..4e2563a8a 100644 --- a/src/psyc/test_psyc.conf +++ b/src/psyc/test_psyc.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [testbed] | 3 | [testbed] |
4 | HOSTNAME = localhost | 4 | HOSTNAME = localhost |
diff --git a/src/regex/test_regex_api_data.conf b/src/regex/test_regex_api_data.conf index 8c87eeb96..60dcdc0b6 100644 --- a/src/regex/test_regex_api_data.conf +++ b/src/regex/test_regex_api_data.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | 3 | ||
4 | [PATHS] | 4 | [PATHS] |
5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-regex-api/ | 5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-regex-api/ |
diff --git a/src/revocation/test_local_revocation.py.in b/src/revocation/test_local_revocation.py.in index 28257715f..067091b58 100644 --- a/src/revocation/test_local_revocation.py.in +++ b/src/revocation/test_local_revocation.py.in | |||
@@ -1,6 +1,6 @@ | |||
1 | #!@PYTHON@ | 1 | #!@PYTHON@ |
2 | # This file is part of GNUnet. | 2 | # This file is part of GNUnet. |
3 | # (C) 2010 Christian Grothoff (and other contributing authors) | 3 | # (C) 2010, 2018 Christian Grothoff (and other contributing authors) |
4 | # | 4 | # |
5 | # GNUnet is free software; you can redistribute it and/or modify | 5 | # GNUnet is free software; you can redistribute it and/or modify |
6 | # it under the terms of the GNU General Public License as published | 6 | # it under the terms of the GNU General Public License as published |
@@ -26,90 +26,89 @@ import re | |||
26 | import shutil | 26 | import shutil |
27 | 27 | ||
28 | if os.name == 'posix': | 28 | if os.name == 'posix': |
29 | config = 'gnunet-config' | 29 | config = 'gnunet-config' |
30 | gnunetarm = 'gnunet-arm' | 30 | gnunetarm = 'gnunet-arm' |
31 | ident = 'gnunet-identity' | 31 | ident = 'gnunet-identity' |
32 | revoc = './gnunet-revocation' | 32 | revoc = './gnunet-revocation' |
33 | elif os.name == 'nt': | 33 | elif os.name == 'nt': |
34 | config = 'gnunet-config.exe' | 34 | config = 'gnunet-config.exe' |
35 | gnunetarm = 'gnunet-arm.exe' | 35 | gnunetarm = 'gnunet-arm.exe' |
36 | ident = 'gnunet-identity.exe' | 36 | ident = 'gnunet-identity.exe' |
37 | revoc = './gnunet-revocation.exe' | 37 | revoc = './gnunet-revocation.exe' |
38 | 38 | ||
39 | TEST_CONFIGURATION = "test_revocation.conf" | 39 | TEST_CONFIGURATION = "test_revocation.conf" |
40 | TEST_REVOCATION_EGO = "revoc_test" | 40 | TEST_REVOCATION_EGO = "revoc_test" |
41 | 41 | ||
42 | 42 | get_clean = subprocess.Popen([config, '-c', TEST_CONFIGURATION, '-s', 'PATHS', '-o', 'GNUNET_HOME', '-f'], stdout=subprocess.PIPE) | |
43 | get_clean = subprocess.Popen ([config, '-c', TEST_CONFIGURATION, '-s', 'PATHS', '-o', 'GNUNET_HOME', '-f'], stdout=subprocess.PIPE) | 43 | cleandir, x = get_clean.communicate() |
44 | cleandir, x = get_clean.communicate () | ||
45 | cleandir = cleandir.decode("utf-8") | 44 | cleandir = cleandir.decode("utf-8") |
46 | cleandir = cleandir.rstrip ('\n').rstrip ('\r') | 45 | cleandir = cleandir.rstrip('\n').rstrip('\r') |
47 | 46 | ||
48 | if os.path.isdir (cleandir): | 47 | if os.path.isdir(cleandir): |
49 | shutil.rmtree (cleandir, True) | 48 | shutil.rmtree(cleandir, True) |
50 | 49 | ||
51 | res = 0 | 50 | res = 0 |
52 | arm = subprocess.Popen ([gnunetarm, '-s', '-c', TEST_CONFIGURATION]) | 51 | arm = subprocess.Popen([gnunetarm, '-s', '-c', TEST_CONFIGURATION]) |
53 | arm.communicate () | 52 | arm.communicate() |
54 | 53 | ||
55 | try: | 54 | try: |
56 | print ("Creating an ego " + TEST_REVOCATION_EGO) | 55 | print("Creating an ego " + TEST_REVOCATION_EGO) |
57 | sys.stdout.flush () | 56 | sys.stdout.flush() |
58 | sys.stderr.flush () | 57 | sys.stderr.flush() |
59 | idc = subprocess.Popen ([ident, '-C', TEST_REVOCATION_EGO, '-c', TEST_CONFIGURATION]) | 58 | idc = subprocess.Popen([ident, '-C', TEST_REVOCATION_EGO, '-c', TEST_CONFIGURATION]) |
60 | idc.communicate () | 59 | idc.communicate() |
61 | if idc.returncode != 0: | 60 | if idc.returncode != 0: |
62 | raise Exception ("gnunet-identity failed to create an ego `" + TEST_REVOCATION_EGO + "'") | 61 | raise Exception("gnunet-identity failed to create an ego `" + TEST_REVOCATION_EGO + "'") |
63 | 62 | ||
64 | sys.stdout.flush () | 63 | sys.stdout.flush() |
65 | sys.stderr.flush () | 64 | sys.stderr.flush() |
66 | idd = subprocess.Popen ([ident, '-d'], stdout=subprocess.PIPE) | 65 | idd = subprocess.Popen([ident, '-d'], stdout=subprocess.PIPE) |
67 | rev_key, x = idd.communicate () | 66 | rev_key, x = idd.communicate() |
68 | rev_key = rev_key.decode("utf-8") | 67 | rev_key = rev_key.decode("utf-8") |
69 | if len (rev_key.split ()) < 3: | 68 | if len(rev_key.split()) < 3: |
70 | raise Exception ("can't get revocation key out of `" + rev_key + "'") | 69 | raise Exception("can't get revocation key out of `" + rev_key + "'") |
71 | rev_key = rev_key.split ()[2] | 70 | rev_key = rev_key.split()[2] |
72 | 71 | ||
73 | print ("Testing key " + rev_key) | 72 | print("Testing key " + rev_key) |
74 | sys.stdout.flush () | 73 | sys.stdout.flush() |
75 | sys.stderr.flush () | 74 | sys.stderr.flush() |
76 | tst = subprocess.Popen ([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE) | 75 | tst = subprocess.Popen([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE) |
77 | output_not_revoked, x = tst.communicate () | 76 | output_not_revoked, x = tst.communicate() |
78 | output_not_revoked = output_not_revoked.decode("utf-8") | 77 | output_not_revoked = output_not_revoked.decode("utf-8") |
79 | if tst.returncode != 0: | 78 | if tst.returncode != 0: |
80 | raise Exception ("gnunet-revocation failed to test a key - " + str (tst.returncode) + ": " + output_not_revoked) | 79 | raise Exception("gnunet-revocation failed to test a key - " + str(tst.returncode) + ": " + output_not_revoked) |
81 | if 'valid' not in output_not_revoked: | 80 | if 'valid' not in output_not_revoked: |
82 | res = 1 | 81 | res = 1 |
83 | print ("Key was not valid") | 82 | print("Key was not valid") |
84 | else: | 83 | else: |
85 | print ("Key was valid") | 84 | print("Key was valid") |
86 | 85 | ||
87 | print ("Revoking key " + rev_key) | 86 | print("Revoking key " + rev_key) |
88 | sys.stdout.flush () | 87 | sys.stdout.flush() |
89 | sys.stderr.flush () | 88 | sys.stderr.flush() |
90 | rev = subprocess.Popen ([revoc, '-R', TEST_REVOCATION_EGO, '-p', '-c', TEST_CONFIGURATION]) | 89 | rev = subprocess.Popen([revoc, '-R', TEST_REVOCATION_EGO, '-p', '-c', TEST_CONFIGURATION]) |
91 | rev.communicate () | 90 | rev.communicate() |
92 | if rev.returncode != 0: | 91 | if rev.returncode != 0: |
93 | raise Exception ("gnunet-revocation failed to revoke a key") | 92 | raise Exception("gnunet-revocation failed to revoke a key") |
94 | 93 | ||
95 | print ("Testing revoked key " + rev_key) | 94 | print("Testing revoked key " + rev_key) |
96 | sys.stdout.flush () | 95 | sys.stdout.flush() |
97 | sys.stderr.flush () | 96 | sys.stderr.flush() |
98 | tst = subprocess.Popen ([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE) | 97 | tst = subprocess.Popen([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE) |
99 | output_revoked, x = tst.communicate () | 98 | output_revoked, x = tst.communicate() |
100 | output_revoked = output_revoked.decode("utf-8") | 99 | output_revoked = output_revoked.decode("utf-8") |
101 | if tst.returncode != 0: | 100 | if tst.returncode != 0: |
102 | raise Exception ("gnunet-revocation failed to test a revoked key") | 101 | raise Exception("gnunet-revocation failed to test a revoked key") |
103 | if 'revoked' not in output_revoked: | 102 | if 'revoked' not in output_revoked: |
104 | res = 1 | 103 | res = 1 |
105 | print ("Key was not revoked") | 104 | print("Key was not revoked") |
106 | else: | 105 | else: |
107 | print ("Key was revoked") | 106 | print("Key was revoked") |
108 | 107 | ||
109 | finally: | 108 | finally: |
110 | arm = subprocess.Popen ([gnunetarm, '-e', '-c', TEST_CONFIGURATION]) | 109 | arm = subprocess.Popen([gnunetarm, '-e', '-c', TEST_CONFIGURATION]) |
111 | arm.communicate () | 110 | arm.communicate() |
112 | if os.path.isdir (cleandir): | 111 | if os.path.isdir(cleandir): |
113 | shutil.rmtree (cleandir, True) | 112 | shutil.rmtree(cleandir, True) |
114 | 113 | ||
115 | sys.exit (res) | 114 | sys.exit(res) |
diff --git a/src/revocation/test_revocation.conf b/src/revocation/test_revocation.conf index 1beeba931..14ecf6064 100644 --- a/src/revocation/test_revocation.conf +++ b/src/revocation/test_revocation.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [paths] | 3 | [paths] |
4 | GNUNET_HOME=$GNUNET_TMP/test-revocation-service | 4 | GNUNET_HOME=$GNUNET_TMP/test-revocation-service |
diff --git a/src/rps/test_rps.conf b/src/rps/test_rps.conf index f171335d6..cf6b3150c 100644 --- a/src/rps/test_rps.conf +++ b/src/rps/test_rps.conf | |||
@@ -29,7 +29,7 @@ HOSTNAME = localhost | |||
29 | # MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS = 100 | 29 | # MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS = 100 |
30 | OVERLAY_TOPOLOGY = CLIQUE | 30 | OVERLAY_TOPOLOGY = CLIQUE |
31 | #OVERLAY_TOPOLOGY = SMALL_WORLD | 31 | #OVERLAY_TOPOLOGY = SMALL_WORLD |
32 | #SCALE_FREE_TOPOLOGY_CAP = | 32 | #SCALE_FREE_TOPOLOGY_CAP = |
33 | 33 | ||
34 | # OVERLAY_RANDOM_LINKS = 25 | 34 | # OVERLAY_RANDOM_LINKS = 25 |
35 | 35 | ||
@@ -74,6 +74,7 @@ DISABLE_TRY_CONNECT = YES | |||
74 | [cadet] | 74 | [cadet] |
75 | DISABLE_TRY_CONNECT = YES | 75 | DISABLE_TRY_CONNECT = YES |
76 | #OPTIONS=-l /tmp/rps_profiler_logs/cadet-[]-%Y-%m-%d.log | 76 | #OPTIONS=-l /tmp/rps_profiler_logs/cadet-[]-%Y-%m-%d.log |
77 | #PREFIX = valgrind | ||
77 | 78 | ||
78 | #[arm] | 79 | #[arm] |
79 | #GLOBAL_POSTFIX=-l /tmp/rps_profiler_logs/other-[]-%Y-%m-%d.log | 80 | #GLOBAL_POSTFIX=-l /tmp/rps_profiler_logs/other-[]-%Y-%m-%d.log |
@@ -120,4 +121,3 @@ AUTOSTART = NO | |||
120 | [fs] | 121 | [fs] |
121 | FORCESTART = NO | 122 | FORCESTART = NO |
122 | AUTOSTART = NO | 123 | AUTOSTART = NO |
123 | |||
diff --git a/src/scalarproduct/test_scalarproduct.conf b/src/scalarproduct/test_scalarproduct.conf index fca141108..c7e2b55f5 100644 --- a/src/scalarproduct/test_scalarproduct.conf +++ b/src/scalarproduct/test_scalarproduct.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-scalarproduct/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-scalarproduct/ |
diff --git a/src/set/test_set.conf b/src/set/test_set.conf index 58bd07773..02afd2ec5 100644 --- a/src/set/test_set.conf +++ b/src/set/test_set.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-set/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-set/ |
diff --git a/src/social/test_social.conf b/src/social/test_social.conf index 701789313..df9815fd2 100644 --- a/src/social/test_social.conf +++ b/src/social/test_social.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/gnunet-test-social/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/gnunet-test-social/ |
diff --git a/src/statistics/test_gnunet_statistics.py.in b/src/statistics/test_gnunet_statistics.py.in index 96714cf9a..64e66f238 100644 --- a/src/statistics/test_gnunet_statistics.py.in +++ b/src/statistics/test_gnunet_statistics.py.in | |||
@@ -8,7 +8,7 @@ import subprocess | |||
8 | import time | 8 | import time |
9 | 9 | ||
10 | if os.name == "nt": | 10 | if os.name == "nt": |
11 | tmp = os.getenv ("TEMP") | 11 | tmp = os.getenv("TEMP") |
12 | elif None != os.environ.get("TMPDIR"): | 12 | elif None != os.environ.get("TMPDIR"): |
13 | tmp = os.getenv("TMPDIR") | 13 | tmp = os.getenv("TMPDIR") |
14 | elif None != os.environ.get("TMP"): | 14 | elif None != os.environ.get("TMP"): |
@@ -17,136 +17,142 @@ else: | |||
17 | tmp = "/tmp" | 17 | tmp = "/tmp" |
18 | 18 | ||
19 | if os.name == 'nt': | 19 | if os.name == 'nt': |
20 | st = './gnunet-statistics.exe' | 20 | st = './gnunet-statistics.exe' |
21 | arm = 'gnunet-arm.exe' | 21 | arm = 'gnunet-arm.exe' |
22 | else: | 22 | else: |
23 | st = './gnunet-statistics' | 23 | st = './gnunet-statistics' |
24 | arm = 'gnunet-arm' | 24 | arm = 'gnunet-arm' |
25 | 25 | ||
26 | run_st = [st, '-c', 'test_statistics_api_data.conf'] | 26 | run_st = [st, '-c', 'test_statistics_api_data.conf'] |
27 | run_arm = [arm, '-c', 'test_statistics_api_data.conf'] | 27 | run_arm = [arm, '-c', 'test_statistics_api_data.conf'] |
28 | debug = os.getenv ('DEBUG') | 28 | debug = os.getenv('DEBUG') |
29 | if debug: | 29 | if debug: |
30 | run_arm += [debug.split (' ')] | 30 | run_arm += [debug.split(' ')] |
31 | 31 | ||
32 | def cleanup (): | 32 | |
33 | shutil.rmtree (os.path.join (tmp, "gnunet/test-gnunet-statistics"), True) | 33 | def cleanup(): |
34 | 34 | shutil.rmtree(os.path.join(tmp, "gnunet/test-gnunet-statistics"), True) | |
35 | def sub_run (args, want_stdo = True, want_stde = False, nofail = False): | 35 | |
36 | if want_stdo: | 36 | |
37 | stdo = subprocess.PIPE | 37 | def sub_run(args, want_stdo=True, want_stde=False, nofail=False): |
38 | else: | 38 | if want_stdo: |
39 | stdo = None | 39 | stdo = subprocess.PIPE |
40 | if want_stde: | 40 | else: |
41 | stde = subprocess.PIPE | 41 | stdo = None |
42 | else: | 42 | if want_stde: |
43 | stde = None | 43 | stde = subprocess.PIPE |
44 | p = subprocess.Popen (args, stdout = stdo, stderr = stde) | 44 | else: |
45 | stdo, stde = p.communicate () | 45 | stde = None |
46 | if not nofail: | 46 | p = subprocess.Popen(args, stdout=stdo, stderr=stde) |
47 | if p.returncode != 0: | 47 | stdo, stde = p.communicate() |
48 | sys.exit (p.returncode) | 48 | if not nofail: |
49 | return (p.returncode, stdo, stde) | 49 | if p.returncode != 0: |
50 | 50 | sys.exit(p.returncode) | |
51 | def fail (result): | 51 | return (p.returncode, stdo, stde) |
52 | print (result) | 52 | |
53 | r_arm (['-e'], want_stdo = False) | 53 | |
54 | sys.exit (1) | 54 | def fail(result): |
55 | 55 | print(result) | |
56 | def r_arm (extra_args, **kw): | 56 | r_arm(['-e'], want_stdo=False) |
57 | rc, stdo, stde = sub_run (run_arm + extra_args, **kw) | 57 | sys.exit(1) |
58 | if rc != 0: | 58 | |
59 | fail ("FAIL: error running {}".format (run_arm)) | 59 | |
60 | return (rc, stdo, stde) | 60 | def r_arm(extra_args, **kw): |
61 | 61 | rc, stdo, stde = sub_run(run_arm + extra_args, **kw) | |
62 | def r_st (extra_args, normal = True, **kw): | ||
63 | rc, stdo, stde = sub_run (run_st + extra_args, **kw) | ||
64 | if normal: | ||
65 | if rc != 0: | 62 | if rc != 0: |
66 | fail ("FAIL: error running {}".format (run_st)) | 63 | fail("FAIL: error running {}".format(run_arm)) |
67 | else: | 64 | return (rc, stdo, stde) |
68 | if rc == 0: | 65 | |
69 | fail ("FAIL: expected error while running {}".format (run_st)) | 66 | |
70 | return (rc, stdo, stde) | 67 | def r_st(extra_args, normal=True, **kw): |
71 | 68 | rc, stdo, stde = sub_run(run_st + extra_args, **kw) | |
72 | def restart (): | 69 | if normal: |
73 | print ("Restarting service...") | 70 | if rc != 0: |
74 | t = r_arm (['-k', 'statistics']) | 71 | fail("FAIL: error running {}".format(run_st)) |
75 | time.sleep (1) | 72 | else: |
76 | t = r_arm (['-i', 'statistics']) | 73 | if rc == 0: |
77 | time.sleep (1) | 74 | fail("FAIL: expected error while running {}".format(run_st)) |
78 | 75 | return (rc, stdo, stde) | |
79 | 76 | ||
80 | cleanup () | 77 | |
81 | 78 | def restart(): | |
82 | print ("Preparing: Starting service...") | 79 | print("Restarting service...") |
83 | t = r_arm (['-s'], want_stdo = False) | 80 | t = r_arm(['-k', 'statistics']) |
84 | time.sleep (1) | 81 | time.sleep(1) |
85 | t = r_arm (['-i', 'statistics'], want_stdo = False) | 82 | t = r_arm(['-i', 'statistics']) |
86 | time.sleep (1) | 83 | time.sleep(1) |
87 | 84 | ||
88 | print ("TEST: Bad argument checking...", end='') | 85 | |
89 | r_st (['-x'], normal = False, nofail = True, want_stdo = False, want_stde = True) | 86 | cleanup() |
90 | print ("PASS") | 87 | |
91 | 88 | print("Preparing: Starting service...") | |
92 | print ("TEST: Set value...", end='') | 89 | t = r_arm(['-s'], want_stdo=False) |
93 | r_st (['-n', 'test', '-s', 'subsystem', b'42'], nofail = True, want_stdo = False) | 90 | time.sleep(1) |
94 | print ("PASS") | 91 | t = r_arm(['-i', 'statistics'], want_stdo=False) |
95 | 92 | time.sleep(1) | |
96 | print ("TEST: Set another value...", end='') | 93 | |
97 | r_st (['-n', 'other', '-s', 'osystem', b'43'], nofail = True, want_stdo = False) | 94 | print("TEST: Bad argument checking...", end='') |
98 | print ("PASS") | 95 | r_st(['-x'], normal=False, nofail=True, want_stdo=False, want_stde=True) |
99 | 96 | print("PASS") | |
100 | print ("TEST: Viewing all stats...", end='') | 97 | |
101 | rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) | 98 | print("TEST: Set value...", end='') |
102 | if len (stdo.splitlines ()) != 2: | 99 | r_st(['-n', 'test', '-s', 'subsystem', b'42'], nofail=True, want_stdo=False) |
103 | fail ("FAIL: unexpected output:\n{}".format (stdo)) | 100 | print("PASS") |
104 | print ("PASS") | 101 | |
105 | 102 | print("TEST: Set another value...", end='') | |
106 | print ("TEST: Viewing stats by name...", end='') | 103 | r_st(['-n', 'other', '-s', 'osystem', b'43'], nofail=True, want_stdo=False) |
107 | rc, stdo, stde = r_st (['-n', 'other'], nofail = True, want_stdo = True) | 104 | print("PASS") |
108 | if len ([x for x in stdo.splitlines () if re.search (b'43', x)]) != 1: | 105 | |
109 | fail ("FAIL: unexpected output:\n{}".format (stdo)) | 106 | print("TEST: Viewing all stats...", end='') |
110 | print ("PASS") | 107 | rc, stdo, stde = r_st([], nofail=True, want_stdo=True) |
111 | 108 | if len(stdo.splitlines()) != 2: | |
112 | print ("TEST: Viewing stats by subsystem...", end='') | 109 | fail("FAIL: unexpected output:\n{}".format(stdo)) |
113 | rc, stdo, stde = r_st (['-s', 'subsystem'], nofail = True, want_stdo = True) | 110 | print("PASS") |
114 | if len ([x for x in stdo.splitlines () if re.search (b'42', x)]) != 1: | 111 | |
115 | fail ("FAIL: unexpected output:\n{}".format (stdo)) | 112 | print("TEST: Viewing stats by name...", end='') |
116 | print ("PASS") | 113 | rc, stdo, stde = r_st(['-n', 'other'], nofail=True, want_stdo=True) |
117 | 114 | if len([x for x in stdo.splitlines() if re.search(b'43', x)]) != 1: | |
118 | print ("TEST: Set persistent value...", end='') | 115 | fail("FAIL: unexpected output:\n{}".format(stdo)) |
119 | rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40', '-p'], nofail = True, want_stdo = False) | 116 | print("PASS") |
120 | rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) | 117 | |
121 | if len ([x for x in stdo.splitlines () if re.search (b'40', x)]) != 1: | 118 | print("TEST: Viewing stats by subsystem...", end='') |
122 | fail ("FAIL: unexpected output:\n{}".format (stdo)) | 119 | rc, stdo, stde = r_st(['-s', 'subsystem'], nofail=True, want_stdo=True) |
123 | print ("PASS") | 120 | if len([x for x in stdo.splitlines() if re.search(b'42', x)]) != 1: |
124 | 121 | fail("FAIL: unexpected output:\n{}".format(stdo)) | |
125 | restart () | 122 | print("PASS") |
126 | 123 | ||
127 | print ("TEST: Checking persistence...", end='') | 124 | print("TEST: Set persistent value...", end='') |
128 | rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) | 125 | rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40', '-p'], nofail=True, want_stdo=False) |
129 | if len ([x for x in stdo.splitlines () if re.search (b'40', x)]) != 1: | 126 | rc, stdo, stde = r_st([], nofail=True, want_stdo=True) |
130 | fail ("FAIL: unexpected output:\n{}".format (stdo)) | 127 | if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1: |
131 | print ("PASS") | 128 | fail("FAIL: unexpected output:\n{}".format(stdo)) |
132 | 129 | print("PASS") | |
133 | print ("TEST: Removing persistence...", end='') | 130 | |
134 | rc, stdo, stde = r_st (['-n', 'lasting', '-s', 'subsystem', '40'], nofail = True, want_stdo = False) | 131 | restart() |
135 | rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) | 132 | |
136 | if len ([x for x in stdo.splitlines () if re.search (b'!', x)]) != 0: | 133 | print("TEST: Checking persistence...", end='') |
137 | fail ("FAIL: unexpected output:\n{}".format (stdo)) | 134 | rc, stdo, stde = r_st([], nofail=True, want_stdo=True) |
138 | print ("PASS") | 135 | if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1: |
139 | 136 | fail("FAIL: unexpected output:\n{}".format(stdo)) | |
140 | restart () | 137 | print("PASS") |
141 | 138 | ||
142 | print ("TEST: Checking removed persistence...", end='') | 139 | print("TEST: Removing persistence...", end='') |
143 | rc, stdo, stde = r_st ([], nofail = True, want_stdo = True) | 140 | rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40'], nofail=True, want_stdo=False) |
144 | if len ([x for x in stdo.splitlines () if re.search (b'40', x)]) != 0: | 141 | rc, stdo, stde = r_st([], nofail=True, want_stdo=True) |
145 | fail ("FAIL: unexpected output:\n{}".format (stdo)) | 142 | if len([x for x in stdo.splitlines() if re.search(b'!', x)]) != 0: |
146 | print ("PASS") | 143 | fail("FAIL: unexpected output:\n{}".format(stdo)) |
147 | 144 | print("PASS") | |
148 | print ("Stopping service...") | 145 | |
149 | t = r_arm (['-e'], want_stdo = False) | 146 | restart() |
150 | time.sleep (1) | 147 | |
151 | 148 | print("TEST: Checking removed persistence...", end='') | |
152 | cleanup () | 149 | rc, stdo, stde = r_st([], nofail=True, want_stdo=True) |
150 | if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 0: | ||
151 | fail("FAIL: unexpected output:\n{}".format(stdo)) | ||
152 | print("PASS") | ||
153 | |||
154 | print("Stopping service...") | ||
155 | t = r_arm(['-e'], want_stdo=False) | ||
156 | time.sleep(1) | ||
157 | |||
158 | cleanup() | ||
diff --git a/src/statistics/test_statistics_api_data.conf b/src/statistics/test_statistics_api_data.conf index 9ef8d0673..d437c2aa8 100644 --- a/src/statistics/test_statistics_api_data.conf +++ b/src/statistics/test_statistics_api_data.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | 3 | ||
4 | [PATHS] | 4 | [PATHS] |
5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-statistics/ | 5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-statistics/ |
diff --git a/src/testbed/buildvars.py.in b/src/testbed/buildvars.py.in index 3ed65ad82..2a881b8f0 100644 --- a/src/testbed/buildvars.py.in +++ b/src/testbed/buildvars.py.in | |||
@@ -1,5 +1,5 @@ | |||
1 | # This file is part of GNUnet. | 1 | # This file is part of GNUnet. |
2 | # (C) 2008--2013 Christian Grothoff (and other contributing authors) | 2 | # (C) 2008--2013, 2018 Christian Grothoff (and other contributing authors) |
3 | # | 3 | # |
4 | # GNUnet is free software; you can redistribute it and/or modify | 4 | # GNUnet is free software; you can redistribute it and/or modify |
5 | # it under the terms of the GNU General Public License as published | 5 | # it under the terms of the GNU General Public License as published |
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | 19 | ||
20 | # file: testbed/buildvars.py | 20 | # file: testbed/buildvars.py |
21 | # brief: file for importing variables from build syste into python | 21 | # brief: file for importing variables from build system into python |
22 | # author: Sree Harsha Totakura | 22 | # author: Sree Harsha Totakura |
23 | 23 | ||
24 | import os | 24 | import os |
@@ -26,9 +26,10 @@ import os | |||
26 | exec_prefix = '@exec_prefix@' | 26 | exec_prefix = '@exec_prefix@' |
27 | libexecdir = '@libexecdir@' | 27 | libexecdir = '@libexecdir@' |
28 | 28 | ||
29 | if libexecdir.startswith (exec_prefix): | 29 | if libexecdir.startswith(exec_prefix): |
30 | libexecdir = libexecdir[len (exec_prefix):] | 30 | libexecdir = libexecdir[len(exec_prefix):] |
31 | 31 | ||
32 | gnunet_prefix = os.environ.get ('GNUNET_PREFIX', None) | 32 | gnunet_prefix = os.environ.get('GNUNET_PREFIX', None) |
33 | if gnunet_prefix and libexecdir.startswith ('/'): | 33 | |
34 | libexecdir = os.path.join (gnunet_prefix, libexecdir[1:]) | 34 | if gnunet_prefix and libexecdir.startswith('/'): |
35 | libexecdir = os.path.join(gnunet_prefix, libexecdir[1:]) | ||
diff --git a/src/testbed/test_testbed_api_template.conf b/src/testbed/test_testbed_api_template.conf index 89f16ed67..049829842 100644 --- a/src/testbed/test_testbed_api_template.conf +++ b/src/testbed/test_testbed_api_template.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | 3 | ||
4 | [testbed] | 4 | [testbed] |
5 | AUTOSTART = NO | 5 | AUTOSTART = NO |
diff --git a/src/transport/test_transport_api_limited_sockets_tcp_peer1.conf b/src/transport/test_transport_api_limited_sockets_tcp_peer1.conf index 9804f171e..e0ad5f847 100644 --- a/src/transport/test_transport_api_limited_sockets_tcp_peer1.conf +++ b/src/transport/test_transport_api_limited_sockets_tcp_peer1.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ template_cfg_peer1.conf | 1 | @INLINE@ template_cfg_peer1.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-transport/api-tcp-p1/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-transport/api-tcp-p1/ |
5 | 5 | ||
diff --git a/src/transport/test_transport_api_limited_sockets_tcp_peer2.conf b/src/transport/test_transport_api_limited_sockets_tcp_peer2.conf index 16dddf744..bb466abba 100644 --- a/src/transport/test_transport_api_limited_sockets_tcp_peer2.conf +++ b/src/transport/test_transport_api_limited_sockets_tcp_peer2.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | @INLINE@ template_cfg_peer2.conf | 1 | @INLINE@ template_cfg_peer2.conf |
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | 2 | @INLINE@ ../../contrib/conf/gnunet/no_autostart_above_core.conf |
3 | 3 | ||
4 | [PATHS] | 4 | [PATHS] |
5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-transport/api-tcp-p2/ | 5 | GNUNET_TEST_HOME = $GNUNET_TMP/test-transport/api-tcp-p2/ |
diff --git a/src/transport/test_transport_defaults.conf b/src/transport/test_transport_defaults.conf index ddb523986..3f38eeab7 100644 --- a/src/transport/test_transport_defaults.conf +++ b/src/transport/test_transport_defaults.conf | |||
@@ -1,4 +1,4 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | 1 | @INLINE@ ../../contrib/conf/gnunet/no_forcestart.conf |
2 | 2 | ||
3 | [PATHS] | 3 | [PATHS] |
4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-transport-api/ | 4 | GNUNET_TEST_HOME = $GNUNET_TMP/test-transport-api/ |
diff --git a/src/util/common_logging.c b/src/util/common_logging.c index df501fbcd..ce9bd6e46 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c | |||
@@ -1344,14 +1344,15 @@ GNUNET_h2s_full (const struct GNUNET_HashCode * hc) | |||
1344 | const char * | 1344 | const char * |
1345 | GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) | 1345 | GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) |
1346 | { | 1346 | { |
1347 | static char buf[256]; | 1347 | static char buf[5]; |
1348 | char *ret; | 1348 | char *ret; |
1349 | 1349 | ||
1350 | if (NULL == pid) | 1350 | if (NULL == pid) |
1351 | return "NULL"; | 1351 | return "NULL"; |
1352 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); | 1352 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); |
1353 | strcpy (buf, | 1353 | strncpy (buf, |
1354 | ret); | 1354 | ret, |
1355 | sizeof (buf) - 1); | ||
1355 | GNUNET_free (ret); | 1356 | GNUNET_free (ret); |
1356 | buf[4] = '\0'; | 1357 | buf[4] = '\0'; |
1357 | return buf; | 1358 | return buf; |
@@ -1372,14 +1373,15 @@ GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) | |||
1372 | const char * | 1373 | const char * |
1373 | GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid) | 1374 | GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid) |
1374 | { | 1375 | { |
1375 | static char buf[256]; | 1376 | static char buf[5]; |
1376 | char *ret; | 1377 | char *ret; |
1377 | 1378 | ||
1378 | if (NULL == pid) | 1379 | if (NULL == pid) |
1379 | return "NULL"; | 1380 | return "NULL"; |
1380 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); | 1381 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); |
1381 | strcpy (buf, | 1382 | strncpy (buf, |
1382 | ret); | 1383 | ret, |
1384 | sizeof (buf) - 1); | ||
1383 | GNUNET_free (ret); | 1385 | GNUNET_free (ret); |
1384 | buf[4] = '\0'; | 1386 | buf[4] = '\0'; |
1385 | return buf; | 1387 | return buf; |
diff --git a/src/util/crypto_bug.c b/src/util/crypto_bug.c index c25e79c63..1c3e9225e 100644 --- a/src/util/crypto_bug.c +++ b/src/util/crypto_bug.c | |||
@@ -28,7 +28,7 @@ | |||
28 | * Enable work-around. Will cause code to call #check_eddsa_key() to | 28 | * Enable work-around. Will cause code to call #check_eddsa_key() to |
29 | * see if we have a bad key, and if so, create a new one. | 29 | * see if we have a bad key, and if so, create a new one. |
30 | */ | 30 | */ |
31 | #define CRYPTO_BUG 1 | 31 | #define CRYPTO_BUG 0 |
32 | 32 | ||
33 | 33 | ||
34 | #if CRYPTO_BUG | 34 | #if CRYPTO_BUG |
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index 1abf0fddc..8d9091b23 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c | |||
@@ -1281,6 +1281,16 @@ eddsa_d_to_a (gcry_mpi_t d) | |||
1281 | gcry_mpi_print (GCRYMPI_FMT_USG, | 1281 | gcry_mpi_print (GCRYMPI_FMT_USG, |
1282 | rawmpi, rawmpilen, &rawmpilen, | 1282 | rawmpi, rawmpilen, &rawmpilen, |
1283 | d)); | 1283 | d)); |
1284 | if (rawmpilen < 32) | ||
1285 | { | ||
1286 | memmove (rawmpi + 32 - rawmpilen, | ||
1287 | rawmpi, | ||
1288 | rawmpilen); | ||
1289 | memset (rawmpi, | ||
1290 | 0, | ||
1291 | 32 - rawmpilen); | ||
1292 | rawmpilen = 32; | ||
1293 | } | ||
1284 | hvec[0].data = digest; | 1294 | hvec[0].data = digest; |
1285 | hvec[0].off = 0; | 1295 | hvec[0].off = 0; |
1286 | hvec[0].len = b > rawmpilen ? (b - rawmpilen) : 0; | 1296 | hvec[0].len = b > rawmpilen ? (b - rawmpilen) : 0; |
diff --git a/src/util/gnunet-qr.py.in b/src/util/gnunet-qr.py.in index 549ce5af1..a5918fdf8 100755 --- a/src/util/gnunet-qr.py.in +++ b/src/util/gnunet-qr.py.in | |||
@@ -4,105 +4,106 @@ import getopt | |||
4 | import subprocess | 4 | import subprocess |
5 | from sys import argv | 5 | from sys import argv |
6 | try: | 6 | try: |
7 | import zbar | 7 | import zbar |
8 | except ImportError as e: | 8 | except ImportError as e: |
9 | print('Cannot run gnunet-qr, please install zbar-python') | 9 | print('Cannot run gnunet-qr, please install zbar-python') |
10 | sys.exit (1) | 10 | sys.exit(1) |
11 | 11 | ||
12 | def help (): | 12 | |
13 | print('gnunet-qr\n\ | 13 | def help(): |
14 | print('gnunet-qr\n\ | ||
14 | Scan a QR code using a video device and import\n\ | 15 | Scan a QR code using a video device and import\n\ |
15 | Arguments mandatory for long options are also mandatory for short options.\n\ | 16 | Arguments mandatory for long options are also mandatory for short options.\n\ |
16 | -c, --config=FILENAME use configuration file FILENAME\n\ | 17 | -c, --config=FILENAME use configuration file FILENAME\n\ |
17 | -d, --device=DEVICE use device DEVICE\n\ | 18 | -d, --device=DEVICE use device DEVICE\n\ |
18 | -s, --silent do not show preview windows\n\ | 19 | -s, --silent do not show preview windows\n\ |
19 | -h, --help print this help\n\ | 20 | -h, --help print this help\n\ |
20 | -v, --verbose be verbose\n\ | 21 | -v, --verbose be verbose\n\ |
21 | Report bugs to gnunet-developers@gnu.org.\n\ | 22 | Report bugs to gnunet-developers@gnu.org.\n\ |
22 | GNUnet home page: http://www.gnu.org/software/gnunet/\n\ | 23 | GNUnet home page: http://www.gnu.org/software/gnunet/\n\ |
23 | General help using GNU software: http://www.gnu.org/gethelp/') | 24 | General help using GNU software: http://www.gnu.org/gethelp/') |
24 | 25 | ||
25 | 26 | ||
26 | if __name__ == '__main__': | 27 | if __name__ == '__main__': |
27 | configuration = '' | 28 | configuration = '' |
28 | device = '/dev/video0' | 29 | device = '/dev/video0' |
29 | url = '' | 30 | url = '' |
30 | verbose = False | 31 | verbose = False |
31 | silent = False | 32 | silent = False |
32 | # Parse arguments | 33 | # Parse arguments |
33 | try: | 34 | try: |
34 | opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config","help", "device","silent","verbose"]) | 35 | opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config", "help", "device", "silent", "verbose"]) |
35 | except getopt.GetoptError as e: | 36 | except getopt.GetoptError as e: |
36 | help () | 37 | help() |
37 | print(str (e)) | 38 | print(str(e)) |
38 | exit (1) | 39 | exit(1) |
39 | for o,a in opts: | 40 | for o, a in opts: |
40 | if o in ("-h", "--help"): | 41 | if o in ("-h", "--help"): |
41 | help () | 42 | help() |
42 | sys.exit (0) | 43 | sys.exit(0) |
43 | elif o in ("-c", "--config"): | 44 | elif o in ("-c", "--config"): |
44 | configuration = a | 45 | configuration = a |
45 | elif o in ("-d", "--device"): | 46 | elif o in ("-d", "--device"): |
46 | device = a | 47 | device = a |
47 | elif o in ("-s", "--silent"): | 48 | elif o in ("-s", "--silent"): |
48 | silent = True | 49 | silent = True |
49 | elif o in ("-v", "--verbose"): | 50 | elif o in ("-v", "--verbose"): |
50 | verbose = True | 51 | verbose = True |
51 | if (True == verbose): | 52 | if (True == verbose): |
52 | print('Initializing') | 53 | print('Initializing') |
53 | # create a Processor | 54 | # create a Processor |
54 | proc = zbar.Processor() | 55 | proc = zbar.Processor() |
56 | |||
57 | # configure the Processor | ||
58 | proc.parse_config('enable') | ||
59 | |||
60 | # initialize the Processor | ||
61 | try: | ||
62 | if (True == verbose): | ||
63 | print('Opening video device ' + device) | ||
64 | proc.init(device) | ||
65 | except Exception as e: | ||
66 | print('Failed to open device ' + device) | ||
67 | exit(1) | ||
68 | |||
69 | # enable the preview window | ||
70 | # if (True == silent): | ||
71 | # proc.visible = True | ||
72 | # else: | ||
73 | # proc.visible = False | ||
74 | |||
75 | proc.visible = True | ||
76 | # read at least one barcode (or until window closed) | ||
77 | try: | ||
78 | if (True == verbose): | ||
79 | print('Capturing') | ||
80 | proc.process_one() | ||
81 | except Exception as e: | ||
82 | # Window was closed without finding code | ||
83 | exit(1) | ||
55 | 84 | ||
56 | # configure the Processor | 85 | # hide the preview window |
57 | proc.parse_config('enable') | 86 | proc.visible = False |
58 | 87 | ||
59 | # initialize the Processor | 88 | # extract results |
60 | try: | 89 | for symbol in proc.results: |
61 | if (True == verbose): | 90 | # do something useful with results |
62 | print('Opening video device ' + device) | 91 | if (True == verbose): |
63 | proc.init(device) | 92 | print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data) |
64 | except Exception as e: | 93 | args = list() |
65 | print('Failed to open device ' + device) | 94 | args.append("gnunet-uri") |
66 | exit (1) | 95 | if (configuration != ''): |
67 | 96 | args.append(str("-c " + str(configuration))) | |
68 | # enable the preview window | 97 | args.append(str(symbol.data)) |
69 | #if (True == silent): | 98 | cmd = '' |
70 | # proc.visible = True | 99 | for a in args: |
71 | #else: | 100 | cmd += " " + str(a) |
72 | # proc.visible = False | 101 | if (verbose): |
73 | 102 | print('Running `' + cmd +'`') | |
74 | proc.visible = True | 103 | res=subprocess.call(args) |
75 | # read at least one barcode (or until window closed) | 104 | if (0 != res): |
76 | try: | 105 | print('Failed to add URI ' + str(symbol.data)) |
77 | if (True == verbose): | 106 | else: |
78 | print('Capturing') | 107 | print('Added URI ' + str(symbol.data)) |
79 | proc.process_one() | 108 | exit(res) |
80 | except Exception as e: | 109 | exit(1) |
81 | # Window was closed without finding code | ||
82 | exit (1) | ||
83 | |||
84 | # hide the preview window | ||
85 | proc.visible = False | ||
86 | |||
87 | # extract results | ||
88 | for symbol in proc.results: | ||
89 | # do something useful with results | ||
90 | if (True == verbose): | ||
91 | print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data) | ||
92 | args = list() | ||
93 | args.append("gnunet-uri") | ||
94 | if (configuration != ''): | ||
95 | args.append (str("-c " + str(configuration))) | ||
96 | args.append (str(symbol.data)) | ||
97 | cmd = '' | ||
98 | for a in args: | ||
99 | cmd += " " + str(a) | ||
100 | if (verbose): | ||
101 | print('Running `' + cmd +'`') | ||
102 | res=subprocess.call(args) | ||
103 | if (0 != res): | ||
104 | print('Failed to add URI ' + str(symbol.data)) | ||
105 | else: | ||
106 | print('Added URI ' + str(symbol.data)) | ||
107 | exit (res) | ||
108 | exit (1) | ||
diff --git a/src/util/mq.c b/src/util/mq.c index dbcce704d..81a42e0c6 100644 --- a/src/util/mq.c +++ b/src/util/mq.c | |||
@@ -1071,6 +1071,32 @@ GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq, | |||
1071 | 1071 | ||
1072 | 1072 | ||
1073 | /** | 1073 | /** |
1074 | * Obtain message contained in envelope. | ||
1075 | * | ||
1076 | * @param env the envelope | ||
1077 | * @return message contained in the envelope | ||
1078 | */ | ||
1079 | const struct GNUNET_MessageHeader * | ||
1080 | GNUNET_MQ_env_get_msg (const struct GNUNET_MQ_Envelope *env) | ||
1081 | { | ||
1082 | return env->mh; | ||
1083 | } | ||
1084 | |||
1085 | |||
1086 | /** | ||
1087 | * Return next envelope in queue. | ||
1088 | * | ||
1089 | * @param env a queued envelope | ||
1090 | * @return next one, or NULL | ||
1091 | */ | ||
1092 | const struct GNUNET_MQ_Envelope * | ||
1093 | GNUNET_MQ_env_next (const struct GNUNET_MQ_Envelope *env) | ||
1094 | { | ||
1095 | return env->next; | ||
1096 | } | ||
1097 | |||
1098 | |||
1099 | /** | ||
1074 | * Register function to be called whenever @a mq is being | 1100 | * Register function to be called whenever @a mq is being |
1075 | * destroyed. | 1101 | * destroyed. |
1076 | * | 1102 | * |
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index 68f02587a..21f902578 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -515,8 +515,8 @@ handle_response (void *cls, | |||
515 | if ( (NULL != rh->addr_callback) && | 515 | if ( (NULL != rh->addr_callback) && |
516 | (GNUNET_SYSERR != rh->was_transmitted) ) | 516 | (GNUNET_SYSERR != rh->was_transmitted) ) |
517 | rh->addr_callback (rh->cls, | 517 | rh->addr_callback (rh->cls, |
518 | NULL, | 518 | NULL, |
519 | 0); | 519 | 0); |
520 | } | 520 | } |
521 | rh->was_transmitted = GNUNET_NO; | 521 | rh->was_transmitted = GNUNET_NO; |
522 | GNUNET_RESOLVER_request_cancel (rh); | 522 | GNUNET_RESOLVER_request_cancel (rh); |