2bafc369491562620455012ebbd3ac77a0b688a2
[oweals/gnunet.git] / src / dht / dht.h
1 /*
2      This file is part of GNUnet.
3      (C) 2001, 2002, 2003, 2004, 2009 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 2, 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  * @author Christian Grothoff
23  * @author Nathan Evans
24  * @file dht/dht.h
25  */
26
27 #ifndef DHT_H_
28 #define DHT_H_
29
30 #define DEBUG_DHT GNUNET_NO
31
32 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
33                                                    const struct GNUNET_MessageHeader
34                                                    * msg);
35
36 /**
37  * FIXME.
38  */
39 struct GNUNET_DHT_StopMessage
40 {
41   /**
42    * Type: GNUNET_MESSAGE_TYPE_DHT_MESSAGE
43    */
44   struct GNUNET_MessageHeader header;
45
46   /**
47    * Always zero.
48    */
49   uint32_t reserved GNUNET_PACKED;
50
51   /**
52    * Unique ID identifying this request
53    */
54   uint64_t unique_id GNUNET_PACKED;
55
56 };
57
58
59 /**
60  * Generic DHT message, wrapper for other message types
61  */
62 struct GNUNET_DHT_RouteMessage
63 {
64   /**
65    * Type: GNUNET_MESSAGE_TYPE_DHT_ROUTE
66    */
67   struct GNUNET_MessageHeader header;
68
69   /**
70    * Message options
71    */
72   uint32_t options GNUNET_PACKED;
73
74   /**
75    * The key to search for
76    */
77   GNUNET_HashCode key;
78
79   /**
80    * Unique ID identifying this request
81    */
82   uint64_t unique_id GNUNET_PACKED;
83
84   /**
85    * Replication level for this message
86    */
87   uint32_t desired_replication_level GNUNET_PACKED;
88
89   /**
90    * Is this message uniquely identified?  If so it will
91    * be fire and forget, if not we will wait for a receipt
92    * from the service.
93    */
94   uint32_t unique GNUNET_PACKED;
95
96   /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
97
98 };
99
100 struct GNUNET_DHT_RouteResultMessage
101 {
102   /**
103    * Type: GNUNET_MESSAGE_TYPE_DHT_ROUTE_RESULT
104    */
105   struct GNUNET_MessageHeader header;
106
107   /**
108    * Message options
109    */
110   uint32_t options GNUNET_PACKED;
111
112   /**
113    * The key that was searched for
114    */
115   GNUNET_HashCode key;
116
117   /**
118    * Unique ID identifying this request
119    */
120   uint64_t unique_id GNUNET_PACKED;
121
122   /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
123 };
124
125 /**
126  * Message to insert data into the DHT
127  */
128 struct GNUNET_DHT_PutMessage
129 {
130   /**
131    * Type: GNUNET_MESSAGE_TYPE_DHT_PUT
132    */
133   struct GNUNET_MessageHeader header;
134
135   /**
136    * The type of data to insert.
137    */
138   size_t type GNUNET_PACKED;
139
140   /**
141    * How long should this data persist?
142    */
143   struct GNUNET_TIME_AbsoluteNBO expiration;
144
145   /**
146    * The size of the data, appended to the end of this message.
147    */
148   size_t data_size GNUNET_PACKED;
149
150 };
151
152
153 /**
154  * Message to request data from the DHT
155  */
156 struct GNUNET_DHT_GetMessage
157 {
158   /**
159    * Type: GNUNET_MESSAGE_TYPE_DHT_GET
160    */
161   struct GNUNET_MessageHeader header;
162
163   /**
164    * The type for the data for the GET request
165    */
166   uint32_t type;
167
168 };
169
170 /**
171  * Message to return data from the DHT
172  */
173 struct GNUNET_DHT_GetResultMessage
174 {
175   /**
176    * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT
177    */
178   struct GNUNET_MessageHeader header;
179
180   /**
181    * The type for the data for the GET request
182    */
183   uint32_t type;
184
185   /**
186    * The key to search for
187    */
188   GNUNET_HashCode key;
189
190   /**
191    * When does this entry expire?
192    */
193   struct GNUNET_TIME_Absolute expiration;
194
195 };
196
197
198 #endif /* DHT_H_ */