aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-08-05 09:48:32 +0000
committerBart Polot <bart@net.in.tum.de>2013-08-05 09:48:32 +0000
commit6af64edc4f4d40d9c4dfb4c03103dd45d1622438 (patch)
tree5bb4f80dc3790e2816d765dd2c3d95fa56872a6d /src/mesh
parent89b4855c206eed2347c158834ba5c1d4de7781dc (diff)
downloadgnunet-6af64edc4f4d40d9c4dfb4c03103dd45d1622438.tar.gz
gnunet-6af64edc4f4d40d9c4dfb4c03103dd45d1622438.zip
- wip
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh-enc.c197
1 files changed, 189 insertions, 8 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c
index 3b63f517e..91ec2feca 100644
--- a/src/mesh/gnunet-service-mesh-enc.c
+++ b/src/mesh/gnunet-service-mesh-enc.c
@@ -4712,6 +4712,191 @@ handle_mesh_connection_destroy (void *cls,
4712 return GNUNET_OK; 4712 return GNUNET_OK;
4713} 4713}
4714 4714
4715
4716/**
4717 * Generic handler for mesh network encrypted traffic.
4718 *
4719 * @param peer Peer identity this notification is about.
4720 * @param message Data message.
4721 * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO;
4722 *
4723 * @return GNUNET_OK to keep the connection open,
4724 * GNUNET_SYSERR to close it (signal serious error)
4725 */
4726static int
4727handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
4728 const struct GNUNET_MESH_Encrypted *msg,
4729 int fwd)
4730{
4731 struct MeshTunnel *t;
4732 struct MeshConnection *c;
4733 GNUNET_PEER_Id hop;
4734 uint32_t pid;
4735 uint32_t ttl;
4736 uint16_t type;
4737 size_t size;
4738
4739 /* Check size */
4740 size = ntohs (msg->header.size);
4741 if (size <
4742 sizeof (struct GNUNET_MESH_Encrypted) +
4743 sizeof (struct GNUNET_MessageHeader))
4744 {
4745 GNUNET_break (0);
4746 return GNUNET_OK;
4747 }
4748 type = ntohs (msg->header.type);
4749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got a %s message from %s\n",
4750 GNUNET_MESH_DEBUG_M2S (type), GNUNET_i2s (peer));
4751
4752 /* Check connection */
4753 c = connection_get (&msg->tid, ntohl (msg->cid));
4754 if (NULL == c)
4755 {
4756 GNUNET_STATISTICS_update (stats, "# unknown connection", 1, GNUNET_NO);
4757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "WARNING connection unknown\n");
4758 return GNUNET_OK;
4759 }
4760 t = c->t;
4761
4762 /* Initialize FWD/BCK data */
4763 pid = ntohl (msg->pid);
4764 if (GMC_is_pid_bigger (pid, fc->last_ack_sent))
4765 {
4766 GNUNET_STATISTICS_update (stats, "# unsolicited data", 1, GNUNET_NO);
4767 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4768 "WARNING Received PID %u, (prev %u), ACK %u\n",
4769 pid, fc->last_pid_recv, fc->last_ack_sent);
4770 return GNUNET_OK;
4771 }
4772 if (NULL != c)
4773 tunnel_change_state (t, MESH_TUNNEL_READY);
4774 tunnel_reset_timeout (t, fwd);
4775 if (NULL != c)
4776 {
4777 /* TODO signature verification */
4778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " it's for us! sending to client\n");
4779 GNUNET_STATISTICS_update (stats, "# data received", 1, GNUNET_NO);
4780 if (GMC_is_pid_bigger (pid, fc->last_pid_recv))
4781 {
4782 uint32_t mid;
4783
4784 mid = ntohl (msg->mid);
4785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4786 " pid %u (mid %u) not seen yet\n", pid, mid);
4787 fc->last_pid_recv = pid;
4788
4789 if (GNUNET_NO == t->reliable ||
4790 ( !GMC_is_pid_bigger (rel->mid_recv, mid) &&
4791 GMC_is_pid_bigger (rel->mid_recv + 64, mid) ) )
4792 {
4793 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4794 "!!! RECV %u\n", ntohl (msg->mid));
4795 if (GNUNET_YES == t->reliable)
4796 {
4797 /* Is this the exact next expected messasge? */
4798 if (mid == rel->mid_recv)
4799 {
4800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "as expected\n");
4801 rel->mid_recv++;
4802 tunnel_send_client_data (t, msg, fwd);
4803 tunnel_send_client_buffered_data (t, c, rel);
4804 }
4805 else
4806 {
4807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "save for later\n");
4808 tunnel_add_buffered_data (t, msg, rel);
4809 }
4810 }
4811 else /* Tunnel unreliable, send to clients directly */
4812 {
4813 tunnel_send_client_data (t, msg, fwd);
4814 }
4815 }
4816 else
4817 {
4818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4819 " MID %u not expected (%u - %u), dropping!\n",
4820 ntohl (msg->mid), rel->mid_recv, rel->mid_recv + 64);
4821 }
4822 }
4823 else
4824 {
4825// GNUNET_STATISTICS_update (stats, "# duplicate PID", 1, GNUNET_NO);
4826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4827 " Pid %u not expected (%u+), dropping!\n",
4828 pid, fc->last_pid_recv + 1);
4829 }
4830 tunnel_send_ack (t, type, fwd);
4831 return GNUNET_OK;
4832 }
4833 fc->last_pid_recv = pid;
4834 if (0 == hop)
4835 {
4836 GNUNET_STATISTICS_update (stats, "# data on dying tunnel", 1, GNUNET_NO);
4837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "data on dying tunnel %s[%X]\n",
4838 GNUNET_PEER_resolve2 (t->id.oid), ntohl (msg->tid));
4839 return GNUNET_OK; /* Next hop has destoyed the tunnel, drop */
4840 }
4841 ttl = ntohl (msg->ttl);
4842 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ttl: %u\n", ttl);
4843 if (ttl == 0)
4844 {
4845 GNUNET_STATISTICS_update (stats, "# TTL drops", 1, GNUNET_NO);
4846 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " TTL is 0, DROPPING!\n");
4847 tunnel_send_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK, fwd);
4848 return GNUNET_OK;
4849 }
4850
4851 if (myid != hop)
4852 {
4853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n");
4854 send_prebuilt_message (message, hop, t);
4855 GNUNET_STATISTICS_update (stats, "# unicast forwarded", 1, GNUNET_NO);
4856 }
4857 return GNUNET_OK;
4858}
4859
4860
4861/**
4862 * Core handler for mesh network traffic going orig->dest.
4863 *
4864 * @param cls Closure (unused).
4865 * @param message Message received.
4866 * @param peer Peer who sent the message.
4867 *
4868 * @return GNUNET_OK to keep the connection open,
4869 * GNUNET_SYSERR to close it (signal serious error)
4870 */
4871static int
4872handle_mesh_fwd (void *cls, const struct GNUNET_PeerIdentity *peer,
4873 const struct GNUNET_MessageHeader *message)
4874{
4875 return handle_mesh_encrypted (peer,
4876 (struct GNUNET_MESH_Encrypted *)message,
4877 GNUNET_YES);
4878}
4879
4880/**
4881 * Core handler for mesh network traffic going dest->orig.
4882 *
4883 * @param cls Closure (unused).
4884 * @param message Message received.
4885 * @param peer Peer who sent the message.
4886 *
4887 * @return GNUNET_OK to keep the connection open,
4888 * GNUNET_SYSERR to close it (signal serious error)
4889 */
4890static int
4891handle_mesh_bck (void *cls, const struct GNUNET_PeerIdentity *peer,
4892 const struct GNUNET_MessageHeader *message)
4893{
4894 return handle_mesh_encrypted (peer,
4895 (struct GNUNET_MESH_Encrypted *)message,
4896 GNUNET_NO);
4897}
4898
4899
4715/** 4900/**
4716 * Core handler for mesh network traffic point-to-point acks. 4901 * Core handler for mesh network traffic point-to-point acks.
4717 * 4902 *
@@ -4913,15 +5098,11 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
4913 {&handle_mesh_connection_ack, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, 5098 {&handle_mesh_connection_ack, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK,
4914 sizeof (struct GNUNET_MESH_ConnectionACK)}, 5099 sizeof (struct GNUNET_MESH_ConnectionACK)},
4915 {&handle_mesh_connection_broken, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN, 5100 {&handle_mesh_connection_broken, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN,
4916 sizeof (struct GNUNET_MESH_ConnectionBroken)}, 5101 sizeof (struct GNUNET_MESH_ConnectionBroken)},
4917 {&handle_mesh_connection_destroy, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY, 5102 {&handle_mesh_connection_destroy, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY,
4918 sizeof (struct GNUNET_MESH_ConnectionDestroy)}, 5103 sizeof (struct GNUNET_MESH_ConnectionDestroy)},
4919 {&handle_mesh_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, 5104 {&handle_mesh_fwd, GNUNET_MESSAGE_TYPE_MESH_FWD, 0},
4920 {&handle_mesh_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, 5105 {&handle_mesh_bck, GNUNET_MESSAGE_TYPE_MESH_BCK, 0},
4921 {&handle_mesh_data_ack, GNUNET_MESSAGE_TYPE_MESH_UNICAST_ACK,
4922 sizeof (struct GNUNET_MESH_DataACK)},
4923 {&handle_mesh_data_ack, GNUNET_MESSAGE_TYPE_MESH_TO_ORIG_ACK,
4924 sizeof (struct GNUNET_MESH_DataACK)},
4925 {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE, 5106 {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE,
4926 sizeof (struct GNUNET_MESH_TunnelKeepAlive)}, 5107 sizeof (struct GNUNET_MESH_TunnelKeepAlive)},
4927 {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE, 5108 {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE,