msgproto.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. * MsgProto is used by each pair of VPN peers as messages through the server, in order to
  25. * establish a direct data connection. MsgProto operates on top of the SCProto message
  26. * service, optionally secured with SSL; see {@link scproto.h} for details.
  27. *
  28. * MsgProto is built with BProto, the protocol and code generator for building
  29. * custom message protocols. The BProto specification file is msgproto.bproto.
  30. *
  31. * It goes roughly like that:
  32. *
  33. * We name one peer the master and the other the slave. The master is the one with
  34. * greater ID.
  35. * When the peers get to know about each other, the master starts the binding procedure.
  36. * It binds/listens to an address, and sends the slave the "youconnect" message. It
  37. * contains a list of external addresses for that bind address and additional parameters.
  38. * Each external address includes a string called a scope name. The slave, which receives
  39. * the "youconnect" message, finds the first external address whose scope it recognizes,
  40. * and attempts to establish connection to that address. If it finds an address, buf fails
  41. * at connecting, it sends "youretry", which makes the master restart the binding procedure
  42. * after some time. If it however does not recognize any external address, it sends
  43. * "cannotconnect" back to the master.
  44. * When the master receives the "cannotconnect", it tries the next bind address, as described
  45. * above. When the master runs out of bind addresses, it sends "cannotbind" to the slave.
  46. * When the slave receives the "cannotbind", it starts its own binding procedure, similarly
  47. * to what is described above, with master and slave reversed. First difference is if the
  48. * master fails to connect to a recognized address, it doesn't send "youretry", but rather
  49. * simply restarts the whole procedure after some time. The other difference is when the
  50. * slave runs out of bind addresses, it not only sends "cannotbind" to the master, but
  51. * registers relaying to the master. And in this case, when the master receives the "cannotbind",
  52. * it doesn't start the binding procedure all all over, but registers relaying to the slave.
  53. */
  54. #ifndef BADVPN_PROTOCOL_MSGPROTO_H
  55. #define BADVPN_PROTOCOL_MSGPROTO_H
  56. #include <generated/bproto_msgproto.h>
  57. #define MSGID_YOUCONNECT 1
  58. #define MSGID_CANNOTCONNECT 2
  59. #define MSGID_CANNOTBIND 3
  60. #define MSGID_YOURETRY 5
  61. #define MSGID_SEED 6
  62. #define MSGID_CONFIRMSEED 7
  63. #define MSG_MAX_PAYLOAD (SC_MAX_MSGLEN - msg_SIZEtype - msg_SIZEpayload(0))
  64. #endif