diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-01-18 16:56:01 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-01-18 16:56:01 +0100 |
commit | 3edc21c27d208e45dc1af76131a480a3ebf1e8d3 (patch) | |
tree | 7cbad238c4651ea1c05b28ae8df41a10dfb3771f /src/cadet/gnunet-service-cadet-new_core.c | |
parent | e02d76e46cd00724d32f81375e8981524ee6f3e2 (diff) | |
download | gnunet-3edc21c27d208e45dc1af76131a480a3ebf1e8d3.tar.gz gnunet-3edc21c27d208e45dc1af76131a480a3ebf1e8d3.zip |
work towards routing
Diffstat (limited to 'src/cadet/gnunet-service-cadet-new_core.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet-new_core.c | 64 |
1 files changed, 59 insertions, 5 deletions
diff --git a/src/cadet/gnunet-service-cadet-new_core.c b/src/cadet/gnunet-service-cadet-new_core.c index d81600b9d..e9fc6bf05 100644 --- a/src/cadet/gnunet-service-cadet-new_core.c +++ b/src/cadet/gnunet-service-cadet-new_core.c | |||
@@ -57,6 +57,16 @@ struct CadetRoute | |||
57 | struct CadetPeer *next_hop; | 57 | struct CadetPeer *next_hop; |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Message queue notifications for @e prev_hop. | ||
61 | */ | ||
62 | struct GCP_MessageQueueManager *prev_mqm; | ||
63 | |||
64 | /** | ||
65 | * Message queue notifications for @e next_hop. | ||
66 | */ | ||
67 | struct GCP_MessageQueueManager *next_mqm; | ||
68 | |||
69 | /** | ||
60 | * Unique identifier for the connection that uses this route. | 70 | * Unique identifier for the connection that uses this route. |
61 | */ | 71 | */ |
62 | struct GNUNET_CADET_ConnectionTunnelIdentifier cid; | 72 | struct GNUNET_CADET_ConnectionTunnelIdentifier cid; |
@@ -123,8 +133,9 @@ route_message (struct CadetPeer *prev, | |||
123 | env); | 133 | env); |
124 | return; | 134 | return; |
125 | } | 135 | } |
126 | GNUNET_assert (0); /* FIXME: determine next hop from route and prev! */ | 136 | /* FIXME: support round-robin queue management here somewhere! */ |
127 | 137 | GCP_send ((prev == route->prev_hop) ? route->next_hop : route->prev_hop, | |
138 | GNUNET_MQ_msg_copy (msg)); | ||
128 | } | 139 | } |
129 | 140 | ||
130 | 141 | ||
@@ -159,7 +170,9 @@ check_connection_create (void *cls, | |||
159 | static void | 170 | static void |
160 | destroy_route (struct CadetRoute *route) | 171 | destroy_route (struct CadetRoute *route) |
161 | { | 172 | { |
162 | GNUNET_break (0); // fIXME: implement! | 173 | GCP_request_mq_cancel (route->next_mqm); |
174 | GCP_request_mq_cancel (route->prev_mqm); | ||
175 | GNUNET_free (route); | ||
163 | } | 176 | } |
164 | 177 | ||
165 | 178 | ||
@@ -173,16 +186,57 @@ static void | |||
173 | handle_connection_create (void *cls, | 186 | handle_connection_create (void *cls, |
174 | const struct GNUNET_CADET_ConnectionCreateMessage *msg) | 187 | const struct GNUNET_CADET_ConnectionCreateMessage *msg) |
175 | { | 188 | { |
176 | struct CadetPeer *peer = cls; | 189 | struct CadetPeer *sender = cls; |
190 | struct CadetPeer *next; | ||
191 | const struct GNUNET_PeerIdentity *pids = (const struct GNUNET_PeerIdentity *) &msg[1]; | ||
192 | struct CadetRoute *route; | ||
177 | uint16_t size = ntohs (msg->header.size) - sizeof (*msg); | 193 | uint16_t size = ntohs (msg->header.size) - sizeof (*msg); |
178 | unsigned int path_length; | 194 | unsigned int path_length; |
195 | unsigned int off; | ||
179 | 196 | ||
180 | path_length = size / sizeof (struct GNUNET_PeerIdentity); | 197 | path_length = size / sizeof (struct GNUNET_PeerIdentity); |
198 | /* Initiator is at offset 0. */ | ||
199 | for (off=1;off<path_length;off++) | ||
200 | if (0 == memcmp (&my_full_id, | ||
201 | &pids[off], | ||
202 | sizeof (struct GNUNET_PeerIdentity))) | ||
203 | break; | ||
204 | if (off == path_length) | ||
205 | { | ||
206 | /* We are not on the path, bogus request */ | ||
207 | GNUNET_break_op (0); | ||
208 | return; | ||
209 | } | ||
210 | /* Check previous hop */ | ||
211 | if (sender != GCP_get (&pids[off - 1], | ||
212 | GNUNET_NO)) | ||
213 | { | ||
214 | /* sender is not on the path, not allowed */ | ||
215 | GNUNET_break_op (0); | ||
216 | return; | ||
217 | } | ||
218 | if (off == path_length - 1) | ||
219 | { | ||
220 | /* We are the destination, create connection */ | ||
221 | return; | ||
222 | } | ||
223 | /* We are merely a hop on the way, check if we can support the route */ | ||
224 | next = GCP_get (&pids[off + 1], | ||
225 | GNUNET_NO); | ||
226 | if (NULL == next) | ||
227 | { | ||
228 | /* unworkable, send back BROKEN */ | ||
229 | GNUNET_break (0); // FIXME... | ||
230 | return; | ||
231 | } | ||
232 | |||
233 | route = GNUNET_new (struct CadetRoute); | ||
234 | |||
181 | #if FIXME | 235 | #if FIXME |
182 | GCC_handle_create (peer, | 236 | GCC_handle_create (peer, |
183 | &msg->cid, | 237 | &msg->cid, |
184 | path_length, | 238 | path_length, |
185 | (const struct GNUNET_PeerIdentity *) &msg[1]); | 239 | route); |
186 | #endif | 240 | #endif |
187 | } | 241 | } |
188 | 242 | ||