2 This file is part of GNUnet.
3 Copyright (C) 2009-2016 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.
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
39 #if 0 /* keep Emacsens' auto-indent happy */
44 #include "gnunet_util_lib.h"
47 * Version number of the transport API.
49 #define GNUNET_TRANSPORT_CORE_VERSION 0x00000000
53 * Opaque handle to the service.
55 struct GNUNET_TRANSPORT_CoreHandle;
59 * Function called to notify transport users that another
60 * peer connected to us.
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
71 (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
72 const struct GNUNET_PeerIdentity *peer,
73 struct GNUNET_MQ_Handle *mq);
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
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
88 (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
89 const struct GNUNET_PeerIdentity *peer,
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.
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`.
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
110 (*GNUNET_TRANSPORT_NotifyExcessBandwidth)(void *cls,
111 const struct GNUNET_PeerIdentity *neighbour,
117 * Connect to the transport service. Note that the connection may
118 * complete (or fail) asynchronously.
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
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,
138 GNUNET_TRANSPORT_NotifyConnect nc,
139 GNUNET_TRANSPORT_NotifyDisconnect nd,
140 GNUNET_TRANSPORT_NotifyExcessBandwidth neb);
144 * Disconnect from the transport service.
146 * @param handle handle returned from connect
149 GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle);
153 * Checks if a given peer is connected to us and get the message queue.
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
159 struct GNUNET_MQ_Handle *
160 GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
161 const struct GNUNET_PeerIdentity *peer);
164 #if 0 /* keep Emacsens' auto-indent happy */
171 /* ifndef GNUNET_TRANSPORT_CORE_SERVICE_H */
174 /** @} */ /* end of group */
176 /* end of gnunet_transport_core_service.h */