Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
node: refuse a provider TTL not exceeding the reprovide interval; drop --mesh
Antonio Ojeab0408082ea0d
diff --git a/cmd/agentmesh-node/main.go b/cmd/agentmesh-node/main.goindex b7ab1c39..ecc663ee 100644--- a/cmd/agentmesh-node/main.go+++ b/cmd/agentmesh-node/main.go@@ -66,7 +66,6 @@ var (bindAddrFlag stringmetricsAddrFlag stringsocketPathFlag string- meshFlag stringdiscoveryIntervalFlag stringlistenAddrs []stringenableRelayFlag bool@@ -863,8 +862,6 @@ func main() {runCmd.Flags().StringVar(&bindAddrFlag, "bind-addr", "127.0.0.1:8080", "Local TCP address for the HTTP server (MCP and Sidecar API); pass an empty value to serve only on the Unix socket")runCmd.Flags().StringVar(&socketPathFlag, "socket-path", "", "Unix socket serving the same API, where the socket's owner-only permissions replace the API token (defaults to <data-dir>/"+node.DefaultSocketName+"; pass an empty value to disable)")runCmd.Flags().StringVar(&metricsAddrFlag, "metrics-addr", "", "Serve Prometheus /metrics, /healthz and /readyz on this address without authentication (e.g. 0.0.0.0:9090), for scrapers and probes that hold no API token; off by default")- runCmd.Flags().StringVar(&meshFlag, "mesh", "public-mesh", "No effect; kept so existing invocations still parse")- _ = runCmd.Flags().MarkDeprecated("mesh", "the node no longer announces itself under a mesh name; the flag has no effect")runCmd.Flags().StringVar(&discoveryIntervalFlag, "discovery-interval", node.DefaultDiscoveryInterval, "Delay before the first announcement of this node's services to the DHT, capped at 5s; they are re-announced every 5 minutes after that")runCmd.Flags().DurationVar(&monitorBootstrapFlag, "monitor-bootstrap", 2*time.Minute, "Initial wait before monitoring router connection")runCmd.Flags().DurationVar(&monitorCheckIntervalFlag, "monitor-interval", 1*time.Minute, "Interval for checking router connection")@@ -893,7 +890,7 @@ func main() {runCmd.Flags().StringVar(&tlsCertFlag, "tls-cert", "", "Path to TLS certificate for sidecar API")runCmd.Flags().StringVar(&tlsKeyFlag, "tls-key", "", "Path to TLS key for sidecar API")runCmd.Flags().StringVar(&tlsCAFlag, "tls-ca", "", "Path to TLS CA for sidecar API mTLS")- runCmd.Flags().DurationVar(&dhtProviderAddrTTLFlag, "dht-provider-addr-ttl", node.DefaultDHTProviderAddrTTL, "How long a DHT provider record lives after its last announcement")+ runCmd.Flags().DurationVar(&dhtProviderAddrTTLFlag, "dht-provider-addr-ttl", node.DefaultDHTProviderAddrTTL, "How long a DHT provider record this node stores lives after its last announcement; longer than the 5m between announcements, three times it by default")runCmd.Flags().DurationVar(&dhtMaxRecordAgeFlag, "dht-max-record-age", 0, "Maximum age for DHT records (0s uses library default)")runCmd.Flags().IntVar(&dhtLookupLimitFlag, "dht-lookup-limit", 0, "Maximum number of providers to query from the DHT (0 uses default 20)")runCmd.Flags().IntVar(&discoveryConcurrencyFlag, "discovery-concurrency", 0, "Max concurrent catalog fetches during discovery (0 uses default 10)")diff --git a/internal/node/node.go b/internal/node/node.goindex 6791e7fe..e84d2c83 100644--- a/internal/node/node.go+++ b/internal/node/node.go@@ -792,12 +792,8 @@ func (n *AgentMeshNode) Start(ctx context.Context) error {// Start connection monitorn.startConnectionMonitor(ctx, n.config.MonitorBootstrap, n.config.MonitorInterval, 3)- // Periodically and on-demand reprovide registered services to the DHT.- // A record lives DHTProviderAddrTTL after its last announcement, so the- // announcements come at least three times within it, as the default- // pair does; an operator who shortens the TTL does not get a service- // that is absent most of the time.- n.startReprovideLoop(ctx, n.reprovideInterval())+ // Periodically and on-demand reprovide registered services to the DHT+ n.startReprovideLoop(ctx, ReprovideInterval)// Everything read from the control plane (keys, bans, router addresses,// policy) in one loop; gossip events only bring the next pull forward.@@ -819,16 +815,6 @@ func (n *AgentMeshNode) triggerReprovide() {}}-// reprovideInterval is ReprovideInterval, or a third of a shorter provider-// TTL, never under a second.-func (n *AgentMeshNode) reprovideInterval() time.Duration {- ttl := n.config.DHTProviderAddrTTL- if ttl <= 0 || ttl/3 >= ReprovideInterval {- return ReprovideInterval- }- return max(ttl/3, time.Second)-}-func (n *AgentMeshNode) startReprovideLoop(ctx context.Context, interval time.Duration) {go func() {initialDelay := 5 * time.Seconddiff --git a/internal/node/node_test.go b/internal/node/node_test.goindex 13471a69..43da0fd8 100644--- a/internal/node/node_test.go+++ b/internal/node/node_test.go@@ -791,7 +791,7 @@ func TestNewAgentMeshNode_DHTOptions(t *testing.T) {PrivKey: priv,Store: store,ListenAddrs: []string{"/ip4/127.0.0.1/tcp/0"},- DHTProviderAddrTTL: 10 * time.Second,+ DHTProviderAddrTTL: 10 * time.Minute,DHTMaxRecordAge: 15 * time.Second,DHTLookupLimit: 50,DiscoveryConcurrency: 5,@@ -802,8 +802,8 @@ func TestNewAgentMeshNode_DHTOptions(t *testing.T) {t.Fatalf("failed to create node with DHT options: %v", err)}- if node.config.DHTProviderAddrTTL != 10*time.Second {- t.Errorf("expected DHTProviderAddrTTL to be 10s, got %v", node.config.DHTProviderAddrTTL)+ if node.config.DHTProviderAddrTTL != 10*time.Minute {+ t.Errorf("expected DHTProviderAddrTTL to be 10m, got %v", node.config.DHTProviderAddrTTL)}if node.config.DHTMaxRecordAge != 15*time.Second {t.Errorf("expected DHTMaxRecordAge to be 15s, got %v", node.config.DHTMaxRecordAge)@@ -891,25 +891,3 @@ func TestFindProvidersSkipsRevoked(t *testing.T) {t.Errorf("revoked peer returned as provider: %v", providers)}}--// A provider record lives DHTProviderAddrTTL; the node announces at least-// three times within it, so a shorter TTL shortens the interval and the-// default pair stays as it was.-func TestReprovideIntervalFollowsProviderTTL(t *testing.T) {- for _, tc := range []struct {- ttl time.Duration- want time.Duration- }{- {0, ReprovideInterval},- {DefaultDHTProviderAddrTTL, ReprovideInterval},- {time.Hour, ReprovideInterval},- {30 * time.Second, 10 * time.Second},- {5 * time.Second, 5 * time.Second / 3},- {time.Second, time.Second},- } {- n := &AgentMeshNode{config: Options{DHTProviderAddrTTL: tc.ttl}}- if got := n.reprovideInterval(); got != tc.want {- t.Errorf("ttl %s: reprovide every %s, want %s", tc.ttl, got, tc.want)- }- }-}diff --git a/internal/node/options.go b/internal/node/options.goindex 1e14327e..afb45332 100644--- a/internal/node/options.go+++ b/internal/node/options.go@@ -283,5 +283,10 @@ func (o *Options) Validate() error {if len(o.ControlPlanePubKey) > 0 && len(o.ControlPlanePubKey) != ed25519.PublicKeySize {return fmt.Errorf("control plane public key must be %d bytes, got %d", ed25519.PublicKeySize, len(o.ControlPlanePubKey))}+ // A record that expires between two announcements is absent most of the+ // time; the node refuses the configuration rather than announcing faster.+ if o.DHTProviderAddrTTL != 0 && o.DHTProviderAddrTTL <= ReprovideInterval {+ return fmt.Errorf("DHTProviderAddrTTL %s must be strictly longer than the %s between announcements; %s is used by default", o.DHTProviderAddrTTL, ReprovideInterval, DefaultDHTProviderAddrTTL)+ }return nil}diff --git a/internal/node/options_test.go b/internal/node/options_test.goindex 109370b2..c003e3e5 100644--- a/internal/node/options_test.go+++ b/internal/node/options_test.go@@ -19,6 +19,7 @@ import ("crypto/rand""strings""testing"+ "time""github.com/google/agentmesh/api""github.com/libp2p/go-libp2p/core/crypto"@@ -56,6 +57,37 @@ func TestOptionsValidateControlPlaneKeySize(t *testing.T) {}}+// A provider record that expires between two announcements is absent most+// of the time. The node refuses the configuration instead of compensating.+func TestOptionsValidateProviderTTLOutlivesReprovide(t *testing.T) {+ priv, _, err := crypto.GenerateEd25519Key(rand.Reader)+ if err != nil {+ t.Fatal(err)+ }+ store, err := NewStore(t.TempDir())+ if err != nil {+ t.Fatal(err)+ }+ defer func() { _ = store.Close() }()+ base := Options{PrivKey: priv, Store: store, RequiredRole: api.RoleNode}++ for _, ttl := range []time.Duration{0, DefaultDHTProviderAddrTTL, time.Hour} {+ o := base+ o.DHTProviderAddrTTL = ttl+ if err := o.Validate(); err != nil {+ t.Errorf("DHTProviderAddrTTL %s rejected: %v", ttl, err)+ }+ }+ for _, ttl := range []time.Duration{ReprovideInterval, ReprovideInterval - time.Second} {+ o := base+ o.DHTProviderAddrTTL = ttl+ err = o.Validate()+ if err == nil || !strings.Contains(err.Error(), "between announcements") {+ t.Errorf("DHTProviderAddrTTL %s: err = %v, want a refusal naming the announcement interval", o.DHTProviderAddrTTL, err)+ }+ }+}+func TestOptionsReachability(t *testing.T) {priv, _, err := crypto.GenerateEd25519Key(rand.Reader)if err != nil {diff --git a/site/content/docs/reference/agentmesh-node.md b/site/content/docs/reference/agentmesh-node.mdindex 8d8a1c22..a2c2feed 100644--- a/site/content/docs/reference/agentmesh-node.md+++ b/site/content/docs/reference/agentmesh-node.md@@ -117,7 +117,7 @@ explains how to enroll.| `--discovery-interval` | `30s` | Delay before the first announcement of this node's services to the DHT, capped at 5 s; services are re-announced every 5 minutes after that. || `--dht-lookup-limit` | `20` | Providers to query per DHT lookup. || `--discovery-concurrency` | `10` | Concurrent catalog fetches during discovery. |-| `--dht-provider-addr-ttl` | `15m` | How long a service announcement lives after a node last made it. Nodes re-announce every 5 minutes, so a node that is gone drops out of discovery within this time. `0` keeps the default. |+| `--dht-provider-addr-ttl` | `15m` | How long a service announcement this node stores lives after the announcing node last made it. Nodes re-announce every 5 minutes, so a node that is gone drops out of discovery within this time. A value of 5 minutes or less is refused at startup: the record would expire between two announcements. `0` keeps the default. || `--dht-max-record-age` | library default | DHT value record lifetime. || `--backend-probe-timeout` | `2s` | How long a service backend may take to answer before the node declines to advertise it. Raise it for subprocesses that start slowly. || `--secrets-dir` | `/etc/agentmesh/secrets` | Directory holding the credentials that the control plane's [egress destinations](../policy/#egress-destinations) name, one file per credential name. The platform puts the files there; the node reads a file on every request to the destination. |diff --git a/tests/e2e/lib/container_mesh.bash b/tests/e2e/lib/container_mesh.bashindex 301d36be..d2a7738d 100644--- a/tests/e2e/lib/container_mesh.bash+++ b/tests/e2e/lib/container_mesh.bash@@ -575,9 +575,6 @@ if [[ -z "${MESH_HELPERS_LOADED:-}" ]]; then--listen "/ip4/0.0.0.0/udp/5001/quic-v1" \--listen "/ip4/0.0.0.0/tcp/5002" \--bind-addr "0.0.0.0:8080" \- --mesh "${MESH_PREFIX}" \- --dht-provider-addr-ttl 5s \- --dht-max-record-age 5s \"${config_args[@]}" >/dev/nullMESH_CONTAINERS+=("${name}")