mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 04:37:36 +03:00
remove the ConnStateCallback from the client
Dial and DialAddr return once the connection is forward secure. There is currently no option to get the session earlier, this will be added later.
This commit is contained in:
parent
30a0211243
commit
612323985b
4 changed files with 78 additions and 242 deletions
|
@ -16,34 +16,29 @@ import (
|
|||
|
||||
var _ = Describe("Client", func() {
|
||||
var (
|
||||
cl *client
|
||||
config *Config
|
||||
sess *mockSession
|
||||
packetConn *mockPacketConn
|
||||
addr net.Addr
|
||||
versionNegotiateConnStateCalled bool
|
||||
cl *client
|
||||
config *Config
|
||||
sess *mockSession
|
||||
packetConn *mockPacketConn
|
||||
addr net.Addr
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
Eventually(areSessionsRunning).Should(BeFalse())
|
||||
versionNegotiateConnStateCalled = false
|
||||
packetConn = &mockPacketConn{}
|
||||
config = &Config{
|
||||
ConnState: func(_ Session, state ConnState) {
|
||||
if state == ConnStateVersionNegotiated {
|
||||
versionNegotiateConnStateCalled = true
|
||||
}
|
||||
},
|
||||
Versions: []protocol.VersionNumber{protocol.SupportedVersions[0], 77, 78},
|
||||
}
|
||||
addr = &net.UDPAddr{IP: net.IPv4(192, 168, 100, 200), Port: 1337}
|
||||
sess = &mockSession{connectionID: 0x1337}
|
||||
cl = &client{
|
||||
config: config,
|
||||
connectionID: 0x1337,
|
||||
session: sess,
|
||||
version: protocol.SupportedVersions[0],
|
||||
conn: &conn{pconn: packetConn, currentAddr: addr},
|
||||
config: config,
|
||||
connectionID: 0x1337,
|
||||
session: sess,
|
||||
version: protocol.SupportedVersions[0],
|
||||
conn: &conn{pconn: packetConn, currentAddr: addr},
|
||||
errorChan: make(chan struct{}),
|
||||
handshakeChan: make(chan struct{}),
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -55,7 +50,7 @@ var _ = Describe("Client", func() {
|
|||
})
|
||||
|
||||
Context("Dialing", func() {
|
||||
It("creates a new client", func() {
|
||||
PIt("creates a new client", func() {
|
||||
packetConn.dataToRead = []byte{0x0, 0x1, 0x0}
|
||||
sess, err := Dial(packetConn, addr, "quic.clemente.io:1337", config)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -82,41 +77,6 @@ var _ = Describe("Client", func() {
|
|||
_, err := Dial(packetConn, addr, "quic.clemente.io:1337", config)
|
||||
Expect(err).To(MatchError(testErr))
|
||||
})
|
||||
|
||||
// now we're only testing that Dial doesn't return directly after version negotiation
|
||||
PIt("doesn't return after version negotiation is established if no ConnState is defined", func() {
|
||||
// TODO(#506): Fix test
|
||||
packetConn.dataToRead = []byte{0x0, 0x1, 0x0}
|
||||
config.ConnState = nil
|
||||
var dialReturned bool
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
_, err := Dial(packetConn, addr, "quic.clemente.io:1337", config)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
dialReturned = true
|
||||
}()
|
||||
Consistently(func() bool { return dialReturned }).Should(BeFalse())
|
||||
})
|
||||
|
||||
It("only establishes a connection once it is forward-secure if no ConnState is defined", func() {
|
||||
config.ConnState = nil
|
||||
client := &client{conn: &conn{pconn: packetConn, currentAddr: addr}, config: config}
|
||||
client.connStateChangeOrErrCond.L = &client.mutex
|
||||
var returned bool
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
_, err := client.establishConnection()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
returned = true
|
||||
}()
|
||||
Consistently(func() bool { return returned }).Should(BeFalse())
|
||||
// switch to a secure connection
|
||||
client.cryptoChangeCallback(nil, false)
|
||||
Consistently(func() bool { return returned }).Should(BeFalse())
|
||||
// switch to a forward-secure connection
|
||||
client.cryptoChangeCallback(nil, true)
|
||||
Eventually(func() bool { return returned }).Should(BeTrue())
|
||||
})
|
||||
})
|
||||
|
||||
It("errors on invalid public header", func() {
|
||||
|
@ -124,9 +84,9 @@ var _ = Describe("Client", func() {
|
|||
Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.InvalidPacketHeader))
|
||||
})
|
||||
|
||||
// this test requires a real session (because it calls the close callback)
|
||||
// this test requires a real session
|
||||
// and a real UDP conn (because it unblocks and errors when it is closed)
|
||||
It("properly closes", func(done Done) {
|
||||
PIt("properly closes", func(done Done) {
|
||||
Eventually(areSessionsRunning).Should(BeFalse())
|
||||
udpConn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1)})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -213,8 +173,7 @@ var _ = Describe("Client", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
err = cl.handlePacket(nil, b.Bytes())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(cl.connState).To(Equal(ConnStateVersionNegotiated))
|
||||
Eventually(func() bool { return versionNegotiateConnStateCalled }).Should(BeTrue())
|
||||
Expect(cl.versionNegotiated).To(BeTrue())
|
||||
})
|
||||
|
||||
It("changes the version after receiving a version negotiation packet", func() {
|
||||
|
@ -226,8 +185,7 @@ var _ = Describe("Client", func() {
|
|||
err := cl.handlePacket(nil, composeVersionNegotiation(0x1337, []protocol.VersionNumber{newVersion}))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(cl.version).To(Equal(newVersion))
|
||||
Expect(cl.connState).To(Equal(ConnStateVersionNegotiated))
|
||||
Eventually(func() bool { return versionNegotiateConnStateCalled }).Should(BeTrue())
|
||||
Expect(cl.versionNegotiated).To(BeTrue())
|
||||
// it swapped the sessions
|
||||
Expect(cl.session).ToNot(Equal(sess))
|
||||
Expect(cl.connectionID).ToNot(Equal(0x1337)) // it generated a new connection ID
|
||||
|
@ -260,13 +218,12 @@ var _ = Describe("Client", func() {
|
|||
|
||||
It("ignores delayed version negotiation packets", func() {
|
||||
// if the version was not yet negotiated, handlePacket would return a VersionNegotiationMismatch error, see above test
|
||||
cl.connState = ConnStateVersionNegotiated
|
||||
cl.versionNegotiated = true
|
||||
Expect(sess.packetCount).To(BeZero())
|
||||
err := cl.handlePacket(nil, composeVersionNegotiation(0x1337, []protocol.VersionNumber{1}))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(cl.connState).To(Equal(ConnStateVersionNegotiated))
|
||||
Expect(cl.versionNegotiated).To(BeTrue())
|
||||
Expect(sess.packetCount).To(BeZero())
|
||||
Consistently(func() bool { return versionNegotiateConnStateCalled }).Should(BeFalse())
|
||||
})
|
||||
|
||||
It("drops version negotiation packets that contain the offered version", func() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue