82b0df9a2a765ac8aef005883f72e0846cf5584f
[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_YES
31
32 typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
33                                                   struct GNUNET_MessageHeader *msg);
34
35 /**
36  * Generic DHT message, wrapper for other message types
37  */
38 struct GNUNET_DHT_Message
39 {
40   /**
41    * Type: GNUNET_MESSAGE_TYPE_DHT_MESSAGE
42    */
43   struct GNUNET_MessageHeader header;
44
45   /**
46    * The key to search for
47    */
48   GNUNET_HashCode key;
49
50   /**
51    * Replication level for this message
52    */
53   uint16_t desired_replication_level;
54
55   /**
56    * Message options
57    */
58   uint16_t options;
59
60   /**
61    * Is this message uniquely identified?  If so it has
62    * a unique_id appended to it.
63    */
64   /* uint16_t unique; I don't think we need this, it should be held in the encapsulated message */
65
66   /* uint64_t unique_id*/
67   /* */
68   /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */
69
70 };
71
72 /**
73  * Message to insert data into the DHT
74  */
75 struct GNUNET_DHT_PutMessage
76 {
77   /**
78    * Type: GNUNET_MESSAGE_TYPE_DHT_PUT
79    */
80   struct GNUNET_MessageHeader header;
81
82   /**
83    * The type of data to insert.
84    */
85   size_t type;
86
87   /**
88    * The size of the data, appended to the end of this message.
89    */
90   size_t data_size;
91
92   /**
93    * How long should this data persist?
94    */
95   struct GNUNET_TIME_Absolute expiration;
96
97 };
98
99
100 /**
101  * Message to request data from the DHT
102  */
103 struct GNUNET_DHT_GetMessage
104 {
105   /**
106    * Type: GNUNET_MESSAGE_TYPE_DHT_GET
107    */
108   struct GNUNET_MessageHeader header;
109
110   /**
111    * The type for the data for the GET request
112    */
113   size_t type;
114
115   /**
116    * The key to search for
117    */
118   GNUNET_HashCode key;
119
120 };
121
122 /**
123  * Message to return data from the DHT
124  */
125 struct GNUNET_DHT_GetResultMessage
126 {
127   /**
128    * Type: GNUNET_MESSAGE_TYPE_DHT_GET_RESULT
129    */
130   struct GNUNET_MessageHeader header;
131
132   /**
133    * The type for the data for the GET request
134    */
135   size_t type;
136
137   /**
138    * The key to search for
139    */
140   GNUNET_HashCode key;
141
142   /**
143    * The size of the data, appended to the end of this message.
144    */
145   size_t data_size;
146
147 };
148
149 /**
150  * Message to request data from the DHT
151  */
152 struct GNUNET_DHT_FindPeerMessage
153 {
154   /**
155    * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER
156    */
157   struct GNUNET_MessageHeader header;
158
159   /**
160    * The key being looked up
161    */
162   GNUNET_HashCode key;
163
164 };
165
166 /**
167  * Message to return data from the DHT
168  */
169 struct GNUNET_DHT_FindPeerResultMessage
170 {
171   /**
172    * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT
173    */
174   struct GNUNET_MessageHeader header;
175
176   /**
177    * The peer that was searched for
178    */
179   struct GNUNET_PeerIdentity peer;
180
181   /**
182    * The size of the HELLO for the returned peer,
183    * appended to the end of this message, 0 if
184    * no hello.
185    */
186   size_t data_size;
187
188 };
189
190 #endif /* DHT_H_ */