RouteHeader.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #ifndef RouteHeader_H
  16. #define RouteHeader_H
  17. #include "util/Assert.h"
  18. #include "wire/SwitchHeader.h"
  19. /**
  20. * This header is never sent on the wire, it is only used for communicating to the SessionManager
  21. * which node you wish to communicate with and what path the packet should take.
  22. * Everything "below" the SessionManager is encrypted end-to-end, everything "above" has this
  23. * header. SessionManager will place this header on top of packets in order to tell the upper
  24. * layers the packet's origin. Upper layers must use this header in order to tell the SessionManager
  25. * to whom the packet should be sent.
  26. * Some of the fields in this header may be left zero when sending to the SessionManager,
  27. * for example if the publicKey of the node to communicate with is not known, you may send 32
  28. * bytes of zeros and the SessionManager will attempt to find the key in the SessionTable or
  29. * it will buffer the packet and trigger a search.
  30. * When the SessionManager emits a packet, all fields except possibly the version field will be
  31. * properly filled. If the version field is zero, the SessionManager has not determined the version
  32. * of the peer.
  33. */
  34. struct RouteHeader
  35. {
  36. /** public key of peer node, 0 if unknown, always sent from SessionManager. */
  37. uint8_t publicKey[32];
  38. /**
  39. * The switch header to use.
  40. * label_be may be zero if unknown.
  41. * version will be automatically set to the node's current version.
  42. */
  43. struct SwitchHeader sh;
  44. /** Protocol version of peer node, 0 if unknown, sometimes 0 from SessionManager. */
  45. uint32_t version_be;
  46. /**
  47. * If set, this header is incoming from another node, this means the ip6, publicKey and
  48. * switch label are of the *source* of the packet, not the destination.
  49. */
  50. #define RouteHeader_flags_INCOMING 1
  51. #define RouteHeader_flags_CTRLMSG (1<<1)
  52. uint8_t flags;
  53. uint8_t unused;
  54. uint16_t alsoUnused;
  55. /** IPv6 of peer node REQUIRED */
  56. uint8_t ip6[16];
  57. };
  58. #define RouteHeader_SIZE (56 + SwitchHeader_SIZE)
  59. Assert_compileTime(RouteHeader_SIZE == sizeof(struct RouteHeader));
  60. #endif