diff options
author | Janos Guljas <janos@resenje.org> | 2018-09-24 23:40:22 +0800 |
---|---|---|
committer | Janos Guljas <janos@resenje.org> | 2018-09-24 23:56:00 +0800 |
commit | 9e99a0c2b94daa351325688702e2a49e34f60dbf (patch) | |
tree | a66c070a9c55eff5dda766cb35b013657eab37df /swarm/network/stream/peer.go | |
parent | 1f45ba9bb1c19489a6c8bf9caf100e56dcb79788 (diff) | |
download | dexon-9e99a0c2b94daa351325688702e2a49e34f60dbf.tar dexon-9e99a0c2b94daa351325688702e2a49e34f60dbf.tar.gz dexon-9e99a0c2b94daa351325688702e2a49e34f60dbf.tar.bz2 dexon-9e99a0c2b94daa351325688702e2a49e34f60dbf.tar.lz dexon-9e99a0c2b94daa351325688702e2a49e34f60dbf.tar.xz dexon-9e99a0c2b94daa351325688702e2a49e34f60dbf.tar.zst dexon-9e99a0c2b94daa351325688702e2a49e34f60dbf.zip |
cmd/swarm, swarm: add stream peer servers limit
Diffstat (limited to 'swarm/network/stream/peer.go')
-rw-r--r-- | swarm/network/stream/peer.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/swarm/network/stream/peer.go b/swarm/network/stream/peer.go index 1466a7a9c..aeaf7bbfa 100644 --- a/swarm/network/stream/peer.go +++ b/swarm/network/stream/peer.go @@ -18,6 +18,7 @@ package stream import ( "context" + "errors" "fmt" "sync" "time" @@ -46,6 +47,10 @@ func (e *notFoundError) Error() string { return fmt.Sprintf("%s not found for stream %q", e.t, e.s) } +// ErrMaxPeerServers will be returned if peer server limit is reached. +// It will be sent in the SubscribeErrorMsg. +var ErrMaxPeerServers = errors.New("max peer servers") + // Peer is the Peer extension for the streaming protocol type Peer struct { *protocols.Peer @@ -204,6 +209,11 @@ func (p *Peer) setServer(s Stream, o Server, priority uint8) (*server, error) { if p.servers[s] != nil { return nil, fmt.Errorf("server %s already registered", s) } + + if p.streamer.maxPeerServers > 0 && len(p.servers) >= p.streamer.maxPeerServers { + return nil, ErrMaxPeerServers + } + os := &server{ Server: o, stream: s, @@ -346,6 +356,7 @@ func (p *Peer) removeClient(s Stream) error { return newNotFoundError("client", s) } client.close() + delete(p.clients, s) return nil } |