DHTModule.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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* 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 (* handleIncoming)(struct DHTMessage* message, void* context);
  42. /**
  43. * @param message the message which will be sent to the peer.
  44. * @param context the module's state.
  45. * @return -1 if the message should not be propigated to any more modules.
  46. * use with caution as it may be interpreted as network loss.
  47. */
  48. int (* handleOutgoing)(struct DHTMessage* message, void* context);
  49. };
  50. #endif