using proxy settings
[oweals/gnunet.git] / src / dht / gnunet-service-xdht_neighbours.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file dht/gnunet-service-xdht_neighbours.h
23  * @brief GNUnet DHT routing code
24  * @author Christian Grothoff
25  * @author Nathan Evans
26  */
27 #ifndef GNUNET_SERVICE_XDHT_NEIGHBOURS_H
28 #define GNUNET_SERVICE_XDHT_NEIGHBOURS_H
29
30 #include "gnunet_util_lib.h"
31 #include "gnunet_block_lib.h"
32 #include "gnunet_dht_service.h"
33
34 /**
35  * FIXME: Change the comment to explain about usage of this in find successor.
36  * Field in trail setup message to understand if the message is sent to an
37  * intermediate finger, friend or me. 
38  */
39 enum current_destination_type /* FIXME: enum GSX_CurrentDestinationType */
40 {
41   /**
42    * Look in friend AND finger tables for a trail to the key.
43    */
44   /* FIXME: GSX_CDT_ */ FRIEND,
45   
46   /**
47    * Look in the routing table to follow a trail to reach to the
48    * destination.  It is also allowed (but currently not implemented)
49    * to look into friend/finger tables for a better trail to the key
50    * and (if one is found) 'abort' the current trail and switch to
51    * the better one.
52    */
53   FINGER,
54
55   /**
56    * "Returned" if the origin is the closest peer to the destination;
57    * Must not be passed to "GDS_NEIGHBOURS_handle_put".
58    */
59   MY_ID,
60
61   /**
62    * FIXME.
63    */
64   VALUE
65 };
66
67 /**
68  * Perform a PUT operation.  Forwards the given request to other
69  * peers.   Does not store the data locally.  Does not give the
70  * data to local clients.  May do nothing if this is the only
71  * 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 expiration_time when does the content expire
78  * @param hop_count how many hops has this message traversed so far
79  * @param key key for the content
80  * @param put_path_length number of entries in @a put_path
81  * @param put_path peers this request has traversed so far (if tracked)
82  * @param data payload to store
83  * @param data_size number of bytes in @a data
84  */
85 void
86 GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
87                            enum GNUNET_DHT_RouteOption options,
88                            uint32_t desired_replication_level,
89                            struct GNUNET_TIME_Absolute expiration_time,
90                            uint32_t hop_count,
91                            const struct GNUNET_HashCode * key,
92                            unsigned int put_path_length,
93                            struct GNUNET_PeerIdentity *put_path,
94                            const void *data, size_t data_size,
95                            struct GNUNET_PeerIdentity *current_destination,
96                            struct GNUNET_PeerIdentity *current_source,
97                            enum current_destination_type dest_type,
98                            struct GNUNET_PeerIdentity *target_peer_id);
99
100
101 /**
102  * 
103  * @param source_peer
104  * @param get_path
105  * @param get_path_length
106  * @param key
107  */
108 void
109 GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type block_type,
110                            enum GNUNET_DHT_RouteOption options,
111                            uint32_t desired_replication_level,
112                            uint32_t hop_count,
113                            struct GNUNET_PeerIdentity *get_peer_path,
114                            unsigned int get_path_length,
115                            struct GNUNET_HashCode *key,
116                            struct GNUNET_PeerIdentity *target_peer,
117                            struct GNUNET_PeerIdentity *current_destination,
118                            struct GNUNET_PeerIdentity *current_source,
119                            enum current_destination_type current_dest_type);
120
121
122 /**
123  * FIXME: I am removing source peer as the first element in the trail
124  * is source identity.
125  * Send get result back to requesting client. 
126  * @param expiration when will the reply expire
127  * @param key the query this reply is for
128  * @param get_path_length number of peers in @a get_path
129  * @param get_path path the reply took on get
130  * @param put_path_length number of peers in @a put_path
131  * @param put_path path the reply took on put
132  * @param type type of the reply
133  * @param data_size number of bytes in @a data
134  * @param data application payload data
135  * @param get_path
136  * @param get_path_length
137  */
138 void 
139 GDS_NEIGHBOURS_send_get_result (struct GNUNET_TIME_Absolute expiration,
140                                 const struct GNUNET_HashCode *key,
141                                 unsigned int put_path_length,
142                                 const struct GNUNET_PeerIdentity *put_path,
143                                 enum GNUNET_BLOCK_Type type, size_t data_size,
144                                 const void *data,
145                                 struct GNUNET_PeerIdentity *get_path,
146                                 unsigned int get_path_length,
147                                 unsigned int current_trail_index,
148                                 struct GNUNET_PeerIdentity *next_hop,
149                                 struct GNUNET_PeerIdentity *source_peer);
150
151 /**
152  * FIXME: Here you should update the fields of struct PeerGetResultMessage.
153  * At the end of this message you should add the data and get path and send 
154  * to the original requesting client. and there you should call GDS_CLIENT_handle_reply
155  * with correct parameter. 
156  * @param expiration
157  * @param key
158  * @param get_path_length
159  * @param get_path
160  * @param put_path_length
161  * @param put_path
162  * @param type
163  * @param data_size
164  * @param data
165  */
166 void 
167 GDS_NEIGHBOURS_datacache_get (struct GNUNET_TIME_Absolute expiration,
168                               const struct GNUNET_HashCode *key,
169                               unsigned int get_path_length,
170                               const struct GNUNET_PeerIdentity *get_path,
171                               unsigned int put_path_length,
172                               const struct GNUNET_PeerIdentity *put_path,
173                               enum GNUNET_BLOCK_Type type, size_t data_size,
174                               const void *data);
175
176
177 /**
178  * Initialize neighbours subsystem.
179  *
180  * @return GNUNET_OK on success, GNUNET_SYSERR on error
181  */
182 int
183 GDS_NEIGHBOURS_init (void);
184
185
186 /**
187  * Shutdown neighbours subsystem.
188  */
189 void
190 GDS_NEIGHBOURS_done (void);
191
192
193 /**
194  * Get the ID of the local node.
195  *
196  * @return identity of the local node
197  */
198 struct GNUNET_PeerIdentity *
199 GDS_NEIGHBOURS_get_id ();
200
201
202 #endif