transport.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file transport/transport.h
  19. * @brief common internal definitions for transport service
  20. * @author Christian Grothoff
  21. */
  22. #ifndef TRANSPORT_H
  23. #define TRANSPORT_H
  24. #include "gnunet_crypto_lib.h"
  25. #include "gnunet_time_lib.h"
  26. #include "gnunet_transport_service.h"
  27. #include "gnunet_constants.h"
  28. #define DEBUG_TRANSPORT GNUNET_EXTRA_LOGGING
  29. /**
  30. * For how long do we allow unused bandwidth
  31. * from the past to carry over into the future? (in seconds)
  32. */
  33. #define MAX_BANDWIDTH_CARRY_S GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S
  34. /**
  35. * How often do we (at most) do a full quota
  36. * recalculation? (in ms)
  37. */
  38. #define MIN_QUOTA_REFRESH_TIME 2000
  39. /**
  40. * What's the maximum number of sockets transport uses for validation and
  41. * neighbors
  42. */
  43. #define DEFAULT_MAX_FDS 256
  44. /**
  45. * Maximum frequency for re-evaluating latencies for all transport addresses.
  46. */
  47. #define LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1)
  48. /**
  49. * Maximum frequency for re-evaluating latencies for connected addresses.
  50. */
  51. #define CONNECTED_LATENCY_EVALUATION_MAX_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
  52. /**
  53. * Similiar to GNUNET_TRANSPORT_NotifyDisconnect but in and out quotas are
  54. * included here. These values are not required outside transport_api
  55. *
  56. * @param cls closure
  57. * @param peer the peer that connected
  58. * @param bandwidth_in inbound bandwidth in NBO
  59. * @param bandwidth_out outbound bandwidth in NBO
  60. *
  61. */
  62. typedef void
  63. (*NotifyConnect) (void *cls,
  64. const struct GNUNET_PeerIdentity *peer,
  65. struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
  66. struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
  67. GNUNET_NETWORK_STRUCT_BEGIN
  68. /**
  69. * Message from the transport service to the library
  70. * asking to check if both processes agree about this
  71. * peers identity.
  72. */
  73. struct StartMessage
  74. {
  75. /**
  76. * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_START
  77. */
  78. struct GNUNET_MessageHeader header;
  79. /**
  80. * 0: no options
  81. * 1: The 'self' field should be checked
  82. * 2: this client is interested in payload traffic
  83. */
  84. uint32_t options;
  85. /**
  86. * Identity we think we have. If it does not match, the
  87. * receiver should print out an error message and disconnect.
  88. */
  89. struct GNUNET_PeerIdentity self;
  90. };
  91. /**
  92. * Message from the transport service to the library
  93. * informing about neighbors.
  94. */
  95. struct ConnectInfoMessage
  96. {
  97. /**
  98. * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
  99. */
  100. struct GNUNET_MessageHeader header;
  101. /**
  102. * Identity of the new neighbour.
  103. */
  104. struct GNUNET_PeerIdentity id;
  105. /**
  106. * Current inbound quota for this peer
  107. */
  108. struct GNUNET_BANDWIDTH_Value32NBO quota_in;
  109. /**
  110. * Current outbound quota for this peer
  111. */
  112. struct GNUNET_BANDWIDTH_Value32NBO quota_out;
  113. };
  114. /**
  115. * Message from the transport service to the library
  116. * informing about disconnects.
  117. */
  118. struct DisconnectInfoMessage
  119. {
  120. /**
  121. * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
  122. */
  123. struct GNUNET_MessageHeader header;
  124. /**
  125. * Reserved, always zero.
  126. */
  127. uint32_t reserved GNUNET_PACKED;
  128. /**
  129. * Who got disconnected?
  130. */
  131. struct GNUNET_PeerIdentity peer;
  132. };
  133. /**
  134. * Message type for sending a request connect message
  135. * to the transport service. Must be done before transport
  136. * api will allow messages to be queued/sent to transport
  137. * service for transmission to a peer.
  138. */
  139. struct TransportRequestConnectMessage
  140. {
  141. /**
  142. * Message header with type #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT
  143. */
  144. struct GNUNET_MessageHeader header;
  145. /**
  146. * Reserved (0).
  147. */
  148. uint32_t reserved GNUNET_PACKED;
  149. /**
  150. * Identity of the peer we would like to connect to.
  151. */
  152. struct GNUNET_PeerIdentity peer;
  153. };
  154. /**
  155. * Message type for sending a request connection to
  156. * a peer to be torn down.
  157. */
  158. struct TransportRequestDisconnectMessage
  159. {
  160. /**
  161. * Message header with type #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_DISCONNECT
  162. */
  163. struct GNUNET_MessageHeader header;
  164. /**
  165. * Reserved (0).
  166. */
  167. uint32_t reserved GNUNET_PACKED;
  168. /**
  169. * Identity of the peer we would like to connect to.
  170. */
  171. struct GNUNET_PeerIdentity peer;
  172. };
  173. /**
  174. * Message used to set a particular bandwidth quota. Sent TO the
  175. * service to set an incoming quota, sent FROM the service to update
  176. * an outgoing quota.
  177. */
  178. struct QuotaSetMessage
  179. {
  180. /**
  181. * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
  182. */
  183. struct GNUNET_MessageHeader header;
  184. /**
  185. * Quota.
  186. */
  187. struct GNUNET_BANDWIDTH_Value32NBO quota;
  188. /**
  189. * About which peer are we talking here?
  190. */
  191. struct GNUNET_PeerIdentity peer;
  192. };
  193. /**
  194. * Message used to notify the transport API about a message
  195. * received from the network. The actual message follows.
  196. */
  197. struct InboundMessage
  198. {
  199. /**
  200. * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
  201. */
  202. struct GNUNET_MessageHeader header;
  203. /**
  204. * Which peer sent the message?
  205. */
  206. struct GNUNET_PeerIdentity peer;
  207. };
  208. /**
  209. * Message used to notify the transport API that it can
  210. * send another message to the transport service.
  211. */
  212. struct SendOkMessage
  213. {
  214. /**
  215. * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
  216. */
  217. struct GNUNET_MessageHeader header;
  218. /**
  219. * #GNUNET_OK if the transmission succeeded,
  220. * #GNUNET_SYSERR if it failed (i.e. network disconnect);
  221. * in either case, it is now OK for this client to
  222. * send us another message for the given peer.
  223. */
  224. uint32_t success GNUNET_PACKED;
  225. /**
  226. * Size of message sent
  227. */
  228. uint32_t bytes_msg GNUNET_PACKED;
  229. /**
  230. * Size of message sent over wire
  231. * Includes plugin and protocol specific overhead
  232. */
  233. uint32_t bytes_physical GNUNET_PACKED;
  234. /**
  235. * Which peer can send more now?
  236. */
  237. struct GNUNET_PeerIdentity peer;
  238. };
  239. /**
  240. * Message used to notify the transport API about an address to string
  241. * conversion. Message is followed by the string with the humand-readable
  242. * address. For each lookup, multiple results may be returned. The
  243. * last message must have a @e res of #GNUNET_OK and an @e addr_len
  244. * of zero.
  245. */
  246. struct AddressToStringResultMessage
  247. {
  248. /**
  249. * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY
  250. */
  251. struct GNUNET_MessageHeader header;
  252. /**
  253. * #GNUNET_OK if the conversion succeeded,
  254. * #GNUNET_SYSERR if it failed
  255. */
  256. uint32_t res GNUNET_PACKED;
  257. /**
  258. * Length of the following string, zero if @e is #GNUNET_SYSERR
  259. */
  260. uint32_t addr_len GNUNET_PACKED;
  261. };
  262. /**
  263. * Message used to notify the transport service about a message
  264. * to be transmitted to another peer. The actual message follows.
  265. */
  266. struct OutboundMessage
  267. {
  268. /**
  269. * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
  270. */
  271. struct GNUNET_MessageHeader header;
  272. /**
  273. * Always zero.
  274. */
  275. uint32_t reserved GNUNET_PACKED;
  276. /**
  277. * Allowed delay.
  278. */
  279. struct GNUNET_TIME_RelativeNBO timeout;
  280. /**
  281. * Which peer should receive the message?
  282. */
  283. struct GNUNET_PeerIdentity peer;
  284. };
  285. /**
  286. * Message from the library to the transport service
  287. * asking for converting a transport address to a
  288. * human-readable UTF-8 string.
  289. */
  290. struct AddressLookupMessage
  291. {
  292. /**
  293. * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING
  294. */
  295. struct GNUNET_MessageHeader header;
  296. /**
  297. * Should the conversion use numeric IP addresses (otherwise
  298. * a reverse DNS lookup is OK -- if applicable).
  299. */
  300. int16_t numeric_only GNUNET_PACKED;
  301. /**
  302. * Length of the (binary) address in bytes, in big-endian.
  303. */
  304. uint16_t addrlen GNUNET_PACKED;
  305. /**
  306. * timeout to give up (for DNS resolution timeout mostly)
  307. */
  308. struct GNUNET_TIME_RelativeNBO timeout;
  309. /* followed by @e addrlen bytes of the actual address, then
  310. * followed by the 0-terminated name of the transport */
  311. };
  312. /**
  313. * Message from the transport service to the library containing information
  314. * about a peer. Information contained are:
  315. * - current address used to communicate with this peer
  316. * - state
  317. * - state timeout
  318. *
  319. * Memory layout:
  320. * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
  321. */
  322. struct ValidationIterateResponseMessage
  323. {
  324. /**
  325. * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE
  326. */
  327. struct GNUNET_MessageHeader header;
  328. /**
  329. * For alignment.
  330. */
  331. uint32_t reserved;
  332. /**
  333. * Peer identity
  334. */
  335. struct GNUNET_PeerIdentity peer;
  336. /**
  337. * Local info about the address
  338. */
  339. uint32_t local_address_info GNUNET_PACKED;
  340. /**
  341. * Address length
  342. */
  343. uint32_t addrlen GNUNET_PACKED;
  344. /**
  345. * Length of the plugin name
  346. */
  347. uint32_t pluginlen GNUNET_PACKED;
  348. /**
  349. * State
  350. */
  351. uint32_t state GNUNET_PACKED;
  352. /**
  353. * At what time did we successfully validate the address last.
  354. * Will be NEVER if the address failed validation.
  355. */
  356. struct GNUNET_TIME_AbsoluteNBO last_validation;
  357. /**
  358. * Until when is the address believed to be valid.
  359. * Will be ZERO if the address is not belived to be valid.
  360. */
  361. struct GNUNET_TIME_AbsoluteNBO valid_until;
  362. /**
  363. * When will we next try to validate the address (typically
  364. * done before @e valid_until happens).
  365. */
  366. struct GNUNET_TIME_AbsoluteNBO next_validation;
  367. };
  368. /**
  369. * Message from the library to the transport service
  370. * asking for binary addresses known for a peer.
  371. */
  372. struct ValidationMonitorMessage
  373. {
  374. /**
  375. * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST
  376. */
  377. struct GNUNET_MessageHeader header;
  378. /**
  379. * One shot call or continous replies?
  380. */
  381. uint32_t one_shot GNUNET_PACKED;
  382. /**
  383. * The identity of the peer to look up.
  384. */
  385. struct GNUNET_PeerIdentity peer;
  386. };
  387. /**
  388. * Message from the library to the transport service
  389. * asking for binary addresses known for a peer.
  390. */
  391. struct PeerMonitorMessage
  392. {
  393. /**
  394. * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST
  395. */
  396. struct GNUNET_MessageHeader header;
  397. /**
  398. * One shot call or continous replies?
  399. */
  400. uint32_t one_shot GNUNET_PACKED;
  401. /**
  402. * The identity of the peer to look up.
  403. */
  404. struct GNUNET_PeerIdentity peer;
  405. };
  406. /**
  407. * Message from the library to the transport service
  408. * asking for binary addresses known for a peer.
  409. */
  410. struct TrafficMetricMessage
  411. {
  412. /**
  413. * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC
  414. */
  415. struct GNUNET_MessageHeader header;
  416. /**
  417. * Always zero.
  418. */
  419. uint32_t reserved GNUNET_PACKED;
  420. /**
  421. * The identity of the peer to look up.
  422. */
  423. struct GNUNET_PeerIdentity peer;
  424. /**
  425. * Fake properties to generate.
  426. */
  427. struct GNUNET_ATS_PropertiesNBO properties;
  428. /**
  429. * Fake delay to add on inbound traffic.
  430. */
  431. struct GNUNET_TIME_RelativeNBO delay_in;
  432. /**
  433. * Fake delay to add on outbound traffic.
  434. */
  435. struct GNUNET_TIME_RelativeNBO delay_out;
  436. };
  437. /**
  438. * Message from the transport service to the library containing information
  439. * about a peer. Information contained are:
  440. * - current address used to communicate with this peer
  441. * - state
  442. * - state timeout
  443. *
  444. * Memory layout:
  445. * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
  446. */
  447. struct PeerIterateResponseMessage
  448. {
  449. /**
  450. * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE
  451. */
  452. struct GNUNET_MessageHeader header;
  453. /**
  454. * For alignment.
  455. */
  456. uint32_t reserved;
  457. /**
  458. * Peer identity
  459. */
  460. struct GNUNET_PeerIdentity peer;
  461. /**
  462. * Timeout for the state this peer is in
  463. */
  464. struct GNUNET_TIME_AbsoluteNBO state_timeout;
  465. /**
  466. * Local info about the address
  467. */
  468. uint32_t local_address_info GNUNET_PACKED;
  469. /**
  470. * State this peer is in as an `enum GNUNET_TRANSPORT_PeerState`
  471. */
  472. uint32_t state GNUNET_PACKED;
  473. /**
  474. * Address length
  475. */
  476. uint32_t addrlen GNUNET_PACKED;
  477. /**
  478. * Length of the plugin name
  479. */
  480. uint32_t pluginlen GNUNET_PACKED;
  481. };
  482. /**
  483. * Change in blacklisting (either request or notification,
  484. * depending on which direction it is going).
  485. */
  486. struct BlacklistMessage
  487. {
  488. /**
  489. * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
  490. * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
  491. */
  492. struct GNUNET_MessageHeader header;
  493. /**
  494. * 0 for the query, #GNUNET_OK (allowed) or #GNUNET_SYSERR (disallowed)
  495. * for the response.
  496. */
  497. uint32_t is_allowed GNUNET_PACKED;
  498. /**
  499. * Which peer is being blacklisted or queried?
  500. */
  501. struct GNUNET_PeerIdentity peer;
  502. };
  503. /**
  504. * Transport-level connection status update.
  505. */
  506. struct TransportPluginMonitorMessage
  507. {
  508. /**
  509. * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT.
  510. */
  511. struct GNUNET_MessageHeader header;
  512. /**
  513. * An `enum GNUNET_TRANSPORT_SessionState` in NBO.
  514. */
  515. uint16_t session_state GNUNET_PACKED;
  516. /**
  517. * #GNUNET_YES if this is an inbound connection,
  518. * #GNUNET_NO if this is an outbound connection,
  519. * #GNUNET_SYSERR if connections of this plugin
  520. * are so fundamentally bidirectional
  521. * that they have no 'initiator'
  522. * Value given in NBO.
  523. */
  524. int16_t is_inbound GNUNET_PACKED;
  525. /**
  526. * Number of messages waiting transmission.
  527. */
  528. uint32_t msgs_pending GNUNET_PACKED;
  529. /**
  530. * Number of bytes waiting for transmission.
  531. */
  532. uint32_t bytes_pending GNUNET_PACKED;
  533. /**
  534. * When will this transport plugin session time out?
  535. */
  536. struct GNUNET_TIME_AbsoluteNBO timeout;
  537. /**
  538. * Until how long is this plugin currently blocked from reading?
  539. */
  540. struct GNUNET_TIME_AbsoluteNBO delay;
  541. /**
  542. * Which peer is this connection for?
  543. */
  544. struct GNUNET_PeerIdentity peer;
  545. /**
  546. * Unique identifier for the session.
  547. */
  548. uint64_t session_id;
  549. /**
  550. * Length of the plugin name in bytes, including 0-termination.
  551. */
  552. uint16_t plugin_name_len GNUNET_PACKED;
  553. /**
  554. * Length of the plugin address in bytes.
  555. */
  556. uint16_t plugin_address_len GNUNET_PACKED;
  557. /* followed by 0-terminated plugin name and
  558. @e plugin_address_len bytes of plugin address */
  559. };
  560. GNUNET_NETWORK_STRUCT_END
  561. /* end of transport.h */
  562. #endif