small pixel drawing of a pufferfish cascade

fix cascade bind regression
Jes Olson j3s@c3f.net
Mon, 20 Feb 2023 04:35:44 -0800
commit

60a2e19940e15af33ddea2cd27d1ab4f9123cd52

parent

d9e4dd869f5bcc83accc4fccdd9a68194aa8a9de

4 files changed, 42 insertions(+), 5 deletions(-)

jump to
M agent/agent.goagent/agent.go

@@ -189,8 +189,6 @@ n, err = a.serf.Join(addrs, true)

if err != nil { return n, fmt.Errorf("Error joining: %v\n", err) } - // TODO: when joining fails, we don't get an error here - serf & memberlist - // just print to stdout and serf.Join returns without issue. return n, err }
M agent/config.goagent/config.go

@@ -6,7 +6,7 @@ "os"

) const DefaultBindPort int = 4443 -const DefaultClientPort int = 4443 +const DefaultClientPort int = 4444 func DefaultConfig() *Config { hostname, err := os.Hostname()
A ipaddr/ipaddr.go

@@ -0,0 +1,34 @@

+package ipaddr + +import ( + "log" + "net" + "strconv" + "strings" +) + +// resolveHost will take a single host string and convert it to a list of TCPAddrs +// This will process any port in the input as well as looking up the hostname using +// normal DNS resolution. +func ParseIPPort(IPPort string) *net.TCPAddr { + var addr net.TCPAddr + ip, portStr, err := net.SplitHostPort(IPPort) + if err != nil { + if strings.Contains(err.Error(), "missing port in address") { + ip = IPPort + } else { + log.Printf("error splitting ip+port '%s' into IP and port: %s\n", IPPort, err) + return &addr + } + } else { + addr.Port, err = strconv.Atoi(portStr) + if err != nil { + log.Printf("Parsed port '%s' is not an integer: %s\n", portStr, err) + return &addr + } + } + + addr.IP = net.ParseIP(ip) + + return &addr +}
M main.gomain.go

@@ -10,6 +10,7 @@ "syscall"

"time" "git.j3s.sh/cascade/agent" + "git.j3s.sh/cascade/ipaddr" "git.j3s.sh/cascade/list" )

@@ -47,6 +48,7 @@ }

func handleAgent() { config := getAgentConfig() + fmt.Printf("%+v", config) agent := agent.New(config) if err := agent.Start(); err != nil { fmt.Println(err)

@@ -134,8 +136,11 @@ func getAgentConfig() *agent.Config {

config := agent.DefaultConfig() // CASCADE_BIND=192.168.0.15:12345 if os.Getenv("CASCADE_BIND") != "" { - //TODO - // config.BindAddr = os.Getenv("CASCADE_BIND") + addr := ipaddr.ParseIPPort(os.Getenv("CASCADE_BIND")) + config.BindAddr.IP = addr.IP + if addr.Port != 0 { + config.BindAddr.Port = addr.Port + } } // CASCADE_JOIN=127.0.0.1,127.0.0.5 if os.Getenv("CASCADE_JOIN") != "" {