diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-29 18:04:01 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-29 18:04:01 +0000 |
commit | 56c32ea37a52b239494a7f91933e60eb7caf30f3 (patch) | |
tree | 5c8c8ef6b577da4931ec3e546b2fb60ed0e8f029 /src/transport/transport_api_address_lookup.c | |
parent | 5ca85864950a1fe92613f5ed3a69cd08d248423e (diff) | |
download | gnunet-56c32ea37a52b239494a7f91933e60eb7caf30f3.tar.gz gnunet-56c32ea37a52b239494a7f91933e60eb7caf30f3.zip |
- finale commit for the api change
Diffstat (limited to 'src/transport/transport_api_address_lookup.c')
-rw-r--r-- | src/transport/transport_api_address_lookup.c | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c index 5904de5e2..489ba8a5a 100644 --- a/src/transport/transport_api_address_lookup.c +++ b/src/transport/transport_api_address_lookup.c | |||
@@ -42,12 +42,12 @@ | |||
42 | /** | 42 | /** |
43 | * Context for the address lookup. | 43 | * Context for the address lookup. |
44 | */ | 44 | */ |
45 | struct GNUNET_TRANSPORT_PeerAddressLookupContext | 45 | struct GNUNET_TRANSPORT_PeerIterateContext |
46 | { | 46 | { |
47 | /** | 47 | /** |
48 | * Function to call with the human-readable address. | 48 | * Function to call with the binary address. |
49 | */ | 49 | */ |
50 | GNUNET_TRANSPORT_AddressLookUpCallback cb; | 50 | GNUNET_TRANSPORT_PeerIterateCallback cb; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Closure for cb. | 53 | * Closure for cb. |
@@ -76,11 +76,12 @@ static void | |||
76 | peer_address_response_processor (void *cls, | 76 | peer_address_response_processor (void *cls, |
77 | const struct GNUNET_MessageHeader *msg) | 77 | const struct GNUNET_MessageHeader *msg) |
78 | { | 78 | { |
79 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *pal_ctx = cls; | 79 | struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx = cls; |
80 | struct AddressIterateResponseMessage *air_msg = (struct AddressIterateResponseMessage *) &msg[1]; | 80 | struct AddressIterateResponseMessage *air_msg; |
81 | const struct GNUNET_HELLO_Address *address; | 81 | struct GNUNET_HELLO_Address *address; |
82 | uint16_t size; | 82 | uint16_t size; |
83 | if (air_msg == NULL) | 83 | |
84 | if (msg == NULL) | ||
84 | { | 85 | { |
85 | pal_ctx->cb (pal_ctx->cb_cls, NULL); | 86 | pal_ctx->cb (pal_ctx->cb_cls, NULL); |
86 | GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); | 87 | GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); |
@@ -98,6 +99,16 @@ peer_address_response_processor (void *cls, | |||
98 | return; | 99 | return; |
99 | } | 100 | } |
100 | 101 | ||
102 | if (size < sizeof (struct GNUNET_MessageHeader) + sizeof (struct AddressIterateResponseMessage)) | ||
103 | { | ||
104 | GNUNET_break_op (0); | ||
105 | pal_ctx->cb (pal_ctx->cb_cls, NULL ); | ||
106 | GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); | ||
107 | GNUNET_free (pal_ctx); | ||
108 | return; | ||
109 | } | ||
110 | |||
111 | air_msg = (struct AddressIterateResponseMessage *) &msg[1]; | ||
101 | size_t tlen = ntohl(air_msg->pluginlen); | 112 | size_t tlen = ntohl(air_msg->pluginlen); |
102 | size_t alen = ntohl(air_msg->addrlen); | 113 | size_t alen = ntohl(air_msg->addrlen); |
103 | 114 | ||
@@ -113,7 +124,7 @@ peer_address_response_processor (void *cls, | |||
113 | char * addr = (char *) &air_msg[1]; | 124 | char * addr = (char *) &air_msg[1]; |
114 | char * transport_name = &addr[alen]; | 125 | char * transport_name = &addr[alen]; |
115 | 126 | ||
116 | if (transport_name[tlen] != '\0') | 127 | if (transport_name[tlen-1] != '\0') |
117 | { | 128 | { |
118 | GNUNET_break_op (0); | 129 | GNUNET_break_op (0); |
119 | pal_ctx->cb (pal_ctx->cb_cls, NULL ); | 130 | pal_ctx->cb (pal_ctx->cb_cls, NULL ); |
@@ -122,8 +133,6 @@ peer_address_response_processor (void *cls, | |||
122 | return; | 133 | return; |
123 | } | 134 | } |
124 | 135 | ||
125 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "peer %s transport_name: %s\n",GNUNET_i2s(&air_msg->peer), transport_name); | ||
126 | |||
127 | address = GNUNET_HELLO_address_allocate(&air_msg->peer, transport_name, addr, alen); | 136 | address = GNUNET_HELLO_address_allocate(&air_msg->peer, transport_name, addr, alen); |
128 | 137 | ||
129 | /* expect more replies */ | 138 | /* expect more replies */ |
@@ -131,28 +140,36 @@ peer_address_response_processor (void *cls, | |||
131 | GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout)); | 140 | GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout)); |
132 | 141 | ||
133 | pal_ctx->cb (pal_ctx->cb_cls, address); | 142 | pal_ctx->cb (pal_ctx->cb_cls, address); |
143 | GNUNET_free (address); | ||
134 | } | 144 | } |
135 | 145 | ||
136 | 146 | ||
137 | /** | 147 | /** |
138 | * Return all the known addresses for a peer. | 148 | * Return all the known addresses for a specific peer or all peers. |
149 | * Returns continously all address if one_shot is set to GNUNET_NO | ||
150 | * | ||
151 | * CHANGE: Returns the address(es) that we are currently using for this | ||
152 | * peer. Upon completion, the 'AddressLookUpCallback' is called one more | ||
153 | * time with 'NULL' for the address and the peer. After this, the operation must no | ||
154 | * longer be explicitly cancelled. | ||
139 | * | 155 | * |
140 | * @param cfg configuration to use | 156 | * @param cfg configuration to use |
141 | * @param peer peer identity to look up the addresses of | 157 | * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers |
158 | * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL), | ||
159 | * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly cancelled) | ||
142 | * @param timeout how long is the lookup allowed to take at most | 160 | * @param timeout how long is the lookup allowed to take at most |
143 | * @param peer_address_callback function to call with the results | 161 | * @param peer_address_callback function to call with the results |
144 | * @param peer_address_callback_cls closure for peer_address_callback | 162 | * @param peer_address_callback_cls closure for peer_address_callback |
145 | * @return handle to cancel the operation, NULL on error | ||
146 | */ | 163 | */ |
147 | struct GNUNET_TRANSPORT_PeerAddressLookupContext * | 164 | struct GNUNET_TRANSPORT_PeerIterateContext * |
148 | GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, | 165 | GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, |
149 | const struct GNUNET_PeerIdentity *peer, | 166 | const struct GNUNET_PeerIdentity *peer, |
150 | int one_shot, | 167 | int one_shot, |
151 | struct GNUNET_TIME_Relative timeout, | 168 | struct GNUNET_TIME_Relative timeout, |
152 | GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, | 169 | GNUNET_TRANSPORT_PeerIterateCallback peer_address_callback, |
153 | void *peer_address_callback_cls) | 170 | void *peer_address_callback_cls) |
154 | { | 171 | { |
155 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *pal_ctx; | 172 | struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx; |
156 | struct AddressIterateMessage msg; | 173 | struct AddressIterateMessage msg; |
157 | struct GNUNET_CLIENT_Connection *client; | 174 | struct GNUNET_CLIENT_Connection *client; |
158 | struct GNUNET_TIME_Absolute abs_timeout; | 175 | struct GNUNET_TIME_Absolute abs_timeout; |
@@ -174,7 +191,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Ha | |||
174 | else | 191 | else |
175 | memcpy (&msg.peer, peer , sizeof (struct GNUNET_PeerIdentity)); | 192 | memcpy (&msg.peer, peer , sizeof (struct GNUNET_PeerIdentity)); |
176 | 193 | ||
177 | pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); | 194 | pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerIterateContext)); |
178 | pal_ctx->cb = peer_address_callback; | 195 | pal_ctx->cb = peer_address_callback; |
179 | pal_ctx->cb_cls = peer_address_callback_cls; | 196 | pal_ctx->cb_cls = peer_address_callback_cls; |
180 | pal_ctx->timeout = abs_timeout; | 197 | pal_ctx->timeout = abs_timeout; |
@@ -195,7 +212,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Ha | |||
195 | */ | 212 | */ |
196 | void | 213 | void |
197 | GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct | 214 | GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct |
198 | GNUNET_TRANSPORT_PeerAddressLookupContext | 215 | GNUNET_TRANSPORT_PeerIterateContext |
199 | *alc) | 216 | *alc) |
200 | { | 217 | { |
201 | GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO); | 218 | GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO); |
@@ -203,7 +220,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct | |||
203 | } | 220 | } |
204 | 221 | ||
205 | /** | 222 | /** |
206 | * Return all the known addresses for all peers. | 223 | * Return all addresses for all peers. |
207 | * | 224 | * |
208 | * @param cfg configuration to use | 225 | * @param cfg configuration to use |
209 | * @param timeout how long is the lookup allowed to take at most | 226 | * @param timeout how long is the lookup allowed to take at most |
@@ -213,7 +230,7 @@ GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct | |||
213 | void | 230 | void |
214 | GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | 231 | GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, |
215 | struct GNUNET_TIME_Relative timeout, | 232 | struct GNUNET_TIME_Relative timeout, |
216 | GNUNET_TRANSPORT_AddressLookUpCallback | 233 | GNUNET_TRANSPORT_PeerIterateCallback |
217 | peer_address_callback, | 234 | peer_address_callback, |
218 | void *peer_address_callback_cls) | 235 | void *peer_address_callback_cls) |
219 | { | 236 | { |