2 This file is part of GNUnet.
3 Copyright (C) 2009-2019 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @author Christian Grothoff
24 * API of the transport service towards the CORE service (TNG version)
26 * @defgroup transport TRANSPORT service
27 * Communication with other peers
29 * @see [Documentation](https://gnunet.org/transport-service)
33 #ifndef GNUNET_TRANSPORT_CORE_SERVICE_H
34 #define GNUNET_TRANSPORT_CORE_SERVICE_H
38 #if 0 /* keep Emacsens' auto-indent happy */
43 #include "gnunet_util_lib.h"
46 * Version number of the transport API.
48 #define GNUNET_TRANSPORT_CORE_VERSION 0x00000000
52 * Opaque handle to the service.
54 struct GNUNET_TRANSPORT_CoreHandle;
58 * Function called to notify transport users that another
59 * peer connected to us.
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
69 typedef void *(*GNUNET_TRANSPORT_NotifyConnect) (
71 const struct GNUNET_PeerIdentity *peer,
72 struct GNUNET_MQ_Handle *mq);
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
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
86 typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (
88 const struct GNUNET_PeerIdentity *peer,
93 * Connect to the transport service. Note that the connection may
94 * complete (or fail) asynchronously.
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
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,
114 GNUNET_TRANSPORT_NotifyConnect nc,
115 GNUNET_TRANSPORT_NotifyDisconnect nd);
119 * Disconnect from the transport service.
121 * @param handle handle returned from connect
124 GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle);
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
134 * Used to provide flow control, this is our equivalent to
135 * #GNUNET_SERVICE_client_continue() of an ordinary service.
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
144 * @param ch core handle
145 * @param pid which peer was the message from that was fully processed by CORE
148 GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch,
149 const struct GNUNET_PeerIdentity *pid);
153 * Checks if a given peer is connected to us and get the message queue.
154 * Convenience function.
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
160 struct GNUNET_MQ_Handle *
161 GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
162 const struct GNUNET_PeerIdentity *peer);
165 #if 0 /* keep Emacsens' auto-indent happy */
172 /* ifndef GNUNET_TRANSPORT_CORE_SERVICE_H */
175 /** @} */ /* end of group */
177 /* end of gnunet_transport_core_service.h */