gnunet_transport_service.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2009-2014 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. 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. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. /**
  18. * @author Christian Grothoff
  19. *
  20. * @file
  21. * Low-level P2P IO
  22. *
  23. * @defgroup transport Transport service
  24. * Low-level P2P IO
  25. * @{
  26. */
  27. #ifndef GNUNET_TRANSPORT_SERVICE_H
  28. #define GNUNET_TRANSPORT_SERVICE_H
  29. #ifdef __cplusplus
  30. extern "C"
  31. {
  32. #if 0 /* keep Emacsens' auto-indent happy */
  33. }
  34. #endif
  35. #endif
  36. #include "gnunet_util_lib.h"
  37. #include "gnunet_ats_service.h"
  38. /**
  39. * Version number of the transport API.
  40. */
  41. #define GNUNET_TRANSPORT_VERSION 0x00000002
  42. /**
  43. * Function called by the transport for each received message.
  44. *
  45. * @param cls closure
  46. * @param peer (claimed) identity of the other peer
  47. * @param message the message
  48. */
  49. typedef void
  50. (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
  51. const struct GNUNET_PeerIdentity *peer,
  52. const struct GNUNET_MessageHeader *message);
  53. /**
  54. * Opaque handle to the service.
  55. */
  56. struct GNUNET_TRANSPORT_Handle;
  57. /**
  58. * Function called to notify transport users that another
  59. * peer connected to us.
  60. *
  61. * @param cls closure
  62. * @param peer the peer that connected
  63. */
  64. typedef void
  65. (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
  66. const struct GNUNET_PeerIdentity *peer);
  67. /**
  68. * Function called to notify transport users that another
  69. * peer disconnected from us.
  70. *
  71. * @param cls closure
  72. * @param peer the peer that disconnected
  73. */
  74. typedef void
  75. (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
  76. const struct GNUNET_PeerIdentity *peer);
  77. /**
  78. * Connect to the transport service. Note that the connection may
  79. * complete (or fail) asynchronously.
  80. *
  81. * @param cfg configuration to use
  82. * @param self our own identity (API should check that it matches
  83. * the identity found by transport), or NULL (no check)
  84. * @param cls closure for the callbacks
  85. * @param rec receive function to call, or NULL
  86. * @param nc function to call on connect events, or NULL
  87. * @param nd function to call on disconnect events, or NULL
  88. * @return NULL on error
  89. */
  90. struct GNUNET_TRANSPORT_Handle *
  91. GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
  92. const struct GNUNET_PeerIdentity *self,
  93. void *cls,
  94. GNUNET_TRANSPORT_ReceiveCallback rec,
  95. GNUNET_TRANSPORT_NotifyConnect nc,
  96. GNUNET_TRANSPORT_NotifyDisconnect nd);
  97. /**
  98. * Function called if we have "excess" bandwidth to a peer.
  99. * The notification will happen the first time we have excess
  100. * bandwidth, and then only again after the client has performed
  101. * some transmission to the peer.
  102. *
  103. * Excess bandwidth is defined as being allowed (by ATS) to send
  104. * more data, and us reaching the limit of the capacity build-up
  105. * (which, if we go past it, means we don't use available bandwidth).
  106. * See also the "max carry" in `struct GNUNET_BANDWIDTH_Tracker`.
  107. *
  108. * @param cls the closure
  109. * @param neighbour peer that we have excess bandwidth to
  110. */
  111. typedef void
  112. (*GNUNET_TRANSPORT_NotifyExcessBandwidth)(void *cls,
  113. const struct GNUNET_PeerIdentity *neighbour);
  114. /**
  115. * Connect to the transport service. Note that the connection may
  116. * complete (or fail) asynchronously.
  117. *
  118. * @param cfg configuration to use
  119. * @param self our own identity (API should check that it matches
  120. * the identity found by transport), or NULL (no check)
  121. * @param cls closure for the callbacks
  122. * @param rec receive function to call, or NULL
  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
  126. * @return NULL on error
  127. */
  128. struct GNUNET_TRANSPORT_Handle *
  129. GNUNET_TRANSPORT_connect2 (const struct GNUNET_CONFIGURATION_Handle *cfg,
  130. const struct GNUNET_PeerIdentity *self,
  131. void *cls,
  132. GNUNET_TRANSPORT_ReceiveCallback rec,
  133. GNUNET_TRANSPORT_NotifyConnect nc,
  134. GNUNET_TRANSPORT_NotifyDisconnect nd,
  135. GNUNET_TRANSPORT_NotifyExcessBandwidth neb);
  136. /**
  137. * Disconnect from the transport service.
  138. *
  139. * @param handle handle returned from connect
  140. */
  141. void
  142. GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
  143. /* ************************* Sending *************************** */
  144. /**
  145. * Opaque handle for a transmission-ready request.
  146. */
  147. struct GNUNET_TRANSPORT_TransmitHandle;
  148. /**
  149. * Function called to notify a client about the connection begin ready
  150. * to queue more data. @a buf will be NULL and @a size zero if the
  151. * connection was closed for writing in the meantime.
  152. *
  153. * @param cls closure
  154. * @param size number of bytes available in @a buf
  155. * @param buf where the callee should write the message
  156. * @return number of bytes written to @a buf
  157. */
  158. typedef size_t
  159. (*GNUNET_TRANSPORT_TransmitReadyNotify) (void *cls,
  160. size_t size,
  161. void *buf);
  162. /**
  163. * Check if we could queue a message of the given size for
  164. * transmission. The transport service will take both its internal
  165. * buffers and bandwidth limits imposed by the other peer into
  166. * consideration when answering this query.
  167. *
  168. * @param handle connection to transport service
  169. * @param target who should receive the message
  170. * @param size how big is the message we want to transmit?
  171. * @param timeout after how long should we give up (and call
  172. * notify with buf NULL and size 0)?
  173. * @param notify function to call when we are ready to
  174. * send such a message
  175. * @param notify_cls closure for @a notify
  176. * @return NULL if someone else is already waiting to be notified
  177. * non-NULL if the notify callback was queued (can be used to cancel
  178. * using #GNUNET_TRANSPORT_notify_transmit_ready_cancel())
  179. */
  180. struct GNUNET_TRANSPORT_TransmitHandle *
  181. GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
  182. const struct GNUNET_PeerIdentity *target,
  183. size_t size,
  184. struct GNUNET_TIME_Relative timeout,
  185. GNUNET_TRANSPORT_TransmitReadyNotify notify,
  186. void *notify_cls);
  187. /**
  188. * Cancel the specified transmission-ready notification.
  189. *
  190. * @param th handle of the transmission notification request to cancel
  191. */
  192. void
  193. GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct GNUNET_TRANSPORT_TransmitHandle *th);
  194. /**
  195. * Checks if a given peer is connected to us
  196. *
  197. * @param handle connection to transport service
  198. * @param peer the peer to check
  199. * @return #GNUNET_YES (connected) or #GNUNET_NO (disconnected)
  200. */
  201. int
  202. GNUNET_TRANSPORT_check_peer_connected (struct GNUNET_TRANSPORT_Handle *handle,
  203. const struct GNUNET_PeerIdentity *peer);
  204. /* *********************** Metric manipulation ***************** */
  205. /**
  206. * Set transport metrics for a peer and a direction
  207. *
  208. * @param handle transport handle
  209. * @param peer the peer to set the metric for
  210. * @param prop the performance metrics to set
  211. * @param delay_in inbound delay to introduce
  212. * @param delay_out outbound delay to introduce
  213. *
  214. * Note: Delay restrictions in receiving direction will be enforced
  215. * with one message delay.
  216. */
  217. void
  218. GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle,
  219. const struct GNUNET_PeerIdentity *peer,
  220. const struct GNUNET_ATS_Properties *prop,
  221. struct GNUNET_TIME_Relative delay_in,
  222. struct GNUNET_TIME_Relative delay_out);
  223. /* *************************** HELLO *************************** */
  224. /**
  225. * Function called whenever there is an update to the
  226. * HELLO of this peer.
  227. *
  228. * @param cls closure
  229. * @param hello our updated HELLO
  230. */
  231. typedef void
  232. (*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls,
  233. const struct GNUNET_MessageHeader *hello);
  234. /**
  235. * Handle to cancel a #GNUNET_TRANSPORT_get_hello() operation.
  236. */
  237. struct GNUNET_TRANSPORT_GetHelloHandle;
  238. /**
  239. * Obtain updates on changes to the HELLO message for this peer. The callback
  240. * given in this function is never called synchronously.
  241. *
  242. * @param handle connection to transport service
  243. * @param rec function to call with the HELLO
  244. * @param rec_cls closure for @a rec
  245. * @return handle to cancel the operation
  246. */
  247. struct GNUNET_TRANSPORT_GetHelloHandle *
  248. GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
  249. GNUNET_TRANSPORT_HelloUpdateCallback rec,
  250. void *rec_cls);
  251. /**
  252. * Stop receiving updates about changes to our HELLO message.
  253. *
  254. * @param ghh handle to cancel
  255. */
  256. void
  257. GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh);
  258. /**
  259. * Handle for a #GNUNET_TRANSPORT_offer_hello operation
  260. */
  261. struct GNUNET_TRANSPORT_OfferHelloHandle;
  262. /**
  263. * Offer the transport service the HELLO of another peer. Note that
  264. * the transport service may just ignore this message if the HELLO is
  265. * malformed or useless due to our local configuration.
  266. *
  267. * @param handle connection to transport service
  268. * @param hello the hello message
  269. * @param cont continuation to call when HELLO has been sent,
  270. * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail
  271. * tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success
  272. * @param cont_cls closure for @a cont
  273. * @return a GNUNET_TRANSPORT_OfferHelloHandle handle or NULL on failure,
  274. * in case of failure @a cont will not be called
  275. *
  276. */
  277. struct GNUNET_TRANSPORT_OfferHelloHandle *
  278. GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
  279. const struct GNUNET_MessageHeader *hello,
  280. GNUNET_SCHEDULER_TaskCallback cont,
  281. void *cont_cls);
  282. /**
  283. * Cancel the request to transport to offer the HELLO message
  284. *
  285. * @param ohh the `struct GNUNET_TRANSPORT_OfferHelloHandle` to cancel
  286. */
  287. void
  288. GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh);
  289. /* *********************** Address to String ******************* */
  290. /**
  291. * Handle to cancel a pending address lookup.
  292. */
  293. struct GNUNET_TRANSPORT_AddressToStringContext;
  294. /**
  295. * Function to call with a textual representation of an address. This
  296. * function will be called several times with different possible
  297. * textual representations, and a last time with @a address being NULL
  298. * to signal the end of the iteration. Note that @a address NULL
  299. * always is the last call, regardless of the value in @a res.
  300. *
  301. * @param cls closure
  302. * @param address NULL on end of iteration,
  303. * otherwise 0-terminated printable UTF-8 string,
  304. * in particular an empty string if @a res is #GNUNET_NO
  305. * @param res result of the address to string conversion:
  306. * if #GNUNET_OK: conversion successful
  307. * if #GNUNET_NO: address was invalid (or not supported)
  308. * if #GNUNET_SYSERR: communication error (IPC error)
  309. */
  310. typedef void
  311. (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
  312. const char *address,
  313. int res);
  314. /**
  315. * Convert a binary address into a human readable address.
  316. *
  317. * @param cfg configuration to use
  318. * @param address address to convert (binary format)
  319. * @param numeric should (IP) addresses be displayed in numeric form
  320. * (otherwise do reverse DNS lookup)
  321. * @param timeout how long is the lookup allowed to take at most
  322. * @param aluc function to call with the results
  323. * @param aluc_cls closure for @a aluc
  324. * @return handle to cancel the operation, NULL on error
  325. */
  326. struct GNUNET_TRANSPORT_AddressToStringContext *
  327. GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
  328. const struct GNUNET_HELLO_Address *address,
  329. int numeric,
  330. struct GNUNET_TIME_Relative timeout,
  331. GNUNET_TRANSPORT_AddressToStringCallback aluc,
  332. void *aluc_cls);
  333. /**
  334. * Cancel request for address conversion.
  335. *
  336. * @param pic the context handle
  337. */
  338. void
  339. GNUNET_TRANSPORT_address_to_string_cancel (struct GNUNET_TRANSPORT_AddressToStringContext *pic);
  340. /* *********************** Monitoring ************************** */
  341. /**
  342. * Possible state of a neighbour. Initially, we are #GNUNET_TRANSPORT_PS_NOT_CONNECTED.
  343. *
  344. * Then, there are two main paths. If we receive a SYN message, we give
  345. * the inbound address to ATS. After the check we ask ATS for a suggestion
  346. * (#GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS). If ATS makes a suggestion, we
  347. * send our SYN_ACK and go to #GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK.
  348. * If we receive a ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
  349. * (and notify everyone about the new connection). If the operation times out,
  350. * we go to #GNUNET_TRANSPORT_PS_DISCONNECT.
  351. *
  352. * The other case is where we transmit a SYN message first. We
  353. * start with #GNUNET_TRANSPORT_PS_INIT_ATS. If we get an address, we send
  354. * the SYN message and go to state #GNUNET_TRANSPORT_PS_CONNECT_SENT.
  355. * Once we receive a SYN_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED
  356. * (and notify everyone about the new connection and send
  357. * back a ACK). If the operation times out, we go to
  358. * #GNUNET_TRANSPORT_PS_DISCONNECT.
  359. *
  360. * If the session is in trouble (i.e. transport-level disconnect or
  361. * timeout), we go to #GNUNET_TRANSPORT_PS_RECONNECT_ATS where we ask ATS for a new
  362. * address (we don't notify anyone about the disconnect yet). Once we
  363. * have a new address, we enter #GNUNET_TRANSPORT_PS_RECONNECT_SENT and send a
  364. * SYN message. If we receive a
  365. * SYN_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED and nobody noticed that we had
  366. * trouble; we also send a ACK at this time just in case. If
  367. * the operation times out, we go to #GNUNET_TRANSPORT_PS_DISCONNECT (and notify everyone
  368. * about the lost connection).
  369. *
  370. * If ATS decides to switch addresses while we have a normal
  371. * connection, we go to #GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_SYN_SENT
  372. * and send a SESSION_CONNECT. If we get a ACK back, we switch the
  373. * primary connection to the suggested alternative from ATS, go back
  374. * to #GNUNET_TRANSPORT_PS_CONNECTED and send a ACK to the other peer just to be
  375. * sure. If the operation times out
  376. * we go to #GNUNET_TRANSPORT_PS_CONNECTED (and notify ATS that the given alternative
  377. * address is "invalid").
  378. *
  379. * Once a session is in #GNUNET_TRANSPORT_PS_DISCONNECT, it is cleaned up and then goes
  380. * to (#GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED). If we receive an explicit disconnect
  381. * request, we can go from any state to #GNUNET_TRANSPORT_PS_DISCONNECT, possibly after
  382. * generating disconnect notifications.
  383. *
  384. * Note that it is quite possible that while we are in any of these
  385. * states, we could receive a 'SYN' request from the other peer.
  386. * We then enter a 'weird' state where we pursue our own primary state
  387. * machine (as described above), but with the 'send_connect_ack' flag
  388. * set to 1. If our state machine allows us to send a 'SYN_ACK'
  389. * (because we have an acceptable address), we send the 'SYN_ACK'
  390. * and set the 'send_connect_ack' to 2. If we then receive a
  391. * 'ACK', we go to #GNUNET_TRANSPORT_PS_CONNECTED (and reset 'send_connect_ack'
  392. * to 0).
  393. *
  394. */
  395. enum GNUNET_TRANSPORT_PeerState
  396. {
  397. /**
  398. * Fresh peer or completely disconnected
  399. */
  400. GNUNET_TRANSPORT_PS_NOT_CONNECTED = 0,
  401. /**
  402. * Asked to initiate connection, trying to get address from ATS
  403. */
  404. GNUNET_TRANSPORT_PS_INIT_ATS,
  405. /**
  406. * Sent SYN message to other peer, waiting for SYN_ACK
  407. */
  408. GNUNET_TRANSPORT_PS_SYN_SENT,
  409. /**
  410. * Received a SYN, asking ATS about address suggestions.
  411. */
  412. GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
  413. /**
  414. * SYN request from other peer was SYN_ACK'ed, waiting for ACK.
  415. */
  416. GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
  417. /**
  418. * Got our SYN_ACK/ACK, connection is up.
  419. */
  420. GNUNET_TRANSPORT_PS_CONNECTED,
  421. /**
  422. * Connection got into trouble, rest of the system still believes
  423. * it to be up, but we're getting a new address from ATS.
  424. */
  425. GNUNET_TRANSPORT_PS_RECONNECT_ATS,
  426. /**
  427. * Sent SYN over new address (either by ATS telling us to switch
  428. * addresses or from RECONNECT_ATS); if this fails, we need to tell
  429. * the rest of the system about a disconnect.
  430. */
  431. GNUNET_TRANSPORT_PS_RECONNECT_SENT,
  432. /**
  433. * We have some primary connection, but ATS suggested we switch
  434. * to some alternative; we now sent a SYN message for the
  435. * alternative session to the other peer and waiting for a
  436. * SYN_ACK to make this our primary connection.
  437. */
  438. GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
  439. /**
  440. * Disconnect in progress (we're sending the DISCONNECT message to the
  441. * other peer; after that is finished, the state will be cleaned up).
  442. */
  443. GNUNET_TRANSPORT_PS_DISCONNECT,
  444. /**
  445. * We're finished with the disconnect; and are cleaning up the state
  446. * now! We put the struct into this state when we are really in the
  447. * task that calls 'free' on it and are about to remove the record
  448. * from the map. We should never find a 'struct NeighbourMapEntry'
  449. * in this state in the map. Accessing a 'struct NeighbourMapEntry'
  450. * in this state virtually always means using memory that has been
  451. * freed (the exception being the cleanup code in #free_neighbour()).
  452. */
  453. GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED
  454. };
  455. /**
  456. * Convert a transport state to a human readable string.
  457. *
  458. * @param state the state
  459. */
  460. const char *
  461. GNUNET_TRANSPORT_ps2s (enum GNUNET_TRANSPORT_PeerState state);
  462. /**
  463. * Check if a state is defined as connected
  464. *
  465. * @param state the state value
  466. * @return #GNUNET_YES or #GNUNET_NO
  467. */
  468. int
  469. GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state);
  470. /**
  471. * Handle for a #GNUNET_TRANSPORT_monitor_peers operation.
  472. */
  473. struct GNUNET_TRANSPORT_PeerMonitoringContext;
  474. /**
  475. * Function to call with information about a peer
  476. *
  477. * If one_shot was set to #GNUNET_YES to iterate over all peers once,
  478. * a final call with NULL for peer and address will follow when done.
  479. * In this case state and timeout do not contain valid values.
  480. *
  481. * The #GNUNET_TRANSPORT_monitor_peers_cancel() call MUST not be called from
  482. * within this function!
  483. *
  484. *
  485. * @param cls closure
  486. * @param peer peer this update is about,
  487. * NULL if this is the final last callback for a iteration operation
  488. * @param address address, NULL if this is the final callback for iteration op
  489. * @param state current state this peer is in
  490. * @param state_timeout timeout for the current state of the peer
  491. */
  492. typedef void
  493. (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls,
  494. const struct GNUNET_PeerIdentity *peer,
  495. const struct GNUNET_HELLO_Address *address,
  496. enum GNUNET_TRANSPORT_PeerState state,
  497. struct GNUNET_TIME_Absolute state_timeout);
  498. /**
  499. * Return information about a specific peer or all peers currently known to
  500. * transport service once or in monitoring mode. To obtain information about
  501. * a specific peer, a peer identity can be passed. To obtain information about
  502. * all peers currently known to transport service, NULL can be passed as peer
  503. * identity.
  504. *
  505. * For each peer, the callback is called with information about the address used
  506. * to communicate with this peer, the state this peer is currently in and the
  507. * the current timeout for this state.
  508. *
  509. * Upon completion, the #GNUNET_TRANSPORT_PeerIterateCallback is called one
  510. * more time with `NULL`. After this, the operation must no longer be
  511. * explicitly canceled.
  512. *
  513. * The #GNUNET_TRANSPORT_monitor_peers_cancel call MUST not be called in the
  514. * the peer_callback!
  515. *
  516. * @param cfg configuration to use
  517. * @param peer a specific peer identity to obtain information for,
  518. * NULL for all peers
  519. * @param one_shot #GNUNET_YES to return the current state and then end (with NULL+NULL),
  520. * #GNUNET_NO to monitor peers continuously
  521. * @param timeout how long is the lookup allowed to take at most
  522. * @param peer_callback function to call with the results
  523. * @param peer_callback_cls closure for @a peer_callback
  524. */
  525. struct GNUNET_TRANSPORT_PeerMonitoringContext *
  526. GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
  527. const struct GNUNET_PeerIdentity *peer,
  528. int one_shot,
  529. struct GNUNET_TIME_Relative timeout,
  530. GNUNET_TRANSPORT_PeerIterateCallback peer_callback,
  531. void *peer_callback_cls);
  532. /**
  533. * Cancel request to monitor peers
  534. *
  535. * @param pic handle for the request to cancel
  536. */
  537. void
  538. GNUNET_TRANSPORT_monitor_peers_cancel (struct GNUNET_TRANSPORT_PeerMonitoringContext *pic);
  539. /**
  540. * Handle for a #GNUNET_TRANSPORT_monitor_validation_entries() operation.
  541. */
  542. struct GNUNET_TRANSPORT_ValidationMonitoringContext;
  543. /**
  544. * Current state of a validation process.
  545. *
  546. * FIXME: what state is used to indicate that a validation
  547. * was successful? If that is clarified/determined, "UGH" in
  548. * ~gnunet-peerinfo-gtk.c:1103 should be resolved.
  549. */
  550. enum GNUNET_TRANSPORT_ValidationState
  551. {
  552. /**
  553. * Undefined state
  554. *
  555. * Used for final callback indicating operation done
  556. */
  557. GNUNET_TRANSPORT_VS_NONE,
  558. /**
  559. * Fresh validation entry
  560. *
  561. * Entry was just created, no validation process was executed
  562. */
  563. GNUNET_TRANSPORT_VS_NEW,
  564. /**
  565. * Updated validation entry
  566. *
  567. * This is an update for an existing validation entry
  568. */
  569. GNUNET_TRANSPORT_VS_UPDATE,
  570. /**
  571. * Timeout for validation entry
  572. *
  573. * A timeout occured during the validation process
  574. */
  575. GNUNET_TRANSPORT_VS_TIMEOUT,
  576. /**
  577. * Validation entry is removed
  578. *
  579. * The validation entry is getting removed due to a failed validation
  580. */
  581. GNUNET_TRANSPORT_VS_REMOVE
  582. };
  583. /**
  584. * Function to call with validation information about a peer
  585. *
  586. * This function is called by the transport validation monitoring api to
  587. * indicate a change to a validation entry. The information included represent
  588. * the current state of the validation entry,
  589. *
  590. * If the monitoring was called with `one_shot==GNUNET_YES`, a final callback
  591. * with `address==NULL` is executed.
  592. *
  593. * @param cls closure
  594. * @param address address this update is about,
  595. * NULL if this is the final last callback for a iteration operation
  596. * @param last_validation when was this address last validated
  597. * @param valid_until when does this address expire
  598. * @param next_validation time of the next validation operation
  599. * @param state state in the validation state machine
  600. */
  601. typedef void
  602. (*GNUNET_TRANSPORT_ValidationIterateCallback) (void *cls,
  603. const struct GNUNET_HELLO_Address *address,
  604. struct GNUNET_TIME_Absolute last_validation,
  605. struct GNUNET_TIME_Absolute valid_until,
  606. struct GNUNET_TIME_Absolute next_validation,
  607. enum GNUNET_TRANSPORT_ValidationState state);
  608. /**
  609. * Convert validation state to human-readable string.
  610. *
  611. * @param state the state value
  612. * @return corresponding string
  613. */
  614. const char *
  615. GNUNET_TRANSPORT_vs2s (enum GNUNET_TRANSPORT_ValidationState state);
  616. /**
  617. * Return information about pending address validation operations for a specific
  618. * or all peers
  619. *
  620. * @param cfg configuration to use
  621. * @param peer a specific peer identity to obtain validation entries for,
  622. * NULL for all peers
  623. * @param one_shot #GNUNET_YES to return all entries and then end (with NULL+NULL),
  624. * #GNUNET_NO to monitor validation entries continuously
  625. * @param timeout how long is the lookup allowed to take at most
  626. * @param validation_callback function to call with the results
  627. * @param validation_callback_cls closure for @a validation_callback
  628. */
  629. struct GNUNET_TRANSPORT_ValidationMonitoringContext *
  630. GNUNET_TRANSPORT_monitor_validation_entries (const struct GNUNET_CONFIGURATION_Handle *cfg,
  631. const struct GNUNET_PeerIdentity *peer,
  632. int one_shot,
  633. struct GNUNET_TIME_Relative timeout,
  634. GNUNET_TRANSPORT_ValidationIterateCallback validation_callback,
  635. void *validation_callback_cls);
  636. /**
  637. * Return information about all current pending validation operations
  638. *
  639. * @param vic handle for the request to cancel
  640. */
  641. void
  642. GNUNET_TRANSPORT_monitor_validation_entries_cancel (struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic);
  643. /* *********************** Blacklisting ************************ */
  644. /**
  645. * Handle for blacklisting peers.
  646. */
  647. struct GNUNET_TRANSPORT_Blacklist;
  648. /**
  649. * Function that decides if a connection is acceptable or not.
  650. *
  651. * @param cls closure
  652. * @param pid peer to approve or disapproave
  653. * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
  654. */
  655. typedef int
  656. (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls,
  657. const struct GNUNET_PeerIdentity *pid);
  658. /**
  659. * Install a blacklist callback. The service will be queried for all
  660. * existing connections as well as any fresh connections to check if
  661. * they are permitted. If the blacklisting callback is unregistered,
  662. * all hosts that were denied in the past will automatically be
  663. * whitelisted again. Cancelling the blacklist handle is also the
  664. * only way to re-enable connections from peers that were previously
  665. * blacklisted.
  666. *
  667. * @param cfg configuration to use
  668. * @param cb callback to invoke to check if connections are allowed
  669. * @param cb_cls closure for @a cb
  670. * @return NULL on error, otherwise handle for cancellation
  671. */
  672. struct GNUNET_TRANSPORT_Blacklist *
  673. GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
  674. GNUNET_TRANSPORT_BlacklistCallback cb,
  675. void *cb_cls);
  676. /**
  677. * Abort the blacklist. Note that this function is the only way for
  678. * removing a peer from the blacklist.
  679. *
  680. * @param br handle of the request that is to be cancelled
  681. */
  682. void
  683. GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br);
  684. /**
  685. * Handle for a plugin session state monitor.
  686. */
  687. struct GNUNET_TRANSPORT_PluginMonitor;
  688. /**
  689. * Abstract representation of a plugin's session.
  690. * Corresponds to the `struct GNUNET_ATS_Session` within the TRANSPORT service.
  691. */
  692. struct GNUNET_TRANSPORT_PluginSession;
  693. /**
  694. * Possible states of a session in a plugin.
  695. */
  696. enum GNUNET_TRANSPORT_SessionState
  697. {
  698. /**
  699. * The session was created (first call for each session object).
  700. */
  701. GNUNET_TRANSPORT_SS_INIT,
  702. /**
  703. * Initial session handshake is in progress.
  704. */
  705. GNUNET_TRANSPORT_SS_HANDSHAKE,
  706. /**
  707. * Session is fully UP.
  708. */
  709. GNUNET_TRANSPORT_SS_UP,
  710. /**
  711. * This is just an update about the session,
  712. * the state did not change.
  713. */
  714. GNUNET_TRANSPORT_SS_UPDATE,
  715. /**
  716. * Session is being torn down and about to disappear.
  717. * Last call for each session object.
  718. */
  719. GNUNET_TRANSPORT_SS_DONE
  720. };
  721. /**
  722. * Information about a plugin's session.
  723. */
  724. struct GNUNET_TRANSPORT_SessionInfo
  725. {
  726. /**
  727. * New state of the session.
  728. */
  729. enum GNUNET_TRANSPORT_SessionState state;
  730. /**
  731. * #GNUNET_YES if this is an inbound connection,
  732. * #GNUNET_NO if this is an outbound connection,
  733. * #GNUNET_SYSERR if connections of this plugin
  734. * are so fundamentally bidirectional
  735. * that they have no 'initiator'
  736. */
  737. int is_inbound;
  738. /**
  739. * Number of messages pending transmission for this session.
  740. */
  741. uint32_t num_msg_pending;
  742. /**
  743. * Number of bytes pending transmission for this session.
  744. */
  745. uint32_t num_bytes_pending;
  746. /**
  747. * Until when does this plugin refuse to receive to manage
  748. * staying within the inbound quota? ZERO if receive is
  749. * active.
  750. */
  751. struct GNUNET_TIME_Absolute receive_delay;
  752. /**
  753. * At what time will this session timeout (unless activity
  754. * happens)?
  755. */
  756. struct GNUNET_TIME_Absolute session_timeout;
  757. /**
  758. * Address used by the session. Can be NULL if none is available.
  759. */
  760. const struct GNUNET_HELLO_Address *address;
  761. };
  762. /**
  763. * Function called by the plugin with information about the
  764. * current sessions managed by the plugin (for monitoring).
  765. *
  766. * @param cls closure
  767. * @param session session handle this information is about,
  768. * NULL to indicate that we are "in sync" (initial
  769. * iteration complete)
  770. * @param session_ctx storage location where the application
  771. * can store data; will point to NULL on #GNUNET_TRANSPORT_SS_INIT,
  772. * and must be reset to NULL on #GNUNET_TRANSPORT_SS_DONE
  773. * @param info information about the state of the session,
  774. * NULL if @a session is also NULL and we are
  775. * merely signalling that the initial iteration is over;
  776. * NULL with @a session being non-NULL if the monitor
  777. * was being cancelled while sessions were active
  778. */
  779. typedef void
  780. (*GNUNET_TRANSPORT_SessionMonitorCallback) (void *cls,
  781. struct GNUNET_TRANSPORT_PluginSession *session,
  782. void **session_ctx,
  783. const struct GNUNET_TRANSPORT_SessionInfo *info);
  784. /**
  785. * Install a plugin session state monitor callback. The callback
  786. * will be notified whenever the session changes.
  787. *
  788. * @param cfg configuration to use
  789. * @param cb callback to invoke on events
  790. * @param cb_cls closure for @a cb
  791. * @return NULL on error, otherwise handle for cancellation
  792. */
  793. struct GNUNET_TRANSPORT_PluginMonitor *
  794. GNUNET_TRANSPORT_monitor_plugins (const struct GNUNET_CONFIGURATION_Handle *cfg,
  795. GNUNET_TRANSPORT_SessionMonitorCallback cb,
  796. void *cb_cls);
  797. /**
  798. * Cancel monitoring the plugin session state. The callback will be
  799. * called once for each session that is up with the "info" argument
  800. * being NULL (this is just to enable client-side cleanup).
  801. *
  802. * @param pm handle of the request that is to be cancelled
  803. */
  804. void
  805. GNUNET_TRANSPORT_monitor_plugins_cancel (struct GNUNET_TRANSPORT_PluginMonitor *pm);
  806. #if 0 /* keep Emacsens' auto-indent happy */
  807. {
  808. #endif
  809. #ifdef __cplusplus
  810. }
  811. #endif
  812. /* ifndef GNUNET_TRANSPORT_SERVICE_H */
  813. #endif
  814. /** @} */ /* end of group */
  815. /* end of gnunet_transport_service.h */