diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-06-18 21:49:23 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-06-18 21:49:23 +0000 |
commit | d8d3021ad9af2abe551fd6cd0fe2529a99d3683c (patch) | |
tree | df0e7f7e1105700f40396e624f1b3f49a20c1197 /src/peerstore/test_peerstore_api_iterate.c | |
parent | 240091007e4aa56fa36edb62f526b0d390879d95 (diff) | |
download | gnunet-d8d3021ad9af2abe551fd6cd0fe2529a99d3683c.tar.gz gnunet-d8d3021ad9af2abe551fd6cd0fe2529a99d3683c.zip |
-fix
Diffstat (limited to 'src/peerstore/test_peerstore_api_iterate.c')
-rw-r--r-- | src/peerstore/test_peerstore_api_iterate.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/src/peerstore/test_peerstore_api_iterate.c b/src/peerstore/test_peerstore_api_iterate.c index 797b3146e..83a6bf7b7 100644 --- a/src/peerstore/test_peerstore_api_iterate.c +++ b/src/peerstore/test_peerstore_api_iterate.c | |||
@@ -29,6 +29,7 @@ | |||
29 | static int ok = 1; | 29 | static int ok = 1; |
30 | 30 | ||
31 | static struct GNUNET_PEERSTORE_Handle *h; | 31 | static struct GNUNET_PEERSTORE_Handle *h; |
32 | static struct GNUNET_PEERSTORE_IterateContext *ic; | ||
32 | 33 | ||
33 | static char *ss = "test_peerstore_api_iterate"; | 34 | static char *ss = "test_peerstore_api_iterate"; |
34 | static struct GNUNET_PeerIdentity p1; | 35 | static struct GNUNET_PeerIdentity p1; |
@@ -40,60 +41,66 @@ static char *val = "test_peerstore_api_iterate_val"; | |||
40 | static int count = 0; | 41 | static int count = 0; |
41 | 42 | ||
42 | 43 | ||
43 | static int | 44 | static void |
44 | iter3_cb (void *cls, const struct GNUNET_PEERSTORE_Record *record, | 45 | iter3_cb (void *cls, const struct GNUNET_PEERSTORE_Record *record, |
45 | const char *emsg) | 46 | const char *emsg) |
46 | { | 47 | { |
47 | if (NULL != emsg) | 48 | if (NULL != emsg) |
48 | return GNUNET_NO; | 49 | { |
50 | GNUNET_PEERSTORE_iterate_cancel (ic); | ||
51 | return; | ||
52 | } | ||
49 | if (NULL != record) | 53 | if (NULL != record) |
50 | { | 54 | { |
51 | count++; | 55 | count++; |
52 | return GNUNET_YES; | 56 | return; |
53 | } | 57 | } |
54 | GNUNET_assert (count == 3); | 58 | GNUNET_assert (count == 3); |
55 | ok = 0; | 59 | ok = 0; |
56 | GNUNET_PEERSTORE_disconnect (h, GNUNET_NO); | 60 | GNUNET_PEERSTORE_disconnect (h, GNUNET_NO); |
57 | GNUNET_SCHEDULER_shutdown (); | 61 | GNUNET_SCHEDULER_shutdown (); |
58 | return GNUNET_YES; | ||
59 | } | 62 | } |
60 | 63 | ||
61 | 64 | ||
62 | static int | 65 | static void |
63 | iter2_cb (void *cls, const struct GNUNET_PEERSTORE_Record *record, | 66 | iter2_cb (void *cls, const struct GNUNET_PEERSTORE_Record *record, |
64 | const char *emsg) | 67 | const char *emsg) |
65 | { | 68 | { |
66 | if (NULL != emsg) | 69 | if (NULL != emsg) |
67 | return GNUNET_NO; | 70 | { |
71 | GNUNET_PEERSTORE_iterate_cancel (ic); | ||
72 | return; | ||
73 | } | ||
68 | if (NULL != record) | 74 | if (NULL != record) |
69 | { | 75 | { |
70 | count++; | 76 | count++; |
71 | return GNUNET_YES; | 77 | return; |
72 | } | 78 | } |
73 | GNUNET_assert (count == 2); | 79 | GNUNET_assert (count == 2); |
74 | count = 0; | 80 | count = 0; |
75 | GNUNET_PEERSTORE_iterate (h, ss, NULL, NULL, GNUNET_TIME_UNIT_FOREVER_REL, | 81 | ic = GNUNET_PEERSTORE_iterate (h, ss, NULL, NULL, GNUNET_TIME_UNIT_FOREVER_REL, |
76 | iter3_cb, NULL); | 82 | iter3_cb, NULL); |
77 | return GNUNET_YES; | ||
78 | } | 83 | } |
79 | 84 | ||
80 | 85 | ||
81 | static int | 86 | static void |
82 | iter1_cb (void *cls, const struct GNUNET_PEERSTORE_Record *record, | 87 | iter1_cb (void *cls, const struct GNUNET_PEERSTORE_Record *record, |
83 | const char *emsg) | 88 | const char *emsg) |
84 | { | 89 | { |
85 | if (NULL != emsg) | 90 | if (NULL != emsg) |
86 | return GNUNET_NO; | 91 | { |
92 | GNUNET_PEERSTORE_iterate_cancel (ic); | ||
93 | return; | ||
94 | } | ||
87 | if (NULL != record) | 95 | if (NULL != record) |
88 | { | 96 | { |
89 | count++; | 97 | count++; |
90 | return GNUNET_YES; | 98 | return; |
91 | } | 99 | } |
92 | GNUNET_assert (count == 1); | 100 | GNUNET_assert (count == 1); |
93 | count = 0; | 101 | count = 0; |
94 | GNUNET_PEERSTORE_iterate (h, ss, &p1, NULL, GNUNET_TIME_UNIT_FOREVER_REL, | 102 | ic = GNUNET_PEERSTORE_iterate (h, ss, &p1, NULL, GNUNET_TIME_UNIT_FOREVER_REL, |
95 | iter2_cb, NULL); | 103 | iter2_cb, NULL); |
96 | return GNUNET_YES; | ||
97 | } | 104 | } |
98 | 105 | ||
99 | 106 | ||
@@ -114,7 +121,7 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
114 | GNUNET_PEERSTORE_store (h, ss, &p2, k3, val, strlen (val) + 1, | 121 | GNUNET_PEERSTORE_store (h, ss, &p2, k3, val, strlen (val) + 1, |
115 | GNUNET_TIME_UNIT_FOREVER_ABS, | 122 | GNUNET_TIME_UNIT_FOREVER_ABS, |
116 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL); | 123 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL); |
117 | GNUNET_PEERSTORE_iterate (h, ss, &p1, k1, GNUNET_TIME_UNIT_FOREVER_REL, | 124 | ic = GNUNET_PEERSTORE_iterate (h, ss, &p1, k1, GNUNET_TIME_UNIT_FOREVER_REL, |
118 | iter1_cb, NULL); | 125 | iter1_cb, NULL); |
119 | } | 126 | } |
120 | 127 | ||