gnunet_dhtu_plugin.h (6908B)
1 /* 2 This file is part of GNUnet 3 Copyright (C) 2021 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 * @author Christian Grothoff 23 * 24 * @file 25 * API for DHT network underlay 26 */ 27 #ifndef PLUGIN_DHTU_H 28 #define PLUGIN_DHTU_H 29 30 31 #include "gnunet_util_lib.h" 32 33 34 #ifdef __cplusplus 35 extern "C" 36 { 37 #if 0 /* keep Emacsens' auto-indent happy */ 38 } 39 #endif 40 #endif 41 42 43 /** 44 * Opaque handle that the underlay offers for our address to be used when 45 * sending messages to another peer. 46 */ 47 struct GNUNET_DHTU_Source; 48 49 /** 50 * Opaque handle that the underlay offers for the target peer when sending 51 * messages to another peer. 52 */ 53 struct GNUNET_DHTU_Target; 54 55 /** 56 * Opaque handle expressing a preference of the DHT to 57 * keep a particular target connected. 58 */ 59 struct GNUNET_DHTU_PreferenceHandle; 60 61 62 /** 63 * The datastore service will pass a pointer to a struct 64 * of this type as the first and only argument to the 65 * entry point of each datastore plugin. 66 */ 67 struct GNUNET_DHTU_PluginEnvironment 68 { 69 /** 70 * Configuration to use. 71 */ 72 const struct GNUNET_CONFIGURATION_Handle *cfg; 73 74 /** 75 * Closure to use for callbacks. 76 */ 77 void *cls; 78 79 /** 80 * Function to call with new addresses of this peer. 81 * 82 * @param cls the closure 83 * @param address address under which we are likely reachable, 84 * pointer will remain valid until @e address_del_cb is called; to be used for HELLOs. Example: "ip+udp://1.1.1.1:2086/" 85 * @param source handle for sending from this address, NULL if we can only receive 86 * @param[out] ctx storage space for DHT to use in association with this address 87 */ 88 void 89 (*address_add_cb)(void *cls, 90 const char *address, 91 struct GNUNET_DHTU_Source *source, 92 void **ctx); 93 94 /** 95 * Function to call with expired addresses of this peer. 96 * 97 * @param[in] ctx storage space used by the DHT in association with this address 98 */ 99 void 100 (*address_del_cb)(void *ctx); 101 102 /** 103 * We have a new estimate on the size of the underlay. 104 * 105 * @param cls closure 106 * @param timestamp time when the estimate was received from the server (or created by the server) 107 * @param logestimate the log(Base 2) value of the current network size estimate 108 * @param std_dev standard deviation for the estimate, negative if unavailable 109 */ 110 void 111 (*network_size_cb)(void *cls, 112 struct GNUNET_TIME_Absolute timestamp, 113 double logestimate, 114 double std_dev); 115 116 /** 117 * Function to call when we connect to a peer and can henceforth transmit to 118 * that peer. 119 * 120 * @param cls the closure 121 * @param target handle to the target, 122 * pointer will remain valid until @e disconnect_cb is called 123 * @param pid peer identity, 124 * pointer will remain valid until @e disconnect_cb is called 125 * @param[out] ctx storage space for DHT to use in association with this target 126 */ 127 void 128 (*connect_cb)(void *cls, 129 struct GNUNET_DHTU_Target *target, 130 const struct GNUNET_PeerIdentity *pid, 131 void **ctx); 132 133 134 /** 135 * Function to call when we disconnected from a peer and can henceforth 136 * cannot transmit to that peer anymore. 137 * 138 * @param[in] ctx storage space used by the DHT in association with this target 139 */ 140 void 141 (*disconnect_cb)(void *ctx); 142 143 /** 144 * Function to call when we receive a message. 145 * 146 * @param cls the closure 147 * @param origin where the message originated from 148 * @param[in,out] tctx ctx of target address where we received the message from 149 * @param[in,out] sctx ctx of our own source address at which we received the message 150 * @param message the message we received @param message_size number of 151 * bytes in @a message 152 */ 153 void 154 (*receive_cb)(void *cls, 155 void **tctx, 156 void **sctx, 157 const void *message, 158 size_t message_size); 159 160 }; 161 162 163 /** 164 * @brief struct returned by the initialization function of the plugin 165 */ 166 struct GNUNET_DHTU_PluginFunctions 167 { 168 /** 169 * Closure to pass to all plugin functions. 170 */ 171 void *cls; 172 173 /** 174 * Request creation of a session with a peer at the given @a address. 175 * 176 * @param cls closure (internal context for the plugin) 177 * @param pid target identity of the peer to connect to 178 * @param address target address URI to connect to 179 */ 180 void 181 (*try_connect) (void *cls, 182 const struct GNUNET_PeerIdentity *pid, 183 const char *address); 184 185 186 /** 187 * Request underlay to keep the connection to @a target alive if possible. 188 * Hold may be called multiple times to express a strong preference to 189 * keep a connection, say because a @a target is in multiple tables. 190 * 191 * @param cls closure 192 * @param target connection to keep alive 193 */ 194 struct GNUNET_DHTU_PreferenceHandle * 195 (*hold)(void *cls, 196 struct GNUNET_DHTU_Target *target); 197 198 /** 199 * Do no longer request underlay to keep the connection alive. 200 * 201 * @param cls closure 202 * @param target connection to keep alive 203 */ 204 void 205 (*drop)(struct GNUNET_DHTU_PreferenceHandle *ph); 206 207 /** 208 * Send message to some other participant over the network. Note that 209 * sending is not guaranteeing that the other peer actually received the 210 * message. For any given @a target, the DHT must wait for the @a 211 * finished_cb to be called before calling send() again. 212 * 213 * @param cls closure (internal context for the plugin) 214 * @param target receiver identification 215 * @param msg message 216 * @param msg_size number of bytes in @a msg 217 * @param finished_cb function called once transmission is done 218 * (not called if @a target disconnects, then only the 219 * disconnect_cb is called). 220 * @param finished_cb_cls closure for @a finished_cb 221 */ 222 void 223 (*send) (void *cls, 224 struct GNUNET_DHTU_Target *target, 225 const void *msg, 226 size_t msg_size, 227 GNUNET_SCHEDULER_TaskCallback finished_cb, 228 void *finished_cb_cls); 229 230 }; 231 232 233 #if 0 /* keep Emacsens' auto-indent happy */ 234 { 235 #endif 236 #ifdef __cplusplus 237 } 238 #endif 239 240 #endif