mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/network/stream: fix data races in GetPeerSubscriptions
This commit is contained in:
parent
73d5c97595
commit
d233560768
1 changed files with 6 additions and 0 deletions
|
|
@ -938,16 +938,22 @@ It returns a map of node IDs with an array of string representations of Stream o
|
||||||
func (api *API) GetPeerSubscriptions() map[string][]string {
|
func (api *API) GetPeerSubscriptions() map[string][]string {
|
||||||
//create the empty map
|
//create the empty map
|
||||||
pstreams := make(map[string][]string)
|
pstreams := make(map[string][]string)
|
||||||
|
|
||||||
//iterate all streamer peers
|
//iterate all streamer peers
|
||||||
|
api.streamer.peersMu.RLock()
|
||||||
|
defer api.streamer.peersMu.RUnlock()
|
||||||
|
|
||||||
for id, p := range api.streamer.peers {
|
for id, p := range api.streamer.peers {
|
||||||
var streams []string
|
var streams []string
|
||||||
//every peer has a map of stream servers
|
//every peer has a map of stream servers
|
||||||
//every stream server represents a subscription
|
//every stream server represents a subscription
|
||||||
|
p.serverMu.RLock()
|
||||||
for s := range p.servers {
|
for s := range p.servers {
|
||||||
//append the string representation of the stream
|
//append the string representation of the stream
|
||||||
//to the list for this peer
|
//to the list for this peer
|
||||||
streams = append(streams, s.String())
|
streams = append(streams, s.String())
|
||||||
}
|
}
|
||||||
|
p.serverMu.RUnlock()
|
||||||
//set the array of stream servers to the map
|
//set the array of stream servers to the map
|
||||||
pstreams[id.String()] = streams
|
pstreams[id.String()] = streams
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue