Skip to content

Commit

Permalink
resolving the seed hostname on join
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar committed Nov 18, 2017
1 parent b7a4cfe commit e9f69d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
19 changes: 17 additions & 2 deletions broker/cluster/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,23 @@ func (s *Swarm) update() {
}

// Join attempts to join a set of existing peers.
func (s *Swarm) Join(peers ...string) []error {
return s.router.ConnectionMaker.InitiateConnections(peers, false)
func (s *Swarm) Join(peers ...string) (errs []error) {

// Resolve the host-names of the peers provided
var addrs []string
for _, h := range peers {
ips, err := net.LookupHost(h)
if err != nil {
errs = append(errs, err)
}
addrs = append(addrs, ips...)
}

// Use all the available addresses to initiate the connections
if s.router != nil {
errs = s.router.ConnectionMaker.InitiateConnections(addrs, false)
}
return
}

// Merge merges the incoming state and returns a delta
Expand Down
7 changes: 7 additions & 0 deletions broker/cluster/swarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,10 @@ func Test_merge(t *testing.T) {
assert.NoError(t, err)
assert.True(t, subscribed)
}

func TestJoin(t *testing.T) {
s := new(Swarm)

errs := s.Join("google.com", "127.0.0.1")
assert.Empty(t, errs)
}

0 comments on commit e9f69d6

Please sign in to comment.