//====== Copyright Valve Corporation, All rights reserved. ====================
//
// Wire format messages for Steam Networking sockets connections
// over direct UDP (not relayed).
//
//=============================================================================
syntax = "proto2";
option optimize_for = SPEED;

// We don't use the service generation functionality
option cc_generic_services = false;

import "steamnetworkingsockets_messages_certs.proto";
import "steamnetworkingsockets_messages.proto";

/// Control message ID.
enum ESteamNetworkingUDPMsgID
{
	// Steam networking using direct UDP connect
	k_ESteamNetworkingUDPMsg_ChallengeRequest = 32;			// Client->server
	k_ESteamNetworkingUDPMsg_ChallengeReply = 33;			// Server->client
	k_ESteamNetworkingUDPMsg_ConnectRequest = 34;			// Client->server
	k_ESteamNetworkingUDPMsg_ConnectOK = 35;				// Server->client
	k_ESteamNetworkingUDPMsg_ConnectionClosed = 36;			// Client<->server.  A reply is requested to this packet
	k_ESteamNetworkingUDPMsg_NoConnection = 37;				// Client<->server.  A reply should never be sent to this packet
};

// k_ESteamNetworkingUDPMsg_ChallengeRequest
message CMsgSteamSockets_UDP_ChallengeRequest
{
	optional fixed32 connection_id = 1;
	//optional fixed64 client_steam_id = 2;
	optional fixed64 my_timestamp = 3; // Please send this back to me

	// Version of the code I'm running
	optional uint32 protocol_version = 4;
};

// k_ESteamNetworkingUDPMsg_ChallengeReply
message CMsgSteamSockets_UDP_ChallengeReply
{
	optional fixed32 connection_id = 1;
	optional fixed64 challenge = 2;
	//optional uint32 required_proof_of_work_bits = 3;
	optional fixed64 your_timestamp = 3; // the my_timestamp you sent to us in ChallengeRequest

	// Version of the code I'm running
	optional uint32 protocol_version = 4;
};

// k_ESteamNetworkingUDPMsg_ConnectRequest
message CMsgSteamSockets_UDP_ConnectRequest
{
	optional fixed32 client_connection_id = 1;
	optional fixed64 challenge = 2;
	//optional fixed64 proof_of_work = 4;
	optional fixed64 my_timestamp = 5; // Please send this back to me
	optional uint32 ping_est_ms = 6; // My estimate of the ping time

	/// My ephemeral keys, and any crypto parameter negotiation.
	optional CMsgSteamDatagramSessionCryptInfoSigned crypt = 7;

	/// Certificate that contains:
	/// - my public key.
	/// - my identity, if certificate was issued to a single user
	/// - signature of a CA, if authenticated connection is being attempted.
	optional CMsgSteamDatagramCertificateSigned cert = 4;

	// Version of the code I'm running.  This has been moved into the
	// signed crypt parameters so that it could not be forged.
	optional uint32 legacy_protocol_version = 8;

	// Identity of host making connect request is in the cert, usually.
	// (Even if cert is unsigned.)  But, if cert was not issued to my specific
	// identity (e.g. it is for all gameservers in a data center, etc) then
	// I need to communicate my identity seperately.
	optional string identity_string = 10;

	//
	// Legacy fields
	//

	optional fixed64 legacy_client_steam_id = 3;
	optional CMsgSteamNetworkingIdentityLegacyBinary legacy_identity_binary = 9;
};

// k_ESteamDatagramMsg_UDP_ConnectOK
message CMsgSteamSockets_UDP_ConnectOK
{
	optional fixed32 client_connection_id = 1;
	optional fixed32 server_connection_id = 5;
	optional fixed64 your_timestamp = 3; // the timestamp (or whatever) you send to us in ConnectRequest
	optional uint32 delay_time_usec = 4; // number of microseconds between when we received your request and we replied

	/// My ephemeral keys, and any crypto parameter negotiation.
	optional CMsgSteamDatagramSessionCryptInfoSigned crypt = 7;

	/// Certificate used to prove my identity
	optional CMsgSteamDatagramCertificateSigned cert = 8;

	// Identity of server is in the cert, usually.
	// (Even if cert is unsigned.)  But, if cert was not issued to my specific
	// identity (e.g. it is for all gameservers in a data center, etc) then
	// I need to communicate my identity seperately.
	optional string identity_string = 11;

	//
	// Legacy fields
	//

	optional fixed64 legacy_server_steam_id = 2;
	//optional uint32 protocol_version = 9; // moved into crypt, to prevent tampering
	optional CMsgSteamNetworkingIdentityLegacyBinary legacy_identity_binary = 10;
};

// k_ESteamDatagramMsg_UDP_ConnectionClosed
message CMsgSteamSockets_UDP_ConnectionClosed
{
	//optional fixed32 legacy_client_connection_id = 1;
	optional fixed32 to_connection_id = 4;
	optional fixed32 from_connection_id = 5;
	optional string debug = 2;
	optional uint32 reason_code = 3;
};

// k_ESteamDatagramMsg_UDP_NoConnection
message CMsgSteamSockets_UDP_NoConnection
{
	//optional fixed32 legacy_client_connection_id = 1; // The client-side connection ID
	optional fixed32 from_connection_id = 2; // "My" portion of the connection ID you tried to use (always present), but that connection doesn't exist or has been closed.
	optional fixed32 to_connection_id = 3; // Your portion of the connection ID you sent (if any)
};

message CMsgSteamSockets_UDP_Stats
{
	// End to end stats
	optional CMsgSteamDatagramConnectionQuality stats = 1;

	enum Flags
	{
		//ACK_REQUEST_RELAY = 1; // Reserved
		ACK_REQUEST_E2E = 2;
		ACK_REQUEST_IMMEDIATE = 4;
		//NOT_PRIMARY_SESSION = 8; // Reserved
		NOT_PRIMARY_TRANSPORT_E2E = 16; 
	};

	/// Additional flags.  Should we try to put these in the
	/// message header and save a few bytes?
	optional uint32 flags = 3;
};

// Do not remove this comment due to a bug on the Mac OS X protobuf compiler

