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