diff options
Diffstat (limited to 'src/service/dht/gnunet-service-dht.h')
-rw-r--r-- | src/service/dht/gnunet-service-dht.h | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/src/service/dht/gnunet-service-dht.h b/src/service/dht/gnunet-service-dht.h new file mode 100644 index 000000000..893c90109 --- /dev/null +++ b/src/service/dht/gnunet-service-dht.h | |||
@@ -0,0 +1,212 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009-2016 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your 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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file dht/gnunet-service-dht.h | ||
23 | * @brief GNUnet DHT globals | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #ifndef GNUNET_SERVICE_DHT_H | ||
27 | #define GNUNET_SERVICE_DHT_H | ||
28 | |||
29 | #include "gnunet-service-dht_datacache.h" | ||
30 | #include "gnunet-service-dht_neighbours.h" | ||
31 | #include "gnunet_statistics_service.h" | ||
32 | |||
33 | |||
34 | #define DEBUG_DHT GNUNET_EXTRA_LOGGING | ||
35 | |||
36 | /** | ||
37 | * Information we keep per underlay. | ||
38 | */ | ||
39 | struct GDS_Underlay; | ||
40 | |||
41 | /** | ||
42 | * Configuration we use. | ||
43 | */ | ||
44 | extern const struct GNUNET_CONFIGURATION_Handle *GDS_cfg; | ||
45 | |||
46 | /** | ||
47 | * Handle for the service. | ||
48 | */ | ||
49 | extern struct GNUNET_SERVICE_Handle *GDS_service; | ||
50 | |||
51 | /** | ||
52 | * Our handle to the BLOCK library. | ||
53 | */ | ||
54 | extern struct GNUNET_BLOCK_Context *GDS_block_context; | ||
55 | |||
56 | /** | ||
57 | * Handle for the statistics service. | ||
58 | */ | ||
59 | extern struct GNUNET_STATISTICS_Handle *GDS_stats; | ||
60 | |||
61 | /** | ||
62 | * Our HELLO builder. | ||
63 | */ | ||
64 | extern struct GNUNET_HELLO_Builder *GDS_my_hello; | ||
65 | |||
66 | /** | ||
67 | * Identity of this peer. | ||
68 | */ | ||
69 | extern struct GNUNET_PeerIdentity GDS_my_identity; | ||
70 | |||
71 | /** | ||
72 | * Hash of the identity of this peer. | ||
73 | */ | ||
74 | extern struct GNUNET_HashCode GDS_my_identity_hash; | ||
75 | |||
76 | /** | ||
77 | * Our private key. | ||
78 | */ | ||
79 | extern struct GNUNET_CRYPTO_EddsaPrivateKey GDS_my_private_key; | ||
80 | |||
81 | |||
82 | /** | ||
83 | * Ask all underlays to connect to peer @a pid at @a address. | ||
84 | * | ||
85 | * @param pid identity of the peer we would connect to | ||
86 | * @param address an address of @a pid | ||
87 | */ | ||
88 | void | ||
89 | GDS_u_try_connect (const struct GNUNET_PeerIdentity *pid, | ||
90 | const char *address); | ||
91 | |||
92 | |||
93 | /** | ||
94 | * Send message to some other participant over the network. Note that | ||
95 | * sending is not guaranteeing that the other peer actually received the | ||
96 | * message. For any given @a target, the DHT must wait for the @a | ||
97 | * finished_cb to be called before calling send() again. | ||
98 | * | ||
99 | * @param u underlay to use for transmission | ||
100 | * @param target receiver identification | ||
101 | * @param msg message | ||
102 | * @param msg_size number of bytes in @a msg | ||
103 | * @param finished_cb function called once transmission is done | ||
104 | * (not called if @a target disconnects, then only the | ||
105 | * disconnect_cb is called). | ||
106 | * @param finished_cb_cls closure for @a finished_cb | ||
107 | */ | ||
108 | void | ||
109 | GDS_u_send (struct GDS_Underlay *u, | ||
110 | struct GNUNET_DHTU_Target *target, | ||
111 | const void *msg, | ||
112 | size_t msg_size, | ||
113 | GNUNET_SCHEDULER_TaskCallback finished_cb, | ||
114 | void *finished_cb_cls); | ||
115 | |||
116 | |||
117 | /** | ||
118 | * Drop a hold @a ph from underlay @a u. | ||
119 | * | ||
120 | * @param u the underlay controlling the hold | ||
121 | * @param ph the preference handle | ||
122 | */ | ||
123 | void | ||
124 | GDS_u_drop (struct GDS_Underlay *u, | ||
125 | struct GNUNET_DHTU_PreferenceHandle *ph); | ||
126 | |||
127 | |||
128 | /** | ||
129 | * Create a hold on @a target at underlay @a u. | ||
130 | * | ||
131 | * @param u the underlay controlling the target | ||
132 | * @param target the peer to hold the connection to | ||
133 | */ | ||
134 | struct GNUNET_DHTU_PreferenceHandle * | ||
135 | GDS_u_hold (struct GDS_Underlay *u, | ||
136 | struct GNUNET_DHTU_Target *target); | ||
137 | |||
138 | |||
139 | /** | ||
140 | * Handle a reply we've received from another peer. If the reply | ||
141 | * matches any of our pending queries, forward it to the respective | ||
142 | * client(s). | ||
143 | * | ||
144 | * @param bd block details | ||
145 | * @param query_hash hash of the original query, might not match key in @a bd | ||
146 | * @param get_path_length number of entries in @a get_path | ||
147 | * @param get_path path the reply has taken | ||
148 | * @return true on success, false on failures | ||
149 | */ | ||
150 | bool | ||
151 | GDS_CLIENTS_handle_reply (const struct GNUNET_DATACACHE_Block *bd, | ||
152 | const struct GNUNET_HashCode *query_hash, | ||
153 | unsigned int get_path_length, | ||
154 | const struct GNUNET_DHT_PathElement *get_path); | ||
155 | |||
156 | |||
157 | /** | ||
158 | * Check if some client is monitoring GET messages and notify | ||
159 | * them in that case. If tracked, @a path should include the local peer. | ||
160 | * | ||
161 | * | ||
162 | * @param options Options, for instance RecordRoute, DemultiplexEverywhere. | ||
163 | * @param type The type of data in the request. | ||
164 | * @param hop_count Hop count so far. | ||
165 | * @param desired_replication_level Desired replication level. | ||
166 | * @param key Key of the requested data. | ||
167 | */ | ||
168 | void | ||
169 | GDS_CLIENTS_process_get (enum GNUNET_DHT_RouteOption options, | ||
170 | enum GNUNET_BLOCK_Type type, | ||
171 | uint32_t hop_count, | ||
172 | uint32_t desired_replication_level, | ||
173 | const struct GNUNET_HashCode *key); | ||
174 | |||
175 | |||
176 | /** | ||
177 | * Check if some client is monitoring GET RESP messages and notify | ||
178 | * them in that case. | ||
179 | * | ||
180 | * @param bd block details | ||
181 | * @param get_path Peers on GET path (or NULL if not recorded). | ||
182 | * @param get_path_length number of entries in @a get_path. | ||
183 | */ | ||
184 | void | ||
185 | GDS_CLIENTS_process_get_resp (const struct GNUNET_DATACACHE_Block *bd, | ||
186 | const struct GNUNET_DHT_PathElement *get_path, | ||
187 | unsigned int get_path_length); | ||
188 | |||
189 | |||
190 | /** | ||
191 | * Check if some client is monitoring PUT messages and notify | ||
192 | * them in that case. The @a path should include our own | ||
193 | * peer ID (if recorded). | ||
194 | * | ||
195 | * @param bd details about the block | ||
196 | * @param hop_count Hop count so far. | ||
197 | * @param desired_replication_level Desired replication level. | ||
198 | */ | ||
199 | void | ||
200 | GDS_CLIENTS_process_put (const struct GNUNET_DATACACHE_Block *bd, | ||
201 | uint32_t hop_count, | ||
202 | uint32_t desired_replication_level); | ||
203 | |||
204 | /** | ||
205 | * Return the current NSE | ||
206 | * | ||
207 | * @return the current NSE as a logarithm | ||
208 | */ | ||
209 | double | ||
210 | GDS_NSE_get (void); | ||
211 | |||
212 | #endif | ||