[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19080 - gnunet/src/exit
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19080 - gnunet/src/exit |
Date: |
Tue, 10 Jan 2012 22:52:42 +0100 |
Author: grothoff
Date: 2012-01-10 22:52:42 +0100 (Tue, 10 Jan 2012)
New Revision: 19080
Modified:
gnunet/src/exit/exit.h
gnunet/src/exit/gnunet-daemon-exit.c
Log:
-dealing with new UDP message formats
Modified: gnunet/src/exit/exit.h
===================================================================
--- gnunet/src/exit/exit.h 2012-01-10 17:31:31 UTC (rev 19079)
+++ gnunet/src/exit/exit.h 2012-01-10 21:52:42 UTC (rev 19080)
@@ -128,11 +128,16 @@
struct GNUNET_MessageHeader header;
/**
- * Always 0.
+ * Source port to use for the UDP request (0 to use a random port). In NBO.
*/
- uint32_t reserved;
+ uint16_t source_port;
/**
+ * Destination port to use for the UDP request. In NBO.
+ */
+ uint16_t destination_port;
+
+ /**
* Identification for the desired service.
*/
GNUNET_HashCode service_descriptor;
@@ -157,7 +162,16 @@
*/
int32_t af;
+ /**
+ * Source port to use for the UDP request (0 to use a random port). In NBO.
+ */
+ uint16_t source_port;
+ /**
+ * Destination port to use for the UDP request. In NBO.
+ */
+ uint16_t destination_port;
+
/* followed by IP address of the destination; either
'struct in_addr' or 'struct in6_addr', depending on af */
Modified: gnunet/src/exit/gnunet-daemon-exit.c
===================================================================
--- gnunet/src/exit/gnunet-daemon-exit.c 2012-01-10 17:31:31 UTC (rev
19079)
+++ gnunet/src/exit/gnunet-daemon-exit.c 2012-01-10 21:52:42 UTC (rev
19080)
@@ -25,7 +25,6 @@
* @author Christian Grothoff
*
* TODO:
- * - use new proper message headers for mesh P2P messages
* - factor out crc computations from DNS/EXIT/VPN into shared library?
* - which code should advertise services? the service model is right
* now a bit odd, especially as this code DOES the exit and knows
@@ -1202,7 +1201,7 @@
struct tun_header *tun;
hdr= (struct GNUNET_MessageHeader *) buf;
- hdr->type = htons (42);
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
hdr->size = htons (len);
tun = (struct tun_header*) &hdr[1];
tun->flags = htons (0);
@@ -1477,7 +1476,7 @@
struct tun_header *tun;
hdr= (struct GNUNET_MessageHeader *) buf;
- hdr->type = htons (42);
+ hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
hdr->size = htons (len);
tun = (struct tun_header*) &hdr[1];
tun->flags = htons (0);
@@ -1541,29 +1540,59 @@
const struct GNUNET_ATS_Information *atsi GNUNET_UNUSED)
{
struct TunnelState *state = *tunnel_ctx;
- // FIXME: write proper request struct (!)
- const GNUNET_HashCode *desc = (const GNUNET_HashCode *) &message[1];
- const struct udp_packet *pkt = (const struct udp_packet *) &desc[1];
- const struct SocketAddress *s = (const struct SocketAddress *) desc;
+ const struct GNUNET_EXIT_UdpInternetMessage *msg;
uint16_t pkt_len = ntohs (message->size);
+ const struct in_addr *v4;
+ const struct in6_addr *v6;
+ const void *payload;
+ int af;
- if (pkt_len < sizeof (struct GNUNET_MessageHeader) + sizeof
(GNUNET_HashCode) + sizeof (struct udp_packet))
+ if (pkt_len < sizeof (struct GNUNET_EXIT_UdpInternetMessage))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- pkt_len -= (sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode));
-
+ msg = (const struct GNUNET_EXIT_UdpInternetMessage*) message;
+ pkt_len -= sizeof (struct GNUNET_EXIT_UdpInternetMessage);
+ af = (int) ntohl (msg->af);
+ state->ri.remote_address.af = af;
+ switch (af)
+ {
+ case AF_INET:
+ if (pkt_len < sizeof (struct in_addr))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ v4 = (const struct in_addr*) &msg[1];
+ payload = &v4[1];
+ pkt_len -= sizeof (struct in_addr);
+ state->ri.remote_address.address.ipv4 = *v4;
+ break;
+ case AF_INET6:
+ if (pkt_len < sizeof (struct in6_addr))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ v6 = (const struct in6_addr*) &msg[1];
+ payload = &v6[1];
+ pkt_len -= sizeof (struct in_addr);
+ state->ri.remote_address.address.ipv6 = *v6;
+ break;
+ default:
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ state->ri.remote_address.proto = IPPROTO_UDP;
+ state->ri.remote_address.port = msg->destination_port;
if (NULL == state->heap_node)
- {
- /* first packet, setup record */
- state->ri.remote_address = *s;
setup_state_record (state);
- }
-
+ if (0 != ntohs (msg->source_port))
+ state->ri.local_address.port = msg->source_port;
send_udp_packet_via_tun (&state->ri.remote_address,
&state->ri.local_address,
- &pkt[1], pkt_len - sizeof (struct udp_packet));
+ payload, pkt_len);
return GNUNET_YES;
}
@@ -1589,43 +1618,34 @@
const struct GNUNET_ATS_Information *atsi GNUNET_UNUSED)
{
struct TunnelState *state = *tunnel_ctx;
- // FIXME: write proper request struct (we don't need UDP except dpt either!)
- const GNUNET_HashCode *desc = (const GNUNET_HashCode *) &message[1];
- const struct udp_packet *pkt = (const struct udp_packet *) &desc[1];
+ const struct GNUNET_EXIT_UdpServiceMessage *msg;
uint16_t pkt_len = ntohs (message->size);
-
/* check that we got at least a valid header */
- if (pkt_len < sizeof (struct GNUNET_MessageHeader) + sizeof
(GNUNET_HashCode) + sizeof (struct udp_packet))
+ if (pkt_len < sizeof (struct GNUNET_EXIT_UdpServiceMessage))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- pkt_len -= (sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode));
-
- GNUNET_assert (ntohs (pkt->len) ==
- ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) -
- sizeof (GNUNET_HashCode));
-
- if (NULL == state->serv)
+ msg = (const struct GNUNET_EXIT_UdpServiceMessage*) message;
+ pkt_len -= sizeof (struct GNUNET_EXIT_UdpServiceMessage);
+
+ if (NULL == (state->serv = find_service (udp_services,
&msg->service_descriptor,
+ ntohs (msg->destination_port))))
{
- /* setup fresh connection */
- GNUNET_assert (NULL == state->heap_node);
- if (NULL == (state->serv = find_service (udp_services, desc, ntohs
(pkt->dpt))))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("No service found for %s on port %d!\n"),
- "UDP",
- ntohs (pkt->dpt));
- GNUNET_MESH_tunnel_destroy (state->tunnel);
- return GNUNET_SYSERR;
- }
- state->ri.remote_address = state->serv->address;
- setup_state_record (state);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("No service found for %s on port %d!\n"),
+ "UDP",
+ ntohs (msg->destination_port));
+ return GNUNET_SYSERR;
}
+ state->ri.remote_address = state->serv->address;
+ setup_state_record (state);
+ if (0 != ntohs (msg->source_port))
+ state->ri.local_address.port = msg->source_port;
send_udp_packet_via_tun (&state->ri.remote_address,
&state->ri.local_address,
- &pkt[1], pkt_len - sizeof (struct udp_packet));
+ &msg[1], pkt_len);
return GNUNET_YES;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19080 - gnunet/src/exit,
gnunet <=