GNUnet  0.11.x
plugin_dhtu_gnunet.c
Go to the documentation of this file.
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 
27 #include "platform.h"
28 #incluce "gnunet_dhtu_plugin.h"
29 
35 {
36 
40  void *app_ctx;
41 };
42 
43 
49 {
50 
54  void *app_ctx;
55 
60 
65 
69  unsigned int ph_count;
70 
71 };
72 
78 {
83 
88 
93 };
94 
95 
100 {
101  /* we are IP, we do not do crypto */
102 };
103 
104 
108 struct Plugin
109 {
114 };
115 
116 
126 static ssize_t
127 ip_sign (void *cls,
128  const struct GNUNET_DHTU_PrivateKey *pk,
129  const struct GNUNET_DHTU_SignaturePurpose *purpose,
130  void **sig)
131 {
132  return 0;
133 }
134 
135 
148 static enum GNUNET_GenericReturnValue
149 ip_verify (void *cls,
150  const struct GNUNET_DHTU_PublicKey *pk,
151  const struct GNUNET_DHTU_SignaturePurpose *purpose,
152  const void *sig,
153  size_t sig_size)
154 {
155  return GNUNET_NO;
156 }
157 
158 
165 static void
167  const char *address)
168 {
169  GNUNET_break (0);
170 }
171 
172 
181 static struct GNUNET_DHTU_PreferenceHandle *
182 ip_hold (void *cls,
183  struct GNUNET_DHTU_Target *target)
184 {
186 
188  ph->target = target;
190  target->ph_tail,
191  ph);
192  target->ph_count++;
193  return ph;
194 }
195 
196 
203 static void
205 {
206  struct GNUNET_DHTU_Target *target = ph->target;
207 
209  target->ph_tail,
210  ph);
211  target->ph_count--;
212  GNUNET_free (ph);
213 }
214 
215 
231 static void
232 ip_send (void *cls,
233  struct GNUNET_DHTU_Target *target,
234  const void *msg,
235  size_t msg_size,
236  GNUNET_SCHEDULER_TaskCallback finished_cb,
237  void *finished_cb_cls)
238 {
239  GNUNET_break (0);
240 }
241 
242 
249 void *
251 {
253  struct GNUNET_DHTU_PluginFunctions *api;
254  struct Plugin *plugin;
255 
256  plugin = GNUNET_new (struct Plugin);
257  plugin->env = env;
259  api->cls = plugin;
260  api->sign = &ip_sign;
261  api->verify = &ip_verify;
262  api->try_connect = &ip_try_connect;
263  api->hold = &ip_hold;
264  api->drop = &ip_drop;
265  api->send = &ip_send;
266  return api;
267 }
268 
269 
276 void *
278 {
279  struct GNUNET_DHTU_PluginFunctions *api = cls;
280  struct Plugin *plugin = api->cls;
281 
282  GNUNET_free (plugin);
283  GNUNET_free (api);
284  return NULL;
285 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
Opaque handle for a private key used by this underlay.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
Opaque handle expressing a preference of the DHT to keep a particular target connected.
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
header of what an DHTU signature signs this must be followed by "size - 8" bytes of the actual signed...
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
static void ip_drop(struct GNUNET_DHTU_PreferenceHandle *ph)
Do no long request underlay to keep the connection alive.
struct GNUNET_DHTU_Target * target
Target a preference was expressed for.
static struct GNUNET_DHTU_PreferenceHandle * ip_hold(void *cls, struct GNUNET_DHTU_Target *target)
Request underlay to keep the connection to target alive if possible.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
enum GNUNET_GenericReturnValue(* verify)(void *cls, const struct GNUNET_DHTU_PublicKey *pk, const struct GNUNET_DHTU_SignaturePurpose *purpose, const void *sig, size_t sig_size)
Verify signature in sig over purpose.
struct GNUNET_DHTU_PreferenceHandle * ph_head
Head of preferences expressed for this target.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void * app_ctx
Application context for this target.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
struct GNUNET_DHTU_PreferenceHandle * next
Kept in a DLL.
struct GNUNET_DHTU_PreferenceHandle * ph_tail
Tail of preferences expressed for this target.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
void * app_ctx
Application context for this source.
char * address
Address in URL form ("ip+udp://$IP:$PORT")
Handle for a public key used by another peer.
void * libgnunet_plugin_dhtu_gnunet_done(void *cls)
Exit point from the plugin.
void(* drop)(struct GNUNET_DHTU_PreferenceHandle *ph)
Do no long request underlay to keep the connection alive.
struct returned by the initialization function of the plugin
void * cls
Closure to use for callbacks.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
void * libgnunet_plugin_dhtu_ip_init(void *cls)
Entry point for the plugin.
struct GNUNET_DHTU_PluginEnvironment * env
Callbacks into the DHT.
Opaque handle that the underlay offers for the target peer when sending messages to another peer...
static void ip_try_connect(void *cls, const char *address)
Request creation of a session with a peer at the given address.
void(* send)(void *cls, struct GNUNET_DHTU_Target *target, const void *msg, size_t msg_size, GNUNET_SCHEDULER_TaskCallback finished_cb, void *finished_cb_cls)
Send message to some other participant over the network.
unsigned int ph_count
Preference counter, length of the ph_head DLL.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
Handle for a plugin.
Definition: block.c:37
Opaque handle that the underlay offers for our address to be used when sending messages to another pe...
static enum GNUNET_GenericReturnValue ip_verify(void *cls, const struct GNUNET_DHTU_PublicKey *pk, const struct GNUNET_DHTU_SignaturePurpose *purpose, const void *sig, size_t sig_size)
Verify signature in sig over purpose.
struct Plugin * plugin
struct GNUNET_DHTU_PreferenceHandle *(* hold)(void *cls, struct GNUNET_DHTU_Target *target)
Request underlay to keep the connection to target alive if possible.
static ssize_t ip_sign(void *cls, const struct GNUNET_DHTU_PrivateKey *pk, const struct GNUNET_DHTU_SignaturePurpose *purpose, void **sig)
Use our private key to sign a message.
static void ip_send(void *cls, struct GNUNET_DHTU_Target *target, const void *msg, size_t msg_size, GNUNET_SCHEDULER_TaskCallback finished_cb, void *finished_cb_cls)
Send message to some other participant over the network.
void(* try_connect)(void *cls, const char *address)
Request creation of a session with a peer at the given address.
ssize_t(* sign)(void *cls, const struct GNUNET_DHTU_PrivateKey *pk, const struct GNUNET_DHTU_SignaturePurpose *purpose, void **sig)
Use our private key to sign a message.
void * cls
Closure to pass to all plugin functions.
struct GNUNET_DHTU_PreferenceHandle * prev
Kept in a DLL.
#define GNUNET_free(ptr)
Wrapper around free.