DHTMessage.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 DHTMessage_H
  16. #define DHTMessage_H
  17. #ifdef SUBNODE
  18. #error "this file should not be included in subnode"
  19. #endif
  20. #include "benc/Dict.h"
  21. #include "wire/Message.h"
  22. /**
  23. * Maximum number of bytes in a message.
  24. * Ethernet MTU is 1500 so it's hard to imagine much more.
  25. */
  26. #define DHTMessage_MAX_SIZE 1536
  27. /**
  28. * This struct represents a DHT message which will be passed to the
  29. * modules. The only part of the message which will be available to
  30. * all modules is Message.peer. Incoming modules will have Message.bytes
  31. * and Message.length when they come from the network module.
  32. */
  33. struct DHTMessage;
  34. struct DHTMessage
  35. {
  36. struct Address* address;
  37. Message_t* binMessage;
  38. /** The message as a bencoded dictionary. */
  39. Dict* asDict;
  40. struct EncodingScheme* encodingScheme;
  41. int encIndex;
  42. int pleaseRespond;
  43. /**
  44. * If this message is an outgoing reply, replyTo is the original query.
  45. * For incoming replies or any queries, it is NULL.
  46. */
  47. struct DHTMessage* replyTo;
  48. /** A memory allocator which will be freed after this message is sent. */
  49. struct Allocator* allocator;
  50. };
  51. #endif