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