Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ipv6 leader election #107

Merged
Merged
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
17 changes: 15 additions & 2 deletions cmd/horcrux/cmd/leader_election.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,37 @@ horcrux elect 2 # elect specific leader`,
}

var grpcAddresses []string

// Append local host:port
u, err := url.Parse(config.Config.CosignerConfig.P2PListen)
if err != nil {
fmt.Printf("Error parsing peer URL: %v", err)
} else {
host, port, err := net.SplitHostPort(u.Host)
if err == nil {
grpcAddresses = append(grpcAddresses, fmt.Sprintf("%s:%s", host, port))
if strings.Contains(host, ":") {
// IPv6 Addreses need to be wrapped in brackets
grpcAddresses = append(grpcAddresses, fmt.Sprintf("[%s]:%s", host, port))
} else {
grpcAddresses = append(grpcAddresses, fmt.Sprintf("%s:%s", host, port))
}
}
}

// Append peer host:port
for _, peer := range config.Config.CosignerConfig.Peers {
u, err := url.Parse(peer.P2PAddr)
if err != nil {
fmt.Printf("Error parsing peer URL: %v", err)
} else {
host, port, err := net.SplitHostPort(u.Host)
if err == nil {
grpcAddresses = append(grpcAddresses, fmt.Sprintf("%s:%s", host, port))
if strings.Contains(host, ":") {
// IPv6 Addreses need to be wrapped in brackets
grpcAddresses = append(grpcAddresses, fmt.Sprintf("[%s]:%s", host, port))
} else {
grpcAddresses = append(grpcAddresses, fmt.Sprintf("%s:%s", host, port))
}
}
}
}
Expand Down