utpSock *utp.Socket
dHT *dht.Server
ipBlockList iplist.Ranger
- bannedTorrents map[metainfo.InfoHash]struct{}
+ bannedTorrents map[metainfo.Hash]struct{}
config Config
pruneTimer *time.Timer
extensionBytes peerExtensionBytes
event sync.Cond
closed missinggo.Event
- torrents map[metainfo.InfoHash]*Torrent
+ torrents map[metainfo.Hash]*Torrent
}
func (me *Client) IPBlockList() iplist.Ranger {
}
type hashSorter struct {
- Hashes []metainfo.InfoHash
+ Hashes []metainfo.Hash
}
func (me hashSorter) Len() int {
}
defer f.Close()
scanner := bufio.NewScanner(f)
- cl.bannedTorrents = make(map[metainfo.InfoHash]struct{})
+ cl.bannedTorrents = make(map[metainfo.Hash]struct{})
for scanner.Scan() {
if strings.HasPrefix(strings.TrimSpace(scanner.Text()), "#") {
continue
if len(ihs) != 20 {
return errors.New("bad infohash")
}
- var ih metainfo.InfoHash
+ var ih metainfo.Hash
missinggo.CopyExact(&ih, ihs)
cl.bannedTorrents[ih] = struct{}{}
}
config: *cfg,
defaultStorage: cfg.DefaultStorage,
dopplegangerAddrs: make(map[string]struct{}),
- torrents: make(map[metainfo.InfoHash]*Torrent),
+ torrents: make(map[metainfo.Hash]*Torrent),
}
missinggo.CopyExact(&cl.extensionBytes, defaultExtensionBytes)
cl.event.L = &cl.mu
}
// Returns a handle to the given torrent, if it's present in the client.
-func (cl *Client) Torrent(ih metainfo.InfoHash) (t *Torrent, ok bool) {
+func (cl *Client) Torrent(ih metainfo.Hash) (t *Torrent, ok bool) {
cl.mu.Lock()
defer cl.mu.Unlock()
t, ok = cl.torrents[ih]
return
}
-func (me *Client) torrent(ih metainfo.InfoHash) *Torrent {
+func (me *Client) torrent(ih metainfo.Hash) *Torrent {
return me.torrents[ih]
}
type handshakeResult struct {
peerExtensionBytes
peerID
- metainfo.InfoHash
+ metainfo.Hash
}
// ih is nil if we expect the peer to declare the InfoHash, such as when the
// peer initiated the connection. Returns ok if the handshake was successful,
// and err if there was an unexpected condition other than the peer simply
// abandoning the handshake.
-func handshake(sock io.ReadWriter, ih *metainfo.InfoHash, peerID [20]byte, extensions peerExtensionBytes) (res handshakeResult, ok bool, err error) {
+func handshake(sock io.ReadWriter, ih *metainfo.Hash, peerID [20]byte, extensions peerExtensionBytes) (res handshakeResult, ok bool, err error) {
// Bytes to be sent to the peer. Should never block the sender.
postCh := make(chan []byte, 4)
// A single error value sent when the writer completes.
return
}
missinggo.CopyExact(&res.peerExtensionBytes, b[20:28])
- missinggo.CopyExact(&res.InfoHash, b[28:48])
+ missinggo.CopyExact(&res.Hash, b[28:48])
missinggo.CopyExact(&res.peerID, b[48:68])
peerExtensions.Add(hex.EncodeToString(res.peerExtensionBytes[:]), 1)
// could prevent them trying to reconnect, falsely believing there was
// just a problem.
if ih == nil { // We were waiting for the peer to tell us what they wanted.
- post(res.InfoHash[:])
+ post(res.Hash[:])
post(peerID[:])
}
}
// Returns !ok if handshake failed for valid reasons.
-func (cl *Client) connBTHandshake(c *connection, ih *metainfo.InfoHash) (ret metainfo.InfoHash, ok bool, err error) {
+func (cl *Client) connBTHandshake(c *connection, ih *metainfo.Hash) (ret metainfo.Hash, ok bool, err error) {
res, ok, err := handshake(c.rw, ih, cl.peerID, cl.extensionBytes)
if err != nil || !ok {
return
}
- ret = res.InfoHash
+ ret = res.Hash
c.PeerExtensionBytes = res.peerExtensionBytes
c.PeerID = res.peerID
c.completedHandshake = time.Now()
func (cl *Client) completedMetadata(t *Torrent) {
h := sha1.New()
h.Write(t.metadataBytes)
- var ih metainfo.InfoHash
+ var ih metainfo.Hash
missinggo.CopyExact(&ih, h.Sum(nil))
if ih != t.infoHash {
log.Print("bad metadata")
}
}
-func (cl *Client) cachedMetaInfoFilename(ih metainfo.InfoHash) string {
+func (cl *Client) cachedMetaInfoFilename(ih metainfo.Hash) string {
return filepath.Join(cl.configDir(), "torrents", ih.HexString()+".torrent")
}
// Prepare a Torrent without any attachment to a Client. That means we can
// initialize fields all fields that don't require the Client without locking
// it.
-func newTorrent(ih metainfo.InfoHash) (t *Torrent) {
+func newTorrent(ih metainfo.Hash) (t *Torrent) {
t = &Torrent{
infoHash: ih,
chunkSize: defaultChunkSize,
// Returns nil metainfo if it isn't in the cache. Checks that the retrieved
// metainfo has the correct infohash.
-func (cl *Client) torrentCacheMetaInfo(ih metainfo.InfoHash) (mi *metainfo.MetaInfo, err error) {
+func (cl *Client) torrentCacheMetaInfo(ih metainfo.Hash) (mi *metainfo.MetaInfo, err error) {
if cl.config.DisableMetainfoCache {
return
}
type TorrentSpec struct {
// The tiered tracker URIs.
Trackers [][]string
- InfoHash metainfo.InfoHash
+ InfoHash metainfo.Hash
Info *metainfo.InfoEx
// The name to use if the Name field from the Info isn't available.
DisplayName string
return
}
-func (me *Client) dropTorrent(infoHash metainfo.InfoHash) (err error) {
+func (me *Client) dropTorrent(infoHash metainfo.Hash) (err error) {
t, ok := me.torrents[infoHash]
if !ok {
err = fmt.Errorf("no such torrent")
MagnetURI string
Change
TorrentFilePath string
- InfoHash metainfo.InfoHash
+ InfoHash metainfo.Hash
}
type entity struct {
- metainfo.InfoHash
+ metainfo.Hash
MagnetURI string
TorrentFilePath string
}
w *fsnotify.Watcher
dirName string
Events chan Event
- dirState map[metainfo.InfoHash]entity
+ dirState map[metainfo.Hash]entity
}
func (me *Instance) Close() {
}
}
-func torrentFileInfoHash(fileName string) (ih metainfo.InfoHash, ok bool) {
+func torrentFileInfoHash(fileName string) (ih metainfo.Hash, ok bool) {
mi, _ := metainfo.LoadFromFile(fileName)
if mi == nil {
return
return
}
-func scanDir(dirName string) (ee map[metainfo.InfoHash]entity) {
+func scanDir(dirName string) (ee map[metainfo.Hash]entity) {
d, err := os.Open(dirName)
if err != nil {
log.Print(err)
log.Print(err)
return
}
- ee = make(map[metainfo.InfoHash]entity, len(names))
+ ee = make(map[metainfo.Hash]entity, len(names))
addEntity := func(e entity) {
- e0, ok := ee[e.InfoHash]
+ e0, ok := ee[e.Hash]
if ok {
if e0.MagnetURI == "" || len(e.MagnetURI) < len(e0.MagnetURI) {
return
}
}
- ee[e.InfoHash] = e
+ ee[e.Hash] = e
}
for _, n := range names {
fullName := filepath.Join(dirName, n)
e := entity{
TorrentFilePath: fullName,
}
- missinggo.CopyExact(&e.InfoHash, ih)
+ missinggo.CopyExact(&e.Hash, ih)
addEntity(e)
case ".magnet":
uris, err := magnetFileURIs(fullName)
continue
}
addEntity(entity{
- InfoHash: m.InfoHash,
+ Hash: m.InfoHash,
MagnetURI: uri,
})
}
return
}
-func (me *Instance) torrentRemoved(ih metainfo.InfoHash) {
+func (me *Instance) torrentRemoved(ih metainfo.Hash) {
me.Events <- Event{
InfoHash: ih,
Change: Removed,
func (me *Instance) torrentAdded(e entity) {
me.Events <- Event{
- InfoHash: e.InfoHash,
+ InfoHash: e.Hash,
Change: Added,
MagnetURI: e.MagnetURI,
TorrentFilePath: e.TorrentFilePath,
w: w,
dirName: dirName,
Events: make(chan Event),
- dirState: make(map[metainfo.InfoHash]entity, 0),
+ dirState: make(map[metainfo.Hash]entity, 0),
}
go func() {
i.refresh()