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