aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2011-06-15 07:15:31 +0000
committerPhilipp Tölke <toelke@in.tum.de>2011-06-15 07:15:31 +0000
commit9134c12c64d723c1f86f35cff1e66d0f0e6e9e40 (patch)
tree431fe9ca67724dc729fffce1212a4e7b809f4a7e /src/vpn
parent3c1715418cff7fb0c19dbeb4fa499fd1187db845 (diff)
downloadgnunet-9134c12c64d723c1f86f35cff1e66d0f0e6e9e40.tar.gz
gnunet-9134c12c64d723c1f86f35cff1e66d0f0e6e9e40.zip
let -exit receive packets from the mesh
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-daemon-exit.c151
1 files changed, 151 insertions, 0 deletions
diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c
index 5a9be9335..4530ccdcd 100644
--- a/src/vpn/gnunet-daemon-exit.c
+++ b/src/vpn/gnunet-daemon-exit.c
@@ -79,6 +79,13 @@ static long long unsigned int max_udp_connections = 200;
79 */ 79 */
80static long long unsigned int max_tcp_connections = 200; 80static long long unsigned int max_tcp_connections = 200;
81 81
82struct remote_addr
83{
84 char addrlen;
85 unsigned char addr[16];
86 char proto;
87};
88
82/** 89/**
83 * This struct is saved into the services-hashmap 90 * This struct is saved into the services-hashmap
84 */ 91 */
@@ -125,6 +132,7 @@ struct redirect_state
125 struct GNUNET_MESH_Tunnel *tunnel; 132 struct GNUNET_MESH_Tunnel *tunnel;
126 GNUNET_HashCode desc; 133 GNUNET_HashCode desc;
127 struct redirect_service *serv; 134 struct redirect_service *serv;
135 struct remote_addr remote;
128 136
129 struct GNUNET_CONTAINER_HeapNode* heap_node; 137 struct GNUNET_CONTAINER_HeapNode* heap_node;
130 struct GNUNET_CONTAINER_MultiHashMap *hashmap; 138 struct GNUNET_CONTAINER_MultiHashMap *hashmap;
@@ -905,6 +913,147 @@ receive_tcp_service (void *cls,
905 return GNUNET_YES; 913 return GNUNET_YES;
906} 914}
907 915
916static int
917receive_tcp_remote (void *cls,
918 struct GNUNET_MESH_Tunnel *tunnel,
919 void **tunnel_ctx,
920 const struct GNUNET_PeerIdentity *sender,
921 const struct GNUNET_MessageHeader *message,
922 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
923{
924 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
925 struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
926 struct remote_addr *s = (struct remote_addr *) desc;
927 char *buf;
928 size_t len;
929 unsigned int pkt_len = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - sizeof (GNUNET_HashCode);
930
931 struct redirect_state *state =
932 GNUNET_malloc (sizeof (struct redirect_state));
933 memset (state, 0, sizeof (struct redirect_state));
934 state->tunnel = tunnel;
935 state->hashmap = tcp_connections;
936 memcpy (&state->remote, s, sizeof (struct remote_addr));
937
938 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
939 sizeof (struct ip6_hdr) + pkt_len;
940 buf = alloca (len);
941
942 memset (buf, 0, len);
943
944 switch (s->addrlen)
945 {
946 case 4:
947 prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x06, /* TCP */
948 &s->addr, tunnel, state, (struct ip_pkt *) buf);
949 break;
950 case 16:
951 prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x06, /* TCP */
952 &s->addr, tunnel, state, (struct ip6_pkt *) buf);
953 break;
954 default:
955 GNUNET_assert (0);
956 break;
957 }
958
959 hash_redirect_info (&state->hash, &state->redirect_info, s->addrlen);
960
961 if (GNUNET_NO ==
962 GNUNET_CONTAINER_multihashmap_contains (udp_connections, &state->hash))
963 {
964 GNUNET_CONTAINER_multihashmap_put (udp_connections, &state->hash, state,
965 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
966
967 state->heap_node =
968 GNUNET_CONTAINER_heap_insert (udp_connections_heap, state,
969 GNUNET_TIME_absolute_get ().abs_value);
970
971 if (GNUNET_CONTAINER_heap_get_size (udp_connections_heap) >
972 max_udp_connections)
973 GNUNET_SCHEDULER_add_now (collect_connections, udp_connections_heap);
974 }
975 else
976 GNUNET_free (state);
977
978 (void) GNUNET_DISK_file_write (helper_handle->fh_to_helper, buf, len);
979 return GNUNET_YES;
980
981}
982
983static int
984receive_udp_remote (void *cls,
985 struct GNUNET_MESH_Tunnel *tunnel,
986 void **tunnel_ctx,
987 const struct GNUNET_PeerIdentity *sender,
988 const struct GNUNET_MessageHeader *message,
989 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
990{
991 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
992 struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
993 struct remote_addr *s = (struct remote_addr *) desc;
994 char *buf;
995 size_t len;
996
997 GNUNET_assert (ntohs (pkt->len) ==
998 ntohs (message->size) -
999 sizeof (struct GNUNET_MessageHeader) -
1000 sizeof (GNUNET_HashCode));
1001
1002 /* Prepare the state.
1003 * This will be saved in the hashmap, so that the receiving procedure knows
1004 * through which tunnel this connection has to be routed.
1005 */
1006 struct redirect_state *state =
1007 GNUNET_malloc (sizeof (struct redirect_state));
1008 memset (state, 0, sizeof (struct redirect_state));
1009 state->tunnel = tunnel;
1010 state->hashmap = udp_connections;
1011 memcpy (&state->remote, s, sizeof (struct remote_addr));
1012
1013 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
1014 sizeof (struct ip6_hdr) + ntohs (pkt->len);
1015 buf = alloca (len);
1016
1017 memset (buf, 0, len);
1018
1019 switch (s->addrlen)
1020 {
1021 case 4:
1022 prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
1023 &s->addr, tunnel, state, (struct ip_pkt *) buf);
1024 break;
1025 case 16:
1026 prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
1027 &s->addr, tunnel, state, (struct ip6_pkt *) buf);
1028 break;
1029 default:
1030 GNUNET_assert (0);
1031 break;
1032 }
1033
1034 hash_redirect_info (&state->hash, &state->redirect_info, s->addrlen);
1035
1036 if (GNUNET_NO ==
1037 GNUNET_CONTAINER_multihashmap_contains (udp_connections, &state->hash))
1038 {
1039 GNUNET_CONTAINER_multihashmap_put (udp_connections, &state->hash, state,
1040 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1041
1042 state->heap_node =
1043 GNUNET_CONTAINER_heap_insert (udp_connections_heap, state,
1044 GNUNET_TIME_absolute_get ().abs_value);
1045
1046 if (GNUNET_CONTAINER_heap_get_size (udp_connections_heap) >
1047 max_udp_connections)
1048 GNUNET_SCHEDULER_add_now (collect_connections, udp_connections_heap);
1049 }
1050 else
1051 GNUNET_free (state);
1052
1053 (void) GNUNET_DISK_file_write (helper_handle->fh_to_helper, buf, len);
1054 return GNUNET_YES;
1055}
1056
908/** 1057/**
909 * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt 1058 * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt
910 */ 1059 */
@@ -1020,6 +1169,8 @@ run (void *cls,
1020 const static struct GNUNET_MESH_MessageHandler handlers[] = { 1169 const static struct GNUNET_MESH_MessageHandler handlers[] = {
1021 {receive_udp_service, GNUNET_MESSAGE_TYPE_SERVICE_UDP, 0}, 1170 {receive_udp_service, GNUNET_MESSAGE_TYPE_SERVICE_UDP, 0},
1022 {receive_tcp_service, GNUNET_MESSAGE_TYPE_SERVICE_TCP, 0}, 1171 {receive_tcp_service, GNUNET_MESSAGE_TYPE_SERVICE_TCP, 0},
1172 {receive_udp_remote, GNUNET_MESSAGE_TYPE_REMOTE_UDP, 0},
1173 {receive_tcp_remote, GNUNET_MESSAGE_TYPE_REMOTE_TCP, 0},
1023 {NULL, 0, 0} 1174 {NULL, 0, 0}
1024 }; 1175 };
1025 mesh_handle = GNUNET_MESH_connect (cfg_, NULL, NULL, handlers, NULL); 1176 mesh_handle = GNUNET_MESH_connect (cfg_, NULL, NULL, handlers, NULL);