implement missing function in buffer.c
[libdht.git] / dht.h
blob10dc286a03c8eb1a5471caf98648a1c7651da194
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 <time.h>
21 #include <sys/socket.h>
23 #define DHT_USEUDP (1 << 0)
26 struct dht_node {
27 char *id;
28 uint64_t token;
29 int port;
30 int socket;
31 int ev_queue;
32 int n_replicas;
33 int n_peers;
34 int def_r;
35 int def_w;
36 uint8_t ready;
37 uint32_t flags;
38 struct sockaddr_storage saddr;
39 struct dht_options *opts;
40 struct dht_peer *peers;
41 void *ht;
44 struct dht_peer {
45 char *id;
46 uint64_t token;
47 int socket;
48 uint64_t ready;
49 time_t last_recv;
50 struct sockaddr_storage s_addr;
53 struct dht_options {
54 uint64_t (*partitioner)(const char *);
55 int (*ht_init)(void **);
56 int (*ht_put)(void *, const char *, const char *, struct timespec *);
57 int (*ht_get)(void *, const char *, char **, struct timespec **);
58 int (*ht_del)(void *, const char *);
61 int dht_init(struct dht_node *, const char *, int, int, uint32_t, struct dht_options *);
62 void dht_add_peer(struct dht_node *, const char *, const char *, int);
63 void dht_event_loop(struct dht_node *);
64 int dht_put_tunable(struct dht_node *, const char *, const char *, struct timespec *, int);
65 int dht_get_tunable(struct dht_node *, const char *, char **, int);
66 int dht_put(struct dht_node *, const char *, const char *, struct timespec *);
67 int dht_get(struct dht_node *, const char *, char **);
69 #endif