Cleanup
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
cb35625a53
commit
6b42a78c3f
@ -253,7 +253,6 @@ func (bs *BlockSync) sendRequestToPeer(ctx context.Context, p peer.ID, req *Bloc
|
||||
|
||||
var res BlockSyncResponse
|
||||
r := incrt.New(s, 50<<10, 5*time.Second)
|
||||
|
||||
if err := cborutil.ReadCborRPC(bufio.NewReader(r), &res); err != nil {
|
||||
bs.syncPeers.logFailure(p, time.Since(start))
|
||||
return nil, err
|
||||
|
@ -35,14 +35,28 @@ func New(rd ReaderDeadline, minSpeed int64, maxWait time.Duration) io.Reader {
|
||||
}
|
||||
}
|
||||
|
||||
func (crt *incrt) Read(buf []byte) (n int, err error) {
|
||||
type errNoWait struct{}
|
||||
|
||||
func (err errNoWait) Error() string {
|
||||
return "wait time exceeded"
|
||||
}
|
||||
func (err errNoWait) Timeout() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (crt *incrt) Read(buf []byte) (int, error) {
|
||||
start := now()
|
||||
err = crt.rd.SetReadDeadline(start.Add(crt.wait))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
if crt.wait == 0 {
|
||||
return 0, errNoWait{}
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err := crt.rd.SetReadDeadline(start.Add(crt.wait))
|
||||
if err != nil {
|
||||
log.Warn("unable to set daedline")
|
||||
}
|
||||
|
||||
n, err := crt.rd.Read(buf)
|
||||
|
||||
crt.rd.SetReadDeadline(time.Time{})
|
||||
if err == nil {
|
||||
dur := now().Sub(start)
|
||||
@ -55,8 +69,5 @@ func (crt *incrt) Read(buf []byte) (n int, err error) {
|
||||
crt.wait = crt.maxWait
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
n, err = crt.rd.Read(buf)
|
||||
return n, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user