60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package mesh
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/example/remote-access-platform/agents/rap-node-agent/internal/fabricproto"
|
|
)
|
|
|
|
type FabricTransportSession interface {
|
|
Send(context.Context, fabricproto.Frame) error
|
|
Frames() <-chan fabricproto.Frame
|
|
Errors() <-chan error
|
|
Close() error
|
|
Closed() bool
|
|
}
|
|
|
|
type FabricTransport interface {
|
|
Connect(context.Context, FabricTransportTarget) (FabricTransportSession, error)
|
|
Close() error
|
|
}
|
|
|
|
type FabricTransportTarget struct {
|
|
EndpointID string
|
|
PeerID string
|
|
Endpoint string
|
|
Transport string
|
|
Token string
|
|
TLSConfig *tls.Config
|
|
PeerCertSHA256 string
|
|
Timeout time.Duration
|
|
MaxPayload int
|
|
OutboundBuffer int
|
|
InboundBuffer int
|
|
ErrorBuffer int
|
|
}
|
|
|
|
func FabricTransportForTarget(target FabricTransportTarget, quicTransport *QUICFabricTransport) (FabricTransport, FabricTransportTarget, error) {
|
|
transportLabel := strings.ToLower(strings.TrimSpace(target.Transport))
|
|
endpoint := strings.TrimSpace(target.Endpoint)
|
|
if strings.HasPrefix(strings.ToLower(endpoint), "quic://") {
|
|
if transportLabel == "" {
|
|
transportLabel = "quic"
|
|
}
|
|
target.Endpoint = strings.TrimPrefix(endpoint, "quic://")
|
|
}
|
|
switch transportLabel {
|
|
case "quic", "direct_quic", "udp_quic", "quic_udp", "lan_quic", "reverse_quic", "relay_quic", "ice_quic":
|
|
if quicTransport == nil {
|
|
quicTransport = NewQUICFabricTransport(nil)
|
|
}
|
|
return quicTransport, target, nil
|
|
default:
|
|
return nil, target, fmt.Errorf("unsupported fabric transport %q: quic is required", target.Transport)
|
|
}
|
|
}
|