gnunet_transport_service.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2009-2016 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Christian Grothoff
  18. *
  19. * @file
  20. * Low-level P2P IO
  21. *
  22. * @defgroup transport Transport service
  23. * Low-level P2P IO
  24. *
  25. * @see [Documentation](https://gnunet.org/transport-service)
  26. *
  27. * @{
  28. */
  29. #ifndef GNUNET_TRANSPORT_SERVICE_H
  30. #define GNUNET_TRANSPORT_SERVICE_H
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #if 0 /* keep Emacsens' auto-indent happy */
  34. }
  35. #endif
  36. #endif
  37. #include "gnunet_util_lib.h"
  38. #include "gnunet_ats_service.h"
  39. /**
  40. * Version number of the transport API.
  41. */
  42. #define GNUNET_TRANSPORT_VERSION 0x00000003
  43. /* *************************** HELLO *************************** */
  44. /**
  45. * Handle for a #GNUNET_TRANSPORT_offer_hello operation
  46. */
  47. struct GNUNET_TRANSPORT_OfferHelloHandle;
  48. /**
  49. * Offer the transport service the HELLO of another peer. Note that
  50. * the transport service may just ignore this message if the HELLO is
  51. * malformed or useless due to our local configuration.
  52. *
  53. * @param cfg configuration
  54. * @param hello the hello message
  55. * @param cont continuation to call when HELLO has been sent,
  56. * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail
  57. * tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success
  58. * @param cont_cls closure for @a cont
  59. * @return a `struct GNUNET_TRANSPORT_OfferHelloHandle` handle or NULL on
  60. * failure, in case of failure @a cont will not be called
  61. *
  62. */
  63. struct GNUNET_TRANSPORT_OfferHelloHandle *
  64. GNUNET_TRANSPORT_offer_hello (const struct GNUNET_CONFIGURATION_Handle *cfg,
  65. const struct GNUNET_MessageHeader *hello,
  66. GNUNET_SCHEDULER_TaskCallback cont,
  67. void *cont_cls);
  68. /**
  69. * Cancel the request to transport to offer the HELLO message
  70. *
  71. * @param ohh the `struct GNUNET_TRANSPORT_OfferHelloHandle` to cancel
  72. */
  73. void
  74. GNUNET_TRANSPORT_offer_hello_cancel (
  75. struct GNUNET_TRANSPORT_OfferHelloHandle *ohh);
  76. /* *********************** Address to String ******************* */
  77. /**
  78. * Handle to cancel a pending address lookup.
  79. */
  80. struct GNUNET_TRANSPORT_AddressToStringContext;
  81. /**
  82. * Function to call with a textual representation of an address. This
  83. * function will be called several times with different possible
  84. * textual representations, and a last time with @a address being NULL
  85. * to signal the end of the iteration. Note that @a address NULL
  86. * always is the last call, regardless of the value in @a res.
  87. *
  88. * @param cls closure
  89. * @param address NULL on end of iteration,
  90. * otherwise 0-terminated printable UTF-8 string,
  91. * in particular an empty string if @a res is #GNUNET_NO
  92. * @param res result of the address to string conversion:
  93. * if #GNUNET_OK: conversion successful
  94. * if #GNUNET_NO: address was invalid (or not supported)
  95. * if #GNUNET_SYSERR: communication error (IPC error)
  96. */
  97. typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
  98. const char *address,
  99. int res);
  100. /**
  101. * Convert a binary address into a human readable address.
  102. *
  103. * @param cfg configuration to use
  104. * @param address address to convert (binary format)
  105. * @param numeric should (IP) addresses be displayed in numeric form
  106. * (otherwise do reverse DNS lookup)
  107. * @param timeout how long is the lookup allowed to take at most
  108. * @param aluc function to call with the results
  109. * @param aluc_cls closure for @a aluc
  110. * @return handle to cancel the operation, NULL on error
  111. */
  112. struct GNUNET_TRANSPORT_AddressToStringContext *
  113. GNUNET_TRANSPORT_address_to_string (
  114. const struct GNUNET_CONFIGURATION_Handle *cfg,
  115. const struct GNUNET_HELLO_Address *address,
  116. int numeric,
  117. struct GNUNET_TIME_Relative timeout,
  118. GNUNET_TRANSPORT_AddressToStringCallback aluc,
  119. void *aluc_cls);
  120. /**
  121. * Cancel request for address conversion.
  122. *
  123. * @param alc the context handle
  124. */
  125. void
  126. GNUNET_TRANSPORT_address_to_string_cancel (
  127. struct GNUNET_TRANSPORT_AddressToStringContext *alc);
  128. /* *********************** Monitoring ************************** */
  129. /**
  130. * Possible state of a neighbour. Initially, we are
  131. * #GNUNET_TRANSPORT_PS_NOT_CONNECTED.
  132. *
  133. * Then, there are two main paths. If we receive a SYN message, we give
  134. * the inbound address to ATS. After the check we ask ATS for a suggestion
  135. * (#GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS). If ATS makes a suggestion, we
  136. * send our SYN_ACK and go to #GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK.
  137. * If we receive a ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
  138. * (and notify everyone about the new connection). If the operation times out,
  139. * we go to #GNUNET_TRANSPORT_PS_DISCONNECT.
  140. *
  141. * The other case is where we transmit a SYN message first. We
  142. * start with #GNUNET_TRANSPORT_PS_INIT_ATS. If we get an address, we send
  143. * the SYN message and go to state #GNUNET_TRANSPORT_PS_CONNECT_SENT.
  144. * Once we receive a SYN_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
  145. * (and notify everyone about the new connection and send
  146. * back a ACK). If the operation times out, we go to
  147. * #GNUNET_TRANSPORT_PS_DISCONNECT.
  148. *
  149. * If the session is in trouble (i.e. transport-level disconnect or
  150. * timeout), we go to #GNUNET_TRANSPORT_PS_RECONNECT_ATS where we ask ATS for a
  151. * new address (we don't notify anyone about the disconnect yet). Once we have
  152. * a new address, we enter #GNUNET_TRANSPORT_PS_RECONNECT_SENT and send a SYN
  153. * message. If we receive a SYN_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
  154. * and nobody noticed that we had trouble; we also send a ACK at this time just
  155. * in case. If the operation times out, we go to
  156. * #GNUNET_TRANSPORT_PS_DISCONNECT (and notify everyone about the lost
  157. * connection).
  158. *
  159. * If ATS decides to switch addresses while we have a normal
  160. * connection, we go to #GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_SYN_SENT
  161. * and send a SESSION_CONNECT. If we get a ACK back, we switch the
  162. * primary connection to the suggested alternative from ATS, go back
  163. * to #GNUNET_TRANSPORT_PS_CONNECTED and send a ACK to the other peer just to be
  164. * sure. If the operation times out
  165. * we go to #GNUNET_TRANSPORT_PS_CONNECTED (and notify ATS that the given
  166. * alternative address is "invalid").
  167. *
  168. * Once a session is in #GNUNET_TRANSPORT_PS_DISCONNECT, it is cleaned up and
  169. * then goes to (#GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED). If we receive an
  170. * explicit disconnect request, we can go from any state to
  171. * #GNUNET_TRANSPORT_PS_DISCONNECT, possibly after generating disconnect
  172. * notifications.
  173. *
  174. * Note that it is quite possible that while we are in any of these
  175. * states, we could receive a 'SYN' request from the other peer.
  176. * We then enter a 'weird' state where we pursue our own primary state
  177. * machine (as described above), but with the 'send_connect_ack' flag
  178. * set to 1. If our state machine allows us to send a 'SYN_ACK'
  179. * (because we have an acceptable address), we send the 'SYN_ACK'
  180. * and set the 'send_connect_ack' to 2. If we then receive a
  181. * 'ACK', we go to #GNUNET_TRANSPORT_PS_CONNECTED (and reset 'send_connect_ack'
  182. * to 0).
  183. *
  184. */
  185. enum GNUNET_TRANSPORT_PeerState
  186. {
  187. /**
  188. * Fresh peer or completely disconnected
  189. */
  190. GNUNET_TRANSPORT_PS_NOT_CONNECTED = 0,
  191. /**
  192. * Asked to initiate connection, trying to get address from ATS
  193. */
  194. GNUNET_TRANSPORT_PS_INIT_ATS,
  195. /**
  196. * Sent SYN message to other peer, waiting for SYN_ACK
  197. */
  198. GNUNET_TRANSPORT_PS_SYN_SENT,
  199. /**
  200. * Received a SYN, asking ATS about address suggestions.
  201. */
  202. GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
  203. /**
  204. * SYN request from other peer was SYN_ACK'ed, waiting for ACK.
  205. */
  206. GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
  207. /**
  208. * Got our SYN_ACK/ACK, connection is up.
  209. */
  210. GNUNET_TRANSPORT_PS_CONNECTED,
  211. /**
  212. * Connection got into trouble, rest of the system still believes
  213. * it to be up, but we're getting a new address from ATS.
  214. */
  215. GNUNET_TRANSPORT_PS_RECONNECT_ATS,
  216. /**
  217. * Sent SYN over new address (either by ATS telling us to switch
  218. * addresses or from RECONNECT_ATS); if this fails, we need to tell
  219. * the rest of the system about a disconnect.
  220. */
  221. GNUNET_TRANSPORT_PS_RECONNECT_SENT,
  222. /**
  223. * We have some primary connection, but ATS suggested we switch
  224. * to some alternative; we now sent a SYN message for the
  225. * alternative session to the other peer and waiting for a
  226. * SYN_ACK to make this our primary connection.
  227. */
  228. GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
  229. /**
  230. * Disconnect in progress (we're sending the DISCONNECT message to the
  231. * other peer; after that is finished, the state will be cleaned up).
  232. */
  233. GNUNET_TRANSPORT_PS_DISCONNECT,
  234. /**
  235. * We're finished with the disconnect; and are cleaning up the state
  236. * now! We put the struct into this state when we are really in the
  237. * task that calls 'free' on it and are about to remove the record
  238. * from the map. We should never find a 'struct NeighbourMapEntry'
  239. * in this state in the map. Accessing a 'struct NeighbourMapEntry'
  240. * in this state virtually always means using memory that has been
  241. * freed (the exception being the cleanup code in #free_neighbour()).
  242. */
  243. GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED
  244. };
  245. /**
  246. * Convert a transport state to a human readable string.
  247. *
  248. * @param state the state
  249. */
  250. const char *
  251. GNUNET_TRANSPORT_ps2s (enum GNUNET_TRANSPORT_PeerState state);
  252. /**
  253. * Check if a state is defined as connected
  254. *
  255. * @param state the state value
  256. * @return #GNUNET_YES or #GNUNET_NO
  257. */
  258. int
  259. GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state);
  260. /**
  261. * Handle for a #GNUNET_TRANSPORT_monitor_peers operation.
  262. */
  263. struct GNUNET_TRANSPORT_PeerMonitoringContext;
  264. /**
  265. * Function to call with information about a peer
  266. *
  267. * If one_shot was set to #GNUNET_YES to iterate over all peers once,
  268. * a final call with NULL for peer and address will follow when done.
  269. * In this case state and timeout do not contain valid values.
  270. *
  271. * The #GNUNET_TRANSPORT_monitor_peers_cancel() call MUST not be called from
  272. * within this function!
  273. *
  274. *
  275. * @param cls closure
  276. * @param peer peer this update is about,
  277. * NULL if this is the final last callback for a iteration operation
  278. * @param address address, NULL if this is the final callback for iteration op
  279. * @param state current state this peer is in
  280. * @param state_timeout timeout for the current state of the peer
  281. */
  282. typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) (
  283. void *cls,
  284. const struct GNUNET_PeerIdentity *peer,
  285. const struct GNUNET_HELLO_Address *address,
  286. enum GNUNET_TRANSPORT_PeerState state,
  287. struct GNUNET_TIME_Absolute state_timeout);
  288. /**
  289. * Return information about a specific peer or all peers currently known to
  290. * transport service once or in monitoring mode. To obtain information about
  291. * a specific peer, a peer identity can be passed. To obtain information about
  292. * all peers currently known to transport service, NULL can be passed as peer
  293. * identity.
  294. *
  295. * For each peer, the callback is called with information about the address used
  296. * to communicate with this peer, the state this peer is currently in and the
  297. * the current timeout for this state.
  298. *
  299. * Upon completion, the #GNUNET_TRANSPORT_PeerIterateCallback is called one
  300. * more time with `NULL`. After this, the operation must no longer be
  301. * explicitly canceled.
  302. *
  303. * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called in the
  304. * the peer_callback!
  305. *
  306. * @param cfg configuration to use
  307. * @param peer a specific peer identity to obtain information for,
  308. * NULL for all peers
  309. * @param one_shot #GNUNET_YES to return the current state and then end (with
  310. * NULL+NULL), #GNUNET_NO to monitor peers continuously
  311. * @param peer_callback function to call with the results
  312. * @param peer_callback_cls closure for @a peer_callback
  313. */
  314. struct GNUNET_TRANSPORT_PeerMonitoringContext *
  315. GNUNET_TRANSPORT_monitor_peers (
  316. const struct GNUNET_CONFIGURATION_Handle *cfg,
  317. const struct GNUNET_PeerIdentity *peer,
  318. int one_shot,
  319. GNUNET_TRANSPORT_PeerIterateCallback peer_callback,
  320. void *peer_callback_cls);
  321. /**
  322. * Cancel request to monitor peers
  323. *
  324. * @param pic handle for the request to cancel
  325. */
  326. void
  327. GNUNET_TRANSPORT_monitor_peers_cancel (
  328. struct GNUNET_TRANSPORT_PeerMonitoringContext *pic);
  329. /* *********************** Blacklisting ************************ */
  330. /**
  331. * Handle for blacklisting peers.
  332. */
  333. struct GNUNET_TRANSPORT_Blacklist;
  334. /**
  335. * Function that decides if a connection is acceptable or not.
  336. *
  337. * @param cls closure
  338. * @param pid peer to approve or disapproave
  339. * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
  340. */
  341. typedef int (*GNUNET_TRANSPORT_BlacklistCallback) (
  342. void *cls,
  343. const struct GNUNET_PeerIdentity *pid);
  344. /**
  345. * Install a blacklist callback. The service will be queried for all
  346. * existing connections as well as any fresh connections to check if
  347. * they are permitted. If the blacklisting callback is unregistered,
  348. * all hosts that were denied in the past will automatically be
  349. * whitelisted again. Cancelling the blacklist handle is also the
  350. * only way to re-enable connections from peers that were previously
  351. * blacklisted.
  352. *
  353. * @param cfg configuration to use
  354. * @param cb callback to invoke to check if connections are allowed
  355. * @param cb_cls closure for @a cb
  356. * @return NULL on error, otherwise handle for cancellation
  357. */
  358. struct GNUNET_TRANSPORT_Blacklist *
  359. GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
  360. GNUNET_TRANSPORT_BlacklistCallback cb,
  361. void *cb_cls);
  362. /**
  363. * Abort the blacklist. Note that this function is the only way for
  364. * removing a peer from the blacklist.
  365. *
  366. * @param br handle of the request that is to be cancelled
  367. */
  368. void
  369. GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
  370. /**
  371. * Handle for a plugin session state monitor.
  372. */
  373. struct GNUNET_TRANSPORT_PluginMonitor;
  374. /**
  375. * Abstract representation of a plugin's session.
  376. * Corresponds to the `struct GNUNET_ATS_Session` within the TRANSPORT service.
  377. */
  378. struct GNUNET_TRANSPORT_PluginSession;
  379. /**
  380. * Possible states of a session in a plugin.
  381. */
  382. enum GNUNET_TRANSPORT_SessionState
  383. {
  384. /**
  385. * The session was created (first call for each session object).
  386. */
  387. GNUNET_TRANSPORT_SS_INIT,
  388. /**
  389. * Initial session handshake is in progress.
  390. */
  391. GNUNET_TRANSPORT_SS_HANDSHAKE,
  392. /**
  393. * Session is fully UP.
  394. */
  395. GNUNET_TRANSPORT_SS_UP,
  396. /**
  397. * This is just an update about the session,
  398. * the state did not change.
  399. */
  400. GNUNET_TRANSPORT_SS_UPDATE,
  401. /**
  402. * Session is being torn down and about to disappear.
  403. * Last call for each session object.
  404. */
  405. GNUNET_TRANSPORT_SS_DONE
  406. };
  407. /**
  408. * Information about a plugin's session.
  409. */
  410. struct GNUNET_TRANSPORT_SessionInfo
  411. {
  412. /**
  413. * New state of the session.
  414. */
  415. enum GNUNET_TRANSPORT_SessionState state;
  416. /**
  417. * #GNUNET_YES if this is an inbound connection,
  418. * #GNUNET_NO if this is an outbound connection,
  419. * #GNUNET_SYSERR if connections of this plugin
  420. * are so fundamentally bidirectional
  421. * that they have no 'initiator'
  422. */
  423. int is_inbound;
  424. /**
  425. * Number of messages pending transmission for this session.
  426. */
  427. uint32_t num_msg_pending;
  428. /**
  429. * Number of bytes pending transmission for this session.
  430. */
  431. uint32_t num_bytes_pending;
  432. /**
  433. * Until when does this plugin refuse to receive to manage
  434. * staying within the inbound quota? ZERO if receive is
  435. * active.
  436. */
  437. struct GNUNET_TIME_Absolute receive_delay;
  438. /**
  439. * At what time will this session timeout (unless activity
  440. * happens)?
  441. */
  442. struct GNUNET_TIME_Absolute session_timeout;
  443. /**
  444. * Address used by the session. Can be NULL if none is available.
  445. */
  446. const struct GNUNET_HELLO_Address *address;
  447. };
  448. /**
  449. * Function called by the plugin with information about the
  450. * current sessions managed by the plugin (for monitoring).
  451. *
  452. * @param cls closure
  453. * @param session session handle this information is about,
  454. * NULL to indicate that we are "in sync" (initial
  455. * iteration complete)
  456. * @param session_ctx storage location where the application
  457. * can store data; will point to NULL on #GNUNET_TRANSPORT_SS_INIT,
  458. * and must be reset to NULL on #GNUNET_TRANSPORT_SS_DONE
  459. * @param info information about the state of the session,
  460. * NULL if @a session is also NULL and we are
  461. * merely signalling that the initial iteration is over;
  462. * NULL with @a session being non-NULL if the monitor
  463. * was being cancelled while sessions were active
  464. */
  465. typedef void (*GNUNET_TRANSPORT_SessionMonitorCallback) (
  466. void *cls,
  467. struct GNUNET_TRANSPORT_PluginSession *session,
  468. void **session_ctx,
  469. const struct GNUNET_TRANSPORT_SessionInfo *info);
  470. /**
  471. * Install a plugin session state monitor callback. The callback
  472. * will be notified whenever the session changes.
  473. *
  474. * @param cfg configuration to use
  475. * @param cb callback to invoke on events
  476. * @param cb_cls closure for @a cb
  477. * @return NULL on error, otherwise handle for cancellation
  478. */
  479. struct GNUNET_TRANSPORT_PluginMonitor *
  480. GNUNET_TRANSPORT_monitor_plugins (const struct GNUNET_CONFIGURATION_Handle *cfg,
  481. GNUNET_TRANSPORT_SessionMonitorCallback cb,
  482. void *cb_cls);
  483. /**
  484. * Cancel monitoring the plugin session state. The callback will be
  485. * called once for each session that is up with the "info" argument
  486. * being NULL (this is just to enable client-side cleanup).
  487. *
  488. * @param pm handle of the request that is to be cancelled
  489. */
  490. void
  491. GNUNET_TRANSPORT_monitor_plugins_cancel (
  492. struct GNUNET_TRANSPORT_PluginMonitor *pm);
  493. /**
  494. * Opaque handle to the service.
  495. */
  496. struct GNUNET_TRANSPORT_CoreHandle;
  497. /**
  498. * Function called to notify transport users that another
  499. * peer connected to us.
  500. *
  501. * @param cls closure
  502. * @param peer the identity of the peer that connected; this
  503. * pointer will remain valid until the disconnect, hence
  504. * applications do not necessarily have to make a copy
  505. * of the value if they only need it until disconnect
  506. * @param mq message queue to use to transmit to @a peer
  507. * @return closure to use in MQ handlers
  508. */
  509. typedef void *(*GNUNET_TRANSPORT_NotifyConnect) (
  510. void *cls,
  511. const struct GNUNET_PeerIdentity *peer,
  512. struct GNUNET_MQ_Handle *mq);
  513. /**
  514. * Function called to notify transport users that another peer
  515. * disconnected from us. The message queue that was given to the
  516. * connect notification will be destroyed and must not be used
  517. * henceforth.
  518. *
  519. * @param cls closure from #GNUNET_TRANSPORT_core_connect
  520. * @param peer the peer that disconnected
  521. * @param handlers_cls closure of the handlers, was returned from the
  522. * connect notification callback
  523. */
  524. typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (
  525. void *cls,
  526. const struct GNUNET_PeerIdentity *peer,
  527. void *handler_cls);
  528. /**
  529. * Function called if we have "excess" bandwidth to a peer.
  530. * The notification will happen the first time we have excess
  531. * bandwidth, and then only again after the client has performed
  532. * some transmission to the peer.
  533. *
  534. * Excess bandwidth is defined as being allowed (by ATS) to send
  535. * more data, and us reaching the limit of the capacity build-up
  536. * (which, if we go past it, means we don't use available bandwidth).
  537. * See also the "max carry" in `struct GNUNET_BANDWIDTH_Tracker`.
  538. *
  539. * @param cls the closure
  540. * @param neighbour peer that we have excess bandwidth to
  541. * @param handlers_cls closure of the handlers, was returned from the
  542. * connect notification callback
  543. */
  544. typedef void (*GNUNET_TRANSPORT_NotifyExcessBandwidth) (
  545. void *cls,
  546. const struct GNUNET_PeerIdentity *neighbour,
  547. void *handlers_cls);
  548. /**
  549. * Connect to the transport service. Note that the connection may
  550. * complete (or fail) asynchronously.
  551. *
  552. * @param cfg configuration to use
  553. * @param self our own identity (API should check that it matches
  554. * the identity found by transport), or NULL (no check)
  555. * @param handlers array of message handlers; note that the
  556. * closures provided will be ignored and replaced
  557. * with the respective return value from @a nc
  558. * @param handlers array with handlers to call when we receive messages, or NULL
  559. * @param cls closure for the @a nc, @a nd and @a neb callbacks
  560. * @param nc function to call on connect events, or NULL
  561. * @param nd function to call on disconnect events, or NULL
  562. * @param neb function to call if we have excess bandwidth to a peer, or NULL
  563. * @return NULL on error
  564. */
  565. struct GNUNET_TRANSPORT_CoreHandle *
  566. GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
  567. const struct GNUNET_PeerIdentity *self,
  568. const struct GNUNET_MQ_MessageHandler *handlers,
  569. void *cls,
  570. GNUNET_TRANSPORT_NotifyConnect nc,
  571. GNUNET_TRANSPORT_NotifyDisconnect nd,
  572. GNUNET_TRANSPORT_NotifyExcessBandwidth neb);
  573. /**
  574. * Disconnect from the transport service.
  575. *
  576. * @param handle handle returned from connect
  577. */
  578. void
  579. GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle);
  580. /**
  581. * Checks if a given peer is connected to us and get the message queue.
  582. *
  583. * @param handle connection to transport service
  584. * @param peer the peer to check
  585. * @return NULL if disconnected, otherwise message queue for @a peer
  586. */
  587. struct GNUNET_MQ_Handle *
  588. GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
  589. const struct GNUNET_PeerIdentity *peer);
  590. #if 0 /* keep Emacsens' auto-indent happy */
  591. {
  592. #endif
  593. #ifdef __cplusplus
  594. }
  595. #endif
  596. /* ifndef GNUNET_TRANSPORT_SERVICE_H */
  597. #endif
  598. /** @} */ /* end of group */
  599. /* end of gnunet_transport_service.h */