Example #1
0
func (t *Tracker) ensureTorrentExists(file string) (string, error) {
	tf := file + ".torrent"

	if _, err := os.Stat(tf); os.IsNotExist(err) {
		m, err := torrent.CreateMetaInfoFromFileSystem(nil, file, "0.0.0.0:8888", 0, true)
		if err != nil {
			return tf, err
		}

		m.Announce = "http://" + t.trListen + "/announce"

		meta, err := os.Create(tf)
		if err != nil {
			return tf, err
		}

		defer meta.Close()

		err = m.Bencode(meta)
		if err != nil {
			return tf, err
		}
	}

	return tf, nil
}
Example #2
0
func createTorrentFile(torrentFileName, root, announcePath string) (err error) {
	var metaInfo *torrent.MetaInfo
	metaInfo, err = torrent.CreateMetaInfoFromFileSystem(nil, root, "127.0.0.1:8080", 0, false)
	if err != nil {
		return
	}
	metaInfo.CreatedBy = "testSwarm"
	var torrentFile *os.File
	torrentFile, err = os.Create(torrentFileName)
	if err != nil {
		return
	}
	defer torrentFile.Close()
	err = metaInfo.Bencode(torrentFile)
	if err != nil {
		return
	}
	return
}
Example #3
0
func createTorrentFile(torrentFileName, root, announcePath string) (err error) {
	var metaInfo *torrent.MetaInfo
	metaInfo, err = torrent.CreateMetaInfoFromFileSystem(nil, root, 0, false)
	if err != nil {
		return
	}
	btHost := *tracker
	metaInfo.Announce = "http://" + btHost + "/announce"
	metaInfo.CreatedBy = "docket-registry"
	var torrentFile *os.File
	torrentFile, err = os.Create(torrentFileName)
	if err != nil {
		return
	}
	defer torrentFile.Close()
	err = metaInfo.Bencode(torrentFile)
	if err != nil {
		return
	}
	return
}