2
0

dht.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright (c) 2009-2011 by Juliusz Chroboczek
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. typedef void
  23. dht_callback_t(void *closure, int event,
  24. const unsigned char *info_hash,
  25. const void *data, size_t data_len);
  26. #define DHT_EVENT_NONE 0
  27. #define DHT_EVENT_VALUES 1
  28. #define DHT_EVENT_VALUES6 2
  29. #define DHT_EVENT_SEARCH_DONE 3
  30. #define DHT_EVENT_SEARCH_DONE6 4
  31. extern FILE *dht_debug;
  32. int dht_init(int s, int s6, const unsigned char *id, const unsigned char *v);
  33. int dht_insert_node(const unsigned char *id, struct sockaddr *sa, int salen);
  34. int dht_ping_node(const struct sockaddr *sa, int salen);
  35. int dht_periodic(const void *buf, size_t buflen,
  36. const struct sockaddr *from, int fromlen, time_t *tosleep,
  37. dht_callback_t *callback, void *closure);
  38. int dht_search(const unsigned char *id, int port, int af,
  39. dht_callback_t *callback, void *closure);
  40. int dht_nodes(int af,
  41. int *good_return, int *dubious_return, int *cached_return,
  42. int *incoming_return);
  43. void dht_dump_tables(FILE *f);
  44. int dht_get_nodes(struct sockaddr_in *sin, int *num,
  45. struct sockaddr_in6 *sin6, int *num6);
  46. int dht_uninit(void);
  47. /* This must be provided by the user. */
  48. int dht_sendto(int sockfd, const void *buf, int len, int flags,
  49. const struct sockaddr *to, int tolen);
  50. int dht_blacklisted(const struct sockaddr *sa, int salen);
  51. void dht_hash(void *hash_return, int hash_size,
  52. const void *v1, int len1,
  53. const void *v2, int len2,
  54. const void *v3, int len3);
  55. int dht_random_bytes(void *buf, size_t size);
  56. #ifdef __cplusplus
  57. }
  58. #endif