DHTMessage.h 1.8 KB

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