Commit dcbbf185 authored by acud's avatar acud Committed by GitHub

reduce max peers, introduce context timeout on RetrieveChunk (#355)

* reduce max peers, introduce context timeout on RetrieveChunk
Co-authored-by: default avatarJanos Guljas <janos@resenje.org>
parent efd19f5c
...@@ -71,11 +71,14 @@ func (s *Service) Protocol() p2p.ProtocolSpec { ...@@ -71,11 +71,14 @@ func (s *Service) Protocol() p2p.ProtocolSpec {
} }
const ( const (
maxPeers = 10 maxPeers = 5
retrieveChunkTimeout = 3 * time.Second retrieveChunkTimeout = 10 * time.Second
) )
func (s *Service) RetrieveChunk(ctx context.Context, addr swarm.Address) (data []byte, err error) { func (s *Service) RetrieveChunk(ctx context.Context, addr swarm.Address) (data []byte, err error) {
ctx, cancel := context.WithTimeout(ctx, maxPeers*retrieveChunkTimeout)
defer cancel()
v, err, _ := s.singleflight.Do(addr.String(), func() (v interface{}, err error) { v, err, _ := s.singleflight.Do(addr.String(), func() (v interface{}, err error) {
var skipPeers []swarm.Address var skipPeers []swarm.Address
for i := 0; i < maxPeers; i++ { for i := 0; i < maxPeers; i++ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment