import buffering code
[libdht.git] / dht.h
blob11687850342873eda963eab4b3899124ab50bff7
1 /*
2 * Copyright (c) 2016 Mohamed Aslan <maslan@sce.carleton.ca>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef DHT_H
18 #define DHT_H
20 #include <sys/socket.h>
22 #define DHT_USEUDP (1 << 0)
25 struct dht_node {
26 char *id;
27 uint64_t token;
28 int port;
29 int socket;
30 int ev_queue;
31 int n_replicas;
32 int n_peers;
33 int def_r;
34 int def_w;
35 uint8_t ready;
36 uint32_t flags;
37 struct sockaddr_storage saddr;
38 struct dht_options *opts;
39 struct dht_peer *peers;
40 void *ht;
43 struct dht_peer {
44 char *id;
45 uint64_t token;
46 int socket;
47 uint64_t ready;
48 time_t last_recv;
49 struct sockaddr_storage s_addr;
52 struct dht_options {
53 uint64_t (*partitioner)(const char *);
54 int (*ht_init)(void **);
55 int (*ht_put)(void *, const char *, const char *);
56 int (*ht_get)(void *, const char *, char **);
57 int (*ht_del)(void *, const char *);
60 int dht_init(struct dht_node *, const char *, int, int, uint32_t, struct dht_options *);
61 void dht_add_peer(struct dht_node *, const char *, const char *, int);
62 void dht_event_loop(struct dht_node *);
63 int dht_put_tunable(struct dht_node *, const char *, const char *, int);
64 int dht_get_tunable(int, const char *, char **, int);
65 int dht_put(int, const char *);
66 int dht_get(int, const char *, char **);
68 #endif