SwitchCore.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 SwitchCore_H
  16. #define SwitchCore_H
  17. #include "interface/Interface.h"
  18. #include "util/log/Log.h"
  19. #include "wire/Message.h"
  20. #include "util/Linker.h"
  21. Linker_require("switch/SwitchCore.c")
  22. #include <stdint.h>
  23. /** The switch core which is opaque to users. */
  24. struct SwitchCore;
  25. /**
  26. * Create a new router core.
  27. *
  28. * @param logger what to log output to.
  29. * @param allocator the memory allocator to use for allocating the core context and interfaces.
  30. */
  31. struct SwitchCore* SwitchCore_new(struct Log* logger, struct Allocator* allocator);
  32. /**
  33. * Register a new interface.
  34. * All interfaces are point to point so messages sent down an interface.
  35. *
  36. * @param iface the interface to add.
  37. * @param trust the amount that you trust the connected node.
  38. * @param labelOut_be a buffer which will be filled with the label part for getting
  39. * to the newly added node. It will be set to the big endian value.
  40. * @param core the switchcore.
  41. * @return 0 on success, SwitchCore_addInterface_OUT_OF_SPACE if there are no more interface slots.
  42. */
  43. #define SwitchCore_addInterface_OUT_OF_SPACE -1
  44. int SwitchCore_addInterface(struct Interface* iface,
  45. const uint64_t trust,
  46. uint64_t* labelOut_be,
  47. struct SwitchCore* core);
  48. /**
  49. * Set the router interface.
  50. * This interface is needed by all switches because a switch cannot function without a router.
  51. * Do not send messages before registering this interface and at least one other.
  52. *
  53. * @param iface the router interface.
  54. * @param core the switchcore.
  55. * @return 0
  56. */
  57. int SwitchCore_setRouterInterface(struct Interface* iface, struct SwitchCore* core);
  58. void SwitchCore_swapInterfaces(struct Interface* if1, struct Interface* if2);
  59. #endif