根据Taipei-Torrent修改出的三个bt工具

目前就是测试版本,均修改main.go然后编译即可
tracker

//package xtracker
package main
import (
	"log"
	"os"
	"os/signal"
	"path"

	"github.com/jackpal/Taipei-Torrent/torrent"
	"github.com/jackpal/Taipei-Torrent/tracker"
	"golang.org/x/net/proxy"
)

func main() {

	err := startTracker("0.0.0.0:6969", []string{"test.torrent"})
	if err != nil {
		log.Fatal("Tracker returned error:", err)
	}
	return

}


func startTracker(addr string, torrentFiles []string) (err error) {
	t := tracker.NewTracker()
	// TODO(jackpal) Allow caller to choose port number
	t.Addr = addr
	dial := proxy.FromEnvironment()
	for _, torrentFile := range torrentFiles {
		var metaInfo *torrent.MetaInfo
		metaInfo, err = torrent.GetMetaInfo(dial, torrentFile)
		if err != nil {
			return
		}
		name := metaInfo.Info.Name
		if name == "" {
			name = path.Base(torrentFile)
		}
		err = t.Register(metaInfo.InfoHash, name)
		if err != nil {
			return
		}
	}
	go func() {
		quitChan := listenSigInt()
		select {
		case <-quitChan:
			log.Printf("got control-C")
			t.Quit()
		}
	}()

	err = t.ListenAndServe()
	if err != nil {
		return
	}
	return
}

func listenSigInt() chan os.Signal {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)
	return c
}

bt客户端

//package xbt
package main
import (
	"log"
	"math"

	"github.com/jackpal/Taipei-Torrent/torrent"
	"golang.org/x/net/proxy"
)

var (
	cpuprofile    = "" //If not empty, collects CPU profile samples and writes the profile to the given file before the program exits
	memprofile    = "" //If not empty, writes memory heap allocations to the given file before the program exits
	createTorrent = "" //If not empty, creates a torrent file from the given root. Writes to stdout
	createTracker = "" //Creates a tracker serving the given torrent file on the given address. Example --createTracker=:8080 to serve on port 8080.

	port                = 7777 //Port to listen on. 0 means pick random port. Note that 6881 is blacklisted by some trackers.
	fileDir             = "." //path to directory where files are stored
	seedRatio           = math.Inf(0) //Seed until ratio >= this value before quitting.
	useDeadlockDetector = false //Panic and print stack dumps when the program is stuck.
	useLPD              = false //Use Local Peer Discovery
	useUPnP             = false //Use UPnP to open port in firewall.
	useNATPMP           = false //Use NAT-PMP to open port in firewall.
	gateway             = "" //IP Address of gateway.
	useDHT              = false //Use DHT to get peers.
	trackerlessMode     = false //Do not get peers from the tracker. Good for testing DHT mode.
	proxyAddress        = "" //Address of a SOCKS5 proxy to use.
	initialCheck        = true //Do an initial hash check on files when adding torrents.
	useSFTP             = "" //SFTP connection string, to store torrents over SFTP. e.g. 'username:password@192.168.1.25:22/path/'
	useRamCache         = 0 //Size in MiB of cache in ram, to reduce traffic on torrent storage.
	useHdCache          = 0 //Size in MiB of cache in OS temp directory, to reduce traffic on torrent storage.
	execOnSeeding       = "" //Command to execute when torrent has fully downloaded and has begun seeding.
	quickResume         = false //Save torrenting data to resume faster. '-initialCheck' should be set to false, to prevent hash check on resume.
	maxActive           = 16 //How many torrents should be active at a time. Torrents added beyond this value are queued.
	memoryPerTorrent    = -1 //Maximum memory (in MiB) per torrent used for Active Pieces. 0 means minimum. -1 (default) means unlimited.
	torrentFiles        []string
)

func parseTorrentFlags() (flags *torrent.TorrentFlags, err error) {
	dialer := proxy.FromEnvironment()

	flags = &torrent.TorrentFlags{
		Dial:                dialer,
		Port:                port,
		FileDir:             fileDir,
		SeedRatio:           seedRatio,
		UseDeadlockDetector: useDeadlockDetector,
		UseLPD:              useLPD,
		UseDHT:              useDHT,
		UseUPnP:             useUPnP,
		UseNATPMP:           useNATPMP,
		TrackerlessMode:     trackerlessMode,
		// IP address of gateway
		Gateway:            gateway,
		InitialCheck:       initialCheck,
		FileSystemProvider: torrent.OsFsProvider{},
		Cacher:             nil,
		ExecOnSeeding:      execOnSeeding,
		QuickResume:        quickResume,
		MaxActive:          maxActive,
		MemoryPerTorrent:   memoryPerTorrent,
	}
	return
}


func main() {

	torrentFiles = []string{"test.torrent"}

	torrentFlags, err := parseTorrentFlags()
	if err != nil {
		log.Fatal("Could not parse flags:", err)
	}

	log.Println("Starting.")

	err = torrent.RunTorrents(torrentFlags, torrentFiles)
	if err != nil {
		log.Fatal("Could not run torrents", err)
	}
}


bt种子生成

//package maketorrent
package main
import (
	"github.com/jackpal/Taipei-Torrent/torrent"
	"log"
	"os"
)

var (
	createTorrent = "sbt_client.with-apt-boost" //If not empty, creates a torrent file from the given root. Writes to stdout
	createTracker = "192.168.64.131:6969" //Creates a tracker serving the given torrent file on the given address. Example --createTracker=:8080 to serve on port 8080.
)



func main() {

	err := torrent.WriteMetaInfoBytes(createTorrent, createTracker, os.Stdout)
	if err != nil {
		log.Fatal("Could not create torrent file:", err)
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值