dfb880b4af44c3cfa77962003d459ce27d7ad0df
[oweals/gnunet.git] / src / include / gnunet_dht_service.h
1 /*
2       This file is part of GNUnet
3       (C) 2004, 2005, 2006, 2008, 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  * @file include/gnunet_dht_service.h
23  * @brief API to the DHT service
24  * @author Christian Grothoff
25  */
26
27 #ifndef GNUNET_DHT_SERVICE_H
28 #define GNUNET_DHT_SERVICE_H
29
30 #include "gnunet_util_lib.h"
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40
41 /**
42  * Connection to the DHT service.
43  */
44 struct GNUNET_DHT_Handle;
45
46
47 /**
48  * Initialize the connection with the DHT service.
49  * 
50  * @param cfg configuration to use
51  * @param sched scheduler to use
52  * @return NULL on error
53  */
54 struct GNUNET_DHT_Handle *
55 GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched,
56                     const struct GNUNET_CONFIGURATION_Handle *cfg);
57
58
59 /**
60  * Shutdown connection with the DHT service.
61  *
62  * @param h connection to shut down
63  */
64 void
65 GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *h);
66
67
68 /**
69  * Handle to control a GET operation.
70  */
71 struct GNUNET_DHT_GetHandle;
72
73
74 /**
75  * Iterator called on each result obtained for a GET
76  * operation.
77  *
78  * @param cls closure
79  * @param exp when will this value expire
80  * @param key key of the result
81  * @param type type of the result
82  * @param size number of bytes in data
83  * @param data pointer to the result data
84  */
85 typedef void (*GNUNET_DHT_Iterator)(void *cls,
86                                     struct GNUNET_TIME_Absolute exp,
87                                     const GNUNET_HashCode * key,
88                                     uint32_t type,
89                                     uint32_t size,
90                                     const void *data);
91                       
92
93
94 /**
95  * Perform an asynchronous GET operation on the DHT identified.
96  *
97  * @param h handle to the DHT service
98  * @param type expected type of the response object
99  * @param key the key to look up
100  * @param iter function to call on each result
101  * @param iter_cls closure for iter
102  * @return handle to stop the async get
103  */
104 struct GNUNET_DHT_GetHandle *
105 GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *h,
106                       uint32_t type,
107                       const GNUNET_HashCode * key,
108                       GNUNET_DHT_Iterator iter,
109                       void *iter_cls);
110
111
112 /**
113  * Iterator called on each result obtained from a FIND_PEER
114  * operation
115  *
116  * @param cls closure
117  * @param key the key that was searched
118  * @param data the HELLO of the peer that was returned
119  */
120 typedef void (*GNUNET_DHT_PeerIterator)(void *cls,
121                                     const GNUNET_HashCode * key,
122                                     const void *data);
123
124 /**
125  * Perform an asynchronous FIND_PEER operation on the DHT.
126  *
127  * @param h handle to the DHT service
128  * @param key the key to look up
129  * @param iter function to call on each result
130  * @param iter_cls closure for iter
131  *
132  * @return handle to stop the request
133  */
134 struct GNUNET_DHT_GetHandle *
135 GNUNET_DHT_find_peer_start (struct GNUNET_DHT_Handle *h,
136                       const GNUNET_HashCode * key,
137                       GNUNET_DHT_PeerIterator iter,
138                       void *iter_cls);
139
140 /**
141  * Stop async DHT-get.  Frees associated resources.
142  *
143  * @param record GET operation to stop.
144  */
145 void
146 GNUNET_DHT_get_stop (struct GNUNET_DHT_Handle *handle, struct GNUNET_DHT_GetHandle *get_handle);
147
148
149 /**
150  * Perform a PUT operation on the DHT identified by 'table' storing
151  * a binding of 'key' to 'value'.  The peer does not have to be part
152  * of the table (if so, we will attempt to locate a peer that is!)
153  *
154  * @param h handle to DHT service
155  * @param key the key to store under
156  * @param type type of the value
157  * @param size number of bytes in data; must be less than 64k
158  * @param data the data to store
159  * @param exp desired expiration time for the value
160  * @param cont continuation to call when done; 
161  *             reason will be TIMEOUT on error,
162  *             reason will be PREREQ_DONE on success
163  * @param cont_cls closure for cont
164  * 
165  */
166 int GNUNET_DHT_put (struct GNUNET_DHT_Handle *h, 
167                     const GNUNET_HashCode * key,
168                     uint32_t type,                  
169                     uint32_t size, 
170                     const char *data,
171                     struct GNUNET_TIME_Relative exp,
172                     GNUNET_SCHEDULER_Task cont,
173                     void *cont_cls);
174
175
176 #if 0                           /* keep Emacsens' auto-indent happy */
177 {
178 #endif
179 #ifdef __cplusplus
180 }
181 #endif
182
183
184 #endif 
185 /* gnunet_dht_service.h */