This commit is contained in:
Matt Joiner 2023-02-18 18:35:22 +11:00
parent 81201050bc
commit e8b04c7181
No known key found for this signature in database
GPG Key ID: 6B990B8185E7F782
9 changed files with 27 additions and 19 deletions

View File

@ -808,7 +808,7 @@ func TestBadPeerIpPort(t *testing.T) {
true,
func(cl *Client) {
cl.ipBlockList = iplist.New([]iplist.Range{
iplist.Range{First: net.ParseIP("10.0.0.1"), Last: net.ParseIP("10.0.0.255")},
{First: net.ParseIP("10.0.0.1"), Last: net.ParseIP("10.0.0.255")},
})
},
},
@ -845,5 +845,4 @@ func TestBadPeerIpPort(t *testing.T) {
require.Equal(t, tc.expectedOk, cl.badPeerIPPort(tc.ip, tc.port))
})
}
}

View File

@ -221,7 +221,7 @@ func waitForPieces(ctx context.Context, t *torrent.Torrent, beginIndex, endIndex
}
func writeMetainfoToFile(mi metainfo.MetaInfo, path string) error {
f, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0640)
f, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0o640)
if err != nil {
return err
}

View File

@ -31,9 +31,11 @@
package metainfo
// For more context on why these numbers, see http://wiki.vuze.com/w/Torrent_Piece_Size
const minimumPieceLength = 16 * 1024
const targetPieceCountLog2 = 10
const targetPieceCountMin = 1 << targetPieceCountLog2
const (
minimumPieceLength = 16 * 1024
targetPieceCountLog2 = 10
targetPieceCountMin = 1 << targetPieceCountLog2
)
// Target piece count should be < targetPieceCountMax
const targetPieceCountMax = targetPieceCountMin << 1

View File

@ -115,7 +115,8 @@ func connLessTrusted(l, r *Peer) bool {
func connIsIpv6(nc interface {
LocalAddr() net.Addr
}) bool {
},
) bool {
ra := nc.LocalAddr()
rip := addrIpOrNil(ra)
return rip.To4() == nil && rip.To16() != nil

View File

@ -66,7 +66,7 @@ func GetRequestablePieces(
lastItem.Set(_i)
ih := _i.key.InfoHash
var t = input.Torrent(ih)
t := input.Torrent(ih)
pieceLength := t.PieceLength()
if storageLeft != nil {
if *storageLeft < pieceLength {

View File

@ -71,6 +71,7 @@ func (ts *mmapTorrentStorage) Close() error {
}
return nil
}
func (ts *mmapTorrentStorage) Flush() error {
errs := ts.span.Flush()
if len(errs) > 0 {

View File

@ -13,8 +13,10 @@ type Client struct {
url_ *url.URL
}
type ProxyFunc func(*http.Request) (*url.URL, error)
type DialContextFunc func(ctx context.Context, network, addr string) (net.Conn, error)
type (
ProxyFunc func(*http.Request) (*url.URL, error)
DialContextFunc func(ctx context.Context, network, addr string) (net.Conn, error)
)
type NewClientOpts struct {
Proxy ProxyFunc

View File

@ -233,14 +233,16 @@ func (tc *TrackerClient) Announce(event tracker.AnnounceEvent, infoHash [20]byte
return fmt.Errorf("creating offer: %w", err)
}
err = tc.announce(event, infoHash, []outboundOffer{{
offerId: offerIDBinary,
outboundOfferValue: outboundOfferValue{
originalOffer: offer,
peerConnection: pc,
infoHash: infoHash,
dataChannel: dc,
}},
err = tc.announce(event, infoHash, []outboundOffer{
{
offerId: offerIDBinary,
outboundOfferValue: outboundOfferValue{
originalOffer: offer,
peerConnection: pc,
infoHash: infoHash,
dataChannel: dc,
},
},
})
if err != nil {
dc.Close()

View File

@ -1,10 +1,11 @@
package webtorrent
import (
"testing"
"github.com/anacrolix/log"
qt "github.com/frankban/quicktest"
"github.com/pion/webrtc/v3"
"testing"
)
func TestClosingPeerConnectionDoesNotCloseUnopenedDataChannel(t *testing.T) {