Skip to content
File

Blob: overlay/overlay.go

go62 lines
1package overlay
2 
3import (
4 "context"
5 "crypto/tls"
6 "net"
7 
8 "go.miragespace.co/specter/spec/protocol"
9 "go.miragespace.co/specter/spec/rtt"
10 "go.miragespace.co/specter/spec/transport"
11 "go.miragespace.co/specter/util/atomic"
12 
13 "github.com/quic-go/quic-go"
14 "github.com/zhangyunhao116/skipmap"
15 uberAtomic "go.uber.org/atomic"
16 "go.uber.org/zap"
17)
18 
19type nodeConnection struct {
20 peer *protocol.Node
21 quic *quic.Conn
22 direction direction
23 version string
24}
25 
26type QuicDialer interface {
27 DialEarly(ctx context.Context, addr net.Addr, tlsConf *tls.Config, config *quic.Config) (*quic.Conn, error)
28}
29 
30type TransportConfig struct {
31 Logger *zap.Logger
32 QuicTransport QuicDialer
33 Endpoint *protocol.Node
34 ServerTLS *tls.Config
35 ClientTLS *tls.Config
36 RTTRecorder rtt.Recorder
37 VirtualTransport bool
38 UseCertificateIdentity bool
39}
40 
41type QUIC struct {
42 backgroundCtx context.Context
43 stopBackground context.CancelFunc
44 
45 cachedConnections *skipmap.StringMap[*nodeConnection]
46 cachedMutex *atomic.KeyedRWMutex
47 negotiations *skipmap.StringMap[chan struct{}] // present only during negotiation
48 
49 started *uberAtomic.Bool
50 closed *uberAtomic.Bool
51 
52 streamChan chan *transport.StreamDelegate
53 dgramChan chan *transport.DatagramDelegate
54 
55 rttChan chan *transport.DatagramDelegate
56 rttMap *skipmap.StringMap[*skipmap.Uint64Map[int64]]
57 
58 clientCert uberAtomic.Value // tls.Certificate
59 
60 TransportConfig
61}