/**
 * @file msgproto.h
 * @author Ambroz Bizjak <ambrop7@gmail.com>
 * 
 * @section LICENSE
 * 
 * This file is part of BadVPN.
 * 
 * BadVPN is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 * 
 * BadVPN is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 * 
 * @section DESCRIPTION
 * 
 * Definitions for MsgProto, the protocol the VPN peers communicate in via the server
 * in order to establish data connections.
 * 
 * MsgProto is built with BProto, the protocol and code generator for building
 * custom message protocols. The BProto specification file is msgproto.bproto.
 * 
 * It goes roughly like that:
 * 
 * We name one peer the master and the other the slave. The master is the one with
 * greater ID.
 * When the peers get to know about each other, the master starts the binding procedure.
 * It binds/listens to an address, and sends the slave the "youconnect" message. It
 * contains a list of external addresses for that bind address and additional parameters.
 * Each external address includes a string called a scope name. The slave, which receives
 * the "youconnect" message, finds the first external address whose scope it recognizes,
 * and attempts to establish connection to that address. If it finds an address, buf fails
 * at connecting, it sends "youretry", which makes the master restart the binding procedure
 * after some time. If it however does not recognize any external address, it sends
 * "cannotconnect" back to the master.
 * When the master receives the "cannotconnect", it tries the next bind address, as described
 * above. When the master runs out of bind addresses, it sends "cannotbind" to the slave.
 * When the slave receives the "cannotbind", it starts its own binding procedure, similarly
 * to what is described above, with master and slave reversed. First difference is if the
 * master fails to connect to a recognized address, it doesn't send "youretry", but rather
 * simply restarts the whole procedure after some time. The other difference is when the
 * slave runs out of bind addresses, it not only sends "cannotbind" to the master, but
 * registers relaying to the master. And in this case, when the master receives the "cannotbind",
 * it doesn't start the binding procedure all all over, but registers relaying to the slave.
 */

#ifndef BADVPN_PROTOCOL_MSGPROTO_H
#define BADVPN_PROTOCOL_MSGPROTO_H

#include <generated/bproto_msgproto.h>

#define MSGID_YOUCONNECT 1
#define MSGID_CANNOTCONNECT 2
#define MSGID_CANNOTBIND 3
#define MSGID_YOURETRY 5
#define MSGID_SEED 6
#define MSGID_CONFIRMSEED 7

#define MSG_MAX_PAYLOAD (SC_MAX_MSGLEN - msg_SIZEtype - msg_SIZEpayload(0))

#endif
