Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ func (c *Config) HTTPEndpoint() string {
if c.HTTPHost == "" {
return ""
}
return fmt.Sprintf("%s:%d", c.HTTPHost, c.HTTPPort)
host := c.HTTPHost
if strings.Contains(host, ":") {
host = "[" + host + "]" // IPv6 address
}
return fmt.Sprintf("%s:%d", host, c.HTTPPort)
}

// DefaultHTTPEndpoint returns the HTTP endpoint used by default.
Expand All @@ -278,7 +282,11 @@ func (c *Config) WSEndpoint() string {
if c.WSHost == "" {
return ""
}
return fmt.Sprintf("%s:%d", c.WSHost, c.WSPort)
host := c.HTTPHost
if strings.Contains(host, ":") {
host = "[" + host + "]" // IPv6 address
}
return fmt.Sprintf("%s:%d", host, c.WSPort)
}

// DefaultWSEndpoint returns the websocket endpoint used by default.
Expand Down
4 changes: 3 additions & 1 deletion node/rpcstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ func (h *httpServer) setListenAddr(host string, port int) error {
if h.listener != nil && (host != h.host || port != h.port) {
return fmt.Errorf("HTTP server already running on %s", h.endpoint)
}

if strings.Contains(host, ":") {
host = "[" + host + "]" // IPv6
}
h.host, h.port = host, port
h.endpoint = fmt.Sprintf("%s:%d", host, port)
return nil
Expand Down