1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00

expose quic.ListenAddrs

This commit is contained in:
Sergey Cherepanov 2023-08-11 17:03:16 +02:00
parent a31f05a201
commit a7368f08ad
No known key found for this signature in database
GPG key ID: 87F8EDE8FBDF637C
2 changed files with 12 additions and 5 deletions

View file

@ -14,6 +14,7 @@ import (
"github.com/quic-go/quic-go"
"go.uber.org/zap"
"net"
"sync"
"time"
)
@ -26,6 +27,7 @@ func New() Quic {
}
type Quic interface {
ListenAddrs(ctx context.Context, addrs ...string) (err error)
transport.Transport
app.ComponentRunnable
}
@ -38,6 +40,7 @@ type quicTransport struct {
listeners []*quic.Listener
listCtx context.Context
listCtxCancel context.CancelFunc
mu sync.Mutex
}
func (q *quicTransport) Init(a *app.App) (err error) {
@ -70,6 +73,13 @@ func (q *quicTransport) Run(ctx context.Context) (err error) {
return fmt.Errorf("can't run service without accepter")
}
q.listCtx, q.listCtxCancel = context.WithCancel(context.Background())
return q.ListenAddrs(ctx, q.conf.ListenAddrs...)
}
func (q *quicTransport) ListenAddrs(ctx context.Context, addrs ...string) (err error) {
q.mu.Lock()
defer q.mu.Unlock()
var tlsConf tls.Config
tlsConf.GetConfigForClient = func(_ *tls.ClientHelloInfo) (*tls.Config, error) {
conf, _, tlsErr := q.secure.TlsConfig()
@ -80,15 +90,12 @@ func (q *quicTransport) Run(ctx context.Context) (err error) {
if err != nil {
return
}
for _, listAddr := range q.conf.ListenAddrs {
for _, listAddr := range addrs {
list, err := quic.ListenAddr(listAddr, &tlsConf, q.quicConf)
if err != nil {
return err
}
q.listeners = append(q.listeners, list)
}
q.listCtx, q.listCtxCancel = context.WithCancel(context.Background())
for _, list := range q.listeners {
go q.acceptLoop(q.listCtx, list)
}
return

View file

@ -74,7 +74,7 @@ func TestQuicTransport_Dial(t *testing.T) {
// common write deadline - 66700 rps
// subconn write deadline - 67100 rps
func TestWriteBenchReuse(t *testing.T) {
//t.Skip()
t.Skip()
var (
numSubConn = 10
numWrites = 10000