mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
save correct hostname in quic Client
This commit is contained in:
parent
3458514744
commit
b9f9c2e429
2 changed files with 13 additions and 13 deletions
19
client.go
19
client.go
|
@ -5,7 +5,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -41,18 +40,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewClient makes a new client
|
// NewClient makes a new client
|
||||||
func NewClient(addr string, cryptoChangeCallback CryptoChangeCallback, versionNegotiateCallback VersionNegotiateCallback) (*Client, error) {
|
func NewClient(host string, cryptoChangeCallback CryptoChangeCallback, versionNegotiateCallback VersionNegotiateCallback) (*Client, error) {
|
||||||
hostname, err := utils.HostnameFromAddr(addr)
|
|
||||||
if err != nil || len(hostname) == 0 {
|
|
||||||
return nil, errHostname
|
|
||||||
}
|
|
||||||
|
|
||||||
p, err := url.Parse(addr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
host := p.Host
|
|
||||||
|
|
||||||
udpAddr, err := net.ResolveUDPAddr("udp", host)
|
udpAddr, err := net.ResolveUDPAddr("udp", host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -67,6 +55,11 @@ func NewClient(addr string, cryptoChangeCallback CryptoChangeCallback, versionNe
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
connectionID := protocol.ConnectionID(rand.Int63())
|
connectionID := protocol.ConnectionID(rand.Int63())
|
||||||
|
|
||||||
|
hostname, _, err := net.SplitHostPort(host)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
client := &Client{
|
client := &Client{
|
||||||
addr: udpAddr,
|
addr: udpAddr,
|
||||||
conn: conn,
|
conn: conn,
|
||||||
|
|
|
@ -41,6 +41,13 @@ var _ = Describe("Client", func() {
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It("sets the correct hostname for new clients", func() {
|
||||||
|
var err error
|
||||||
|
client, err = NewClient("quic.clemente.io:1337", nil, nil)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(client.hostname).To(Equal("quic.clemente.io"))
|
||||||
|
})
|
||||||
|
|
||||||
It("errors on invalid public header", func() {
|
It("errors on invalid public header", func() {
|
||||||
err := client.handlePacket(nil)
|
err := client.handlePacket(nil)
|
||||||
Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.InvalidPacketHeader))
|
Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.InvalidPacketHeader))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue