mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 04:37:36 +03:00
implement sending of stateless resets
This commit is contained in:
parent
6cf20310fe
commit
94046cdb4b
13 changed files with 199 additions and 46 deletions
|
@ -1,6 +1,7 @@
|
|||
package quic
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
|
@ -14,13 +15,14 @@ var (
|
|||
)
|
||||
|
||||
type multiplexer interface {
|
||||
AddConn(net.PacketConn, int) (packetHandlerManager, error)
|
||||
AddConn(c net.PacketConn, connIDLen int, statelessResetKey []byte) (packetHandlerManager, error)
|
||||
RemoveConn(net.PacketConn) error
|
||||
}
|
||||
|
||||
type connManager struct {
|
||||
connIDLen int
|
||||
manager packetHandlerManager
|
||||
connIDLen int
|
||||
statelessResetKey []byte
|
||||
manager packetHandlerManager
|
||||
}
|
||||
|
||||
// The connMultiplexer listens on multiple net.PacketConns and dispatches
|
||||
|
@ -29,7 +31,7 @@ type connMultiplexer struct {
|
|||
mutex sync.Mutex
|
||||
|
||||
conns map[net.PacketConn]connManager
|
||||
newPacketHandlerManager func(net.PacketConn, int, utils.Logger) packetHandlerManager // so it can be replaced in the tests
|
||||
newPacketHandlerManager func(net.PacketConn, int, []byte, utils.Logger) packetHandlerManager // so it can be replaced in the tests
|
||||
|
||||
logger utils.Logger
|
||||
}
|
||||
|
@ -47,19 +49,30 @@ func getMultiplexer() multiplexer {
|
|||
return connMuxer
|
||||
}
|
||||
|
||||
func (m *connMultiplexer) AddConn(c net.PacketConn, connIDLen int) (packetHandlerManager, error) {
|
||||
func (m *connMultiplexer) AddConn(
|
||||
c net.PacketConn,
|
||||
connIDLen int,
|
||||
statelessResetKey []byte,
|
||||
) (packetHandlerManager, error) {
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
|
||||
p, ok := m.conns[c]
|
||||
if !ok {
|
||||
manager := m.newPacketHandlerManager(c, connIDLen, m.logger)
|
||||
p = connManager{connIDLen: connIDLen, manager: manager}
|
||||
manager := m.newPacketHandlerManager(c, connIDLen, statelessResetKey, m.logger)
|
||||
p = connManager{
|
||||
connIDLen: connIDLen,
|
||||
statelessResetKey: statelessResetKey,
|
||||
manager: manager,
|
||||
}
|
||||
m.conns[c] = p
|
||||
}
|
||||
if p.connIDLen != connIDLen {
|
||||
return nil, fmt.Errorf("cannot use %d byte connection IDs on a connection that is already using %d byte connction IDs", connIDLen, p.connIDLen)
|
||||
}
|
||||
if statelessResetKey != nil && !bytes.Equal(p.statelessResetKey, statelessResetKey) {
|
||||
return nil, fmt.Errorf("cannot use different stateless reset keys on the same packet conn")
|
||||
}
|
||||
return p.manager, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue