mirror of https://github.com/voidlizard/hbs2
wip
This commit is contained in:
parent
54d7e1af6f
commit
2334645944
|
@ -470,22 +470,20 @@ downloadFromPeer bu cache env h peer = liftIO $ withPeerM env do
|
|||
|
||||
callCC $ \exit2 -> do
|
||||
|
||||
_wx <- newTVarIO waity
|
||||
_wx <- newTVarIO 10000 -- waity
|
||||
|
||||
for_ bursts $ \(i,chunkN) -> do
|
||||
|
||||
wx <- readTVarIO _wx
|
||||
|
||||
flip fix 0 \again n -> do
|
||||
|
||||
let req = BlockChunks @e coo (BlockGetChunks h chunkSize (fromIntegral i) (fromIntegral chunkN))
|
||||
|
||||
lift $ request peer req
|
||||
|
||||
t0 <- getTimeCoarse
|
||||
|
||||
_num <- newTVarIO 0
|
||||
|
||||
wx <- readTVarIO _wx
|
||||
|
||||
let w0 = 2.0 :: Timeout 'MilliSeconds
|
||||
|
||||
let watchdog = flip fix 0 \next x -> do
|
||||
|
@ -495,6 +493,8 @@ downloadFromPeer bu cache env h peer = liftIO $ withPeerM env do
|
|||
if x == y then retry else pure y
|
||||
either (const none) next r
|
||||
|
||||
t0 <- getTimeCoarse
|
||||
|
||||
r <- liftIO $ pause w0 >> race watchdog do
|
||||
atomically do
|
||||
pieces <- readTVar _sBlockChunks2
|
||||
|
@ -507,13 +507,14 @@ downloadFromPeer bu cache env h peer = liftIO $ withPeerM env do
|
|||
atomically do
|
||||
when (isRight r) do
|
||||
let nano = toNanoSeconds $ TimeoutTS (t1 - t0)
|
||||
let wx1 = 100 * realToFrac nano / 1e6 -- millis
|
||||
let wx1 = max 1000 (100 * realToFrac nano / 1e6) -- millis
|
||||
writeTVar _wx wx1
|
||||
|
||||
case r of
|
||||
Left{} -> do
|
||||
if n < 2 then do
|
||||
debug $ red "Retry" <+> pretty i <+> pretty chunkN <+> pretty h <+> pretty peer
|
||||
w <- readTVarIO _wx
|
||||
debug $ red "Retry" <+> pretty w <+> pretty i <+> pretty chunkN <+> pretty h <+> pretty peer
|
||||
again (succ n)
|
||||
else do
|
||||
exit2 (Left $ DownloadStuckError (HashRef h) peer)
|
||||
|
|
Loading…
Reference in New Issue