diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-08-05 10:14:34 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-08-05 10:14:34 +0000 |
commit | e4547d48bbacb0300390fde17e6b37780fb064a6 (patch) | |
tree | a8b2864a282f89316a747a6aaa2ca3d296112561 /src | |
parent | 36f92dc5adfc028f71123f813638a142035730f5 (diff) | |
download | gnunet-e4547d48bbacb0300390fde17e6b37780fb064a6.tar.gz gnunet-e4547d48bbacb0300390fde17e6b37780fb064a6.zip |
- generic handler for encrypted data
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh-enc.c | 102 |
1 files changed, 32 insertions, 70 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c index b1592a1b5..07c531eec 100644 --- a/src/mesh/gnunet-service-mesh-enc.c +++ b/src/mesh/gnunet-service-mesh-enc.c | |||
@@ -2691,6 +2691,8 @@ channel_send_data_ack (struct MeshChannel *ch, int fwd) | |||
2691 | * | 2691 | * |
2692 | * Note that although the name is fwd_ack, the FWD mean forward *traffic*, | 2692 | * Note that although the name is fwd_ack, the FWD mean forward *traffic*, |
2693 | * the ACK itself goes "back" (towards root). | 2693 | * the ACK itself goes "back" (towards root). |
2694 | * | ||
2695 | * FIXME: use per connection ACKs istead of per-hop. | ||
2694 | * | 2696 | * |
2695 | * @param c Connection on which to send the ACK. | 2697 | * @param c Connection on which to send the ACK. |
2696 | * @param fwd Is this FWD ACK? (Going dest->owner) | 2698 | * @param fwd Is this FWD ACK? (Going dest->owner) |
@@ -4201,7 +4203,7 @@ queue_add (void *cls, uint16_t type, size_t size, | |||
4201 | * Generic handler for mesh network payload traffic. | 4203 | * Generic handler for mesh network payload traffic. |
4202 | * | 4204 | * |
4203 | * @param t Tunnel on which we got this message. | 4205 | * @param t Tunnel on which we got this message. |
4204 | * @param message Data message. | 4206 | * @param message Unencryted data message. |
4205 | * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; | 4207 | * @param fwd Is this FWD traffic? GNUNET_YES : GNUNET_NO; |
4206 | * | 4208 | * |
4207 | * @return GNUNET_OK to keep the connection open, | 4209 | * @return GNUNET_OK to keep the connection open, |
@@ -4773,99 +4775,59 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer, | |||
4773 | pid = ntohl (msg->pid); | 4775 | pid = ntohl (msg->pid); |
4774 | if (GMC_is_pid_bigger (pid, fc->last_ack_sent)) | 4776 | if (GMC_is_pid_bigger (pid, fc->last_ack_sent)) |
4775 | { | 4777 | { |
4776 | GNUNET_STATISTICS_update (stats, "# unsolicited data", 1, GNUNET_NO); | 4778 | GNUNET_STATISTICS_update (stats, "# unsolicited message", 1, GNUNET_NO); |
4777 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4779 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4778 | "WARNING Received PID %u, (prev %u), ACK %u\n", | 4780 | "WARNING Received PID %u, (prev %u), ACK %u\n", |
4779 | pid, fc->last_pid_recv, fc->last_ack_sent); | 4781 | pid, fc->last_pid_recv, fc->last_ack_sent); |
4780 | return GNUNET_OK; | 4782 | return GNUNET_OK; |
4781 | } | 4783 | } |
4784 | if (GNUNET_NO == GMC_is_pid_bigger (pid, fc->last_pid_recv)) | ||
4785 | { | ||
4786 | GNUNET_STATISTICS_update (stats, "# duplicate PID", 1, GNUNET_NO); | ||
4787 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4788 | " Pid %u not expected (%u+), dropping!\n", | ||
4789 | pid, fc->last_pid_recv + 1); | ||
4790 | return GNUNET_OK; | ||
4791 | } | ||
4782 | if (MESH_CONNECTION_SENT == c->state) | 4792 | if (MESH_CONNECTION_SENT == c->state) |
4783 | connection_change_state (c, MESH_CONNECTION_READY); | 4793 | connection_change_state (c, MESH_CONNECTION_READY); |
4784 | connection_reset_timeout (c, fwd); | 4794 | connection_reset_timeout (c, fwd); |
4795 | fc->last_pid_recv = pid; | ||
4785 | 4796 | ||
4786 | /* Is this message for us? */ | 4797 | /* Is this message for us? */ |
4787 | if (NULL != c->t->channel_head) | 4798 | if (NULL != c->t->channel_head) |
4788 | { | 4799 | { |
4789 | /* TODO signature verification */ | 4800 | size_t dsize = size - sizeof (struct GNUNET_MESH_Encrypted); |
4790 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " it's for us! sending to client\n"); | 4801 | char cbuf[dsize]; |
4791 | GNUNET_STATISTICS_update (stats, "# data received", 1, GNUNET_NO); | 4802 | struct GNUNET_MESH_Data *dmsg; |
4792 | if (GMC_is_pid_bigger (pid, fc->last_pid_recv)) | ||
4793 | { | ||
4794 | uint32_t mid; | ||
4795 | 4803 | ||
4796 | mid = ntohl (msg->mid); | 4804 | /* TODO signature verification */ |
4797 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4805 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " it's for us!\n"); |
4798 | " pid %u (mid %u) not seen yet\n", pid, mid); | 4806 | GNUNET_STATISTICS_update (stats, "# messages received", 1, GNUNET_NO); |
4799 | fc->last_pid_recv = pid; | 4807 | |
4800 | 4808 | fc->last_pid_recv = pid; | |
4801 | if (GNUNET_NO == t->reliable || | 4809 | tunnel_decrypt (t, cbuf, &msg[1], dsize, msg->iv, fwd); |
4802 | ( !GMC_is_pid_bigger (rel->mid_recv, mid) && | 4810 | dmsg = (struct GNUNET_MESH_Data *) cbuf; |
4803 | GMC_is_pid_bigger (rel->mid_recv + 64, mid) ) ) | 4811 | handle_data (t, dmsg, fwd); |
4804 | { | 4812 | connection_send_ack (c, fwd); |
4805 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4806 | "!!! RECV %u\n", ntohl (msg->mid)); | ||
4807 | if (GNUNET_YES == t->reliable) | ||
4808 | { | ||
4809 | /* Is this the exact next expected messasge? */ | ||
4810 | if (mid == rel->mid_recv) | ||
4811 | { | ||
4812 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "as expected\n"); | ||
4813 | rel->mid_recv++; | ||
4814 | tunnel_send_client_data (t, msg, fwd); | ||
4815 | tunnel_send_client_buffered_data (t, c, rel); | ||
4816 | } | ||
4817 | else | ||
4818 | { | ||
4819 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "save for later\n"); | ||
4820 | tunnel_add_buffered_data (t, msg, rel); | ||
4821 | } | ||
4822 | } | ||
4823 | else /* Tunnel unreliable, send to clients directly */ | ||
4824 | { | ||
4825 | tunnel_send_client_data (t, msg, fwd); | ||
4826 | } | ||
4827 | } | ||
4828 | else | ||
4829 | { | ||
4830 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4831 | " MID %u not expected (%u - %u), dropping!\n", | ||
4832 | ntohl (msg->mid), rel->mid_recv, rel->mid_recv + 64); | ||
4833 | } | ||
4834 | } | ||
4835 | else | ||
4836 | { | ||
4837 | // GNUNET_STATISTICS_update (stats, "# duplicate PID", 1, GNUNET_NO); | ||
4838 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
4839 | " Pid %u not expected (%u+), dropping!\n", | ||
4840 | pid, fc->last_pid_recv + 1); | ||
4841 | } | ||
4842 | tunnel_send_ack (t, type, fwd); | ||
4843 | return GNUNET_OK; | 4813 | return GNUNET_OK; |
4844 | } | 4814 | } |
4845 | fc->last_pid_recv = pid; | 4815 | |
4846 | if (0 == hop) | 4816 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); |
4847 | { | ||
4848 | GNUNET_STATISTICS_update (stats, "# data on dying tunnel", 1, GNUNET_NO); | ||
4849 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "data on dying tunnel %s[%X]\n", | ||
4850 | GNUNET_PEER_resolve2 (t->id.oid), ntohl (msg->tid)); | ||
4851 | return GNUNET_OK; /* Next hop has destoyed the tunnel, drop */ | ||
4852 | } | ||
4853 | ttl = ntohl (msg->ttl); | 4817 | ttl = ntohl (msg->ttl); |
4854 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ttl: %u\n", ttl); | 4818 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ttl: %u\n", ttl); |
4855 | if (ttl == 0) | 4819 | if (ttl == 0) |
4856 | { | 4820 | { |
4857 | GNUNET_STATISTICS_update (stats, "# TTL drops", 1, GNUNET_NO); | 4821 | GNUNET_STATISTICS_update (stats, "# TTL drops", 1, GNUNET_NO); |
4858 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " TTL is 0, DROPPING!\n"); | 4822 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " TTL is 0, DROPPING!\n"); |
4859 | tunnel_send_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK, fwd); | 4823 | connection_send_ack (c, fwd); |
4860 | return GNUNET_OK; | 4824 | return GNUNET_OK; |
4861 | } | 4825 | } |
4826 | GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); | ||
4827 | |||
4828 | send_prebuilt_message_connection (&msg->header, c, NULL, fwd); | ||
4829 | connection_send_ack (c, fwd); | ||
4862 | 4830 | ||
4863 | if (myid != hop) | ||
4864 | { | ||
4865 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); | ||
4866 | send_prebuilt_message (message, hop, t); | ||
4867 | GNUNET_STATISTICS_update (stats, "# unicast forwarded", 1, GNUNET_NO); | ||
4868 | } | ||
4869 | return GNUNET_OK; | 4831 | return GNUNET_OK; |
4870 | } | 4832 | } |
4871 | 4833 | ||