]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Revert "Merge pull request #54 from zhulik/master"
authorMatt Joiner <anacrolix@gmail.com>
Wed, 6 Jan 2016 01:19:49 +0000 (12:19 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 6 Jan 2016 01:19:49 +0000 (12:19 +1100)
This reverts commit 5cf75b869c469196a8473c4962b99a450daaeeec, reversing
changes made to 09050ff2c5607f3991e6ec6422ed57ba0dee0bad.

.gitignore [deleted file]
client.go
client_test.go
cmd/magnet-metainfo/main.go
cmd/torrent/main.go
file.go
fs/torrentfs.go
issue35_test.go
reader.go
t.go
torrent.go

diff --git a/.gitignore b/.gitignore
deleted file mode 100644 (file)
index 62c8935..0000000
+++ /dev/null
@@ -1 +0,0 @@
-.idea/
\ No newline at end of file
index 05e0351a5588327f98cda3de9b15b974447e0944..322c7e704b138531fab1188465086016247b4254 100644 (file)
--- a/client.go
+++ b/client.go
@@ -678,7 +678,7 @@ func (cl *Client) Torrent(ih InfoHash) (T Torrent, ok bool) {
        if !ok {
                return
        }
-       T = clientTorrent{cl, t}
+       T = Torrent{cl, t}
        return
 }
 
@@ -1828,7 +1828,7 @@ func (me *Client) openNewConns(t *torrent) {
                        return
                }
                var (
-                       k PeersKey
+                       k peersKey
                        p Peer
                )
                for k, p = range t.Peers {
@@ -1945,7 +1945,7 @@ func newTorrent(ih InfoHash) (t *torrent, err error) {
        t = &torrent{
                InfoHash:  ih,
                chunkSize: defaultChunkSize,
-               Peers:     make(map[PeersKey]Peer),
+               Peers:     make(map[peersKey]Peer),
 
                closing:           make(chan struct{}),
                ceasingNetworking: make(chan struct{}),
@@ -2030,7 +2030,7 @@ type Handle interface {
 
 // Returns handles to the files in the torrent. This requires the metainfo is
 // available first.
-func (t clientTorrent) Files() (ret []File) {
+func (t Torrent) Files() (ret []File) {
        t.cl.mu.Lock()
        info := t.Info()
        t.cl.mu.Unlock()
@@ -2052,7 +2052,7 @@ func (t clientTorrent) Files() (ret []File) {
 }
 
 // Marks the pieces in the given region for download.
-func (t clientTorrent) SetRegionPriority(off, len int64) {
+func (t Torrent) SetRegionPriority(off, len int64) {
        t.cl.mu.Lock()
        defer t.cl.mu.Unlock()
        pieceSize := int64(t.usualPieceSize())
@@ -2061,7 +2061,7 @@ func (t clientTorrent) SetRegionPriority(off, len int64) {
        }
 }
 
-func (t clientTorrent) AddPeers(pp []Peer) error {
+func (t Torrent) AddPeers(pp []Peer) error {
        cl := t.cl
        cl.mu.Lock()
        defer cl.mu.Unlock()
@@ -2071,7 +2071,7 @@ func (t clientTorrent) AddPeers(pp []Peer) error {
 
 // Marks the entire torrent for download. Requires the info first, see
 // GotInfo.
-func (t clientTorrent) DownloadAll() {
+func (t Torrent) DownloadAll() {
        t.cl.mu.Lock()
        defer t.cl.mu.Unlock()
        for i := range iter.N(t.numPieces()) {
@@ -2157,10 +2157,8 @@ func TorrentSpecFromMetaInfo(mi *metainfo.MetaInfo) (spec *TorrentSpec) {
 // trackers will be merged with the existing ones. If the Info isn't yet
 // known, it will be set. The display name is replaced if the new spec
 // provides one. Returns new if the torrent wasn't already in the client.
-func (cl *Client) AddTorrentSpec(spec *TorrentSpec) (D Torrent, new bool, err error) {
-       T := clientTorrent{}
+func (cl *Client) AddTorrentSpec(spec *TorrentSpec) (T Torrent, new bool, err error) {
        T.cl = cl
-       D = &T
        cl.mu.Lock()
        defer cl.mu.Unlock()
 
@@ -2725,7 +2723,7 @@ func (cl *Client) verifyPiece(t *torrent, piece int) {
 func (me *Client) Torrents() (ret []Torrent) {
        me.mu.Lock()
        for _, t := range me.torrents {
-               ret = append(ret, clientTorrent{me, t})
+               ret = append(ret, Torrent{me, t})
        }
        me.mu.Unlock()
        return
index 88088bec45d95894eb0bbe17dc57031435396d21..80d1535c18e69becb7129568f99cbc74565f4abe 100644 (file)
@@ -290,7 +290,7 @@ func TestClientTransfer(t *testing.T) {
        // TODO: The piece state publishing is kinda jammed in here until I have a
        // more thorough test.
        go func() {
-               s := leecherGreeting.SubscribePieceStateChanges()
+               s := leecherGreeting.pieceStateChanges.Subscribe()
                defer s.Close()
                for i := range s.Values {
                        log.Print(i)
@@ -410,8 +410,8 @@ func TestMergingTrackersByAddingSpecs(t *testing.T) {
        if new {
                t.FailNow()
        }
-       assert.EqualValues(t, T.Trackers()[0][0].URL(), "http://a")
-       assert.EqualValues(t, T.Trackers()[1][0].URL(), "udp://b")
+       assert.EqualValues(t, T.Trackers[0][0].URL(), "http://a")
+       assert.EqualValues(t, T.Trackers[1][0].URL(), "udp://b")
 }
 
 type badData struct{}
index d3a070c0120b5cb515d2d7a24590a005a478587f..878fc7db9404c81445c57325b9a2ce16bde88982 100644 (file)
@@ -27,9 +27,9 @@ func main() {
                go func() {
                        defer wg.Done()
                        <-t.GotInfo()
-                       mi := t.Info()
+                       mi := t.MetaInfo()
                        t.Drop()
-                       f, err := os.Create(mi.Name + ".torrent")
+                       f, err := os.Create(mi.Info.Name + ".torrent")
                        if err != nil {
                                log.Fatalf("error creating torrent metainfo file: %s", err)
                        }
index 66871794859ba59589ad30d393206282af7e6ed2..4adda93e07cf71678e8a8a8d6764b0bc5af20448 100644 (file)
@@ -54,7 +54,7 @@ func torrentBar(t torrent.Torrent) {
                }
        })
        bar.PrependFunc(func(*uiprogress.Bar) string {
-               return t.Info().Name
+               return t.Name()
        })
        go func() {
                <-t.GotInfo()
diff --git a/file.go b/file.go
index 2395d266de24242700c913dffe87e54ef1cc24e0..cdeb3c70425be9ae4cbfd93005f4f87377e0c5ca 100644 (file)
--- a/file.go
+++ b/file.go
@@ -8,7 +8,7 @@ import (
 
 // Provides access to regions of torrent data that correspond to its files.
 type File struct {
-       t      clientTorrent
+       t      Torrent
        path   string
        offset int64
        length int64
index c4cacd4aed7bfff7a915c52d412a98813f435f7e..9b3f3958768532a1497d9befbd450a4ba2d64928 100644 (file)
@@ -225,7 +225,7 @@ func (dn dirNode) Attr(ctx context.Context, attr *fuse.Attr) error {
 func (me rootNode) Lookup(ctx context.Context, name string) (_node fusefs.Node, err error) {
        for _, t := range me.fs.Client.Torrents() {
                info := t.Info()
-               if t.Info().Name != name || info == nil {
+               if t.Name() != name || info == nil {
                        continue
                }
                __node := node{
index 1d8f113d686e1d8b3beaa3bed937f808f25deb4e..59dbe38fbd83db62991badafd2dff30129e94d7e 100644 (file)
@@ -1,15 +1,15 @@
 package torrent
 
 import (
-       "errors"
-       "fmt"
-       "github.com/anacrolix/torrent/dht"
        "github.com/anacrolix/torrent/metainfo"
-       "io"
-       "os"
+       "testing"
        "path/filepath"
+       "os"
+       "github.com/anacrolix/torrent/dht"
+       "io"
+       "errors"
+       "fmt"
        "runtime"
-       "testing"
 )
 
 var numclients int = 0
@@ -42,12 +42,12 @@ func testingConfig() *Config {
                Seed:                 true,
                DataDir:              filepath.Join(os.TempDir(), "torrent-test/data"),
                ConfigDir:            filepath.Join(os.TempDir(), "torrent-test/config"),
-               DHTConfig: &dht.ServerConfig{
-                       Passive:        false,
+               DHTConfig:            &dht.ServerConfig{
+                       Passive: false,
                        BootstrapNodes: []string{},
-                       NoSecurity:     false,
+                       NoSecurity: false,
                },
-               Debug: true,
+               Debug:                true,
        }
 }
 
@@ -74,7 +74,7 @@ func writeranddata(path string) error {
        return nil
 }
 
-func TestInfohash(t *testing.T) {
+func TestInfohash(t *testing.T){
        os.RemoveAll(filepath.Join(os.TempDir(), "torrent-test"))
        os.MkdirAll(filepath.Join(os.TempDir(), "torrent-test"), 0700)
        var cl_one *Client
index 86d2e07999e4adc5563f9d5a184e04d98fc977bb..e26dfe1d7cf0c4d150a7d3749903daa11e7c3482 100644 (file)
--- a/reader.go
+++ b/reader.go
@@ -8,7 +8,7 @@ import (
 
 // Accesses torrent data via a client.
 type Reader struct {
-       t          *clientTorrent
+       t          *Torrent
        pos        int64
        responsive bool
        readahead  int64
diff --git a/t.go b/t.go
index 173cdd31dd1caa7e9f39a063c71b44ccb9fb5240..65709037ab88a21b62ea9357ccc7d3e1e6ce9d86 100644 (file)
--- a/t.go
+++ b/t.go
@@ -2,62 +2,41 @@ package torrent
 
 import (
        "github.com/anacrolix/missinggo/pubsub"
+
        "github.com/anacrolix/torrent/metainfo"
-       "github.com/anacrolix/torrent/tracker"
 )
 
 // This file contains Torrent, until I decide where the private, lower-case
 // "torrent" type belongs. That type is currently mostly in torrent.go.
 
-// The public interface to a live torrent within a Client.
-type Torrent interface {
-       InfoHash() InfoHash
-       GotInfo() <-chan struct{}
-       Info() *metainfo.Info
-       NewReader() (ret *Reader)
-       PieceStateRuns() []PieceStateRun
-       NumPieces() int
-       Drop()
-       BytesCompleted() int64
-       SubscribePieceStateChanges() *pubsub.Subscription
-       Seeding() bool
-       SetDisplayName(dn string)
-       Client() *Client
-       AddPeers(pp []Peer) error
-       DownloadAll()
-       Trackers() [][]tracker.Client
-       Files() (ret []File)
-       Peers() map[PeersKey]Peer
-}
-
-
-type clientTorrent struct {
+// The public handle to a live torrent within a Client.
+type Torrent struct {
        cl *Client
        *torrent
 }
 
 // The torrent's infohash. This is fixed and cannot change. It uniquely
 // identifies a torrent.
-func (t clientTorrent) InfoHash() InfoHash {
+func (t Torrent) InfoHash() InfoHash {
        return t.torrent.InfoHash
 }
 
 // Closed when the info (.Info()) for the torrent has become available. Using
 // features of Torrent that require the info before it is available will have
 // undefined behaviour.
-func (t clientTorrent) GotInfo() <-chan struct{} {
+func (t Torrent) GotInfo() <-chan struct{} {
        return t.torrent.gotMetainfo
 }
 
 // Returns the metainfo, or nil if it's not yet available.
-func (t clientTorrent) Info() *metainfo.Info {
+func (t Torrent) Info() *metainfo.Info {
        return t.torrent.Info
 }
 
 // Returns a Reader bound to the torrent's data. All read calls block until
 // the data requested is actually available. Priorities are set to ensure the
 // data requested will be downloaded as soon as possible.
-func (t clientTorrent) NewReader() (ret *Reader) {
+func (t Torrent) NewReader() (ret *Reader) {
        ret = &Reader{
                t:         &t,
                readahead: 5 * 1024 * 1024,
@@ -68,25 +47,25 @@ func (t clientTorrent) NewReader() (ret *Reader) {
 // Returns the state of pieces of the torrent. They are grouped into runs of
 // same state. The sum of the state run lengths is the number of pieces
 // in the torrent.
-func (t clientTorrent) PieceStateRuns() []PieceStateRun {
+func (t Torrent) PieceStateRuns() []PieceStateRun {
        t.stateMu.Lock()
        defer t.stateMu.Unlock()
        return t.torrent.pieceStateRuns()
 }
 
-func (t clientTorrent) NumPieces() int {
+func (t Torrent) NumPieces() int {
        return t.numPieces()
 }
 
 // Drop the torrent from the client, and close it.
-func (t clientTorrent) Drop() {
+func (t Torrent) Drop() {
        t.cl.mu.Lock()
        t.cl.dropTorrent(t.torrent.InfoHash)
        t.cl.mu.Unlock()
 }
 
 // Number of bytes of the entire torrent we have completed.
-func (t clientTorrent) BytesCompleted() int64 {
+func (t Torrent) BytesCompleted() int64 {
        t.cl.mu.RLock()
        defer t.cl.mu.RUnlock()
        return t.bytesCompleted()
@@ -94,13 +73,13 @@ func (t clientTorrent) BytesCompleted() int64 {
 
 // The subscription emits as (int) the index of pieces as their state changes.
 // A state change is when the PieceState for a piece alters in value.
-func (t clientTorrent) SubscribePieceStateChanges() *pubsub.Subscription {
+func (t Torrent) SubscribePieceStateChanges() *pubsub.Subscription {
        return t.torrent.pieceStateChanges.Subscribe()
 }
 
 // Returns true if the torrent is currently being seeded. This occurs when the
 // client is willing to upload without wanting anything in return.
-func (t clientTorrent) Seeding() bool {
+func (t Torrent) Seeding() bool {
        t.cl.mu.Lock()
        defer t.cl.mu.Unlock()
        return t.cl.seeding(t.torrent)
@@ -108,23 +87,8 @@ func (t clientTorrent) Seeding() bool {
 
 // Clobbers the torrent display name. The display name is used as the torrent
 // name if the metainfo is not available.
-func (t clientTorrent) SetDisplayName(dn string) {
+func (t Torrent) SetDisplayName(dn string) {
        t.cl.mu.Lock()
        defer t.cl.mu.Unlock()
        t.torrent.setDisplayName(dn)
 }
-
-// Client returns Torrent's client instance
-func (t clientTorrent) Client() *Client {
-       return t.cl
-}
-
-// Trackers returns torrent's trackers
-func (t clientTorrent) Trackers() [][]tracker.Client {
-       return t.torrent.Trackers
-}
-
-// Peers returns torrent's peers
-func (t clientTorrent) Peers() map[PeersKey]Peer {
-       return t.torrent.Peers
-}
index db554e679d5433f6d91b8fc41e2a908e9da6b8b5..b2478656cc72d5fe7f4cf4d19dc662dc5956bf6b 100644 (file)
@@ -39,7 +39,7 @@ func (t *torrent) pieceNumPendingBytes(index int) (count pp.Integer) {
        return
 }
 
-type PeersKey struct {
+type peersKey struct {
        IPBytes string
        Port    int
 }
@@ -78,7 +78,7 @@ type torrent struct {
        // Reserve of peers to connect to. A peer can be both here and in the
        // active connections if were told about the peer after connecting with
        // them. That encourages us to reconnect to peers that are well known.
-       Peers     map[PeersKey]Peer
+       Peers     map[peersKey]Peer
        wantPeers sync.Cond
 
        // BEP 12 Multitracker Metadata Extension. The tracker.Client instances
@@ -180,7 +180,7 @@ func (t *torrent) addPeer(p Peer, cl *Client) {
        if len(t.Peers) >= torrentPeersHighWater {
                return
        }
-       key := PeersKey{string(p.IP), p.Port}
+       key := peersKey{string(p.IP), p.Port}
        if _, ok := t.Peers[key]; ok {
                return
        }