Remove a bunch of dead code

This commit is contained in:
Matt Joiner 2014-12-28 12:51:09 +11:00
parent e0d936e920
commit d54c5ddf24
5 changed files with 9 additions and 83 deletions

View File

@ -328,11 +328,6 @@ func (c *connection) SetInterested(interested bool) {
c.Interested = interested c.Interested = interested
} }
var (
// Four consecutive zero bytes that comprise a keep alive on the wire.
keepAliveBytes [4]byte
)
// Writes buffers to the socket from the write channel. // Writes buffers to the socket from the write channel.
func (conn *connection) writer() { func (conn *connection) writer() {
// Reduce write syscalls. // Reduce write syscalls.

View File

@ -1,16 +1,11 @@
package dht package dht
import ( import (
"bitbucket.org/anacrolix/go.torrent/iplist"
"bitbucket.org/anacrolix/go.torrent/logonce"
"bitbucket.org/anacrolix/go.torrent/util"
"bitbucket.org/anacrolix/sync"
"crypto" "crypto"
_ "crypto/sha1" _ "crypto/sha1"
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt" "fmt"
"github.com/anacrolix/libtorgo/bencode"
"io" "io"
"log" "log"
"math/big" "math/big"
@ -18,6 +13,12 @@ import (
"net" "net"
"os" "os"
"time" "time"
"bitbucket.org/anacrolix/go.torrent/iplist"
"bitbucket.org/anacrolix/go.torrent/logonce"
"bitbucket.org/anacrolix/go.torrent/util"
"bitbucket.org/anacrolix/sync"
"github.com/anacrolix/libtorgo/bencode"
) )
const maxNodes = 10000 const maxNodes = 10000
@ -855,49 +856,6 @@ func (t *transaction) setOnResponse(f func(m Msg)) {
t.onResponse = f t.onResponse = f
} }
func unmarshalNodeInfoBinary(b []byte) (ret []NodeInfo, err error) {
if len(b)%26 != 0 {
err = errors.New("bad buffer length")
return
}
ret = make([]NodeInfo, 0, len(b)/26)
for i := 0; i < len(b); i += 26 {
var ni NodeInfo
err = ni.UnmarshalCompact(b[i : i+26])
if err != nil {
return
}
ret = append(ret, ni)
}
return
}
func extractNodes(d Msg) (nodes []NodeInfo, err error) {
if d["y"] != "r" {
return
}
r, ok := d["r"]
if !ok {
err = errors.New("missing r dict")
return
}
rd, ok := r.(map[string]interface{})
if !ok {
err = errors.New("bad r value type")
return
}
n, ok := rd["nodes"]
if !ok {
return
}
ns, ok := n.(string)
if !ok {
err = errors.New("bad nodes value type")
return
}
return unmarshalNodeInfoBinary([]byte(ns))
}
func (s *Server) liftNodes(d Msg) { func (s *Server) liftNodes(d Msg) {
if d["y"] != "r" { if d["y"] != "r" {
return return

16
misc.go
View File

@ -99,22 +99,6 @@ func newRequest(index, begin, length peer_protocol.Integer) request {
return request{index, chunkSpec{begin, length}} return request{index, chunkSpec{begin, length}}
} }
type pieceByBytesPendingSlice struct {
Pending, Indices []peer_protocol.Integer
}
func (pcs pieceByBytesPendingSlice) Len() int {
return len(pcs.Indices)
}
func (me pieceByBytesPendingSlice) Less(i, j int) bool {
return me.Pending[me.Indices[i]] < me.Pending[me.Indices[j]]
}
func (me pieceByBytesPendingSlice) Swap(i, j int) {
me.Indices[i], me.Indices[j] = me.Indices[j], me.Indices[i]
}
var ( var (
// Requested data not yet available. // Requested data not yet available.
ErrDataNotReady = errors.New("data not ready") ErrDataNotReady = errors.New("data not ready")

View File

@ -2,7 +2,6 @@ package torrent
import ( import (
"container/heap" "container/heap"
"container/list"
"fmt" "fmt"
"io" "io"
"log" "log"
@ -11,11 +10,10 @@ import (
"sync" "sync"
"time" "time"
"bitbucket.org/anacrolix/go.torrent/util"
"bitbucket.org/anacrolix/go.torrent/mmap_span" "bitbucket.org/anacrolix/go.torrent/mmap_span"
pp "bitbucket.org/anacrolix/go.torrent/peer_protocol" pp "bitbucket.org/anacrolix/go.torrent/peer_protocol"
"bitbucket.org/anacrolix/go.torrent/tracker" "bitbucket.org/anacrolix/go.torrent/tracker"
"bitbucket.org/anacrolix/go.torrent/util"
"github.com/anacrolix/libtorgo/bencode" "github.com/anacrolix/libtorgo/bencode"
"github.com/anacrolix/libtorgo/metainfo" "github.com/anacrolix/libtorgo/metainfo"
) )
@ -36,15 +34,6 @@ func (t *torrent) PieceNumPendingBytes(index pp.Integer) (count pp.Integer) {
return return
} }
type pieceBytesLeft struct {
Piece, BytesLeft int
}
type torrentPiece struct {
piece
bytesLeftElement *list.Element
}
type peersKey struct { type peersKey struct {
IPBytes string IPBytes string
Port int Port int
@ -59,7 +48,7 @@ type torrent struct {
ceasingNetworking chan struct{} ceasingNetworking chan struct{}
InfoHash InfoHash InfoHash InfoHash
Pieces []*torrentPiece Pieces []*piece
length int64 length int64
// Prevent mutations to Data memory maps while in use as they're not safe. // Prevent mutations to Data memory maps while in use as they're not safe.
dataLock sync.RWMutex dataLock sync.RWMutex
@ -186,7 +175,7 @@ func (t *torrent) setMetadata(md metainfo.Info, dataDir string, infoBytes []byte
} }
t.length = t.Data.Size() t.length = t.Data.Size()
for _, hash := range infoPieceHashes(&md) { for _, hash := range infoPieceHashes(&md) {
piece := &torrentPiece{} piece := &piece{}
piece.Event.L = eventLocker piece.Event.L = eventLocker
util.CopyExact(piece.Hash[:], hash) util.CopyExact(piece.Hash[:], hash)
t.Pieces = append(t.Pieces, piece) t.Pieces = append(t.Pieces, piece)