fix bad free
[oweals/gnunet.git] / src / include / gnunet_transport_core_service.h
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 /**
19  * @author Christian Grothoff
20  *
21  * @file
22  * API of the transport service towards the CORE service.
23  *
24  * @defgroup transport TRANSPORT service
25  * Communication with other peers
26  *
27  * @see [Documentation](https://gnunet.org/transport-service)
28  *
29  * @{
30  */
31 #ifndef GNUNET_TRANSPORT_CORE_SERVICE_H
32 #define GNUNET_TRANSPORT_CORE_SERVICE_H
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0                           /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41
42 #include "gnunet_util_lib.h"
43
44 /**
45  * Version number of the transport API.
46  */
47 #define GNUNET_TRANSPORT_CORE_VERSION 0x00000000
48
49
50 /**
51  * Opaque handle to the service.
52  */
53 struct GNUNET_TRANSPORT_CoreHandle;
54
55
56 /**
57  * Function called to notify transport users that another
58  * peer connected to us.
59  *
60  * @param cls closure
61  * @param peer the identity of the peer that connected; this
62  *        pointer will remain valid until the disconnect, hence
63  *        applications do not necessarily have to make a copy 
64  *        of the value if they only need it until disconnect
65  * @param mq message queue to use to transmit to @a peer
66  * @return closure to use in MQ handlers
67  */
68 typedef void *
69 (*GNUNET_TRANSPORT_NotifyConnecT) (void *cls,
70                                    const struct GNUNET_PeerIdentity *peer,
71                                    struct GNUNET_MQ_Handle *mq);
72
73
74 /**
75  * Function called to notify transport users that another peer
76  * disconnected from us.  The message queue that was given to the
77  * connect notification will be destroyed and must not be used
78  * henceforth.
79  *
80  * @param cls closure from #GNUNET_TRANSPORT_core_connect
81  * @param peer the peer that disconnected
82  * @param handlers_cls closure of the handlers, was returned from the
83  *                    connect notification callback
84  */
85 typedef void
86 (*GNUNET_TRANSPORT_NotifyDisconnecT) (void *cls,
87                                       const struct GNUNET_PeerIdentity *peer,
88                                       void *handler_cls);
89
90
91 /**
92  * Function called if we have "excess" bandwidth to a peer.
93  * The notification will happen the first time we have excess
94  * bandwidth, and then only again after the client has performed
95  * some transmission to the peer.
96  *
97  * Excess bandwidth is defined as being allowed (by ATS) to send
98  * more data, and us reaching the limit of the capacity build-up
99  * (which, if we go past it, means we don't use available bandwidth).
100  * See also the "max carry" in `struct GNUNET_BANDWIDTH_Tracker`.
101  *
102  * @param cls the closure
103  * @param neighbour peer that we have excess bandwidth to
104  * @param handlers_cls closure of the handlers, was returned from the
105  *                    connect notification callback
106  */
107 typedef void
108 (*GNUNET_TRANSPORT_NotifyExcessBandwidtH)(void *cls,
109                                           const struct GNUNET_PeerIdentity *neighbour,
110                                           void *handlers_cls);
111
112
113
114 /**
115  * Connect to the transport service.  Note that the connection may
116  * complete (or fail) asynchronously.
117  *
118  * @param cfg configuration to use
119  * @param self our own identity (API should check that it matches
120  *             the identity found by transport), or NULL (no check)
121  * @param handlers array of message handlers; note that the
122  *                 closures provided will be ignored and replaced
123  *                 with the respective return value from @a nc
124  * @param handlers array with handlers to call when we receive messages, or NULL
125  * @param cls closure for the @a nc, @a nd and @a neb callbacks
126  * @param nc function to call on connect events, or NULL
127  * @param nd function to call on disconnect events, or NULL
128  * @param neb function to call if we have excess bandwidth to a peer, or NULL
129  * @return NULL on error
130  */
131 struct GNUNET_TRANSPORT_CoreHandle *
132 GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
133                                const struct GNUNET_PeerIdentity *self,
134                                const struct GNUNET_MQ_MessageHandler *handlers,
135                                void *cls,
136                                GNUNET_TRANSPORT_NotifyConnecT nc,
137                                GNUNET_TRANSPORT_NotifyDisconnecT nd,
138                                GNUNET_TRANSPORT_NotifyExcessBandwidtH neb);
139
140
141 /**
142  * Disconnect from the transport service.
143  *
144  * @param handle handle returned from connect
145  */
146 void
147 GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle);
148
149
150 /**
151  * Checks if a given peer is connected to us and get the message queue.
152  *
153  * @param handle connection to transport service
154  * @param peer the peer to check
155  * @return NULL if disconnected, otherwise message queue for @a peer
156  */
157 struct GNUNET_MQ_Handle *
158 GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
159                               const struct GNUNET_PeerIdentity *peer);
160
161
162 #if 0                           /* keep Emacsens' auto-indent happy */
163 {
164 #endif
165 #ifdef __cplusplus
166 }
167 #endif
168
169 /* ifndef GNUNET_TRANSPORT_CORE_SERVICE_H */
170 #endif
171
172 /** @} */  /* end of group */
173
174 /* end of gnunet_transport_core_service.h */