Initial project snapshot
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package mesh
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// HTTPPeerTransport sends synthetic mesh envelopes to explicitly configured
|
||||
// peer endpoints. It is intentionally narrow: production forwarding remains
|
||||
// disabled and only SyntheticRuntime messages use this transport.
|
||||
type HTTPPeerTransport struct {
|
||||
PeerURLs map[string]string
|
||||
HTTPClient *http.Client
|
||||
}
|
||||
|
||||
func NewHTTPPeerTransport(peerURLs map[string]string) *HTTPPeerTransport {
|
||||
normalized := make(map[string]string, len(peerURLs))
|
||||
for nodeID, baseURL := range peerURLs {
|
||||
nodeID = strings.TrimSpace(nodeID)
|
||||
baseURL = strings.TrimRight(strings.TrimSpace(baseURL), "/")
|
||||
if nodeID != "" && baseURL != "" {
|
||||
normalized[nodeID] = baseURL
|
||||
}
|
||||
}
|
||||
return &HTTPPeerTransport{PeerURLs: normalized}
|
||||
}
|
||||
|
||||
func (t *HTTPPeerTransport) SendSynthetic(ctx context.Context, nextNodeID string, envelope SyntheticEnvelope) (SyntheticEnvelope, error) {
|
||||
if t == nil {
|
||||
return SyntheticEnvelope{}, ErrSyntheticPeerUnavailable
|
||||
}
|
||||
baseURL := strings.TrimRight(strings.TrimSpace(t.PeerURLs[nextNodeID]), "/")
|
||||
if baseURL == "" {
|
||||
return SyntheticEnvelope{}, ErrSyntheticPeerUnavailable
|
||||
}
|
||||
client := NewClient(baseURL)
|
||||
if t.HTTPClient != nil {
|
||||
client.HTTPClient = t.HTTPClient
|
||||
}
|
||||
return client.SendSynthetic(ctx, envelope)
|
||||
}
|
||||
Reference in New Issue
Block a user