forked from quic-go/quic-go
move connection ID generation from the utils to the protocol package
This commit is contained in:
@@ -44,7 +44,7 @@ type client struct {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// make it possible to mock connection ID generation in the tests
|
// make it possible to mock connection ID generation in the tests
|
||||||
generateConnectionID = utils.GenerateConnectionID
|
generateConnectionID = protocol.GenerateConnectionID
|
||||||
errCloseSessionForNewVersion = errors.New("closing session in order to recreate it with a new version")
|
errCloseSessionForNewVersion = errors.New("closing session in order to recreate it with a new version")
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -384,7 +384,7 @@ func (c *client) handleVersionNegotiationPacket(hdr *wire.Header) error {
|
|||||||
c.initialVersion = c.version
|
c.initialVersion = c.version
|
||||||
c.version = newVersion
|
c.version = newVersion
|
||||||
var err error
|
var err error
|
||||||
c.connectionID, err = utils.GenerateConnectionID()
|
c.connectionID, err = protocol.GenerateConnectionID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
package utils
|
package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// A ConnectionID in QUIC
|
||||||
|
type ConnectionID uint64
|
||||||
|
|
||||||
// GenerateConnectionID generates a connection ID using cryptographic random
|
// GenerateConnectionID generates a connection ID using cryptographic random
|
||||||
func GenerateConnectionID() (protocol.ConnectionID, error) {
|
func GenerateConnectionID() (ConnectionID, error) {
|
||||||
b := make([]byte, 8)
|
b := make([]byte, 8)
|
||||||
_, err := rand.Read(b)
|
_, err := rand.Read(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return protocol.ConnectionID(binary.LittleEndian.Uint64(b)), nil
|
return ConnectionID(binary.LittleEndian.Uint64(b)), nil
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package utils
|
package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
@@ -52,9 +52,6 @@ func (t PacketType) String() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A ConnectionID in QUIC
|
|
||||||
type ConnectionID uint64
|
|
||||||
|
|
||||||
// A ByteCount in QUIC
|
// A ByteCount in QUIC
|
||||||
type ByteCount uint64
|
type ByteCount uint64
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user