DHTMessage.h 1.7 KB

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