msgproto.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @file msgproto.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * Definitions for MsgProto, the protocol the VPN peers communicate in via the server
  25. * in order to establish data connections.
  26. *
  27. * MsgProto is built with BProto, the protocol and code generator for building
  28. * custom message protocols. The BProto specification file is msgproto.bproto.
  29. *
  30. * It goes roughly like that:
  31. *
  32. * We name one peer the master and the other the slave. The master is the one with
  33. * greater ID.
  34. * When the peers get to know about each other, the master starts the binding procedure.
  35. * It binds/listens to an address, and sends the slave the "youconnect" message. It
  36. * contains a list of external addresses for that bind address and additional parameters.
  37. * Each external address includes a string called a scope name. The slave, which receives
  38. * the "youconnect" message, finds the first external address whose scope it recognizes,
  39. * and attempts to establish connection to that address. If it finds an address, buf fails
  40. * at connecting, it sends "youretry", which makes the master restart the binding procedure
  41. * after some time. If it however does not recognize any external address, it sends
  42. * "cannotconnect" back to the master.
  43. * When the master receives the "cannotconnect", it tries the next bind address, as described
  44. * above. When the master runs out of bind addresses, it sends "cannotbind" to the slave.
  45. * When the slave receives the "cannotbind", it starts its own binding procedure, similarly
  46. * to what is described above, with master and slave reversed. First difference is if the
  47. * master fails to connect to a recognized address, it doesn't send "youretry", but rather
  48. * simply restarts the whole procedure after some time. The other difference is when the
  49. * slave runs out of bind addresses, it not only sends "cannotbind" to the master, but
  50. * registers relaying to the master. And in this case, when the master receives the "cannotbind",
  51. * it doesn't start the binding procedure all all over, but registers relaying to the slave.
  52. */
  53. #ifndef BADVPN_PROTOCOL_MSGPROTO_H
  54. #define BADVPN_PROTOCOL_MSGPROTO_H
  55. #include <generated/bproto_msgproto.h>
  56. #define MSGID_YOUCONNECT 1
  57. #define MSGID_CANNOTCONNECT 2
  58. #define MSGID_CANNOTBIND 3
  59. #define MSGID_YOURETRY 5
  60. #define MSGID_SEED 6
  61. #define MSGID_CONFIRMSEED 7
  62. #define MSG_MAX_PAYLOAD (SC_MAX_MSGLEN - msg_SIZEtype - msg_SIZEpayload(0))
  63. #endif