-
-
Notifications
You must be signed in to change notification settings - Fork 631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add variables and comments #938
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
16c1e40
add webseed update timer
mh0lt 5d3d599
steal stability
mh0lt fa9fd1a
Merge pull request #1 from erigontech/webseed_update_timer
mh0lt 472bfbc
close body in same go routine as do
mh0lt 9db99ed
Merge pull request #2 from erigontech/http_body_close_simplification
mh0lt a06a84c
Added comments and variables instead of raw reason strings
mh0lt 5a0c693
Merge branch 'master' of https://github.com/erigontech/torrent
mh0lt 9d8abf6
added params and comments
mh0lt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ type webseedPeer struct { | |
client webseed.Client | ||
activeRequests map[Request]webseed.Request | ||
requesterCond sync.Cond | ||
updateRequestor *time.Timer | ||
lastUnhandledErr time.Time | ||
} | ||
|
||
|
@@ -72,7 +73,6 @@ func (ws *webseedPeer) intoSpec(r Request) webseed.RequestSpec { | |
} | ||
|
||
func (ws *webseedPeer) _request(r Request) bool { | ||
ws.requesterCond.Signal() | ||
return true | ||
} | ||
|
||
|
@@ -91,15 +91,17 @@ func (ws *webseedPeer) doRequest(r Request) error { | |
func (ws *webseedPeer) requester(i int) { | ||
ws.requesterCond.L.Lock() | ||
defer ws.requesterCond.L.Unlock() | ||
start: | ||
|
||
for !ws.peer.closed.IsSet() { | ||
// Restart is set if we don't need to wait for the requestCond before trying again. | ||
restart := false | ||
|
||
ws.peer.requestState.Requests.Iterate(func(x RequestIndex) bool { | ||
r := ws.peer.t.requestIndexToRequest(x) | ||
if _, ok := ws.activeRequests[r]; ok { | ||
return true | ||
} | ||
|
||
err := ws.doRequest(r) | ||
ws.requesterCond.L.Unlock() | ||
if err != nil && !errors.Is(err, context.Canceled) { | ||
|
@@ -117,10 +119,38 @@ start: | |
ws.requesterCond.L.Lock() | ||
return false | ||
}) | ||
if restart { | ||
goto start | ||
|
||
if !restart { | ||
if !ws.peer.t.dataDownloadDisallowed.Bool() && ws.peer.isLowOnRequests() && len(ws.peer.getDesiredRequestState().Requests.requestIndexes) > 0 { | ||
if ws.updateRequestor == nil { | ||
ws.updateRequestor = time.AfterFunc(updateRequestsTimerDuration, func() { requestUpdate(ws) }) | ||
} | ||
} | ||
|
||
ws.requesterCond.Wait() | ||
|
||
if ws.updateRequestor != nil { | ||
ws.updateRequestor.Stop() | ||
ws.updateRequestor = nil | ||
} | ||
} | ||
} | ||
} | ||
|
||
func requestUpdate(ws *webseedPeer) { | ||
if ws != nil { | ||
if !ws.peer.closed.IsSet() { | ||
if len(ws.peer.getDesiredRequestState().Requests.requestIndexes) > 0 { | ||
if ws.peer.isLowOnRequests() { | ||
if time.Since(ws.peer.lastRequestUpdate) > updateRequestsTimerDuration { | ||
ws.peer.updateRequests(peerUpdateRequestsTimerReason) | ||
return | ||
} | ||
} | ||
|
||
ws.requesterCond.Signal() | ||
} | ||
} | ||
ws.requesterCond.Wait() | ||
} | ||
} | ||
|
||
|
@@ -142,6 +172,7 @@ func (ws *webseedPeer) handleUpdateRequests() { | |
ws.peer.t.cl.lock() | ||
defer ws.peer.t.cl.unlock() | ||
ws.peer.maybeUpdateActualRequestState() | ||
ws.requesterCond.Signal() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it's very likely appropriate. |
||
}() | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something here doesn't feel right. I don't think this part of the code should be determining if updating is appropriate. Sorry to block on this so long, but a lot of the other changes seem worthwhile so I'm trying to minimize this change to a minimum so it can make sense in isolation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mh0lt let's break it to 2 PR's?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you rebase you should find less changes are needed too. Thanks for your efforts.