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