Mercurial > pidgin.yaz
diff libpurple/nat-pmp.h @ 15907:2cf21661f828
Cleanup and fixes for nat-pmp. We no longer do the whole 'try 10 times, doubling the delay in a blocking manner' ttempt from the original code; as I note in the comments above where the attempt is made a single time, this leads to about 8 minutes of nonresponsiveness if the router both doesn't support nat-pmp and doesn't send back a response to let the program know.
purple_pmp_create_map() and purple_pmp_destroy_map() now return a gboolean indicating success, as the internal data structures of nat-pmp are certainly not needed elsewhere.
The #includes are slightly reordered from the cleanup Mark did (thanks, Mark :) ), as with my OS X 10.3 cross-compiler, anyways, route.h needs to come after the sys includes to be properly handled.
author | Evan Schoenberg <evan.s@dreskin.net> |
---|---|
date | Sun, 25 Mar 2007 01:29:58 +0000 |
parents | 9cfe41743c65 |
children | 1a12ce76c4f4 |
line wrap: on
line diff
--- a/libpurple/nat-pmp.h Sun Mar 25 01:01:22 2007 +0000 +++ b/libpurple/nat-pmp.h Sun Mar 25 01:29:58 2007 +0000 @@ -32,8 +32,9 @@ #define _PURPLE_NAT_PMP_H #include <stdint.h> +#include <glib.h> -#define PURPLE_PMP_LIFETIME 3600 /* seconds */ +#define PURPLE_PMP_LIFETIME 3600 /* 3600 seconds */ /* * uint8_t: version, opcodes @@ -46,41 +47,10 @@ PURPLE_PMP_TYPE_TCP } PurplePmpType; -typedef struct { - uint8_t version; - uint8_t opcode; -} PurplePmpIpRequest; - -typedef struct { - uint8_t version; - uint8_t opcode; // 128 + n - uint16_t resultcode; - uint32_t epoch; - uint32_t address; -} PurplePmpIpResponse; - -typedef struct { - uint8_t version; - uint8_t opcode; - char reserved[2]; - uint16_t privateport; - uint16_t publicport; - uint32_t lifetime; -} PurplePmpMapRequest; - -typedef struct { - uint8_t version; - uint8_t opcode; - uint16_t resultcode; - uint32_t epoch; - uint16_t privateport; - uint16_t publicport; - uint32_t lifetime; -} PurplePmpMapResponse; - /** * */ + /* * TODO: This should probably cache the result of this lookup requests * so that subsequent calls to this function do not require a @@ -89,13 +59,25 @@ char *purple_pmp_get_public_ip(); /** + * Remove the NAT-PMP mapping for a specified type on a specified port * + * @param type The PurplePmpType + * @param privateport The private port on which we are listening locally + * @param publicport The public port on which we are expecting a response + * @param lifetime The lifetime of the mapping. It is recommended that this be PURPLE_PMP_LIFETIME. + * + * @returns TRUE if succesful; FALSE if unsuccessful */ -PurplePmpMapResponse *purple_pmp_create_map(PurplePmpType type, uint16_t privateport, uint16_t publicport, uint32_t lifetime); +gboolean purple_pmp_create_map(PurplePmpType type, unsigned short privateport, unsigned short publicport, int lifetime); /** + * Remove the NAT-PMP mapping for a specified type on a specified port * + * @param type The PurplePmpType + * @param privateport The private port on which the mapping was previously made + * + * @returns TRUE if succesful; FALSE if unsuccessful */ -PurplePmpMapResponse *purple_pmp_destroy_map(PurplePmpType type, uint16_t privateport); - -#endif /* _PURPLE_NAT_PMP_H_ */ +gboolean purple_pmp_destroy_map(PurplePmpType type, unsigned short privateport); + +#endif \ No newline at end of file