DHTModule.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 DHTModule_H
  16. #define DHTModule_H
  17. #ifdef SUBNODE
  18. #error "this file should not be included in subnode"
  19. #endif
  20. #include "dht/DHTMessage.h"
  21. /**
  22. * This represents a DHT module.
  23. * Pass one of these to DHTModule_register() and it
  24. * will handle dht requests and responses.
  25. */
  26. struct DHTModule;
  27. struct DHTModule {
  28. /**
  29. * A user friendly null terminated string which will be used to
  30. * manipulate the module using the DHTModules API.
  31. */
  32. const char* const name;
  33. /**
  34. * The module's state.
  35. */
  36. void* context;
  37. /**
  38. * @param the message which came in from a peer.
  39. * @param context the module's state.
  40. * @return 1 if a response should be sent for this message.
  41. * -1 if the message is known invalid and should not be passed
  42. * to any more handlers.
  43. */
  44. int (* handleIncoming)(struct DHTMessage* message, void* context);
  45. /**
  46. * @param message the message which will be sent to the peer.
  47. * @param context the module's state.
  48. * @return -1 if the message should not be propigated to any more modules.
  49. * use with caution as it may be interpreted as network loss.
  50. */
  51. int (* handleOutgoing)(struct DHTMessage* message, void* context);
  52. };
  53. #endif