<commit_before>/*
Package torrent implements a torrent client.

Simple example:

	c := &Client{}
	c.Start()
	defer c.Stop()
	if err := c.AddTorrent(externalMetaInfoPackageSux); err != nil {
		return fmt.Errors("error adding torrent: %s", err)
	}
	c.WaitAll()
	log.Print("erhmahgerd, torrent downloaded")

*/
package torrent

import (
	"bufio"
	"bytes"
	"container/heap"
	"crypto/rand"
	"crypto/sha1"
	"encoding/hex"
	"errors"
	"expvar"
	"fmt"
	"io"
	"log"
	"math/big"
	mathRand "math/rand"
	"net"
	"net/url"
	"os"
	"path/filepath"
	"sort"
	"strings"
	"syscall"
	"time"

	"bitbucket.org/anacrolix/go.torrent/mse"

	"bitbucket.org/anacrolix/go.torrent/data"
	filePkg "bitbucket.org/anacrolix/go.torrent/data/file"
	"bitbucket.org/anacrolix/go.torrent/dht"
	"bitbucket.org/anacrolix/go.torrent/internal/pieceordering"
	"bitbucket.org/anacrolix/go.torrent/iplist"
	"bitbucket.org/anacrolix/go.torrent/logonce"
	pp "bitbucket.org/anacrolix/go.torrent/peer_protocol"
	"bitbucket.org/anacrolix/go.torrent/tracker"
	_ "bitbucket.org/anacrolix/go.torrent/tracker/udp"
	. "bitbucket.org/anacrolix/go.torrent/util"
	"bitbucket.org/anacrolix/sync"
	"bitbucket.org/anacrolix/utp"
	"github.com/anacrolix/libtorgo/bencode"
	"github.com/anacrolix/libtorgo/metainfo"
)

var (
	unusedDownloadedChunksCount = expvar.NewInt("unusedDownloadedChunksCount")
	chunksDownloadedCount       = expvar.NewInt("chunksDownloadedCount")
	peersFoundByDHT             = expvar.NewInt("peersFoundByDHT")
	peersFoundByPEX             = expvar.NewInt("peersFoundByPEX")
	peersFoundByTracker         = expvar.NewInt("peersFoundByTracker")
	uploadChunksPosted          = expvar.NewInt("uploadChunksPosted")
	unexpectedCancels           = expvar.NewInt("unexpectedCancels")
	postedCancels               = expvar.NewInt("postedCancels")
	duplicateConnsAvoided       = expvar.NewInt("duplicateConnsAvoided")
	failedPieceHashes           = expvar.NewInt("failedPieceHashes")
	unsuccessfulDials           = expvar.NewInt("unsuccessfulDials")
	successfulDials             = expvar.NewInt("successfulDials")
	acceptedConns               = expvar.NewInt("acceptedConns")
	inboundConnsBlocked         = expvar.NewInt("inboundConnsBlocked")
	peerExtensions              = expvar.NewMap("peerExtensions")
)

const (
	// Justification for set bits follows.
	//
	// Extension protocol: http://www.bittorrent.org/beps/bep_0010.html
	// DHT: http://www.bittorrent.org/beps/bep_0005.html
	// Fast Extension: http://bittorrent.org/beps/bep_0006.html ([7]|=4)
	defaultExtensionBytes = "\x00\x00\x00\x00\x00\x10\x00\x05"

	socketsPerTorrent     = 40
	torrentPeersHighWater = 200
	torrentPeersLowWater  = 50

	// Limit how long handshake can take. This is to reduce the lingering
	// impact of a few bad apples. 4s loses 1% of successful handshakes that
	// are obtained with 60s timeout, and 5% of unsuccessful handshakes.
	handshakeTimeout = 45 * time.Second

	pruneInterval = 10 * time.Second
)<commit_msg>Disable AllowedFast<commit_after>/*
Package torrent implements a torrent client.

Simple example:

	c := &Client{}
	c.Start()
	defer c.Stop()
	if err := c.AddTorrent(externalMetaInfoPackageSux); err != nil {
		return fmt.Errors("error adding torrent: %s", err)
	}
	c.WaitAll()
	log.Print("erhmahgerd, torrent downloaded")

*/
package torrent

import (
	"bufio"
	"bytes"
	"container/heap"
	"crypto/rand"
	"crypto/sha1"
	"encoding/hex"
	"errors"
	"expvar"
	"fmt"
	"io"
	"log"
	"math/big"
	mathRand "math/rand"
	"net"
	"net/url"
	"os"
	"path/filepath"
	"sort"
	"strconv"
	"strings"
	"syscall"
	"time"

	"github.com/bradfitz/iter"

	"bitbucket.org/anacrolix/go.torrent/mse"

	"bitbucket.org/anacrolix/go.torrent/data"
	filePkg "bitbucket.org/anacrolix/go.torrent/data/file"
	"bitbucket.org/anacrolix/go.torrent/dht"
	"bitbucket.org/anacrolix/go.torrent/internal/pieceordering"
	"bitbucket.org/anacrolix/go.torrent/iplist"
	"bitbucket.org/anacrolix/go.torrent/logonce"
	pp "bitbucket.org/anacrolix/go.torrent/peer_protocol"
	"bitbucket.org/anacrolix/go.torrent/tracker"
	_ "bitbucket.org/anacrolix/go.torrent/tracker/udp"
	. "bitbucket.org/anacrolix/go.torrent/util"
	"bitbucket.org/anacrolix/sync"
	"bitbucket.org/anacrolix/utp"
	"github.com/anacrolix/libtorgo/bencode"
	"github.com/anacrolix/libtorgo/metainfo"
)

var (
	unusedDownloadedChunksCount = expvar.NewInt("unusedDownloadedChunksCount")
	chunksDownloadedCount       = expvar.NewInt("chunksDownloadedCount")
	peersFoundByDHT             = expvar.NewInt("peersFoundByDHT")
	peersFoundByPEX             = expvar.NewInt("peersFoundByPEX")
	peersFoundByTracker         = expvar.NewInt("peersFoundByTracker")
	uploadChunksPosted          = expvar.NewInt("uploadChunksPosted")
	unexpectedCancels           = expvar.NewInt("unexpectedCancels")
	postedCancels               = expvar.NewInt("postedCancels")
	duplicateConnsAvoided       = expvar.NewInt("duplicateConnsAvoided")
	failedPieceHashes           = expvar.NewInt("failedPieceHashes")
	unsuccessfulDials           = expvar.NewInt("unsuccessfulDials")
	successfulDials             = expvar.NewInt("successfulDials")
	acceptedConns               = expvar.NewInt("acceptedConns")
	inboundConnsBlocked         = expvar.NewInt("inboundConnsBlocked")
	peerExtensions              = expvar.NewMap("peerExtensions")
)

const (
	// Justification for set bits follows.
	//
	// Extension protocol: http://www.bittorrent.org/beps/bep_0010.html ([5]|=0x10)
	// DHT: http://www.bittorrent.org/beps/bep_0005.html ([7]|=1)
	// Fast Extension:
	// 	 http://bittorrent.org/beps/bep_0006.html ([7]|=4)
	//   Disabled until AllowedFast is implemented
	defaultExtensionBytes = "\x00\x00\x00\x00\x00\x10\x00\x01"

	socketsPerTorrent     = 40
	torrentPeersHighWater = 200
	torrentPeersLowWater  = 50

	// Limit how long handshake can take. This is to reduce the lingering
	// impact of a few bad apples. 4s loses 1% of successful handshakes that
	// are obtained with 60s timeout, and 5% of unsuccessful handshakes.
	handshakeTimeout = 45 * time.Second

	pruneInterval = 10 * time.Second
)
{'fraction_non_alphanumeric': 0.12705530642750373, 'fraction_numerical': 0.016608536787908985, 'mean_word_length': 3.9079054604726977, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6452238', 'n_tokens_mistral': 2411, 'n_tokens_neox': 2291, 'n_words': 342}