From e7b142c680c3b1ee57397fbfe5235702825ac0dd Mon Sep 17 00:00:00 2001 From: Jordan Sissel Date: Tue, 2 Jul 2013 22:08:33 -0700 Subject: [PATCH] - pick a server at random when connecting --- publisher1.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/publisher1.go b/publisher1.go index 202135e..de83486 100644 --- a/publisher1.go +++ b/publisher1.go @@ -1,6 +1,7 @@ package main import ( + "math/rand" "bytes" "encoding/binary" "encoding/pem" @@ -133,8 +134,11 @@ func connect(config *NetworkConfig) (socket *tls.Conn) { tlsconfig.RootCAs.AddCert(cert) } - address := "127.0.0.1:3333" for { + // Pick a random server from the list. + address := config.Servers[rand.Int() % len(config.Servers)] + log.Printf("Connecting to %s\n", address) + tcpsocket, err := net.DialTimeout("tcp", address, config.Timeout) if err != nil { log.Printf("Failure connecting to %s: %s\n", address, err) -- GitLab