Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
router: expire provider records 15 minutes after the last announcement
Tomas Tormo323a06923f83
diff --git a/cmd/sam-one/main.go b/cmd/sam-one/main.goindex 023192eb..db7253fe 100644--- a/cmd/sam-one/main.go+++ b/cmd/sam-one/main.go@@ -250,7 +250,7 @@ func main() {rootCmd.Flags().IntVar(&routerTunables.LowWaterMark, "router-low-watermark", 0, "Connection manager low watermark (0 keeps the component default)")rootCmd.Flags().IntVar(&routerTunables.HighWaterMark, "router-high-watermark", 0, "Connection manager high watermark (0 keeps the component default)")rootCmd.Flags().IntVar(&routerTunables.ConnsPerSourceIP, "router-conns-per-source-ip", 0, "Per-source-IP connection budget (0 follows the high watermark; proxied peers share source IPs)")- rootCmd.Flags().DurationVar(&routerTunables.DHTProviderAddrTTL, "router-dht-provider-addr-ttl", 0, "DHT provider address TTL (0 keeps the library default)")+ rootCmd.Flags().DurationVar(&routerTunables.DHTProviderAddrTTL, "router-dht-provider-addr-ttl", 0, "How long a DHT provider record lives after its last announcement (0 keeps the component default of 15m)")rootCmd.Flags().DurationVar(&routerTunables.DHTMaxRecordAge, "router-dht-max-record-age", 0, "DHT record max age (0 keeps the library default)")rootCmd.Flags().DurationVar(&routerTunables.RelayLimitDuration, "router-relay-limit-duration", 0, "Relayed connection lifetime (0 keeps the component default of 1h; use e.g. 24h for longer)")rootCmd.Flags().Var(&routerTunables.RelayLimitData, "router-relay-limit-data", "Bytes relayed per direction per connection, e.g. 512MiB (0 keeps the component default: no limit)")diff --git a/cmd/sam-router/main.go b/cmd/sam-router/main.goindex 12a4542e..c7565208 100644--- a/cmd/sam-router/main.go+++ b/cmd/sam-router/main.go@@ -127,7 +127,7 @@ func main() {rootCmd.Flags().BoolVar(&allowLoopback, "allow-loopback", false, "Allow loopback and link-local addresses for discovery")rootCmd.Flags().IntVar(&connsPerSourceIP, "conns-per-source-ip", 0, "Max inbound connections per source IP (0 keeps libp2p's default of 8); raise behind TLS-terminating proxies or NAT where many peers share source IPs")rootCmd.Flags().StringVar(&logLevel, "log-level", "info", "Log level (debug, info, warn, error)")- rootCmd.Flags().DurationVar(&dhtProviderAddrTTL, "dht-provider-addr-ttl", 0, "Time-To-Live for DHT provider addresses (0s uses library default)")+ rootCmd.Flags().DurationVar(&dhtProviderAddrTTL, "dht-provider-addr-ttl", router.DefaultDHTProviderAddrTTL, "How long a DHT provider record lives after its last announcement (0 = the default)")rootCmd.Flags().DurationVar(&dhtMaxRecordAge, "dht-max-record-age", 0, "Maximum age for DHT records (0s uses library default)")rootCmd.Flags().IntVar(&lowWaterMark, "low-watermark", 1000, "Connection manager low watermark limit")rootCmd.Flags().IntVar(&highWaterMark, "high-watermark", 4000, "Connection manager high watermark limit")diff --git a/internal/router/config.go b/internal/router/config.goindex 21e7a2f5..074c5063 100644--- a/internal/router/config.go+++ b/internal/router/config.go@@ -39,6 +39,8 @@ type Options struct {AllowLoopback boolBiscuitTimeout time.DurationLogVerbose bool+ // DHTProviderAddrTTL is how long a provider record lives after its last+ // announcement; 0 is DefaultDHTProviderAddrTTL.DHTProviderAddrTTL time.DurationDHTMaxRecordAge time.DurationLowWaterMark intdiff --git a/internal/router/router.go b/internal/router/router.goindex 7b2255dc..0c552c6b 100644--- a/internal/router/router.go+++ b/internal/router/router.go@@ -72,6 +72,10 @@ const (DefaultLowWaterMark = 1000DefaultHighWaterMark = 4000ConnGracePeriod = 1 * time.Minute+ // DefaultDHTProviderAddrTTL is three of a node's 5-minute reprovides: a+ // node that is gone drops out of discovery within it, one late reprovide+ // does not. The library default (48h) keeps every past identity listed.+ DefaultDHTProviderAddrTTL = 15 * time.Minute)var _ coreconnmgr.ConnectionGater = (*routerConnGate)(nil)@@ -474,14 +478,11 @@ func (r *Router) Start() (retErr error) {dht.Mode(dht.ModeServer),dht.ProtocolPrefix("/sam"),}- var pmOpts []records.Option- if r.config.DHTProviderAddrTTL > 0 {- pmOpts = append(pmOpts, records.ProviderAddrTTL(r.config.DHTProviderAddrTTL))- pmOpts = append(pmOpts, records.ProvideValidity(r.config.DHTProviderAddrTTL))- }- if len(pmOpts) > 0 {- dhtOpts = append(dhtOpts, dht.ProviderManagerOpts(pmOpts...))+ providerTTL := r.config.DHTProviderAddrTTL+ if providerTTL <= 0 {+ providerTTL = DefaultDHTProviderAddrTTL}+ dhtOpts = append(dhtOpts, dht.ProviderManagerOpts(records.ProviderAddrTTL(providerTTL), records.ProvideValidity(providerTTL)))if r.config.DHTMaxRecordAge > 0 {dhtOpts = append(dhtOpts, dht.MaxRecordAge(r.config.DHTMaxRecordAge))}diff --git a/site/content/docs/reference/router.md b/site/content/docs/reference/router.mdindex 7fd8a2d6..96c0bdb9 100644--- a/site/content/docs/reference/router.md+++ b/site/content/docs/reference/router.md@@ -42,7 +42,8 @@ replica count.| `--allow-loopback` | `false` | Announce and accept loopback and link-local addresses. For a router and nodes on one host. || `--conns-per-source-ip` | `8` (libp2p default) | Inbound connections accepted per source IP. Raise it behind a TLS-terminating proxy or a NAT that puts many peers on one address. || `--low-watermark`, `--high-watermark` | `1000`, `4000` | Connection manager limits. Above the high mark, connections are trimmed down to the low mark. |-| `--dht-provider-addr-ttl`, `--dht-max-record-age` | library defaults | DHT record lifetimes. |+| `--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-max-record-age` | library default | DHT value record lifetime. || `--relay-limit-duration`, `--relay-limit-data` | `1h`, `0` | Caps on each relayed connection: lifetime, and bytes per direction (`512MiB`, `1GB`). The relay cuts the connection when either is reached. `0` means no limit. || `--metrics-addr` | off | Serve `/metrics`, `/healthz` and `/readyz` without authentication on this address. `/readyz` returns `200` once the router is enrolled and the libp2p host is up. Keep this address separate from the libp2p ports and inside the cluster. || `--log-level` | `info` | `debug`, `info`, `warn`, `error`. `LOG_FORMAT=json` selects JSON output. |diff --git a/site/content/docs/reference/sam-one.md b/site/content/docs/reference/sam-one.mdindex 9ce07755..0986dbf8 100644--- a/site/content/docs/reference/sam-one.md+++ b/site/content/docs/reference/sam-one.md@@ -65,7 +65,7 @@ of zero leaves the default of that component unchanged.| `--router-lease-renew-interval` | `--lease-renew-interval` || `--router-low-watermark`, `--router-high-watermark` | `--low-watermark`, `--high-watermark` || `--router-conns-per-source-ip` | `--conns-per-source-ip`. `0` follows the high watermark, because peers behind a proxy share source IPs. |-| `--router-dht-provider-addr-ttl`, `--router-dht-max-record-age` | The DHT record lifetimes. |+| `--router-dht-provider-addr-ttl`, `--router-dht-max-record-age` | `--dht-provider-addr-ttl`, `--dht-max-record-age`. `0` keeps `15m` and the library default. || `--router-relay-limit-duration`, `--router-relay-limit-data` | `--relay-limit-duration`, `--relay-limit-data`. `0` keeps `1h` and no data limit, so set a long duration such as `24h` instead of an unlimited one. || `--router-allow-loopback` | `--allow-loopback`. Defaults to `true` here, for a laptop. Disable it on a public deployment. |