MsgCore.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 MsgCore_H
  16. #define MsgCore_H
  17. #include "interface/Iface.h"
  18. #include "crypto/random/Random.h"
  19. #include "util/events/EventBase.h"
  20. #include "benc/Dict.h"
  21. #include "memory/Allocator.h"
  22. #include "dht/Address.h"
  23. #include "switch/EncodingScheme.h"
  24. #include "util/log/Log.h"
  25. #include "util/Linker.h"
  26. Linker_require("subnode/MsgCore.c");
  27. struct MsgCore_Handler;
  28. struct MsgCore;
  29. typedef void (* MsgCore_HandlerCb)(Dict* msg,
  30. struct Address* src,
  31. struct Allocator* tmpAlloc,
  32. struct MsgCore_Handler* handler);
  33. struct MsgCore_Handler
  34. {
  35. MsgCore_HandlerCb cb;
  36. void* userData;
  37. };
  38. void MsgCore_sendResponse(struct MsgCore* core,
  39. Dict* msgDict,
  40. struct Address* target,
  41. struct Allocator* alloc);
  42. struct MsgCore_Promise;
  43. typedef void (* MsgCore_PromiseCb)(Dict* msg, struct Address* src, struct MsgCore_Promise* promise);
  44. struct MsgCore_Promise
  45. {
  46. Dict* msg;
  47. struct Address* target;
  48. struct Allocator* alloc;
  49. void* userData;
  50. MsgCore_PromiseCb cb;
  51. };
  52. struct MsgCore_Promise* MsgCore_createQuery(struct MsgCore* core,
  53. uint32_t timeoutMilliseconds,
  54. struct Allocator* alloc);
  55. struct MsgCore_Handler* MsgCore_onQuery(struct MsgCore* core,
  56. char* queryType,
  57. struct Allocator* alloc);
  58. struct MsgCore
  59. {
  60. struct Iface interRouterIf;
  61. };
  62. struct MsgCore* MsgCore_new(struct EventBase* base,
  63. struct Random* rand,
  64. struct Allocator* allocator,
  65. struct Log* log,
  66. struct EncodingScheme* scheme);
  67. #endif