mirror of
https://github.com/hanzoai/base.git
synced 2026-10-21 03:41:50 +00:00
* fix(zap): make mDNS discovery opt-in With ZAP on a non-loopback address, plugins/zap still ran mDNS unless --no-mdns was passed: it announced _hanzo-base._tcp on the LAN, and handlePeerEvent dialled any peer that announced it back. Hanzo nodes reach each other through explicit peers, so discovery is now off unless --mdns or ZAP_MDNS asks for it, and never on loopback. --no-mdns still forces it off, so v1.5.93 configs keep their meaning. Every other ZAP node in the repo already sets NoDiscovery. Co-Authored-By: Claude Opus 5 <[email protected]> * fix(tasks): take hanzoai/tasks v1.53.2, whose ZAP clients do not listen plugins/tasks dials a Tasks server through hanzoai/tasks' SDK client. At v1.52.9 that client, like pkg/tasks', started its node on Port 0, listening on every interface, before dialling out. v1.53.2 dials without starting a listener (hanzoai/tasks b4a8209c). zap-proto/zip moves to v1.36.9 with it. Co-Authored-By: Claude Opus 5 <[email protected]> --------- Co-authored-by: Claude Opus 5 <[email protected]>
69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
// Package zap provides a ZAP binary protocol transport for Hanzo Base.
|
|
//
|
|
// Instead of HTTP/JSON, clients can communicate with Base using the
|
|
// ZAP zero-copy binary protocol for significantly lower latency and
|
|
// memory usage.
|
|
package zap
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/hanzoai/base/tools/osutils"
|
|
)
|
|
|
|
// Config for the ZAP transport plugin.
|
|
type Config struct {
|
|
// Port to listen on for ZAP connections (default 9999).
|
|
Port int
|
|
|
|
// Address is the host:port to listen on, overriding Port (default
|
|
// ZAP_ADDR). Empty means the HTTP server's host on Port, so a Base
|
|
// serving HTTP on loopback serves ZAP on loopback too. ":9999" is every
|
|
// interface, which is only what an operator gets by writing it.
|
|
Address string
|
|
|
|
// MDNS turns on mDNS: the node advertises itself on the LAN and dials the
|
|
// peers it finds there (default ZAP_MDNS, else off). Hanzo nodes reach each
|
|
// other through explicit peers, so discovery runs only for an operator who
|
|
// asks for it, and never on a loopback address, where no peer that learned
|
|
// of the node could reach it.
|
|
MDNS bool
|
|
|
|
// NoMDNS keeps mDNS off even when MDNS asks for it. It predates MDNS, from
|
|
// when discovery was on by default, and stays so that configs written for
|
|
// v1.5.93 keep meaning what they say.
|
|
NoMDNS bool
|
|
|
|
// ServiceType for mDNS discovery (default "_hanzo-base._tcp").
|
|
ServiceType string
|
|
|
|
// NodeID for ZAP peer identification (default hostname-based).
|
|
NodeID string
|
|
|
|
// Enabled controls whether the ZAP listener starts (default true).
|
|
Enabled bool
|
|
}
|
|
|
|
// DefaultConfig returns a Config with sensible defaults.
|
|
func DefaultConfig() Config {
|
|
nodeID, _ := os.Hostname()
|
|
if nodeID == "" {
|
|
nodeID = "base-node"
|
|
}
|
|
|
|
port := 9999
|
|
if p := os.Getenv("ZAP_PORT"); p != "" {
|
|
fmt.Sscanf(p, "%d", &port)
|
|
}
|
|
|
|
return Config{
|
|
Port: port,
|
|
Address: os.Getenv("ZAP_ADDR"),
|
|
MDNS: osutils.Bool("ZAP_MDNS", false),
|
|
ServiceType: "_hanzo-base._tcp",
|
|
NodeID: nodeID,
|
|
Enabled: !osutils.Bool("ZAP_DISABLED", false),
|
|
}
|
|
}
|