metadataChanged: sync.Cond{
L: cl.locker(),
},
+ webSeeds: make(map[string]*peer),
}
t._pendingPieces.NewSet = priorityBitmapStableNewSet
t.requestStrategy = cl.config.DefaultRequestStrategy(t.requestStrategyCallbacks(), &cl._mu)
var ss []string
slices.MakeInto(&ss, mi.Nodes)
cl.AddDHTNodes(ss)
+ for _, url := range mi.UrlList {
+ T.addWebSeed(url)
+ }
return
}
cancel(request) bool
request(request) bool
connectionFlags() string
- close()
+ _close()
postCancel(request)
drop()
}
}
cn.discardPieceInclination()
cn._pieceRequestOrder.Clear()
- cn.peerImpl.close()
+ cn.peerImpl._close()
}
-func (cn *PeerConn) close() {
+func (cn *PeerConn) _close() {
if cn.pex.IsEnabled() {
cn.pex.Close()
}
// conceivable that the best connection should do this, since it's least likely to waste our time if
// assigned to the highest priority pieces, and assigning more than one this role would cause
// significant wasted bandwidth.
-func (cn *PeerConn) shouldRequestWithoutBias() bool {
+func (cn *peer) shouldRequestWithoutBias() bool {
return cn.t.requestStrategy.shouldRequestWithoutBias(cn.requestStrategyConnection())
}
}
// check callers updaterequests
-func (cn *PeerConn) stopRequestingPiece(piece pieceIndex) bool {
+func (cn *peer) stopRequestingPiece(piece pieceIndex) bool {
return cn._pieceRequestOrder.Remove(bitmap.BitIndex(piece))
}
// preference. Connection piece priority is specific to a connection and is
// used to pseudorandomly avoid connections always requesting the same pieces
// and thus wasting effort.
-func (cn *PeerConn) updatePiecePriority(piece pieceIndex) bool {
+func (cn *peer) updatePiecePriority(piece pieceIndex) bool {
tpp := cn.t.piecePriority(piece)
if !cn.peerHasPiece(piece) {
tpp = PiecePriorityNone
return cn._pieceRequestOrder.Set(bitmap.BitIndex(piece), prio) || cn.shouldRequestWithoutBias()
}
-func (cn *PeerConn) getPieceInclination() []int {
+func (cn *peer) getPieceInclination() []int {
if cn.pieceInclination == nil {
cn.pieceInclination = cn.t.getConnPieceInclination()
}
func (t *Torrent) piecePriorityChanged(piece pieceIndex) {
// t.logger.Printf("piece %d priority changed", piece)
- for c := range t.conns {
+ t.iterPeers(func(c *peer) {
if c.updatePiecePriority(piece) {
// log.Print("conn piece priority changed")
c.updateRequests()
}
- }
+ })
t.maybeNewConns()
t.publishPieceChange(piece)
}
// c.drop()
// }
// }
- for conn := range t.conns {
+ t.iterPeers(func(conn *peer) {
if conn.peerHasPiece(piece) {
conn.updateRequests()
}
- }
+ })
}
func (t *Torrent) tryCreateMorePieceHashers() {
torrent.Add("request timeouts", 1)
cb.t.cl.lock()
defer cb.t.cl.unlock()
- for cn := range cb.t.conns {
+ cb.t.iterPeers(func(cn *peer) {
if cn.peerHasPiece(pieceIndex(r.Index)) {
cn.updateRequests()
}
- }
+ })
}
func (t *Torrent) disallowDataDownloadLocked() {
log.Printf("disallowing data download")
t.dataDownloadDisallowed = true
- for c := range t.conns {
+ t.iterPeers(func(c *peer) {
c.updateRequests()
- }
+ })
}
func (t *Torrent) AllowDataDownload() {
defer t.cl.unlock()
log.Printf("AllowDataDownload")
t.dataDownloadDisallowed = false
- for c := range t.conns {
+ t.iterPeers(func(c *peer) {
c.updateRequests()
- }
-
+ })
}
func (t *Torrent) SetOnWriteChunkError(f func(error)) {
if _, ok := t.webSeeds[url]; ok {
return
}
- t.webSeeds[url] = &peer{
- peerImpl: &webSeed{},
+ p := &peer{
+ t: t,
+ connString: url,
+ outgoing: true,
+ network: "http",
+ reconciledHandshakeStats: true,
+ peerSentHaveAll: true,
}
+ ws := webSeed{
+ peer: p,
+ }
+ p.peerImpl = &ws
+ t.webSeeds[url] = p
+
}
func (t *Torrent) peerIsActive(p *peer) (active bool) {
type webSeed struct {
peer *peer
httpClient *http.Client
+ url string
+}
+
+func (ws *webSeed) postCancel(r request) {
+ panic("implement me")
}
func (ws *webSeed) writeInterested(interested bool) bool {
func (ws *webSeed) updateRequests() {
ws.peer.doRequestState()
}
+
+func (ws *webSeed) _close() {}