Skip to content

Commit

Permalink
GetPeers now retuns a list of memberlist.Nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
gdiazlo committed Nov 20, 2018
1 parent 7749711 commit fd96b9e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions gossip/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,25 @@ func (a *Agent) decodeMetadata(buf []byte) (*AgentMeta, error) {
return meta, nil
}

func (a *Agent) GetPeers(max int, agentType AgentType) []*Member {
func memberToNode(members []*Member) []*memberlist.Node {
list := make([]*memberlist.Node, 0)
for _, m := range members {
list = append(list, &memberlist.Node{Addr: m.Addr, Port: m.Port})
}
return list
}

func (a *Agent) GetPeers(max int, agentType AgentType) []*memberlist.Node {

fullList := a.topology.Get(agentType)
if len(fullList) <= max {
return fullList
return memberToNode(fullList)
}

var filteredList []*Member
for i := 0; i < max; i++ {
filteredList = append(filteredList, fullList[i])
}

return filteredList
return memberToNode(filteredList)
}

0 comments on commit fd96b9e

Please sign in to comment.