Mercurial > pidgin
comparison src/stun.c @ 12909:8e3b85fe4a55
[gaim-migrate @ 15262]
Make UPnP truly asynchronous.
There are probably still a couple socket calls that should be made nonblocking, but I wanted to commit this before it became even bigger. This contains a number of probable leak fixes in the upnp stuff.
The UPnP stuff has been updated to use gaim_url_fetch_request() instead of the specific implementation.
To make this all work, I had to make gaim_network_listen() and gaim_network_listen_range() also asynchronous - seems to work just fine apart from the UPnP calls seeming to take longer than they should (I'm planning to look into this).
I also triggered a STUN and UPnP discovery on startup so that we hopefully have the information when we need it.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Tue, 17 Jan 2006 05:48:51 +0000 |
parents | a7bf698eb37c |
children | c3167a1dd817 |
comparison
equal
deleted
inserted
replaced
12908:4f2b96f23700 | 12909:8e3b85fe4a55 |
---|---|
271 do_callbacks(); | 271 do_callbacks(); |
272 #endif | 272 #endif |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 static void hbn_cb(GSList *hosts, gpointer data, const char *error_message) { | 276 |
277 static void hbn_listen_cb(int fd, gpointer data) { | |
278 GSList *hosts = data; | |
277 struct stun_conn *sc; | 279 struct stun_conn *sc; |
278 static struct stun_header hdr_data; | 280 static struct stun_header hdr_data; |
279 int ret, fd; | 281 int ret; |
280 | 282 |
281 if(!hosts || !hosts->data) { | 283 if(fd < 0) { |
282 nattype.status = GAIM_STUN_STATUS_UNDISCOVERED; | |
283 nattype.lookup_time = time(NULL); | |
284 do_callbacks(); | |
285 return; | |
286 } | |
287 | |
288 | |
289 fd = gaim_network_listen_range(12108, 12208, SOCK_DGRAM); | |
290 | |
291 if(!fd) { | |
292 nattype.status = GAIM_STUN_STATUS_UNKNOWN; | 284 nattype.status = GAIM_STUN_STATUS_UNKNOWN; |
293 nattype.lookup_time = time(NULL); | 285 nattype.lookup_time = time(NULL); |
294 do_callbacks(); | 286 do_callbacks(); |
295 return; | 287 return; |
296 } | 288 } |
335 sc->packet = &hdr_data; | 327 sc->packet = &hdr_data; |
336 sc->packetsize = sizeof(struct stun_header); | 328 sc->packetsize = sizeof(struct stun_header); |
337 sc->timeout = gaim_timeout_add(500, (GSourceFunc) timeoutfunc, sc); | 329 sc->timeout = gaim_timeout_add(500, (GSourceFunc) timeoutfunc, sc); |
338 } | 330 } |
339 | 331 |
332 static void hbn_cb(GSList *hosts, gpointer data, const char *error_message) { | |
333 | |
334 if(!hosts || !hosts->data) { | |
335 nattype.status = GAIM_STUN_STATUS_UNDISCOVERED; | |
336 nattype.lookup_time = time(NULL); | |
337 do_callbacks(); | |
338 return; | |
339 } | |
340 | |
341 if (!gaim_network_listen_range(12108, 12208, SOCK_DGRAM, hbn_listen_cb, hosts)) { | |
342 nattype.status = GAIM_STUN_STATUS_UNKNOWN; | |
343 nattype.lookup_time = time(NULL); | |
344 do_callbacks(); | |
345 return; | |
346 } | |
347 | |
348 | |
349 } | |
350 | |
340 static void do_test1(GaimSrvResponse *resp, int results, gpointer sdata) { | 351 static void do_test1(GaimSrvResponse *resp, int results, gpointer sdata) { |
341 const char *servername = sdata; | 352 const char *servername = sdata; |
342 int port = 3478; | 353 int port = 3478; |
343 | 354 |
344 if(results) { | 355 if(results) { |
415 return &nattype; | 426 return &nattype; |
416 } | 427 } |
417 | 428 |
418 void gaim_stun_init() { | 429 void gaim_stun_init() { |
419 gaim_prefs_add_string("/core/network/stun_server", ""); | 430 gaim_prefs_add_string("/core/network/stun_server", ""); |
420 } | 431 gaim_stun_discover(NULL); |
432 } |