glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / dht / gnunet-service-dht_neighbours.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009, 2010, 2011 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14 */
15
16 /**
17  * @file dht/gnunet-service-dht_neighbours.h
18  * @brief GNUnet DHT routing code
19  * @author Christian Grothoff
20  * @author Nathan Evans
21  */
22 #ifndef GNUNET_SERVICE_DHT_NEIGHBOURS_H
23 #define GNUNET_SERVICE_DHT_NEIGHBOURS_H
24
25 #include "gnunet_util_lib.h"
26 #include "gnunet_block_lib.h"
27 #include "gnunet_dht_service.h"
28
29 /**
30  * Hash of the identity of this peer.
31  */
32 extern struct GNUNET_HashCode my_identity_hash;
33
34
35 /**
36  * Perform a PUT operation.  Forwards the given request to other
37  * peers.   Does not store the data locally.  Does not give the
38  * data to local clients.  May do nothing if this is the only
39  * peer in the network (or if we are the closest peer in the
40  * network).
41  *
42  * @param type type of the block
43  * @param options routing options
44  * @param desired_replication_level desired replication level
45  * @param expiration_time when does the content expire
46  * @param hop_count how many hops has this message traversed so far
47  * @param bf Bloom filter of peers this PUT has already traversed
48  * @param key key for the content
49  * @param put_path_length number of entries in put_path
50  * @param put_path peers this request has traversed so far (if tracked)
51  * @param data payload to store
52  * @param data_size number of bytes in data
53  * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
54  */
55 int
56 GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
57                            enum GNUNET_DHT_RouteOption options,
58                            uint32_t desired_replication_level,
59                            struct GNUNET_TIME_Absolute expiration_time,
60                            uint32_t hop_count,
61                            struct GNUNET_CONTAINER_BloomFilter *bf,
62                            const struct GNUNET_HashCode *key,
63                            unsigned int put_path_length,
64                            struct GNUNET_PeerIdentity *put_path,
65                            const void *data, size_t data_size);
66
67
68 /**
69  * Perform a GET operation.  Forwards the given request to other
70  * peers.  Does not lookup the key locally.  May do nothing if this is
71  * the only peer in the network (or if we are the closest peer in the
72  * network).
73  *
74  * @param type type of the block
75  * @param options routing options
76  * @param desired_replication_level desired replication count
77  * @param hop_count how many hops did this request traverse so far?
78  * @param key key for the content
79  * @param xquery extended query
80  * @param xquery_size number of bytes in @a xquery
81  * @param bg block group to filter replies
82  * @param peer_bf filter for peers not to select (again, updated)
83  * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
84  */
85 int
86 GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
87                            enum GNUNET_DHT_RouteOption options,
88                            uint32_t desired_replication_level,
89                            uint32_t hop_count,
90                            const struct GNUNET_HashCode *key,
91                            const void *xquery,
92                            size_t xquery_size,
93                            struct GNUNET_BLOCK_Group *bg,
94                            struct GNUNET_CONTAINER_BloomFilter *peer_bf);
95
96
97 /**
98  * Handle a reply (route to origin).  Only forwards the reply back to
99  * other peers waiting for it.  Does not do local caching or
100  * forwarding to local clients.
101  *
102  * @param target neighbour that should receive the block (if still connected)
103  * @param type type of the block
104  * @param expiration_time when does the content expire
105  * @param key key for the content
106  * @param put_path_length number of entries in put_path
107  * @param put_path peers the original PUT traversed (if tracked)
108  * @param get_path_length number of entries in put_path
109  * @param get_path peers this reply has traversed so far (if tracked)
110  * @param data payload of the reply
111  * @param data_size number of bytes in data
112  */
113 void
114 GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
115                              enum GNUNET_BLOCK_Type type,
116                              struct GNUNET_TIME_Absolute expiration_time,
117                              const struct GNUNET_HashCode *key,
118                              unsigned int put_path_length,
119                              const struct GNUNET_PeerIdentity *put_path,
120                              unsigned int get_path_length,
121                              const struct GNUNET_PeerIdentity *get_path,
122                              const void *data,
123                              size_t data_size);
124
125
126 /**
127  * Check whether my identity is closer than any known peers.  If a
128  * non-null bloomfilter is given, check if this is the closest peer
129  * that hasn't already been routed to.
130  *
131  * @param key hash code to check closeness to
132  * @param bloom bloomfilter, exclude these entries from the decision
133  * @return #GNUNET_YES if node location is closest,
134  *         #GNUNET_NO otherwise.
135  */
136 int
137 GDS_am_closest_peer (const struct GNUNET_HashCode *key,
138                      const struct GNUNET_CONTAINER_BloomFilter *bloom);
139
140
141
142 /**
143  * Initialize neighbours subsystem.
144  *
145  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
146  */
147 int
148 GDS_NEIGHBOURS_init (void);
149
150
151 /**
152  * Shutdown neighbours subsystem.
153  */
154 void
155 GDS_NEIGHBOURS_done (void);
156
157
158 /**
159  * Get the ID of the local node.
160  *
161  * @return identity of the local node
162  */
163 struct GNUNET_PeerIdentity *
164 GDS_NEIGHBOURS_get_id (void);
165
166
167 #endif