diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-11-13 22:38:47 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-11-13 22:38:47 +0000 |
commit | 72761db34214aae9f6a9f4a3c0e717b1bd1389d6 (patch) | |
tree | 23b040167f2d9d18fc8772fce2b6f184f4538c85 /src/core/test_core_api_start_only.c | |
parent | 314d8bdb2a4f6b0926bf8f8f1d057cc71c1fd0db (diff) | |
download | gnunet-72761db34214aae9f6a9f4a3c0e717b1bd1389d6.tar.gz gnunet-72761db34214aae9f6a9f4a3c0e717b1bd1389d6.zip |
hxing
Diffstat (limited to 'src/core/test_core_api_start_only.c')
-rw-r--r-- | src/core/test_core_api_start_only.c | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c index 7f6768dd4..e03886e6e 100644 --- a/src/core/test_core_api_start_only.c +++ b/src/core/test_core_api_start_only.c | |||
@@ -51,6 +51,7 @@ static struct PeerContext p1; | |||
51 | 51 | ||
52 | static struct PeerContext p2; | 52 | static struct PeerContext p2; |
53 | 53 | ||
54 | static GNUNET_SCHEDULER_TaskIdentifier timeout_task_id; | ||
54 | 55 | ||
55 | static int ok; | 56 | static int ok; |
56 | 57 | ||
@@ -112,25 +113,26 @@ init_notify (void *cls, | |||
112 | struct PeerContext *p = cls; | 113 | struct PeerContext *p = cls; |
113 | 114 | ||
114 | GNUNET_assert (server != NULL); | 115 | GNUNET_assert (server != NULL); |
115 | p->ch = server; | 116 | GNUNET_assert (p->ch == server); |
116 | if (cls == &p1) | 117 | if (cls == &p1) |
117 | { | 118 | { |
118 | /* connect p2 */ | 119 | /* connect p2 */ |
119 | GNUNET_CORE_connect (p2.cfg, 1, | 120 | p2.ch = GNUNET_CORE_connect (p2.cfg, 1, |
120 | &p2, | 121 | &p2, |
121 | &init_notify, | 122 | &init_notify, |
122 | &connect_notify, | 123 | &connect_notify, |
123 | &disconnect_notify, | 124 | &disconnect_notify, |
124 | NULL, | 125 | NULL, |
125 | &inbound_notify, | 126 | &inbound_notify, |
126 | GNUNET_YES, | 127 | GNUNET_YES, |
127 | &outbound_notify, GNUNET_YES, handlers); | 128 | &outbound_notify, GNUNET_YES, handlers); |
128 | } | 129 | } |
129 | else | 130 | else |
130 | { | 131 | { |
131 | GNUNET_assert (cls == &p2); | 132 | GNUNET_assert (cls == &p2); |
132 | GNUNET_CORE_disconnect (p1.ch); | 133 | GNUNET_CORE_disconnect (p1.ch); |
133 | GNUNET_CORE_disconnect (p2.ch); | 134 | GNUNET_CORE_disconnect (p2.ch); |
135 | GNUNET_SCHEDULER_cancel (timeout_task_id); | ||
134 | ok = 0; | 136 | ok = 0; |
135 | } | 137 | } |
136 | } | 138 | } |
@@ -153,6 +155,26 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
153 | 155 | ||
154 | 156 | ||
155 | static void | 157 | static void |
158 | timeout_task (void *cls, | ||
159 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
160 | { | ||
161 | fprintf (stderr, "Timeout.\n"); | ||
162 | if (p1.ch != NULL) | ||
163 | { | ||
164 | GNUNET_CORE_disconnect (p1.ch); | ||
165 | p1.ch = NULL; | ||
166 | } | ||
167 | if (p2.ch != NULL) | ||
168 | { | ||
169 | GNUNET_CORE_disconnect (p2.ch); | ||
170 | p2.ch = NULL; | ||
171 | } | ||
172 | ok = 42; | ||
173 | } | ||
174 | |||
175 | |||
176 | |||
177 | static void | ||
156 | run (void *cls, | 178 | run (void *cls, |
157 | char *const *args, | 179 | char *const *args, |
158 | const char *cfgfile, | 180 | const char *cfgfile, |
@@ -162,14 +184,17 @@ run (void *cls, | |||
162 | OKPP; | 184 | OKPP; |
163 | setup_peer (&p1, "test_core_api_peer1.conf"); | 185 | setup_peer (&p1, "test_core_api_peer1.conf"); |
164 | setup_peer (&p2, "test_core_api_peer2.conf"); | 186 | setup_peer (&p2, "test_core_api_peer2.conf"); |
165 | GNUNET_CORE_connect (p1.cfg, 1, | 187 | timeout_task_id = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
166 | &p1, | 188 | &timeout_task, |
167 | &init_notify, | 189 | NULL); |
168 | &connect_notify, | 190 | p1.ch = GNUNET_CORE_connect (p1.cfg, 1, |
169 | &disconnect_notify, | 191 | &p1, |
170 | NULL, | 192 | &init_notify, |
171 | &inbound_notify, | 193 | &connect_notify, |
172 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); | 194 | &disconnect_notify, |
195 | NULL, | ||
196 | &inbound_notify, | ||
197 | GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); | ||
173 | } | 198 | } |
174 | 199 | ||
175 | 200 | ||