1
0

DHTModule.h 1.9 KB

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