forked from quic-go/quic-go
introduce ConnectionID type
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
"github.com/lucas-clemente/quic-go/crypto"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
"github.com/lucas-clemente/quic-go/utils"
|
||||
)
|
||||
|
||||
@@ -28,7 +29,7 @@ func main() {
|
||||
serverConfig := quic.NewServerConfig(crypto.NewCurve25519KEX(), keyData)
|
||||
|
||||
// TODO: When should a session be created?
|
||||
sessions := map[uint64]*quic.Session{}
|
||||
sessions := map[protocol.ConnectionID]*quic.Session{}
|
||||
|
||||
addr, err := net.ResolveUDPAddr("udp", "localhost:6121")
|
||||
if err != nil {
|
||||
|
||||
1
frame.go
1
frame.go
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/lucas-clemente/quic-go/utils"
|
||||
)
|
||||
|
||||
// A Frame in QUIC
|
||||
type Frame interface {
|
||||
Write(b *bytes.Buffer) error
|
||||
}
|
||||
|
||||
@@ -2,3 +2,6 @@ package protocol
|
||||
|
||||
// A PacketNumber in QUIC
|
||||
type PacketNumber uint64
|
||||
|
||||
// A ConnectionID in QUIC
|
||||
type ConnectionID uint64
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
type PublicHeader struct {
|
||||
VersionFlag bool
|
||||
ResetFlag bool
|
||||
ConnectionID uint64
|
||||
ConnectionID protocol.ConnectionID
|
||||
QuicVersion uint32
|
||||
PacketNumber protocol.PacketNumber
|
||||
// packetNumberLen uint8
|
||||
@@ -33,7 +33,7 @@ func (h *PublicHeader) WritePublicHeader(b *bytes.Buffer) error {
|
||||
}
|
||||
|
||||
b.WriteByte(publicFlagByte)
|
||||
utils.WriteUint64(b, h.ConnectionID) // TODO: Send shorter connection id if possible
|
||||
utils.WriteUint64(b, uint64(h.ConnectionID)) // TODO: Send shorter connection id if possible
|
||||
utils.WriteUint32(b, uint32(h.PacketNumber)) // TODO: Send shorter packet number if possible
|
||||
return nil
|
||||
}
|
||||
@@ -71,10 +71,11 @@ func ParsePublicHeader(b io.ByteReader) (*PublicHeader, error) {
|
||||
}
|
||||
|
||||
// Connection ID
|
||||
header.ConnectionID, err = utils.ReadUintN(b, connectionIDLen)
|
||||
connID, err := utils.ReadUintN(b, connectionIDLen)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
header.ConnectionID = protocol.ConnectionID(connID)
|
||||
if header.ConnectionID == 0 {
|
||||
return nil, errors.New("PublicHeader: connection ID cannot be 0")
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ var _ = Describe("Public Header", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(publicHeader.VersionFlag).To(BeTrue())
|
||||
Expect(publicHeader.ResetFlag).To(BeFalse())
|
||||
Expect(publicHeader.ConnectionID).To(Equal(uint64(0x4cfa9f9b668619f6)))
|
||||
Expect(publicHeader.ConnectionID).To(Equal(protocol.ConnectionID(0x4cfa9f9b668619f6)))
|
||||
Expect(publicHeader.QuicVersion).To(Equal(binary.BigEndian.Uint32([]byte("Q030"))))
|
||||
Expect(publicHeader.PacketNumber).To(Equal(protocol.PacketNumber(1)))
|
||||
Expect(b.Len()).To(BeZero())
|
||||
@@ -28,7 +28,7 @@ var _ = Describe("Public Header", func() {
|
||||
publicHeader, err := ParsePublicHeader(b)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(publicHeader.VersionFlag).To(BeFalse())
|
||||
Expect(publicHeader.ConnectionID).To(Equal(uint64(0x4cfa9f9b)))
|
||||
Expect(publicHeader.ConnectionID).To(Equal(protocol.ConnectionID(0x4cfa9f9b)))
|
||||
Expect(b.Len()).To(BeZero())
|
||||
})
|
||||
|
||||
@@ -37,7 +37,7 @@ var _ = Describe("Public Header", func() {
|
||||
publicHeader, err := ParsePublicHeader(b)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(publicHeader.VersionFlag).To(BeFalse())
|
||||
Expect(publicHeader.ConnectionID).To(Equal(uint64(0x4c)))
|
||||
Expect(publicHeader.ConnectionID).To(Equal(protocol.ConnectionID(0x4c)))
|
||||
Expect(b.Len()).To(BeZero())
|
||||
})
|
||||
|
||||
|
||||
@@ -6,11 +6,12 @@ import (
|
||||
"net"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/crypto"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
)
|
||||
|
||||
// A Session is a QUIC session
|
||||
type Session struct {
|
||||
ConnectionID uint64
|
||||
ConnectionID protocol.ConnectionID
|
||||
ServerConfig *ServerConfig
|
||||
|
||||
Connection *net.UDPConn
|
||||
@@ -20,7 +21,7 @@ type Session struct {
|
||||
}
|
||||
|
||||
// NewSession makes a new session
|
||||
func NewSession(conn *net.UDPConn, connectionID uint64, sCfg *ServerConfig) *Session {
|
||||
func NewSession(conn *net.UDPConn, connectionID protocol.ConnectionID, sCfg *ServerConfig) *Session {
|
||||
return &Session{
|
||||
Connection: conn,
|
||||
ConnectionID: connectionID,
|
||||
|
||||
Reference in New Issue
Block a user