Merge branch 'master' of ssh://gnunet.org/gnunet
[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
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @file dht/gnunet-service-dht_neighbours.h
23  * @brief GNUnet DHT routing code
24  * @author Christian Grothoff
25  * @author Nathan Evans
26  */
27 #ifndef GNUNET_SERVICE_DHT_NEIGHBOURS_H
28 #define GNUNET_SERVICE_DHT_NEIGHBOURS_H
29
30 #include "gnunet_util_lib.h"
31 #include "gnunet_block_lib.h"
32 #include "gnunet_dht_service.h"
33
34 /**
35  * Perform a PUT operation.  Forwards the given request to other
36  * peers.   Does not store the data locally.  Does not give the
37  * data to local clients.  May do nothing if this is the only
38  * peer in the network (or if we are the closest peer in the
39  * network).
40  *
41  * @param type type of the block
42  * @param options routing options
43  * @param desired_replication_level desired replication level
44  * @param expiration_time when does the content expire
45  * @param hop_count how many hops has this message traversed so far
46  * @param bf Bloom filter of peers this PUT has already traversed
47  * @param key key for the content
48  * @param put_path_length number of entries in put_path
49  * @param put_path peers this request has traversed so far (if tracked)
50  * @param data payload to store
51  * @param data_size number of bytes in data
52  * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
53  */
54 int
55 GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
56                            enum GNUNET_DHT_RouteOption options,
57                            uint32_t desired_replication_level,
58                            struct GNUNET_TIME_Absolute expiration_time,
59                            uint32_t hop_count,
60                            struct GNUNET_CONTAINER_BloomFilter *bf,
61                            const struct GNUNET_HashCode *key,
62                            unsigned int put_path_length,
63                            struct GNUNET_PeerIdentity *put_path,
64                            const void *data, size_t data_size);
65
66
67 /**
68  * Perform a GET operation.  Forwards the given request to other
69  * peers.  Does not lookup the key locally.  May do nothing if this is
70  * the only peer in the network (or if we are the closest peer in the
71  * network).
72  *
73  * @param type type of the block
74  * @param options routing options
75  * @param desired_replication_level desired replication count
76  * @param hop_count how many hops did this request traverse so far?
77  * @param key key for the content
78  * @param xquery extended query
79  * @param xquery_size number of bytes in @a xquery
80  * @param bg block group to filter replies
81  * @param peer_bf filter for peers not to select (again, updated)
82  * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
83  */
84 int
85 GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
86                            enum GNUNET_DHT_RouteOption options,
87                            uint32_t desired_replication_level,
88                            uint32_t hop_count,
89                            const struct GNUNET_HashCode *key,
90                            const void *xquery,
91                            size_t xquery_size,
92                            struct GNUNET_BLOCK_Group *bg,
93                            struct GNUNET_CONTAINER_BloomFilter *peer_bf);
94
95
96 /**
97  * Handle a reply (route to origin).  Only forwards the reply back to
98  * other peers waiting for it.  Does not do local caching or
99  * forwarding to local clients.
100  *
101  * @param target neighbour that should receive the block (if still connected)
102  * @param type type of the block
103  * @param expiration_time when does the content expire
104  * @param key key for the content
105  * @param put_path_length number of entries in put_path
106  * @param put_path peers the original PUT traversed (if tracked)
107  * @param get_path_length number of entries in put_path
108  * @param get_path peers this reply has traversed so far (if tracked)
109  * @param data payload of the reply
110  * @param data_size number of bytes in data
111  */
112 void
113 GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
114                              enum GNUNET_BLOCK_Type type,
115                              struct GNUNET_TIME_Absolute expiration_time,
116                              const struct GNUNET_HashCode *key,
117                              unsigned int put_path_length,
118                              const struct GNUNET_PeerIdentity *put_path,
119                              unsigned int get_path_length,
120                              const struct GNUNET_PeerIdentity *get_path,
121                              const void *data,
122                              size_t data_size);
123
124
125 /**
126  * Initialize neighbours subsystem.
127  *
128  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
129  */
130 int
131 GDS_NEIGHBOURS_init (void);
132
133
134 /**
135  * Shutdown neighbours subsystem.
136  */
137 void
138 GDS_NEIGHBOURS_done (void);
139
140
141 /**
142  * Get the ID of the local node.
143  *
144  * @return identity of the local node
145  */
146 struct GNUNET_PeerIdentity *
147 GDS_NEIGHBOURS_get_id (void);
148
149
150 #endif