msgproto.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * @file msgproto.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * @section DESCRIPTION
  30. *
  31. * MsgProto is used by each pair of VPN peers as messages through the server, in order to
  32. * establish a direct data connection. MsgProto operates on top of the SCProto message
  33. * service, optionally secured with SSL; see {@link scproto.h} for details.
  34. *
  35. * MsgProto is built with BProto, the protocol and code generator for building
  36. * custom message protocols. The BProto specification file is msgproto.bproto.
  37. *
  38. * It goes roughly like that:
  39. *
  40. * We name one peer the master and the other the slave. The master is the one with
  41. * greater ID.
  42. * When the peers get to know about each other, the master starts the binding procedure.
  43. * It binds/listens to an address, and sends the slave the "youconnect" message. It
  44. * contains a list of external addresses for that bind address and additional parameters.
  45. * Each external address includes a string called a scope name. The slave, which receives
  46. * the "youconnect" message, finds the first external address whose scope it recognizes,
  47. * and attempts to establish connection to that address. If it finds an address, buf fails
  48. * at connecting, it sends "youretry", which makes the master restart the binding procedure
  49. * after some time. If it however does not recognize any external address, it sends
  50. * "cannotconnect" back to the master.
  51. * When the master receives the "cannotconnect", it tries the next bind address, as described
  52. * above. When the master runs out of bind addresses, it sends "cannotbind" to the slave.
  53. * When the slave receives the "cannotbind", it starts its own binding procedure, similarly
  54. * to what is described above, with master and slave reversed. First difference is if the
  55. * master fails to connect to a recognized address, it doesn't send "youretry", but rather
  56. * simply restarts the whole procedure after some time. The other difference is when the
  57. * slave runs out of bind addresses, it not only sends "cannotbind" to the master, but
  58. * registers relaying to the master. And in this case, when the master receives the "cannotbind",
  59. * it doesn't start the binding procedure all all over, but registers relaying to the slave.
  60. */
  61. #ifndef BADVPN_PROTOCOL_MSGPROTO_H
  62. #define BADVPN_PROTOCOL_MSGPROTO_H
  63. #include <generated/bproto_msgproto.h>
  64. #define MSGID_YOUCONNECT 1
  65. #define MSGID_CANNOTCONNECT 2
  66. #define MSGID_CANNOTBIND 3
  67. #define MSGID_YOURETRY 5
  68. #define MSGID_SEED 6
  69. #define MSGID_CONFIRMSEED 7
  70. #define MSG_MAX_PAYLOAD (SC_MAX_MSGLEN - msg_SIZEtype - msg_SIZEpayload(0))
  71. #endif