TODO | 3 ++- fs/torrentfs.go | 18 ++++++------------ metainfo.go | 17 +++++++++++++++++ torrent.go | 4 ++-- diff --git a/TODO b/TODO index 74c698bf765450cd37a773849ba11926fa678280..60275f3769e7adeed2fd0e9d5f0967358c30aebc 100644 --- a/TODO +++ b/TODO @@ -6,4 +6,5 @@ * Track upload and download data. * Remove non-deterministic stuff from unit tests, like the tracker UDP and fuse fs stuff. * Expose a public Torrent type bound to a given client or similar to work with common per-torrent operations. * Split scraping and announcing on DHT into separate routines. - * Ping nodes that stop being good. \ No newline at end of file + * Ping nodes that stop being good. + * Merge duplicate magnet data. \ No newline at end of file diff --git a/fs/torrentfs.go b/fs/torrentfs.go index 4bdcd781446fc4866d46375b2cc1a8983bb219d1..ed5e5b2c69c77a8f98316af923ac5cb59ca4e545 100644 --- a/fs/torrentfs.go +++ b/fs/torrentfs.go @@ -12,7 +12,6 @@ "bazil.org/fuse" fusefs "bazil.org/fuse/fs" "bitbucket.org/anacrolix/go.torrent" - "github.com/anacrolix/libtorgo/metainfo" ) const ( @@ -52,7 +51,7 @@ } type node struct { path []string - metadata *metainfo.Info + metadata *torrent.MetaInfo FS *torrentFS InfoHash torrent.InfoHash } @@ -225,10 +224,6 @@ attr.Mode = os.ModeDir | defaultMode return } -func isSingleFileTorrent(md *metainfo.Info) bool { - return len(md.Files) == 0 -} - func (me rootNode) Lookup(name string, intr fusefs.Intr) (_node fusefs.Node, err fuse.Error) { for _, t := range me.fs.Client.Torrents() { if t.Name() != name || t.Info == nil { @@ -239,7 +234,7 @@ metadata: t.Info, FS: me.fs, InfoHash: t.InfoHash, } - if isSingleFileTorrent(t.Info) { + if t.Info.SingleFile() { _node = fileNode{__node, uint64(t.Info.Length), 0} } else { _node = dirNode{__node} @@ -253,15 +248,14 @@ return } func (me rootNode) ReadDir(intr fusefs.Intr) (dirents []fuse.Dirent, err fuse.Error) { - for _, _torrent := range me.fs.Client.Torrents() { - metaInfo := _torrent.Info - if metaInfo == nil { + for _, t := range me.fs.Client.Torrents() { + if t.Info == nil { continue } dirents = append(dirents, fuse.Dirent{ - Name: metaInfo.Name, + Name: t.Info.Name, Type: func() fuse.DirentType { - if isSingleFileTorrent(metaInfo) { + if t.Info.SingleFile() { return fuse.DT_File } else { return fuse.DT_Dir diff --git a/metainfo.go b/metainfo.go new file mode 100644 index 0000000000000000000000000000000000000000..73429d50271843d34a3e3b5a51c3ec48c7305f97 --- /dev/null +++ b/metainfo.go @@ -0,0 +1,17 @@ +package torrent + +import "github.com/anacrolix/libtorgo/metainfo" + +type MetaInfo struct { + *metainfo.Info +} + +func newMetaInfo(info *metainfo.Info) *MetaInfo { + return &MetaInfo{ + Info: info, + } +} + +func (me *MetaInfo) SingleFile() bool { + return len(me.Info.Files) == 0 +} diff --git a/torrent.go b/torrent.go index 3e42eec0d696d7acf06c44477b776e20d56daa2b..087338263a7bcfc34e7919657eaf68bfc5b1eb2d 100644 --- a/torrent.go +++ b/torrent.go @@ -58,7 +58,7 @@ // Prevent mutations to Data memory maps while in use as they're not safe. dataLock sync.RWMutex Data mmap_span.MMapSpan - Info *metainfo.Info + Info *MetaInfo // Active peer connections. Conns []*connection // Set of addrs to which we're attempting to connect. @@ -195,7 +195,7 @@ } // Called when metadata for a torrent becomes available. func (t *torrent) setMetadata(md metainfo.Info, dataDir string, infoBytes []byte) (err error) { - t.Info = &md + t.Info = newMetaInfo(&md) t.MetaData = infoBytes t.metadataHave = nil t.Data, err = mmapTorrentData(&md, dataDir)