aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api_peer_address_lookup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport_api_peer_address_lookup.c')
-rw-r--r--src/transport/transport_api_peer_address_lookup.c80
1 files changed, 41 insertions, 39 deletions
diff --git a/src/transport/transport_api_peer_address_lookup.c b/src/transport/transport_api_peer_address_lookup.c
index c63856d4a..50536b47d 100644
--- a/src/transport/transport_api_peer_address_lookup.c
+++ b/src/transport/transport_api_peer_address_lookup.c
@@ -82,37 +82,37 @@ peer_address_response_processor (void *cls,
82 uint16_t size; 82 uint16_t size;
83 83
84 if (msg == NULL) 84 if (msg == NULL)
85 { 85 {
86 alucb->cb (alucb->cb_cls, NULL); 86 alucb->cb (alucb->cb_cls, NULL);
87 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); 87 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
88 GNUNET_free (alucb); 88 GNUNET_free (alucb);
89 return; 89 return;
90 } 90 }
91 GNUNET_break (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 91 GNUNET_break (ntohs (msg->type) ==
92 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
92 size = ntohs (msg->size); 93 size = ntohs (msg->size);
93 if (size == sizeof (struct GNUNET_MessageHeader)) 94 if (size == sizeof (struct GNUNET_MessageHeader))
94 { 95 {
95 /* done! */ 96 /* done! */
96 alucb->cb (alucb->cb_cls, NULL); 97 alucb->cb (alucb->cb_cls, NULL);
97 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); 98 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
98 GNUNET_free (alucb); 99 GNUNET_free (alucb);
99 return; 100 return;
100 } 101 }
101 address = (const char *) &msg[1]; 102 address = (const char *) &msg[1];
102 if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') 103 if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
103 { 104 {
104 /* invalid reply */ 105 /* invalid reply */
105 GNUNET_break (0); 106 GNUNET_break (0);
106 alucb->cb (alucb->cb_cls, NULL); 107 alucb->cb (alucb->cb_cls, NULL);
107 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); 108 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
108 GNUNET_free (alucb); 109 GNUNET_free (alucb);
109 return; 110 return;
110 } 111 }
111 /* expect more replies */ 112 /* expect more replies */
112 GNUNET_CLIENT_receive (alucb->client, 113 GNUNET_CLIENT_receive (alucb->client,
113 &peer_address_response_processor, alucb, 114 &peer_address_response_processor, alucb,
114 GNUNET_TIME_absolute_get_remaining 115 GNUNET_TIME_absolute_get_remaining (alucb->timeout));
115 (alucb->timeout));
116 alucb->cb (alucb->cb_cls, address); 116 alucb->cb (alucb->cb_cls, address);
117} 117}
118 118
@@ -127,10 +127,12 @@ peer_address_response_processor (void *cls,
127 * @param peer_address_callback_cls closure for peer_address_callback 127 * @param peer_address_callback_cls closure for peer_address_callback
128 */ 128 */
129void 129void
130GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, 130GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
131 *cfg,
131 const struct GNUNET_PeerIdentity *peer, 132 const struct GNUNET_PeerIdentity *peer,
132 struct GNUNET_TIME_Relative timeout, 133 struct GNUNET_TIME_Relative timeout,
133 GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, 134 GNUNET_TRANSPORT_AddressLookUpCallback
135 peer_address_callback,
134 void *peer_address_callback_cls) 136 void *peer_address_callback_cls)
135{ 137{
136 struct PeerAddressLookupMessage msg; 138 struct PeerAddressLookupMessage msg;
@@ -139,26 +141,26 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle *
139 141
140 client = GNUNET_CLIENT_connect ("transport", cfg); 142 client = GNUNET_CLIENT_connect ("transport", cfg);
141 if (client == NULL) 143 if (client == NULL)
142 { 144 {
143 peer_address_callback (peer_address_callback_cls, NULL); 145 peer_address_callback (peer_address_callback_cls, NULL);
144 return; 146 return;
145 } 147 }
146 msg.header.size = htons (sizeof(struct PeerAddressLookupMessage)); 148 msg.header.size = htons (sizeof (struct PeerAddressLookupMessage));
147 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP); 149 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP);
148 msg.timeout = GNUNET_TIME_relative_hton (timeout); 150 msg.timeout = GNUNET_TIME_relative_hton (timeout);
149 memcpy(&msg.peer, peer, sizeof(struct GNUNET_PeerIdentity)); 151 memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity));
150 peer_address_lookup_cb = GNUNET_malloc (sizeof (struct AddressLookupCtx)); 152 peer_address_lookup_cb = GNUNET_malloc (sizeof (struct AddressLookupCtx));
151 peer_address_lookup_cb->cb = peer_address_callback; 153 peer_address_lookup_cb->cb = peer_address_callback;
152 peer_address_lookup_cb->cb_cls = peer_address_callback_cls; 154 peer_address_lookup_cb->cb_cls = peer_address_callback_cls;
153 peer_address_lookup_cb->timeout = GNUNET_TIME_relative_to_absolute (timeout); 155 peer_address_lookup_cb->timeout = GNUNET_TIME_relative_to_absolute (timeout);
154 peer_address_lookup_cb->client = client; 156 peer_address_lookup_cb->client = client;
155 GNUNET_assert (GNUNET_OK == 157 GNUNET_assert (GNUNET_OK ==
156 GNUNET_CLIENT_transmit_and_get_response (client, 158 GNUNET_CLIENT_transmit_and_get_response (client,
157 &msg.header, 159 &msg.header,
158 timeout, 160 timeout,
159 GNUNET_YES, 161 GNUNET_YES,
160 &peer_address_response_processor, 162 &peer_address_response_processor,
161 peer_address_lookup_cb)); 163 peer_address_lookup_cb));
162} 164}
163 165
164/* end of transport_api_peer_address_lookup.c */ 166/* end of transport_api_peer_address_lookup.c */