1
0

ETHInterface.h 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 ETHInterface_H
  16. #define ETHInterface_H
  17. #include "util/events/EventBase.h"
  18. #include "interface/Interface.h"
  19. #include "interface/InterfaceController.h"
  20. #include "util/log/Log.h"
  21. #include "memory/Allocator.h"
  22. struct ETHInterface;
  23. /**
  24. * @param base the LibEvent context.
  25. * @param bindDevice the name of the device to bind to.
  26. * @param allocator the memory allocator for this message.
  27. * @param exHandler the handler to deal with whatever exception arises.
  28. * Exceptions:
  29. * ETHInterface_new_PARSE_ADDRESS_FAILED Couldn't parse interface address as a MAC address
  30. * ETHInterface_new_FAILED_CREATING_EVENT Failed creating the event or registering it with
  31. * the libevent event base (shouldn't happen)
  32. * ETHInterface_new_FAILED_FIND_IFACE Failed to find a device with the given name
  33. * ETHInterface_new_FAILED_FIND_MACADDR Failed to find the MAC address of the interface
  34. * ETHInterface_new_SOCKET_FAILED Failed calling socket(), check EVUTIL_SOCKET_ERROR()
  35. * ETHInterface_new_BIND_FAILED Failed calling bind(), check EVUTIL_SOCKET_ERROR()
  36. *
  37. * @param logger
  38. * @param ic the controller which this interface should register with
  39. * and use when starting connections.
  40. * @return a new ETHInterface.
  41. */
  42. #define ETHInterface_new_PARSE_ADDRESS_FAILED -1
  43. #define ETHInterface_new_FAILED_CREATING_EVENT -2
  44. #define ETHInterface_new_FAILED_FIND_IFACE -3
  45. #define ETHInterface_new_FAILED_FIND_MACADDR -4
  46. #define ETHInterface_new_SOCKET_FAILED -5
  47. #define ETHInterface_new_BIND_FAILED -6
  48. struct ETHInterface* ETHInterface_new(struct EventBase* base,
  49. const char* bindDevice,
  50. struct Allocator* allocator,
  51. struct Except* exHandler,
  52. struct Log* logger,
  53. struct InterfaceController* ic);
  54. /**
  55. * Begin an outgoing connection.
  56. *
  57. * @param macAddress the MAC address of the ethernet card to connect to.
  58. * @param cryptoKey the node's public key, this is required to send it traffic.
  59. * @param password if specified, the password for authenticating with the other node.
  60. * @param ethIf the Ether interface.
  61. * @return 0 on success
  62. * ETHInterface_beginConnection_OUT_OF_SPACE if there is no space to store the entry.
  63. * ETHInterface_beginConnection_BAD_KEY invalid (non-cjdns) cryptoKey
  64. * ETHInterface_beginConnection_BAD_IFACE failed to parse interface name.
  65. * ETHInterface_beginConnection_UNKNOWN_ERROR something failed in InterfaceController.
  66. * ETHInterface_beginConnection_BAD_MAC malformed MAC address.
  67. */
  68. #define ETHInterface_beginConnection_OUT_OF_SPACE -1
  69. #define ETHInterface_beginConnection_BAD_KEY -2
  70. #define ETHInterface_beginConnection_BAD_IFACE -3
  71. #define ETHInterface_beginConnection_UNKNOWN_ERROR -4
  72. #define ETHInterface_beginConnection_BAD_MAC -5
  73. int ETHInterface_beginConnection(const char* macAddress,
  74. uint8_t cryptoKey[32],
  75. String* password,
  76. struct ETHInterface* ethIf);
  77. /**
  78. * Get or set the beaconing state of the ethernet interface.
  79. *
  80. * @param ethIf the ethernet iface.
  81. * @param state if not NULL, the state will be set to this, if NULL then nothing will be changed.
  82. * @return the current state after (possibly) setting.
  83. */
  84. #define ETHInterface_beacon_DISABLED 0
  85. #define ETHInterface_beacon_ACCEPTING 1
  86. #define ETHInterface_beacon_ACCEPTING_AND_SENDING 2
  87. int ETHInterface_beacon(struct ETHInterface* ethIf, int* state);
  88. #endif