1
0

RouteHeader.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 <http://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. * Create a layout which puts the SwitchHeader 24 bytes behind the end of the header
  48. * allowing it to be in exactly the right place after encryption thus saving SessionManager
  49. * the need to copy it after encryption/decryption.
  50. */
  51. uint32_t pad;
  52. /** IPv6 of peer node REQUIRED */
  53. uint8_t ip6[16];
  54. };
  55. #define RouteHeader_SIZE (56 + SwitchHeader_SIZE)
  56. Assert_compileTime(RouteHeader_SIZE == sizeof(struct RouteHeader));
  57. #endif