From 3ba991e38aa4d0019e50c05df79651c0d16f3003 Mon Sep 17 00:00:00 2001
From: Matt Joiner <anacrolix@gmail.com>
Date: Tue, 27 Nov 2018 23:57:17 +1100
Subject: [PATCH] Remove unused code

---
 client.go    | 26 --------------------------
 file.go      |  4 ----
 global.go    |  1 -
 listen.go    | 16 ----------------
 multiless.go |  4 ----
 socket.go    |  8 --------
 torrent.go   | 29 -----------------------------
 7 files changed, 88 deletions(-)

diff --git a/client.go b/client.go
index d348a1d8..21919885 100644
--- a/client.go
+++ b/client.go
@@ -308,15 +308,6 @@ func (cl *Client) newDhtServer(conn net.PacketConn) (s *dht.Server, err error) {
 	return
 }
 
-func firstNonEmptyString(ss ...string) string {
-	for _, s := range ss {
-		if s != "" {
-			return s
-		}
-	}
-	return ""
-}
-
 func (cl *Client) Closed() <-chan struct{} {
 	cl.lock()
 	defer cl.unlock()
@@ -490,23 +481,6 @@ func (cl *Client) dopplegangerAddr(addr string) bool {
 	return ok
 }
 
-func ipNetworkSuffix(allowIpv4, allowIpv6 bool) string {
-	switch {
-	case allowIpv4 && allowIpv6:
-		return ""
-	case allowIpv4 && !allowIpv6:
-		return "4"
-	case !allowIpv4 && allowIpv6:
-		return "6"
-	default:
-		panic("unhandled ip network combination")
-	}
-}
-
-func dialUTP(ctx context.Context, addr string, sock utpSocket) (c net.Conn, err error) {
-	return sock.DialContext(ctx, "", addr)
-}
-
 var allPeerNetworks = []string{"tcp4", "tcp6", "udp4", "udp6"}
 
 func peerNetworkEnabled(network string, cfg *ClientConfig) bool {
diff --git a/file.go b/file.go
index 4074700a..15f5e239 100644
--- a/file.go
+++ b/file.go
@@ -91,10 +91,6 @@ func byteRegionExclusivePieces(off, size, pieceSize int64) (begin, end int) {
 	return
 }
 
-func (f *File) exclusivePieces() (begin, end int) {
-	return byteRegionExclusivePieces(f.offset, f.length, int64(f.t.usualPieceSize()))
-}
-
 // Deprecated: Use File.SetPriority.
 func (f *File) Cancel() {
 	f.SetPriority(PiecePriorityNone)
diff --git a/global.go b/global.go
index 7418cd90..b66dd9dd 100644
--- a/global.go
+++ b/global.go
@@ -34,7 +34,6 @@ var (
 	pieceHashedCorrect    = expvar.NewInt("pieceHashedCorrect")
 	pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
 
-	peerExtensions                    = expvar.NewMap("peerExtensions")
 	completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags")
 	// Count of connections to peer with same client ID.
 	connsToSelf        = expvar.NewInt("connsToSelf")
diff --git a/listen.go b/listen.go
index 0e1b5c0d..29015c10 100644
--- a/listen.go
+++ b/listen.go
@@ -2,22 +2,6 @@ package torrent
 
 import "strings"
 
-type peerNetworks struct {
-	tcp4, tcp6 bool
-	utp4, utp6 bool
-}
-
-func handleErr(h func(), fs ...func() error) error {
-	for _, f := range fs {
-		err := f()
-		if err != nil {
-			h()
-			return err
-		}
-	}
-	return nil
-}
-
 func LoopbackListenHost(network string) string {
 	if strings.Contains(network, "4") {
 		return "127.0.0.1"
diff --git a/multiless.go b/multiless.go
index 20ba2bd7..bdc851d8 100644
--- a/multiless.go
+++ b/multiless.go
@@ -1,9 +1,5 @@
 package torrent
 
-func strictCmp(same, less bool) cmper {
-	return func() (bool, bool) { return same, less }
-}
-
 type (
 	cmper     func() (same, less bool)
 	multiLess struct {
diff --git a/socket.go b/socket.go
index e7a200fe..4d343eef 100644
--- a/socket.go
+++ b/socket.go
@@ -90,14 +90,6 @@ func (me tcpSocket) dial(ctx context.Context, addr string) (net.Conn, error) {
 	return me.d(ctx, addr)
 }
 
-func setPort(addr string, port int) string {
-	host, _, err := net.SplitHostPort(addr)
-	if err != nil {
-		panic(err)
-	}
-	return net.JoinHostPort(host, strconv.FormatInt(int64(port), 10))
-}
-
 func listenAll(networks []string, getHost func(string) string, port int, proxyURL string, f firewallCallback) ([]socket, error) {
 	if len(networks) == 0 {
 		return nil, nil
diff --git a/torrent.go b/torrent.go
index 6a455e1f..b376ba59 100644
--- a/torrent.go
+++ b/torrent.go
@@ -35,11 +35,6 @@ func (t *Torrent) chunkIndexSpec(chunkIndex pp.Integer, piece pieceIndex) chunkS
 	return chunkIndexSpec(chunkIndex, t.pieceLength(piece), t.chunkSize)
 }
 
-type peersKey struct {
-	IPBytes string
-	Port    int
-}
-
 // Maintains state of torrent within a Client.
 type Torrent struct {
 	// Torrent-level aggregate statistics. First in struct to ensure 64-bit
@@ -292,10 +287,6 @@ func (t *Torrent) haveMetadataPiece(piece int) bool {
 	}
 }
 
-func (t *Torrent) metadataSizeKnown() bool {
-	return t.metadataBytes != nil
-}
-
 func (t *Torrent) metadataSize() int {
 	return len(t.metadataBytes)
 }
@@ -791,18 +782,6 @@ func chunkIndex(cs chunkSpec, chunkSize pp.Integer) int {
 	return int(cs.Begin / chunkSize)
 }
 
-func (t *Torrent) wantPiece(r request) bool {
-	if !t.wantPieceIndex(pieceIndex(r.Index)) {
-		return false
-	}
-	if t.pieces[r.Index].pendingChunk(r.chunkSpec, t.chunkSize) {
-		return true
-	}
-	// TODO: What about pieces that were wanted, but aren't now, and aren't
-	// completed either? That used to be done here.
-	return false
-}
-
 func (t *Torrent) wantPieceIndex(index pieceIndex) bool {
 	if !t.haveInfo() {
 		return false
@@ -1125,14 +1104,6 @@ func (t *Torrent) maybeCompleteMetadata() error {
 	return nil
 }
 
-func (t *Torrent) readerPieces() (ret bitmap.Bitmap) {
-	t.forReaderOffsetPieces(func(begin, end pieceIndex) bool {
-		ret.AddRange(bitmap.BitIndex(begin), bitmap.BitIndex(end))
-		return true
-	})
-	return
-}
-
 func (t *Torrent) readerPiecePriorities() (now, readahead bitmap.Bitmap) {
 	t.forReaderOffsetPieces(func(begin, end pieceIndex) bool {
 		if end > begin {
-- 
2.51.0