aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_ats.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport_ats.c')
-rw-r--r--src/transport/gnunet-service-transport_ats.c67
1 files changed, 64 insertions, 3 deletions
diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c
index f862f8c47..430c00ba6 100644
--- a/src/transport/gnunet-service-transport_ats.c
+++ b/src/transport/gnunet-service-transport_ats.c
@@ -140,6 +140,56 @@ find_ai (const struct GNUNET_HELLO_Address *address,
140 140
141 141
142/** 142/**
143 * Find matching address info, ignoring sessions.
144 *
145 * @param cls the `struct FindClosure`
146 * @param key which peer is this about
147 * @param value the `struct AddressInfo`
148 * @return #GNUNET_YES to continue to iterate, #GNUNET_NO if we found the value
149 */
150static int
151find_ai_no_session_cb (void *cls,
152 const struct GNUNET_PeerIdentity *key,
153 void *value)
154{
155 struct FindClosure *fc = cls;
156 struct AddressInfo *ai = value;
157
158 if (0 ==
159 GNUNET_HELLO_address_cmp (fc->address,
160 ai->address))
161 {
162 fc->ret = ai;
163 return GNUNET_NO;
164 }
165 return GNUNET_YES;
166}
167
168
169/**
170 * Find the address information struct for the
171 * given address (ignoring sessions)
172 *
173 * @param address address to look for
174 * @return NULL if this combination is unknown
175 */
176static struct AddressInfo *
177find_ai_no_session (const struct GNUNET_HELLO_Address *address)
178{
179 struct FindClosure fc;
180
181 fc.address = address;
182 fc.session = NULL;
183 fc.ret = NULL;
184 GNUNET_CONTAINER_multipeermap_get_multiple (p2a,
185 &address->peer,
186 &find_ai_no_session_cb,
187 &fc);
188 return fc.ret;
189}
190
191
192/**
143 * Test if ATS knows about this address. 193 * Test if ATS knows about this address.
144 * 194 *
145 * @param address the address 195 * @param address the address
@@ -187,11 +237,22 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
187 { 237 {
188 GNUNET_break (NULL != session); 238 GNUNET_break (NULL != session);
189 } 239 }
190 ai = find_ai (address, session); 240 ai = (NULL == session)
241 ? find_ai_no_session (address)
242 : find_ai (address, session);
191 if (NULL != ai) 243 if (NULL != ai)
192 {
193 GNUNET_break (0);
194 return; 244 return;
245 if (NULL != session)
246 {
247 /* in this case, we must not find an existing
248 session-less address, as the caller should
249 have checked for this case if it were possible. */
250 ai = find_ai (address, NULL);
251 if (NULL != ai)
252 {
253 GNUNET_assert (0);
254 return;
255 }
195 } 256 }
196 if (NULL == (papi = GST_plugins_find (address->transport_name))) 257 if (NULL == (papi = GST_plugins_find (address->transport_name)))
197 { 258 {