-remove debug message
[oweals/gnunet.git] / src / include / gnunet_transport_core_service.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009-2019 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 (TNG version)
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 #if 0 /* keep Emacsens' auto-indent happy */
39 }
40 #endif
41 #endif
42
43 #include "gnunet_util_lib.h"
44
45 /**
46  * Version number of the transport API.
47  */
48 #define GNUNET_TRANSPORT_CORE_VERSION 0x00000000
49
50
51 /**
52  * Opaque handle to the service.
53  */
54 struct GNUNET_TRANSPORT_CoreHandle;
55
56
57 /**
58  * Function called to notify transport users that another
59  * peer connected to us.
60  *
61  * @param cls closure
62  * @param peer the identity of the peer that connected; this
63  *        pointer will remain valid until the disconnect, hence
64  *        applications do not necessarily have to make a copy
65  *        of the value if they only need it until disconnect
66  * @param mq message queue to use to transmit to @a peer
67  * @return closure to use in MQ handlers
68  */
69 typedef void *(*GNUNET_TRANSPORT_NotifyConnect) (
70   void *cls,
71   const struct GNUNET_PeerIdentity *peer,
72   struct GNUNET_MQ_Handle *mq);
73
74
75 /**
76  * Function called to notify transport users that another peer
77  * disconnected from us.  The message queue that was given to the
78  * connect notification will be destroyed and must not be used
79  * henceforth.
80  *
81  * @param cls closure from #GNUNET_TRANSPORT_core_connect
82  * @param peer the peer that disconnected
83  * @param handlers_cls closure of the handlers, was returned from the
84  *                    connect notification callback
85  */
86 typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (
87   void *cls,
88   const struct GNUNET_PeerIdentity *peer,
89   void *handler_cls);
90
91
92 /**
93  * Connect to the transport service.  Note that the connection may
94  * complete (or fail) asynchronously.
95  *
96  * @param cfg configuration to use
97  * @param self our own identity (API should check that it matches
98  *             the identity found by transport), or NULL (no check)
99  * @param handlers array of message handlers; note that the
100  *                 closures provided will be ignored and replaced
101  *                 with the respective return value from @a nc
102  * @param handlers array with handlers to call when we receive messages, or NULL
103  * @param cls closure for the @a nc, @a nd and @a neb callbacks
104  * @param nc function to call on connect events, or NULL
105  * @param nd function to call on disconnect events, or NULL
106  * @param neb function to call if we have excess bandwidth to a peer, or NULL
107  * @return NULL on error
108  */
109 struct GNUNET_TRANSPORT_CoreHandle *
110 GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
111                                const struct GNUNET_PeerIdentity *self,
112                                const struct GNUNET_MQ_MessageHandler *handlers,
113                                void *cls,
114                                GNUNET_TRANSPORT_NotifyConnect nc,
115                                GNUNET_TRANSPORT_NotifyDisconnect nd);
116
117
118 /**
119  * Disconnect from the transport service.
120  *
121  * @param handle handle returned from connect
122  */
123 void
124 GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle);
125
126
127 /**
128  * Notification from the CORE service to the TRANSPORT service
129  * that the CORE service has finished processing a message from
130  * TRANSPORT (via the @code{handlers} of #GNUNET_TRANSPORT_core_connect())
131  * and that it is thus now OK for TRANSPORT to send more messages
132  * for @a pid.
133  *
134  * Used to provide flow control, this is our equivalent to
135  * #GNUNET_SERVICE_client_continue() of an ordinary service.
136  *
137  * Note that due to the use of a window, TRANSPORT may send multiple
138  * messages destined for the same peer even without an intermediate
139  * call to this function. However, CORE must still call this function
140  * once per message received, as otherwise eventually the window will
141  * be full and TRANSPORT will stop providing messages to CORE for @a
142  * pid.
143  *
144  * @param ch core handle
145  * @param pid which peer was the message from that was fully processed by CORE
146  */
147 void
148 GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch,
149                                         const struct GNUNET_PeerIdentity *pid);
150
151
152 /**
153  * Checks if a given peer is connected to us and get the message queue.
154  * Convenience function.
155  *
156  * @param handle connection to transport service
157  * @param peer the peer to check
158  * @return NULL if disconnected, otherwise message queue for @a peer
159  */
160 struct GNUNET_MQ_Handle *
161 GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
162                               const struct GNUNET_PeerIdentity *peer);
163
164
165 #if 0 /* keep Emacsens' auto-indent happy */
166 {
167 #endif
168 #ifdef __cplusplus
169 }
170 #endif
171
172 /* ifndef GNUNET_TRANSPORT_CORE_SERVICE_H */
173 #endif
174
175 /** @} */ /* end of group */
176
177 /* end of gnunet_transport_core_service.h */