mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
dfbc2e81e3
quic-go now vendors all of its dependencies, so we don't need to vendor them here. Created by running: gvt delete github.com/lucas-clemente/quic-go gvt delete github.com/bifurcation/mint gvt delete github.com/lucas-clemente/aes12 gvt delete github.com/lucas-clemente/fnv128a gvt delete github.com/lucas-clemente/quic-go-certificates gvt delete github.com/aead/chacha20 gvt delete github.com/hashicorp/golang-lru gvt fetch -tag v0.10.0-no-integrationtests github.com/lucas-clemente/quic-go
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package quic
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"sync"
|
|
|
|
"github.com/lucas-clemente/quic-go/internal/utils"
|
|
)
|
|
|
|
var (
|
|
connMuxerOnce sync.Once
|
|
connMuxer multiplexer
|
|
)
|
|
|
|
type multiplexer interface {
|
|
AddConn(net.PacketConn, int) (packetHandlerManager, error)
|
|
}
|
|
|
|
type connManager struct {
|
|
connIDLen int
|
|
manager packetHandlerManager
|
|
}
|
|
|
|
// The connMultiplexer listens on multiple net.PacketConns and dispatches
|
|
// incoming packets to the session handler.
|
|
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
|
|
|
|
logger utils.Logger
|
|
}
|
|
|
|
var _ multiplexer = &connMultiplexer{}
|
|
|
|
func getMultiplexer() multiplexer {
|
|
connMuxerOnce.Do(func() {
|
|
connMuxer = &connMultiplexer{
|
|
conns: make(map[net.PacketConn]connManager),
|
|
logger: utils.DefaultLogger.WithPrefix("muxer"),
|
|
newPacketHandlerManager: newPacketHandlerMap,
|
|
}
|
|
})
|
|
return connMuxer
|
|
}
|
|
|
|
func (m *connMultiplexer) AddConn(c net.PacketConn, connIDLen int) (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}
|
|
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)
|
|
}
|
|
return p.manager, nil
|
|
}
|