aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-08-03 01:15:22 +0000
committerBart Polot <bart@net.in.tum.de>2013-08-03 01:15:22 +0000
commitfa1458083e2f819bacc3b0c64f778040e2ad8e10 (patch)
tree52ed64894c74a7763db2c40fc342d5f8720d55d1
parentcfb352a9378aa8f8ab3ef27e945946ea3c7b0e9c (diff)
downloadgnunet-fa1458083e2f819bacc3b0c64f778040e2ad8e10.tar.gz
gnunet-fa1458083e2f819bacc3b0c64f778040e2ad8e10.zip
- channel data manipulation
-rw-r--r--src/mesh/gnunet-service-mesh-enc.c368
-rw-r--r--src/mesh/mesh_protocol_enc.h9
2 files changed, 155 insertions, 222 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c
index caa9439b6..aec80124b 100644
--- a/src/mesh/gnunet-service-mesh-enc.c
+++ b/src/mesh/gnunet-service-mesh-enc.c
@@ -924,15 +924,15 @@ path_add_to_peers (struct MeshPeerPath *p, int confirmed);
924 924
925 925
926/** 926/**
927 * Search for a channel by global ID using full PeerIdentities. 927 * Search for a tunnel by global ID using full PeerIdentities.
928 * 928 *
929 * @param oid owner of the tunnel. 929 * @param t Tunnel containing the channel.
930 * @param tid global tunnel number. 930 * @param chid Public channel number.
931 * 931 *
932 * @return tunnel handler, NULL if doesn't exist. 932 * @return channel handler, NULL if doesn't exist
933 */ 933 */
934static struct MeshChannel * 934static struct MeshChannel *
935channel_get (const struct GNUNET_PeerIdentity *oid, MESH_ChannelNumber tid); 935channel_get (struct MeshTunnel2 *t, MESH_ChannelNumber chid);
936 936
937 937
938/** 938/**
@@ -2472,37 +2472,29 @@ channel_get_by_local_id (struct MeshClient *c, MESH_ChannelNumber chid)
2472 return GNUNET_CONTAINER_multihashmap32_get (c->own_channels, chid); 2472 return GNUNET_CONTAINER_multihashmap32_get (c->own_channels, chid);
2473} 2473}
2474 2474
2475
2476/** 2475/**
2477 * Search for a tunnel by global ID using PEER_ID 2476 * Search for a tunnel by global ID using full PeerIdentities.
2478 * 2477 *
2479 * @param pi owner of the tunnel 2478 * @param t Tunnel containing the channel.
2480 * @param tid global tunnel number 2479 * @param chid Public channel number.
2481 * 2480 *
2482 * @return tunnel handler, NULL if doesn't exist 2481 * @return channel handler, NULL if doesn't exist
2483 */ 2482 */
2484static struct MeshChannel * 2483static struct MeshChannel *
2485channel_get_by_pi (GNUNET_PEER_Id pi, MESH_ChannelNumber tid) 2484channel_get (struct MeshTunnel2 *t, MESH_ChannelNumber chid)
2486{ 2485{
2487// struct GNUNET_HashCode hash; 2486 struct MeshChannel *ch;
2488 2487
2489// return GNUNET_CONTAINER_multihashmap_get (tunnels, &hash); FIXME 2488 if (NULL == t)
2490 return NULL; 2489 return NULL;
2491}
2492 2490
2491 for (ch = t->channel_head; NULL != ch; ch = ch->next)
2492 {
2493 if (ch->id == chid)
2494 break;
2495 }
2493 2496
2494/** 2497 return ch;
2495 * Search for a tunnel by global ID using full PeerIdentities
2496 *
2497 * @param oid owner of the tunnel
2498 * @param tid global tunnel number
2499 *
2500 * @return tunnel handler, NULL if doesn't exist
2501 */
2502static struct MeshChannel *
2503channel_get (const struct GNUNET_PeerIdentity *oid, MESH_ChannelNumber tid)
2504{
2505 return channel_get_by_pi (GNUNET_PEER_search (oid), tid);
2506} 2498}
2507 2499
2508 2500
@@ -4205,6 +4197,137 @@ queue_add (void *cls, uint16_t type, size_t size,
4205/******************************************************************************/ 4197/******************************************************************************/
4206 4198
4207 4199
4200
4201/**
4202 * Generic handler for mesh network payload traffic.
4203 *
4204 * @param t Tunnel on which we got this message.
4205 * @param message Data message.
4206 * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
4207 *
4208 * @return GNUNET_OK to keep the connection open,
4209 * GNUNET_SYSERR to close it (signal serious error)
4210 */
4211static int
4212handle_data (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *msg, int fwd)
4213{
4214 struct MeshChannelReliability *rel;
4215 struct MeshChannel *ch;
4216 struct MeshClient *c;
4217 uint32_t mid;
4218 uint16_t type;
4219 size_t size;
4220
4221 /* Check size */
4222 size = ntohs (msg->header.size);
4223 if (size <
4224 sizeof (struct GNUNET_MESH_Data) +
4225 sizeof (struct GNUNET_MessageHeader))
4226 {
4227 GNUNET_break (0);
4228 return GNUNET_OK;
4229 }
4230 type = ntohs (msg->header.type);
4231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got a %s message\n",
4232 GNUNET_MESH_DEBUG_M2S (type));
4233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " payload of type %s\n",
4234 GNUNET_MESH_DEBUG_M2S (ntohs (msg[1].header.type)));
4235
4236 /* Check channel */
4237 ch = channel_get (t, ntohl (msg->chid));
4238 if (NULL == ch)
4239 {
4240 GNUNET_STATISTICS_update (stats, "# data on unknown channel", 1, GNUNET_NO);
4241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel unknown\n");
4242 return GNUNET_OK;
4243 }
4244
4245 /* Initialize FWD/BCK data */
4246 c = fwd ? ch->client : ch->owner;
4247 rel = fwd ? ch->bck_rel : ch->fwd_rel;
4248
4249 if (NULL == c)
4250 {
4251 GNUNET_break (0);
4252 return GNUNET_OK;
4253 }
4254
4255 tunnel_change_state (t, MESH_TUNNEL_READY);
4256
4257 GNUNET_STATISTICS_update (stats, "# data received", 1, GNUNET_NO);
4258
4259 mid = ntohl (msg->mid);
4260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " mid %u\n", mid);
4261
4262 if (GNUNET_NO == ch->reliable ||
4263 ( !GMC_is_pid_bigger (rel->mid_recv, mid) &&
4264 GMC_is_pid_bigger (rel->mid_recv + 64, mid) ) )
4265 {
4266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "!!! RECV %u\n", mid);
4267 if (GNUNET_YES == ch->reliable)
4268 {
4269 /* Is this the exact next expected messasge? */
4270 if (mid == rel->mid_recv)
4271 {
4272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "as expected\n");
4273 rel->mid_recv++;
4274 channel_send_client_data (ch, msg, fwd);
4275 channel_send_client_buffered_data (ch, c, rel);
4276 }
4277 else
4278 {
4279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "save for later\n");
4280 channel_rel_add_buffered_data (msg, rel);
4281 }
4282 }
4283 else /* Tunnel unreliable, send to clients directly */
4284 {
4285 channel_send_client_data (ch, msg, fwd);
4286 }
4287 }
4288 else
4289 {
4290 GNUNET_break_op (0);
4291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4292 " MID %u not expected (%u - %u), dropping!\n",
4293 mid, rel->mid_recv, rel->mid_recv + 64);
4294 }
4295
4296 channel_send_data_ack (ch, fwd);
4297 return GNUNET_OK;
4298}
4299
4300
4301/**
4302 * Handler for mesh network traffic going from the origin to a peer
4303 *
4304 * @param t Tunnel on which we got this message.
4305 * @param message Data message.
4306 *
4307 * @return GNUNET_OK to keep the connection open,
4308 * GNUNET_SYSERR to close it (signal serious error)
4309 */
4310static int
4311handle_unicast (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *message)
4312{
4313 return handle_data (t, message, GNUNET_YES);
4314}
4315
4316/**
4317 * Handler for mesh network traffic towards the owner of a tunnel.
4318 *
4319 * @param t Tunnel on which we got this message.
4320 * @param message Data message.
4321 *
4322 * @return GNUNET_OK to keep the connection open,
4323 * GNUNET_SYSERR to close it (signal serious error)
4324 */
4325static int
4326handle_to_orig (struct MeshTunnel2 *t, const struct GNUNET_MESH_Data *message)
4327{
4328 return handle_data (t, message, GNUNET_NO);
4329}
4330
4208/** 4331/**
4209 * Core handler for connection creation. 4332 * Core handler for connection creation.
4210 * 4333 *
@@ -4493,197 +4616,6 @@ handle_mesh_connection_destroy (void *cls,
4493 4616
4494 4617
4495/** 4618/**
4496 * Generic handler for mesh network payload traffic.
4497 *
4498 * @param peer Peer identity this notification is about.
4499 * @param message Data message.
4500 * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
4501 *
4502 * @return GNUNET_OK to keep the connection open,
4503 * GNUNET_SYSERR to close it (signal serious error)
4504 */
4505static int
4506handle_mesh_data (const struct GNUNET_PeerIdentity *peer,
4507 const struct GNUNET_MessageHeader *message,
4508 int fwd)
4509{
4510 struct GNUNET_MESH_Data *msg;
4511 struct MeshFlowControl *fc;
4512 struct MeshChannelReliability *rel;
4513 struct MeshChannel *ch;
4514 struct MeshTunnel2 *t;
4515 struct MeshClient *c;
4516 GNUNET_PEER_Id hop;
4517 uint32_t pid;
4518 uint32_t ttl;
4519 uint16_t type;
4520 size_t size;
4521
4522 /* Check size */
4523 size = ntohs (message->size);
4524 if (size <
4525 sizeof (struct GNUNET_MESH_Data) +
4526 sizeof (struct GNUNET_MessageHeader))
4527 {
4528 GNUNET_break (0);
4529 return GNUNET_OK;
4530 }
4531 type =ntohs (message->type);
4532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got a %s message from %s\n",
4533 GNUNET_MESH_DEBUG_M2S (type), GNUNET_i2s (peer));
4534 msg = (struct GNUNET_MESH_Data *) message;
4535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " payload of type %s\n",
4536 GNUNET_MESH_DEBUG_M2S (ntohs (msg[1].header.type)));
4537
4538 /* Check channel */
4539 ch = channel_get (&msg->oid, ntohl (msg->tid));
4540 if (NULL == t)
4541 {
4542 /* TODO notify back: we don't know this tunnel */
4543 GNUNET_STATISTICS_update (stats, "# data on unknown tunnel", 1, GNUNET_NO);
4544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "WARNING tunnel unknown\n");
4545 return GNUNET_OK;
4546 }
4547
4548 /* Initialize FWD/BCK data */
4549 pid = ntohl (msg->pid);
4550 fc = fwd ? &t->prev_fc : &t->next_fc;
4551 c = fwd ? t->client : t->owner;
4552 rel = fwd ? t->bck_rel : t->fwd_rel;
4553 hop = fwd ? t->next_hop : t->prev_hop;
4554 if (GMC_is_pid_bigger (pid, fc->last_ack_sent))
4555 {
4556 GNUNET_STATISTICS_update (stats, "# unsolicited data", 1, GNUNET_NO);
4557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4558 "WARNING Received PID %u, (prev %u), ACK %u\n",
4559 pid, fc->last_pid_recv, fc->last_ack_sent);
4560 return GNUNET_OK;
4561 }
4562 if (NULL != c)
4563 tunnel_change_state (t, MESH_TUNNEL_READY);
4564 tunnel_reset_timeout (t, fwd);
4565 if (NULL != c)
4566 {
4567 /* TODO signature verification */
4568 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " it's for us! sending to client\n");
4569 GNUNET_STATISTICS_update (stats, "# data received", 1, GNUNET_NO);
4570 if (GMC_is_pid_bigger (pid, fc->last_pid_recv))
4571 {
4572 uint32_t mid;
4573
4574 mid = ntohl (msg->mid);
4575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4576 " pid %u (mid %u) not seen yet\n", pid, mid);
4577 fc->last_pid_recv = pid;
4578
4579 if (GNUNET_NO == t->reliable ||
4580 ( !GMC_is_pid_bigger (rel->mid_recv, mid) &&
4581 GMC_is_pid_bigger (rel->mid_recv + 64, mid) ) )
4582 {
4583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4584 "!!! RECV %u\n", ntohl (msg->mid));
4585 if (GNUNET_YES == t->reliable)
4586 {
4587 /* Is this the exact next expected messasge? */
4588 if (mid == rel->mid_recv)
4589 {
4590 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "as expected\n");
4591 rel->mid_recv++;
4592 tunnel_send_client_data (t, msg, fwd);
4593 tunnel_send_client_buffered_data (t, c, rel);
4594 }
4595 else
4596 {
4597 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "save for later\n");
4598 tunnel_add_buffered_data (t, msg, rel);
4599 }
4600 }
4601 else /* Tunnel unreliable, send to clients directly */
4602 {
4603 tunnel_send_client_data (t, msg, fwd);
4604 }
4605 }
4606 else
4607 {
4608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4609 " MID %u not expected (%u - %u), dropping!\n",
4610 ntohl (msg->mid), rel->mid_recv, rel->mid_recv + 64);
4611 }
4612 }
4613 else
4614 {
4615// GNUNET_STATISTICS_update (stats, "# duplicate PID", 1, GNUNET_NO);
4616 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4617 " Pid %u not expected (%u+), dropping!\n",
4618 pid, fc->last_pid_recv + 1);
4619 }
4620 tunnel_send_ack (t, type, fwd);
4621 return GNUNET_OK;
4622 }
4623 fc->last_pid_recv = pid;
4624 if (0 == hop)
4625 {
4626 GNUNET_STATISTICS_update (stats, "# data on dying tunnel", 1, GNUNET_NO);
4627 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "data on dying tunnel %s[%X]\n",
4628 GNUNET_PEER_resolve2 (t->id.oid), ntohl (msg->tid));
4629 return GNUNET_OK; /* Next hop has destoyed the tunnel, drop */
4630 }
4631 ttl = ntohl (msg->ttl);
4632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ttl: %u\n", ttl);
4633 if (ttl == 0)
4634 {
4635 GNUNET_STATISTICS_update (stats, "# TTL drops", 1, GNUNET_NO);
4636 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " TTL is 0, DROPPING!\n");
4637 tunnel_send_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK, fwd);
4638 return GNUNET_OK;
4639 }
4640
4641 if (myid != hop)
4642 {
4643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n");
4644 send_prebuilt_message (message, hop, t);
4645 GNUNET_STATISTICS_update (stats, "# unicast forwarded", 1, GNUNET_NO);
4646 }
4647 return GNUNET_OK;
4648}
4649
4650
4651/**
4652 * Core handler for mesh network traffic going from the origin to a peer
4653 *
4654 * @param cls Closure (unused).
4655 * @param peer Peer identity of sending neighbor.
4656 * @param message Message.
4657 *
4658 * @return GNUNET_OK to keep the connection open,
4659 * GNUNET_SYSERR to close it (signal serious error)
4660 */
4661static int
4662handle_mesh_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
4663 const struct GNUNET_MessageHeader *message)
4664{
4665 return handle_mesh_data (peer, message, GNUNET_YES);
4666}
4667
4668/**
4669 * Core handler for mesh network traffic towards the owner of a tunnel.
4670 *
4671 * @param cls Closure (unused).
4672 * @param peer Peer identity of sending neighbor.
4673 * @param message Message.
4674 *
4675 * @return GNUNET_OK to keep the connection open,
4676 * GNUNET_SYSERR to close it (signal serious error)
4677 */
4678static int
4679handle_mesh_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
4680 const struct GNUNET_MessageHeader *message)
4681{
4682 return handle_mesh_data (peer, message, GNUNET_NO);
4683}
4684
4685
4686/**
4687 * Core handler for mesh network traffic end-to-end ACKs. 4619 * Core handler for mesh network traffic end-to-end ACKs.
4688 * 4620 *
4689 * @param cls Closure. 4621 * @param cls Closure.
diff --git a/src/mesh/mesh_protocol_enc.h b/src/mesh/mesh_protocol_enc.h
index fef6479e2..ebecb087d 100644
--- a/src/mesh/mesh_protocol_enc.h
+++ b/src/mesh/mesh_protocol_enc.h
@@ -28,6 +28,7 @@
28 28
29#include "platform.h" 29#include "platform.h"
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "mesh_enc.h"
31 32
32#ifdef __cplusplus 33#ifdef __cplusplus
33 34
@@ -150,7 +151,7 @@ struct GNUNET_MESH_ChannelCreate
150 /** 151 /**
151 * ID of the channel 152 * ID of the channel
152 */ 153 */
153 uint32_t chid GNUNET_PACKED; 154 MESH_ChannelNumber chid GNUNET_PACKED;
154 155
155 /** 156 /**
156 * Channel options. 157 * Channel options.
@@ -168,7 +169,7 @@ struct GNUNET_MESH_ChannelDestroy
168 /** 169 /**
169 * ID of the channel 170 * ID of the channel
170 */ 171 */
171 uint32_t chid GNUNET_PACKED; 172 MESH_ChannelNumber chid GNUNET_PACKED;
172}; 173};
173 174
174/** 175/**
@@ -190,7 +191,7 @@ struct GNUNET_MESH_Data
190 /** 191 /**
191 * ID of the channel 192 * ID of the channel
192 */ 193 */
193 uint32_t chid GNUNET_PACKED; 194 MESH_ChannelNumber chid GNUNET_PACKED;
194 195
195 /** 196 /**
196 * Payload follows 197 * Payload follows
@@ -211,7 +212,7 @@ struct GNUNET_MESH_DataACK
211 /** 212 /**
212 * ID of the channel 213 * ID of the channel
213 */ 214 */
214 uint32_t chid GNUNET_PACKED; 215 MESH_ChannelNumber chid GNUNET_PACKED;
215 216
216 /** 217 /**
217 * Bitfield of already-received newer messages 218 * Bitfield of already-received newer messages