gofumpt -extra
This commit is contained in:
parent
74c70d852a
commit
bdb33ef9f7
|
@ -583,7 +583,7 @@ func countDialResult(err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func reducedDialTimeout(minDialTimeout, max time.Duration, halfOpenLimit int, pendingPeers int) (ret time.Duration) {
|
func reducedDialTimeout(minDialTimeout, max time.Duration, halfOpenLimit, pendingPeers int) (ret time.Duration) {
|
||||||
ret = max / time.Duration((pendingPeers+halfOpenLimit)/halfOpenLimit)
|
ret = max / time.Duration((pendingPeers+halfOpenLimit)/halfOpenLimit)
|
||||||
if ret < minDialTimeout {
|
if ret < minDialTimeout {
|
||||||
ret = minDialTimeout
|
ret = minDialTimeout
|
||||||
|
|
|
@ -647,7 +647,7 @@ func TestSetMaxEstablishedConn(t *testing.T) {
|
||||||
|
|
||||||
// Creates a file containing its own name as data. Make a metainfo from that, adds it to the given
|
// Creates a file containing its own name as data. Make a metainfo from that, adds it to the given
|
||||||
// client, and returns a magnet link.
|
// client, and returns a magnet link.
|
||||||
func makeMagnet(t *testing.T, cl *Client, dir string, name string) string {
|
func makeMagnet(t *testing.T, cl *Client, dir, name string) string {
|
||||||
os.MkdirAll(dir, 0o770)
|
os.MkdirAll(dir, 0o770)
|
||||||
file, err := os.Create(filepath.Join(dir, name))
|
file, err := os.Create(filepath.Join(dir, name))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -684,7 +684,7 @@ func TestMultipleTorrentsWithEncryption(t *testing.T) {
|
||||||
|
|
||||||
// Test that the leecher can download a torrent in its entirety from the seeder. Note that the
|
// Test that the leecher can download a torrent in its entirety from the seeder. Note that the
|
||||||
// seeder config is done first.
|
// seeder config is done first.
|
||||||
func testSeederLeecherPair(t *testing.T, seeder func(*ClientConfig), leecher func(*ClientConfig)) {
|
func testSeederLeecherPair(t *testing.T, seeder, leecher func(*ClientConfig)) {
|
||||||
cfg := TestingConfig(t)
|
cfg := TestingConfig(t)
|
||||||
cfg.Seed = true
|
cfg.Seed = true
|
||||||
cfg.DataDir = filepath.Join(cfg.DataDir, "server")
|
cfg.DataDir = filepath.Join(cfg.DataDir, "server")
|
||||||
|
|
4
misc.go
4
misc.go
|
@ -43,7 +43,7 @@ func newRequestFromMessage(msg *pp.Message) Request {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The size in bytes of a metadata extension piece.
|
// The size in bytes of a metadata extension piece.
|
||||||
func metadataPieceSize(totalSize int, piece int) int {
|
func metadataPieceSize(totalSize, piece int) int {
|
||||||
ret := totalSize - piece*(1<<14)
|
ret := totalSize - piece*(1<<14)
|
||||||
if ret > 1<<14 {
|
if ret > 1<<14 {
|
||||||
ret = 1 << 14
|
ret = 1 << 14
|
||||||
|
@ -99,7 +99,7 @@ func validateInfo(info *metainfo.Info) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func chunkIndexSpec(index pp.Integer, pieceLength, chunkSize pp.Integer) ChunkSpec {
|
func chunkIndexSpec(index, pieceLength, chunkSize pp.Integer) ChunkSpec {
|
||||||
ret := ChunkSpec{pp.Integer(index) * chunkSize, chunkSize}
|
ret := ChunkSpec{pp.Integer(index) * chunkSize, chunkSize}
|
||||||
if ret.Begin+ret.Length > pieceLength {
|
if ret.Begin+ret.Length > pieceLength {
|
||||||
ret.Length = pieceLength - ret.Begin
|
ret.Length = pieceLength - ret.Begin
|
||||||
|
|
|
@ -69,7 +69,7 @@ func hash(parts ...[]byte) []byte {
|
||||||
return h.Sum(nil)
|
return h.Sum(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newEncrypt(initer bool, s []byte, skey []byte) (c *rc4.Cipher) {
|
func newEncrypt(initer bool, s, skey []byte) (c *rc4.Cipher) {
|
||||||
c, err := rc4.NewCipher(hash([]byte(func() string {
|
c, err := rc4.NewCipher(hash([]byte(func() string {
|
||||||
if initer {
|
if initer {
|
||||||
return "keyA"
|
return "keyA"
|
||||||
|
@ -542,7 +542,7 @@ func (h *handshake) Do() (ret io.ReadWriter, method CryptoMethod, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitiateHandshake(
|
func InitiateHandshake(
|
||||||
rw io.ReadWriter, skey []byte, initialPayload []byte, cryptoProvides CryptoMethod,
|
rw io.ReadWriter, skey, initialPayload []byte, cryptoProvides CryptoMethod,
|
||||||
) (
|
) (
|
||||||
ret io.ReadWriter, method CryptoMethod, err error,
|
ret io.ReadWriter, method CryptoMethod, err error,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -146,7 +146,7 @@ func fillRand(t testing.TB, bs ...[]byte) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func readAndWrite(rw io.ReadWriter, r []byte, w []byte) error {
|
func readAndWrite(rw io.ReadWriter, r, w []byte) error {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
var wErr error
|
var wErr error
|
||||||
|
|
|
@ -124,7 +124,7 @@ func Handshake(
|
||||||
return res, errors.New("unexpected protocol string")
|
return res, errors.New("unexpected protocol string")
|
||||||
}
|
}
|
||||||
|
|
||||||
copyExact := func(dst []byte, src []byte) {
|
copyExact := func(dst, src []byte) {
|
||||||
if dstLen, srcLen := uint64(len(dst)), uint64(len(src)); dstLen != srcLen {
|
if dstLen, srcLen := uint64(len(dst)), uint64(len(src)); dstLen != srcLen {
|
||||||
panic("dst len " + strconv.FormatUint(dstLen, 10) + " != src len " + strconv.FormatUint(srcLen, 10))
|
panic("dst len " + strconv.FormatUint(dstLen, 10) + " != src len " + strconv.FormatUint(srcLen, 10))
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,7 +235,7 @@ func (cn *Peer) cumInterest() time.Duration {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cn *PeerConn) peerHasAllPieces() (all bool, known bool) {
|
func (cn *PeerConn) peerHasAllPieces() (all, known bool) {
|
||||||
if cn.peerSentHaveAll {
|
if cn.peerSentHaveAll {
|
||||||
return true, true
|
return true, true
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,12 @@ package torrent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/anacrolix/log"
|
"github.com/anacrolix/log"
|
||||||
"github.com/anacrolix/torrent/tracker/http"
|
"github.com/anacrolix/torrent/tracker/http"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"net/url"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/anacrolix/torrent/tracker"
|
"github.com/anacrolix/torrent/tracker"
|
||||||
"github.com/anacrolix/torrent/webtorrent"
|
"github.com/anacrolix/torrent/webtorrent"
|
||||||
|
|
Loading…
Reference in New Issue