-docu
[oweals/gnunet.git] / src / dv / gnunet_dv_service.h
1 /*
2      This file is part of GNUnet.
3      (C) 2013 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 3, 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  * @file dv/gnunet-service-dv.h
24  * @brief DV service API (should only be used by the DV plugin)
25  */
26 #ifndef GNUNET_SERVICE_DV_H
27 #define GNUNET_SERVICE_DV_H
28
29 #include "gnunet_util_lib.h"
30
31
32 /**
33  * Signature of a function to be called if DV
34  * starts to be able to talk to a peer.
35  */
36 typedef void (*GNUNET_DV_ConnectCallback)(void *cls,
37                                           const struct GNUNET_PeerIdentity *peer,
38                                           uint32_t distance);
39
40
41 /**
42  * Signature of a function to be called if DV
43  * is no longer able to talk to a peer.
44  */
45 typedef void (*GNUNET_DV_DisconnectCallback)(void *cls,
46                                              const struct GNUNET_PeerIdentity *peer);
47
48
49 /**
50  * Signature of a function to be called if DV
51  * receives a message for this peer.
52  *
53  * @param cls closure
54  * @param sender sender of the message
55  * @param distance how far did the message travel
56  * @param msg actual message payload
57  */
58 typedef void (*GNUNET_DV_MessageReceivedCallback)(void *cls,
59                                                   const struct GNUNET_PeerIdentity *sender,
60                                                   uint32_t distance,
61                                                   const struct GNUNET_MessageHeader *msg);
62
63
64 /**
65  * Signature of a function called once the delivery of a
66  * message has been successful.
67  *
68  * @param cls closure
69  * @param ok GNUNET_OK on success, GNUNET_SYSERR on error
70  */
71 typedef void (*GNUNET_DV_MessageSentCallback)(void *cls,
72                                               int ok);
73
74
75 /**
76  * Handle to the DV service.
77  */
78 struct GNUNET_DV_ServiceHandle;
79
80
81 /**
82  * Connect to the DV service.
83  *
84  * @param cfg configuration
85  * @param cls closure for callbacks
86  * @param connect_cb function to call on connects
87  * @param disconnect_cb function to call on disconnects
88  * @param message_cb function to call if we receive messages
89  * @return handle to access the service
90  */
91 struct GNUNET_DV_ServiceHandle *
92 GNUNET_DV_service_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
93                            void *cls,
94                            GNUNET_DV_ConnectCallback connect_cb,
95                            GNUNET_DV_DisconnectCallback disconnect_cb,
96                            GNUNET_DV_MessageReceivedCallback message_cb);
97
98
99 /**
100  * Disconnect from DV service.
101  *
102  * @param sh service handle
103  */
104 void
105 GNUNET_DV_service_disconnect (struct GNUNET_DV_ServiceHandle *sh);
106
107
108 /**
109  * Handle for a send operation.
110  */
111 struct GNUNET_DV_TransmitHandle;
112
113
114 /**
115  * Send a message via DV service.
116  *
117  * @param sh service handle
118  * @param target intended recpient
119  * @param msg message payload
120  * @param cb function to invoke when done
121  * @param cb_cls closure for 'cb'
122  * @return handle to cancel the operation
123  */
124 struct GNUNET_DV_TransmitHandle *
125 GNUNET_DV_send (struct GNUNET_DV_ServiceHandle *sh,
126                 const struct GNUNET_PeerIdentity *target,
127                 const struct GNUNET_MessageHeader *msg,
128                 GNUNET_DV_MessageSentCallback cb,
129                 void *cb_cls);
130
131
132 /**
133  * Abort send operation (naturally, the message may have
134  * already been transmitted; this only stops the 'cb'
135  * from being called again).
136  *
137  * @param th send operation to cancel
138  */
139 void
140 GNUNET_DV_send_cancel (struct GNUNET_DV_TransmitHandle *th);
141
142
143 #endif