mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +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"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -41,18 +40,7 @@ var (
|
|||
)
|
||||
|
||||
// NewClient makes a new client
|
||||
func NewClient(addr 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
|
||||
|
||||
func NewClient(host string, cryptoChangeCallback CryptoChangeCallback, versionNegotiateCallback VersionNegotiateCallback) (*Client, error) {
|
||||
udpAddr, err := net.ResolveUDPAddr("udp", host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -67,6 +55,11 @@ func NewClient(addr string, cryptoChangeCallback CryptoChangeCallback, versionNe
|
|||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
connectionID := protocol.ConnectionID(rand.Int63())
|
||||
|
||||
hostname, _, err := net.SplitHostPort(host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := &Client{
|
||||
addr: udpAddr,
|
||||
conn: conn,
|
||||
|
|
|
@ -41,6 +41,13 @@ var _ = Describe("Client", func() {
|
|||
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() {
|
||||
err := client.handlePacket(nil)
|
||||
Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.InvalidPacketHeader))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue