MsgCore.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 struct RTypes_Error_t* (* 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. uint32_t lag;
  52. };
  53. struct MsgCore_Promise* MsgCore_createQuery(struct MsgCore* core,
  54. uint32_t timeoutMilliseconds,
  55. struct Allocator* alloc);
  56. struct MsgCore_Handler* MsgCore_onQuery(struct MsgCore* core,
  57. char* queryType,
  58. struct Allocator* alloc);
  59. struct MsgCore
  60. {
  61. struct Iface interRouterIf;
  62. };
  63. struct MsgCore* MsgCore_new(EventBase_t* base,
  64. struct Random* rand,
  65. struct Allocator* allocator,
  66. struct Log* log,
  67. struct EncodingScheme* scheme);
  68. #endif