Select fabric carrier by endpoint
This commit is contained in:
@@ -3,7 +3,9 @@ package mesh
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/example/remote-access-platform/agents/rap-node-agent/internal/fabricproto"
|
||||
@@ -25,6 +27,7 @@ type FabricTransport interface {
|
||||
type FabricTransportTarget struct {
|
||||
PeerID string
|
||||
Endpoint string
|
||||
Transport string
|
||||
Token string
|
||||
Header http.Header
|
||||
TLSConfig *tls.Config
|
||||
@@ -35,6 +38,29 @@ type FabricTransportTarget struct {
|
||||
ErrorBuffer int
|
||||
}
|
||||
|
||||
func FabricTransportForTarget(target FabricTransportTarget, websocket *WebSocketFabricTransport, quicTransport *QUICFabricTransport) (FabricTransport, FabricTransportTarget, error) {
|
||||
transportLabel := strings.ToLower(strings.TrimSpace(target.Transport))
|
||||
endpoint := strings.TrimSpace(target.Endpoint)
|
||||
if strings.HasPrefix(strings.ToLower(endpoint), "quic://") {
|
||||
transportLabel = "quic"
|
||||
target.Endpoint = strings.TrimPrefix(endpoint, "quic://")
|
||||
}
|
||||
switch transportLabel {
|
||||
case "quic", "direct_quic", "udp_quic", "quic_udp":
|
||||
if quicTransport == nil {
|
||||
quicTransport = NewQUICFabricTransport(nil)
|
||||
}
|
||||
return quicTransport, target, nil
|
||||
case "", "websocket", "ws", "wss", "direct_http", "direct_https", "direct_tcp_tls":
|
||||
if websocket == nil {
|
||||
websocket = NewWebSocketFabricTransport(nil)
|
||||
}
|
||||
return websocket, target, nil
|
||||
default:
|
||||
return nil, target, fmt.Errorf("unsupported fabric transport %q", target.Transport)
|
||||
}
|
||||
}
|
||||
|
||||
type WebSocketFabricTransport struct {
|
||||
Manager *FabricSessionPeerManager
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user