missing changes to headers
[oweals/gnunet.git] / src / include / gnunet_dv_service.h
1 /*
2      This file is part of GNUnet.
3      Copyright (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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @author Christian Grothoff
23  * @file include/gnunet_dv_service.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 #include "gnunet_ats_service.h"
31
32 /**
33  * Signature of a function to be called if DV
34  * starts to be able to talk to a peer.
35  *
36  * @param cls closure
37  * @param peer newly connected peer
38  * @param distance distance to the peer
39  * @param network the peer is located in
40  */
41 typedef void (*GNUNET_DV_ConnectCallback)(void *cls,
42                                           const struct GNUNET_PeerIdentity *peer,
43                                           uint32_t distance,
44                                           enum GNUNET_ATS_Network_Type network);
45
46
47 /**
48  * Signature of a function to be called if DV
49  * distance to a peer is changed.
50  *
51  * @param cls closure
52  * @param peer connected peer
53  * @param distance new distance to the peer
54  * @param network this network will be used to reach the next hop
55  */
56 typedef void (*GNUNET_DV_DistanceChangedCallback)(void *cls,
57                                                   const struct GNUNET_PeerIdentity *peer,
58                                                   uint32_t distance,
59                                                   enum GNUNET_ATS_Network_Type network);
60
61
62 /**
63  * Signature of a function to be called if DV
64  * is no longer able to talk to a peer.
65  *
66  * @param cls closure
67  * @param peer peer that disconnected
68  */
69 typedef void (*GNUNET_DV_DisconnectCallback)(void *cls,
70                                              const struct GNUNET_PeerIdentity *peer);
71
72
73 /**
74  * Signature of a function to be called if DV
75  * receives a message for this peer.
76  *
77  * @param cls closure
78  * @param sender sender of the message
79  * @param distance how far did the message travel
80  * @param msg actual message payload
81  */
82 typedef void (*GNUNET_DV_MessageReceivedCallback)(void *cls,
83                                                   const struct GNUNET_PeerIdentity *sender,
84                                                   uint32_t distance,
85                                                   const struct GNUNET_MessageHeader *msg);
86
87
88 /**
89  * Signature of a function called once the delivery of a
90  * message has been successful.
91  *
92  * @param cls closure
93  * @param ok GNUNET_OK on success, GNUNET_SYSERR on error
94  */
95 typedef void (*GNUNET_DV_MessageSentCallback)(void *cls,
96                                               int ok);
97
98
99 /**
100  * Handle to the DV service.
101  */
102 struct GNUNET_DV_ServiceHandle;
103
104
105 /**
106  * Connect to the DV service.
107  *
108  * @param cfg configuration
109  * @param cls closure for callbacks
110  * @param connect_cb function to call on connects
111  * @param distance_cb function to call if distances change
112  * @param disconnect_cb function to call on disconnects
113  * @param message_cb function to call if we receive messages
114  * @return handle to access the service
115  */
116 struct GNUNET_DV_ServiceHandle *
117 GNUNET_DV_service_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
118                            void *cls,
119                            GNUNET_DV_ConnectCallback connect_cb,
120                            GNUNET_DV_DistanceChangedCallback distance_cb,
121                            GNUNET_DV_DisconnectCallback disconnect_cb,
122                            GNUNET_DV_MessageReceivedCallback message_cb);
123
124
125 /**
126  * Disconnect from DV service.
127  *
128  * @param sh service handle
129  */
130 void
131 GNUNET_DV_service_disconnect (struct GNUNET_DV_ServiceHandle *sh);
132
133
134 /**
135  * Handle for a send operation.
136  */
137 struct GNUNET_DV_TransmitHandle;
138
139
140 /**
141  * Send a message via DV service.
142  *
143  * @param sh service handle
144  * @param target intended recpient
145  * @param msg message payload
146  * @param cb function to invoke when done
147  * @param cb_cls closure for 'cb'
148  * @return handle to cancel the operation
149  */
150 struct GNUNET_DV_TransmitHandle *
151 GNUNET_DV_send (struct GNUNET_DV_ServiceHandle *sh,
152                 const struct GNUNET_PeerIdentity *target,
153                 const struct GNUNET_MessageHeader *msg,
154                 GNUNET_DV_MessageSentCallback cb,
155                 void *cb_cls);
156
157
158 /**
159  * Abort send operation (naturally, the message may have
160  * already been transmitted; this only stops the 'cb'
161  * from being called again).
162  *
163  * @param th send operation to cancel
164  */
165 void
166 GNUNET_DV_send_cancel (struct GNUNET_DV_TransmitHandle *th);
167
168
169 #endif