2 #include "gnunet_client_lib.h"
3 #include "gnunet_arm_service.h"
4 #include "gnunet_hello_lib.h"
5 #include "gnunet_protocols.h"
6 #include "gnunet_server_lib.h"
7 #include "gnunet_time_lib.h"
8 #include "gnunet_transport_service.h"
12 struct AddressLookUpCB {
13 GNUNET_TRANSPORT_AddressLookUpCallback cb;
15 struct GNUNET_TIME_Absolute timeout;
16 struct GNUNET_CLIENT_Connection *client;
22 address_response_processor(void *cls, const struct
23 GNUNET_MessageHeader * msg)
25 struct AddressLookUpCB *alucb = cls;
32 alucb->cb (alucb->cls, NULL);
33 GNUNET_CLIENT_disconnect (alucb->client);
37 size = ntohs(msg->size);
38 if (size == sizeof(struct GNUNET_MessageHeader))
45 address = (const char*) &msg[1];
46 if (address[size - sizeof(struct GNUNET_MessageHeader) - 1] != '\0')
50 alucb->cb (alucb->cls, NULL);
51 GNUNET_CLIENT_disconnect (alucb->client);
57 /* expect more replies */
58 GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb,
59 GNUNET_TIME_absolute_get_remaining (alucb->timeout));
62 alucb->cb (alucb->cls, address);
66 GNUNET_CLIENT_disconnect (alucb->client);
72 GNUNET_TRANSPORT_address_lookup (struct GNUNET_SCHEDULER_Handle *sched,
73 const struct GNUNET_CONFIGURATION_Handle *cfg,
76 const char * nameTrans,
77 struct GNUNET_TIME_Relative timeout,
78 GNUNET_TRANSPORT_AddressLookUpCallback aluc,
81 size_t len = sizeof (struct AddressLookupMessage) + addressLen + strlen (nameTrans) + 1;
82 struct AddressLookupMessage *msg;
83 struct GNUNET_TIME_Absolute abs_timeout;
84 struct AddressLookUpCB *aluCB;
85 struct GNUNET_CLIENT_Connection *client;
87 if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
90 aluc (aluc_cls, NULL);
93 client = GNUNET_CLIENT_connect (sched, "transport", cfg);
96 aluc (aluc_cls, NULL);
99 abs_timeout = GNUNET_TIME_relative_to_absolute(timeout);
100 msg = GNUNET_malloc (len);
101 msg->header->size = htons (len);
102 msg->header->type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP);
103 msg->timeout = GNUNET_TIME_absolute_hton(abs_timeout);
104 msg->addrlen = htonl (addressLen);
105 char *addrbuf = (char*) &msg[1];
106 memcpy (addrbuf, address, addressLen);
107 char *tbuf = &addrbuf[addressLen];
108 memcpy (tbuf, nameTrans, strlen(nameTrans) + 1);
109 aluCB = GNUNET_malloc (sizeof (struct AddressLookUpCB));
111 aluCB->cb_cls = aluc_cls;
112 aluCB->timeout = abs_timeout;
113 aluCB->client = client;
114 GNUNET_CLIENT_transmit_and_get_response(client, msg->header, timeout, GNUNET_YES, &address_response_processor, aluCB);