Commit Graph

3309 Commits

Author SHA1 Message Date
YenForYang ebb7160599
Inlineable `(*Torrent).Seeding()` (#626) 2021-09-15 10:28:14 +10:00
YenForYang e105d8b57a
Inlineable `(*Torrent).SetDisplayName()` (#625) 2021-09-15 10:27:52 +10:00
YenForYang 542970b961
Inlineable `(*Torrent).PieceState()` (#621) 2021-09-15 10:14:28 +10:00
YenForYang d00ba917c0
Inlineable `(*Torrent).AddPeers()` (#622) 2021-09-15 10:14:07 +10:00
YenForYang a0fe0a087d
Inlineable `DownloadPieces()` and `CancelPieces()` (#623) 2021-09-15 10:13:46 +10:00
YenForYang 29638d9e5d
Create default constructor for Client (#567)
Allow for certain values to always be properly initialized on construction -- namely the maps for now. I'm currently working on a change that requires a baseline constructor; this change would make the use of `chansync.BroadcastCond` and `chansync.SetOnce` obsolete -- i.e. one can have channel members without worrying about proper initialization/destruction of a `chan struct{}`.

As for why `makeClient` returns a value instead of a pointer: returning a value gives us more options -- you can always take a pointer from a value later on cheaply, and have things moved to the heap if they weren't already. The same can't be said about getting a value back from a pointer. GC also could potentially have less work to do. Plus I personally find ownership to be an important concept (semi-borrowed from rust) -- use of values make ownership clear.
2021-09-14 23:01:20 +10:00
YenForYang e80b989f8e
Clarify maximum value of "metadata_size" (#609) 2021-09-14 22:36:19 +10:00
YenForYang 57b4e78b0f
Inlineable `(*File).BytesCompleted()` (#612) 2021-09-14 22:11:35 +10:00
YenForYang be8b7b7d35
Optimize `LoopbackListenHost()` (#615) 2021-09-14 21:54:37 +10:00
YenForYang f6b024e157
Inlineable (*reader).SetReadAhead and (*reader).Close (#594)
Small fixes that prevent inlining of public functions
2021-09-14 14:05:37 +10:00
YenForYang a8db640c62
Drop bradfitz/iter dependency (#605)
* Drop bradfitz/iter dependency

`range iter.N` looks nice and doesn't allocate, but unfortunately using a `range` expression blocks a function from being inlined wherever it's used (for now). It's not that we need inlining in all cases, but I do think a C-style for loop looks just as nice and is probably clearer to the majority. There also aren't any clear disadvantages to changing (unless you just happen to dislike the look of C)

* Update misc_test.go

* Update rlreader_test.go

* Update torrent_test.go

* Update bench_test.go

* Update client_test.go

* Update iplist_test.go

* Update mse_test.go

* Update peerconn_test.go

* Update peerconn.go

* Update order_test.go

* Update decoder_test.go

* Update main.go

* Update bench-piece-mark-complete.go

* Update main.go

* Update torrent.go

* Update iplist_test.go

* Update main.go
2021-09-14 13:46:50 +10:00
YenForYang 2203b3bcdf
Cheaper byte to string conversion (#602)
Revamped https://github.com/anacrolix/torrent/pull/587
2021-09-14 10:41:04 +10:00
YenForYang 5332d3e9d4
Inlineable reader.Seek and no-lock return for bad whence (#577)
* Inlineable reader.Seek and no-lock return for bad whence

Couldn't find an elegant way to early exit on bad whence. Using a closure could reduce code duplication slightly, but it's overkill for only 3 cases.

Note that returning 0 on an invalid whence is the behavior of `strings.Reader` and `bytes.Reader`.

* Update reader.go
2021-09-13 22:52:58 +10:00
YenForYang 134eea8418
Fix usages of eachListener() and make inlineable (#599) 2021-09-13 21:35:51 +10:00
YenForYang 52e8c82999
Inlineable methods to access File piecePriority (#601) 2021-09-13 21:17:54 +10:00
YenForYang 5c440e8929
Simplify (*Torrent).gotMetainfo (#581) 2021-09-13 11:41:11 +10:00
YenForYang 1bb6724020
Remove xerrors dependency (#600)
* Remove xerrors dependency

* Update main.go
2021-09-13 11:38:08 +10:00
YenForYang 3b4d4a64ff
Reorder fields to reduce padding in reader (#597)
Reorder some of the fields to reduce the size of `reader`. Not much of a change -- original size was 104 bytes, with changes (moving bool's to the end) the size is 96 bytes. There's also the whole cache-friendly bit -- I tried reordering fields to help here, but I doubt it makes much of a difference.

Some other notes: `sync.Locker` is a 16 byte field. I suggest changing this to something like `*sync.RWMutex` or `*lockWithDeferreds`. This would not only reduce size but would allow access to `RLock`/`RUnlock`.
`pieceRange` could also be shrunk to 8 bytes, but I feel like I'm probably asking for too much lol.
2021-09-13 11:36:35 +10:00
YenForYang 4691b0b8d1
Update ReadCloser interface check to ReadSeekCloser (#595) 2021-09-12 14:14:07 +10:00
Matt Joiner a9cbb644c5
Fix http announce of infohash containing ' ' bytes (#591)
Fixes https://github.com/anacrolix/torrent/issues/534.
2021-09-12 14:11:59 +10:00
Matt Joiner 79ad5e4676 Don't call Client onClose handlers until torrent storages are closed 2021-09-11 11:39:33 +10:00
Matt Joiner 7378d50a3c Fix Torrent.Drop to wait for storage close without client lock 2021-09-11 11:39:33 +10:00
YenForYang d957502528
Avoid allocating memory when checking interface (#588)
Not a big deal, but there isn't a need to allocate an object to check that `*Node` satisfies `bencode.Unmarshaler`.
2021-09-11 08:26:43 +10:00
Matt Joiner 6c9a7fec39 Optimize peersForPieces allocations for make and sorting 2021-09-10 23:07:10 +10:00
Matt Joiner c4445fd201 Optimize requesting peerId Uintptr allocation 2021-09-10 23:07:10 +10:00
Matt Joiner e9193968a3 Disable ensureValidSortedPeersForPieceRequests
Should approximately half the contribution of the parent function to overhead.
2021-09-10 23:07:10 +10:00
Matt Joiner 016bf1b07c Optimize sortPeersForPiece in allocatePendingChunks 2021-09-10 23:07:10 +10:00
Matt Joiner 0d10a1b53a Optimize Torrent.worstBadConn 2021-09-10 23:07:10 +10:00
Matt Joiner 1ef51e7840 Remove reader.opMu
https://github.com/anacrolix/torrent/issues/553
2021-09-10 23:07:10 +10:00
Matt Joiner 35064425eb go fmt ./... 2021-09-09 22:51:24 +10:00
Matt Joiner 5cb47021ac Fix possible misuse of reflect.StringHeader 2021-09-09 22:49:22 +10:00
YenForYang 1fc6093383
useTorrentSources: fix http request resource leak (#562) 2021-09-09 22:39:12 +10:00
YenForYang 62c6fbc8f8
Clarify ownership of (*Torrent).chunkPool (#583)
Basically bind the lifetime of chunkPool to the torrent by using `sync.Pool` in lieu of `*sync.Pool`. Gives the GC ever so slightly less work to do.
2021-09-09 22:27:16 +10:00
Matt Joiner 10d5e6234e Don't readahead until a read occurs 2021-09-09 22:19:48 +10:00
Matt Joiner 58483ae399 Make readahead algorithm linear 2021-09-09 22:19:48 +10:00
Matt Joiner e8b496bee6 Add default sqrt readahead algorithm 2021-09-09 22:19:48 +10:00
Matt Joiner 4912ae2781 Extract common Torrent.newReader 2021-09-09 22:19:48 +10:00
Matt Joiner 3c95512f23
Add Webtor to downstream projects 2021-09-09 22:12:29 +10:00
Matt Joiner 151bf9ea68 Fix unit tests littering working directory 2021-09-09 12:58:07 +10:00
Matt Joiner 128ac28c02
Update README.md 2021-09-08 13:46:03 +10:00
Matt Joiner 6d560b8902
Update README.md 2021-09-08 13:45:25 +10:00
YenForYang 719505a138
Drop xerrors and missinggo/slices dependency for Client (#572)
* Drop xerrors and missinggo/slices dependency for Client

Made `BadPeerIPs` inlineable since I changed `badPeerIPsLocked` anyway. Also eliminated an extra torrentsAsSlice copy since Go wasn't smart enough to figure it out.
2021-09-08 09:34:06 +10:00
Zilog8 ccb90f1252
Improve Closing (#559)
- Prevent double-closing in cmd/torrent
- Move async closing from storage to torrents, and wait on them to finish tidying up before returning/exiting.
2021-09-05 11:33:41 +10:00
Matt Joiner f295057347 Update chansync 2021-09-04 23:34:06 +10:00
Matt Joiner ad70dcdbf4 Return error on sqlite PieceCompletion.Set when closed 2021-09-04 23:07:32 +10:00
Matt Joiner 175b826e73 Rework Reader waiting 2021-09-04 23:07:32 +10:00
YenForYang f86355ac0b Simplify dhtPort()
A similar case of `haveDhtServer`
2021-09-04 23:04:06 +10:00
YenForYang 99ba75f458 Drop xerrors and reflection dependency
Nothing wrong with missinggo.CopyExact -- but fewer dependencies is better IMO.  Also changed String() to use a consistent receiver name -- not a big deal.
2021-09-04 23:01:37 +10:00
afjoseph c76bb42c07 [gomod] Update anacrolix/dht and run 'go mod tidy' 2021-09-04 21:21:52 +10:00
YenForYang d1c0b95a9c Simplify haveDhtServers()
A bit too much functional programming, lol.
2021-09-03 20:41:01 +10:00