Files
rdp-proxy/agents/rap-node-agent/internal/mesh/fabric_transport.go
T
2026-05-16 10:19:16 +03:00

85 lines
2.0 KiB
Go

package mesh
import (
"context"
"crypto/tls"
"net/http"
"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 {
PeerID string
Endpoint string
Token string
Header http.Header
TLSConfig *tls.Config
Timeout time.Duration
MaxPayload int
OutboundBuffer int
InboundBuffer int
ErrorBuffer int
}
type WebSocketFabricTransport struct {
Manager *FabricSessionPeerManager
}
func NewWebSocketFabricTransport(manager *FabricSessionPeerManager) *WebSocketFabricTransport {
if manager == nil {
manager = NewFabricSessionPeerManager()
}
return &WebSocketFabricTransport{Manager: manager}
}
func (t *WebSocketFabricTransport) Connect(ctx context.Context, target FabricTransportTarget) (FabricTransportSession, error) {
manager := t.Manager
if manager == nil {
manager = NewFabricSessionPeerManager()
t.Manager = manager
}
return manager.Get(ctx, FabricSessionPeerTarget{
PeerID: target.PeerID,
BaseURL: target.Endpoint,
Options: FabricSessionDialOptions{
Token: target.Token,
Header: target.Header,
Timeout: target.Timeout,
MaxPayload: target.MaxPayload,
},
Pump: FabricSessionPumpOptions{
OutboundBuffer: target.OutboundBuffer,
InboundBuffer: target.InboundBuffer,
ErrorBuffer: target.ErrorBuffer,
},
})
}
func (t *WebSocketFabricTransport) Close() error {
if t == nil || t.Manager == nil {
return nil
}
return t.Manager.Close()
}
func (t *WebSocketFabricTransport) Snapshot() FabricSessionPeerManagerSnapshot {
if t == nil || t.Manager == nil {
return FabricSessionPeerManagerSnapshot{SchemaVersion: "rap.fabric_session_peer_manager.v1"}
}
return t.Manager.Snapshot()
}