#ifndef NET_QUIC_QUIC_CONFIG_H_
#define NET_QUIC_QUIC_CONFIG_H_
#include <string>
#include "base/basictypes.h"
#include "net/quic/quic_protocol.h"
#include "net/quic/quic_time.h"
namespace net {
class CryptoHandshakeMessage;
enum QuicConfigPresence {
PRESENCE_OPTIONAL,
PRESENCE_REQUIRED,
};
class NET_EXPORT_PRIVATE QuicConfigValue {
public:
QuicConfigValue(QuicTag tag, QuicConfigPresence presence);
virtual ~QuicConfigValue();
virtual void ToHandshakeMessage(CryptoHandshakeMessage* out) const = 0;
virtual QuicErrorCode ProcessClientHello(
const CryptoHandshakeMessage& client_hello,
std::string* error_details) = 0;
virtual QuicErrorCode ProcessServerHello(
const CryptoHandshakeMessage& server_hello,
std::string* error_details) = 0;
protected:
const QuicTag tag_;
const QuicConfigPresence presence_;
};
class NET_EXPORT_PRIVATE QuicNegotiableValue : public QuicConfigValue {
public:
QuicNegotiableValue(QuicTag tag, QuicConfigPresence presence);
virtual ~QuicNegotiableValue();
bool negotiated() const {
return negotiated_;
}
protected:
bool negotiated_;
};
class NET_EXPORT_PRIVATE QuicNegotiableUint32 : public QuicNegotiableValue {
public:
QuicNegotiableUint32(QuicTag name, QuicConfigPresence presence);
virtual ~QuicNegotiableUint32();
void set(uint32 max, uint32 default_value);
uint32 GetUint32() const;
virtual void ToHandshakeMessage(CryptoHandshakeMessage* out) const OVERRIDE;
virtual QuicErrorCode ProcessClientHello(
const CryptoHandshakeMessage& client_hello,
std::string* error_details) OVERRIDE;
virtual QuicErrorCode ProcessServerHello(
const CryptoHandshakeMessage& server_hello,
std::string* error_details) OVERRIDE;
private:
uint32 max_value_;
uint32 default_value_;
uint32 negotiated_value_;
};
class NET_EXPORT_PRIVATE QuicNegotiableTag : public QuicNegotiableValue {
public:
QuicNegotiableTag(QuicTag name, QuicConfigPresence presence);
virtual ~QuicNegotiableTag();
void set(const QuicTagVector& possible_values, QuicTag default_value);
QuicTag GetTag() const;
virtual void ToHandshakeMessage(CryptoHandshakeMessage* out) const OVERRIDE;
virtual QuicErrorCode ProcessClientHello(
const CryptoHandshakeMessage& client_hello,
std::string* error_details) OVERRIDE;
virtual QuicErrorCode ProcessServerHello(
const CryptoHandshakeMessage& server_hello,
std::string* error_details) OVERRIDE;
private:
QuicErrorCode ReadVector(const CryptoHandshakeMessage& msg,
const QuicTag** out,
size_t* out_length,
std::string* error_details) const;
QuicTag negotiated_tag_;
QuicTagVector possible_values_;
QuicTag default_value_;
};
class NET_EXPORT_PRIVATE QuicFixedUint32 : public QuicConfigValue {
public:
QuicFixedUint32(QuicTag name,
QuicConfigPresence presence,
uint32 default_value);
virtual ~QuicFixedUint32();
uint32 GetUint32() const;
void set_value(uint32 value) { value_ = value; }
virtual void ToHandshakeMessage(CryptoHandshakeMessage* out) const OVERRIDE;
virtual QuicErrorCode ProcessClientHello(
const CryptoHandshakeMessage& client_hello,
std::string* error_details) OVERRIDE;
virtual QuicErrorCode ProcessServerHello(
const CryptoHandshakeMessage& server_hello,
std::string* error_details) OVERRIDE;
private:
uint32 value_;
};
class NET_EXPORT_PRIVATE QuicConfig {
public:
QuicConfig();
~QuicConfig();
void set_congestion_control(const QuicTagVector& congestion_control,
QuicTag default_congestion_control);
QuicTag congestion_control() const;
void set_loss_detection(const QuicTagVector& loss_detection,
QuicTag default_loss_detection);
QuicTag loss_detection() const;
void set_idle_connection_state_lifetime(
QuicTime::Delta max_idle_connection_state_lifetime,
QuicTime::Delta default_idle_conection_state_lifetime);
QuicTime::Delta idle_connection_state_lifetime() const;
QuicTime::Delta keepalive_timeout() const;
void set_max_streams_per_connection(size_t max_streams,
size_t default_streams);
uint32 max_streams_per_connection() const;
void set_max_time_before_crypto_handshake(
QuicTime::Delta max_time_before_crypto_handshake);
QuicTime::Delta max_time_before_crypto_handshake() const;
void set_server_initial_congestion_window(size_t max_initial_window,
size_t default_initial_window);
uint32 server_initial_congestion_window() const;
void set_initial_round_trip_time_us(size_t max_rtt, size_t default_rtt);
uint32 initial_round_trip_time_us() const;
void set_peer_initial_flow_control_window_bytes(uint32 window);
uint32 peer_initial_flow_control_window_bytes() const;
bool negotiated();
void SetDefaults();
void EnablePacing(bool enable_pacing);
void ToHandshakeMessage(CryptoHandshakeMessage* out) const;
QuicErrorCode ProcessClientHello(const CryptoHandshakeMessage& client_hello,
std::string* error_details);
QuicErrorCode ProcessServerHello(const CryptoHandshakeMessage& server_hello,
std::string* error_details);
private:
QuicNegotiableTag congestion_control_;
QuicNegotiableTag loss_detection_;
QuicNegotiableUint32 idle_connection_state_lifetime_seconds_;
QuicNegotiableUint32 keepalive_timeout_seconds_;
QuicNegotiableUint32 max_streams_per_connection_;
QuicTime::Delta max_time_before_crypto_handshake_;
QuicNegotiableUint32 server_initial_congestion_window_;
QuicNegotiableUint32 initial_round_trip_time_us_;
QuicFixedUint32 peer_initial_flow_control_window_bytes_;
};
}
#endif