mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-07 01:10:03 +00:00
Add quick listener
This commit is contained in:
@@ -2,11 +2,11 @@ package quic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/quic-go/quic-go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type QuicAddr struct {
|
||||
@@ -36,22 +36,21 @@ func NewConn(session quic.Connection, serverAddress string) net.Conn {
|
||||
}
|
||||
|
||||
func (c *Conn) Read(b []byte) (n int, err error) {
|
||||
// Use the QUIC stream's Read method directly
|
||||
dgram, err := c.session.ReceiveDatagram(c.ctx)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to read from QUIC stream: %v", err)
|
||||
log.Errorf("failed to read from QUIC session: %v", err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Copy data to b, ensuring we don’t exceed the size of b
|
||||
n = copy(b, dgram)
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (c *Conn) Write(b []byte) (int, error) {
|
||||
// Use the QUIC stream's Write method directly
|
||||
err := c.session.SendDatagram(b)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to write to QUIC stream: %v", err)
|
||||
log.Errorf("failed to write to QUIC stream: %v", err)
|
||||
return 0, err
|
||||
}
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/quic-go/quic-go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -35,9 +36,12 @@ func Dial(address string) (net.Conn, error) {
|
||||
EnableDatagrams: true,
|
||||
}
|
||||
|
||||
// todo add support for custom dialer
|
||||
|
||||
session, err := quic.DialAddr(ctx, quicURL, tlsConf, quicConfig)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to dial QUIC server '%s': %v", quicURL, err)
|
||||
log.Errorf("failed to dial to Relay server via QUIC '%s': %s", quicURL, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conn := NewConn(session, address)
|
||||
|
||||
@@ -32,8 +32,6 @@ func Dial(address string) (net.Conn, error) {
|
||||
}
|
||||
parsedURL.Path = ws.URLPath
|
||||
|
||||
log.Infof("------ Dialing to Relay server: %s", wsURL)
|
||||
|
||||
wsConn, resp, err := websocket.Dial(context.Background(), parsedURL.String(), opts)
|
||||
if err != nil {
|
||||
log.Errorf("failed to dial to Relay server '%s': %s", wsURL, err)
|
||||
|
||||
Reference in New Issue
Block a user