make it possible to configure the QUIC versions for the client

This commit is contained in:
Marten Seemann
2017-04-29 22:43:04 +07:00
parent 1b70bd42d9
commit 16ca3012e9
5 changed files with 69 additions and 42 deletions

View File

@@ -47,12 +47,13 @@ func Dial(pconn net.PacketConn, remoteAddr net.Addr, host string, config *Config
return nil, err
}
clientConfig := populateClientConfig(config)
c := &client{
conn: &conn{pconn: pconn, currentAddr: remoteAddr},
connectionID: connID,
hostname: hostname,
config: config,
version: protocol.SupportedVersions[len(protocol.SupportedVersions)-1], // use the highest supported version by default
config: clientConfig,
version: clientConfig.Versions[0],
}
c.connStateChangeOrErrCond.L = &c.mutex
@@ -67,6 +68,19 @@ func Dial(pconn net.PacketConn, remoteAddr net.Addr, host string, config *Config
return c.establishConnection()
}
func populateClientConfig(config *Config) *Config {
versions := config.Versions
if len(versions) == 0 {
versions = protocol.SupportedVersions
}
return &Config{
TLSConfig: config.TLSConfig,
ConnState: config.ConnState,
Versions: versions,
}
}
// DialAddr establishes a new QUIC connection to a server.
// The hostname for SNI is taken from the given address.
func DialAddr(addr string, config *Config) (Session, error) {
@@ -191,7 +205,7 @@ func (c *client) handlePacketWithVersionFlag(hdr *PublicHeader) error {
}
}
ok, highestSupportedVersion := protocol.HighestSupportedVersion(hdr.SupportedVersions)
ok, highestSupportedVersion := protocol.HighestSupportedVersion(c.config.Versions, hdr.SupportedVersions)
if !ok {
return qerr.InvalidVersion
}