aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api_address_lookup.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-01-19 14:20:54 +0000
committerNathan S. Evans <evans@in.tum.de>2010-01-19 14:20:54 +0000
commitb6dbf7e98bb79907562bf67d423b67a030b503e7 (patch)
tree4a63aa64d332add505dd167289630c4c5a385233 /src/transport/transport_api_address_lookup.c
parentfff6dc1db59348e426b4c6cc5a5729080d93a163 (diff)
downloadgnunet-b6dbf7e98bb79907562bf67d423b67a030b503e7.tar.gz
gnunet-b6dbf7e98bb79907562bf67d423b67a030b503e7.zip
pre-commit
Diffstat (limited to 'src/transport/transport_api_address_lookup.c')
-rw-r--r--src/transport/transport_api_address_lookup.c188
1 files changed, 97 insertions, 91 deletions
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c
index 1c0cf7340..961ee0713 100644
--- a/src/transport/transport_api_address_lookup.c
+++ b/src/transport/transport_api_address_lookup.c
@@ -9,108 +9,114 @@
9#include "transport.h" 9#include "transport.h"
10 10
11// FIXME: document 11// FIXME: document
12struct AddressLookUpCB { 12struct AddressLookUpCB
13 GNUNET_TRANSPORT_AddressLookUpCallback cb; 13{
14 void *cls; 14 GNUNET_TRANSPORT_AddressLookUpCallback cb;
15 struct GNUNET_TIME_Absolute timeout; 15 void *cls;
16 struct GNUNET_CLIENT_Connection *client; 16 struct GNUNET_TIME_Absolute timeout;
17 struct GNUNET_CLIENT_Connection *client;
17}; 18};
18 19
19 20
20// FIXME: document 21// FIXME: document
21static void 22static void
22address_response_processor(void *cls, const struct 23address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
23 GNUNET_MessageHeader * msg)
24{ 24{
25 struct AddressLookUpCB *alucb = cls; 25 struct AddressLookUpCB *alucb = cls;
26 const char *address; 26 const char *address;
27 uint16_t size; 27 uint16_t size;
28 28
29 if (msg == NULL) 29 if (msg == NULL)
30 { 30 {
31 /* timeout */ 31 /* timeout */
32 alucb->cb (alucb->cls, NULL); 32 alucb->cb (alucb->cls, NULL);
33 GNUNET_CLIENT_disconnect (alucb->client); 33 GNUNET_CLIENT_disconnect (alucb->client);
34 GNUNET_free (alucb); 34 GNUNET_free (alucb);
35 return; 35 return;
36 } 36 }
37 size = ntohs(msg->size); 37 size = ntohs (msg->size);
38 if (size == sizeof(struct GNUNET_MessageHeader)) 38 if (size == sizeof (struct GNUNET_MessageHeader))
39 { 39 {
40 /* last reply */ 40 /* last reply */
41 address = NULL; 41 address = NULL;
42 } 42 }
43 else 43 else
44 { 44 {
45 address = (const char*) &msg[1]; 45 address = (const char *) &msg[1];
46 if (address[size - sizeof(struct GNUNET_MessageHeader) - 1] != '\0') 46 if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
47 { 47 {
48 /* invalid reply */ 48 /* invalid reply */
49 GNUNET_break_op (0); 49 GNUNET_break_op (0);
50 alucb->cb (alucb->cls, NULL); 50 alucb->cb (alucb->cls, NULL);
51 GNUNET_CLIENT_disconnect (alucb->client); 51 GNUNET_CLIENT_disconnect (alucb->client);
52 GNUNET_free (alucb); 52 GNUNET_free (alucb);
53 return; 53 return;
54 } 54 }
55 else 55 else
56 { 56 {
57 /* expect more replies */ 57 /* expect more replies */
58 GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb, 58 GNUNET_CLIENT_receive (alucb->client, &address_response_processor,
59 GNUNET_TIME_absolute_get_remaining (alucb->timeout)); 59 alucb,
60 } 60 GNUNET_TIME_absolute_get_remaining (alucb->
61 } 61 timeout));
62 alucb->cb (alucb->cls, address); 62 }
63 if (address == NULL) 63 }
64 { 64 alucb->cb (alucb->cls, address);
65 /* done! */ 65 if (address == NULL)
66 GNUNET_CLIENT_disconnect (alucb->client); 66 {
67 GNUNET_free (alucb); 67 /* done! */
68 } 68 GNUNET_CLIENT_disconnect (alucb->client);
69 GNUNET_free (alucb);
70 }
69} 71}
70 72
71void 73void
72GNUNET_TRANSPORT_address_lookup (struct GNUNET_SCHEDULER_Handle *sched, 74GNUNET_TRANSPORT_address_lookup (struct GNUNET_SCHEDULER_Handle *sched,
73 const struct GNUNET_CONFIGURATION_Handle *cfg, 75 const struct GNUNET_CONFIGURATION_Handle
74 const char * address, 76 *cfg, const char *address, size_t addressLen,
75 size_t addressLen, 77 const char *nameTrans,
76 const char * nameTrans, 78 struct GNUNET_TIME_Relative timeout,
77 struct GNUNET_TIME_Relative timeout, 79 GNUNET_TRANSPORT_AddressLookUpCallback aluc,
78 GNUNET_TRANSPORT_AddressLookUpCallback aluc, 80 void *aluc_cls)
79 void *aluc_cls)
80{ 81{
81 size_t len = sizeof (struct AddressLookupMessage) + addressLen + strlen (nameTrans) + 1; 82 size_t len =
82 struct AddressLookupMessage *msg; 83 sizeof (struct AddressLookupMessage) + addressLen + strlen (nameTrans) +
83 struct GNUNET_TIME_Absolute abs_timeout; 84 1;
84 struct AddressLookUpCB *aluCB; 85 struct AddressLookupMessage *msg;
85 struct GNUNET_CLIENT_Connection *client; 86 struct GNUNET_TIME_Absolute abs_timeout;
87 struct AddressLookUpCB *aluCB;
88 struct GNUNET_CLIENT_Connection *client;
86 89
87 if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 90 if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
88 { 91 {
89 GNUNET_break (0); 92 GNUNET_break (0);
90 aluc (aluc_cls, NULL); 93 aluc (aluc_cls, NULL);
91 return; 94 return;
92 } 95 }
93 client = GNUNET_CLIENT_connect (sched, "transport", cfg); 96 client = GNUNET_CLIENT_connect (sched, "transport", cfg);
94 if (client == NULL) 97 if (client == NULL)
95 { 98 {
96 aluc (aluc_cls, NULL); 99 aluc (aluc_cls, NULL);
97 return; 100 return;
98 } 101 }
99 abs_timeout = GNUNET_TIME_relative_to_absolute(timeout); 102 abs_timeout = GNUNET_TIME_relative_to_absolute (timeout);
100 msg = GNUNET_malloc (len); 103 msg = GNUNET_malloc (len);
101 msg->header->size = htons (len); 104 msg->header->size = htons (len);
102 msg->header->type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); 105 msg->header->type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP);
103 msg->timeout = GNUNET_TIME_absolute_hton(abs_timeout); 106 msg->timeout = GNUNET_TIME_absolute_hton (abs_timeout);
104 msg->addrlen = htonl (addressLen); 107 msg->addrlen = htonl (addressLen);
105 char *addrbuf = (char*) &msg[1]; 108 char *addrbuf = (char *) &msg[1];
106 memcpy (addrbuf, address, addressLen); 109 memcpy (addrbuf, address, addressLen);
107 char *tbuf = &addrbuf[addressLen]; 110 char *tbuf = &addrbuf[addressLen];
108 memcpy (tbuf, nameTrans, strlen(nameTrans) + 1); 111 memcpy (tbuf, nameTrans, strlen (nameTrans) + 1);
109 aluCB = GNUNET_malloc (sizeof (struct AddressLookUpCB)); 112 aluCB = GNUNET_malloc (sizeof (struct AddressLookUpCB));
110 aluCB->cb = aluc; 113 aluCB->cb = aluc;
111 aluCB->cb_cls = aluc_cls; 114 aluCB->cb_cls = aluc_cls;
112 aluCB->timeout = abs_timeout; 115 aluCB->timeout = abs_timeout;
113 aluCB->client = client; 116 aluCB->client = client;
114 GNUNET_CLIENT_transmit_and_get_response(client, msg->header, timeout, GNUNET_YES, &address_response_processor, aluCB); 117 GNUNET_CLIENT_transmit_and_get_response (client, msg->header, timeout,
115 GNUNET_free(msg); 118 GNUNET_YES,
119 &address_response_processor,
120 aluCB);
121 GNUNET_free (msg);
116} 122}