UpperDistributor.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 UpperDistributor_H
  16. #define UpperDistributor_H
  17. #include "dht/Address.h"
  18. #include "memory/Allocator.h"
  19. #include "net/EventEmitter.h"
  20. #include "util/log/Log.h"
  21. #include "util/Linker.h"
  22. Linker_require("net/UpperDistributor.c");
  23. /**
  24. * Connects the TUN, DHT and IpTunnel (and other?) handlers to the SessionManager.
  25. * All packets must have SessionManager_UpperHeader on them.
  26. */
  27. struct UpperDistributor
  28. {
  29. struct Iface sessionManagerIf;
  30. struct Iface tunAdapterIf;
  31. struct Iface ipTunnelIf;
  32. struct Iface controlHandlerIf;
  33. };
  34. struct UpperDistributor_Handler
  35. {
  36. enum ContentType type;
  37. int udpPort;
  38. };
  39. /** If the regNum does not corrispond to an existing handler */
  40. #define UpperDistributor_unregisterHandler_NONEXISTANT -1
  41. /** Returns 0 unless there is an error */
  42. int UpperDistributor_unregisterHandler(struct UpperDistributor* ud, int regNum);
  43. /**
  44. * Returns the number of elements in the list.
  45. * If there are no elements, outputList is set to NULL.
  46. */
  47. int UpperDistributor_listHandlers(struct UpperDistributor* ud,
  48. struct UpperDistributor_Handler** outputList,
  49. struct Allocator* alloc);
  50. /** If the port has already been registered to a different contentType */
  51. #define UpperDistributor_registerHandler_PORT_REGISTERED -1
  52. /**
  53. * Register a handler for receiving messages of a given contentType.
  54. * @return 0 unless there is an error.
  55. */
  56. int UpperDistributor_registerHandler(struct UpperDistributor* ud,
  57. enum ContentType ct,
  58. int udpPort);
  59. struct UpperDistributor* UpperDistributor_new(struct Allocator* alloc,
  60. struct Log* log,
  61. struct EventEmitter* ee,
  62. struct Address* myAddress);
  63. #endif