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

main: add ConnectedPeers() to server #2295

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,34 @@ type removeNodeMsg struct {
reply chan error
}

// ConnectedPeers returns an array consisting of all connected peers.
func (s *server) ConnectedPeers() []*peer.Peer {
replyChan := make(chan []*serverPeer, 1)

// Send a query for a subscription for the connected peers.
select {
case s.query <- getPeersMsg{
reply: replyChan,
}:

case <-s.quit:
return nil
}

// Wait for the result here.
select {
case reply := <-replyChan:
peers := make([]*peer.Peer, 0, len(reply))
for _, sp := range reply {
peers = append(peers, sp.Peer)
}

return peers
case <-s.quit:
return nil
}
}

// handleQuery is the central handler for all queries and commands from other
// goroutines related to peer state.
func (s *server) handleQuery(state *peerState, querymsg interface{}) {
Expand Down
Loading