Update external use of ClientConfig

This commit is contained in:
Matt Joiner 2018-06-16 16:33:40 +10:00
parent e97f487d2e
commit cee8e3b9f9
4 changed files with 37 additions and 38 deletions

View File

@ -79,10 +79,12 @@ func dstFileName(picked string) string {
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
var rootGroup struct {
Client torrent.Config `group:"Client Options"`
TestPeers []string `long:"test-peer" description:"address of peer to inject to every torrent"`
Pick string `long:"pick" description:"filename to pick"`
var rootGroup = struct {
Client *torrent.ClientConfig `group:"Client Options"`
TestPeers []string `long:"test-peer" description:"address of peer to inject to every torrent"`
Pick string `long:"pick" description:"filename to pick"`
}{
Client: torrent.NewDefaultClientConfig(),
}
// Don't pass flags.PrintError because it's inconsistent with printing.
// https://github.com/jessevdk/go-flags/issues/132
@ -115,7 +117,7 @@ func main() {
rootGroup.Client.DataDir = tmpdir
client, err := torrent.NewClient(&rootGroup.Client)
client, err := torrent.NewClient(rootGroup.Client)
if err != nil {
log.Fatalf("error creating client: %s", err)
}

View File

@ -155,10 +155,9 @@ func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
tagflag.Parse(&flags)
defer envpprof.Stop()
clientConfig := torrent.Config{
Debug: flags.Debug,
Seed: flags.Seed,
}
clientConfig := torrent.NewDefaultClientConfig()
clientConfig.Debug = flags.Debug
clientConfig.Seed = flags.Seed
if flags.PackedBlocklist != "" {
blocklist, err := iplist.MMapPackedFile(flags.PackedBlocklist)
if err != nil {
@ -180,7 +179,7 @@ func main() {
clientConfig.DownloadRateLimiter = rate.NewLimiter(rate.Limit(flags.DownloadRate), 1<<20)
}
client, err := torrent.NewClient(&clientConfig)
client, err := torrent.NewClient(clientConfig)
if err != nil {
log.Fatalf("error creating client: %s", err)
}

View File

@ -86,13 +86,12 @@ func mainExitCode() int {
defer fuse.Unmount(args.MountDir)
// TODO: Think about the ramifications of exiting not due to a signal.
defer conn.Close()
cfg := torrent.Config{
DataDir: args.DownloadDir,
DisableTrackers: args.DisableTrackers,
NoUpload: true, // Ensure that downloads are responsive.
}
cfg := torrent.NewDefaultClientConfig()
cfg.DataDir = args.DownloadDir
cfg.DisableTrackers = args.DisableTrackers
cfg.NoUpload = true // Ensure that downloads are responsive.
cfg.SetListenAddr(args.ListenAddr.String())
client, err := torrent.NewClient(&cfg)
client, err := torrent.NewClient(cfg)
if err != nil {
log.Print(err)
return 1

View File

@ -88,13 +88,13 @@ func TestUnmountWedged(t *testing.T) {
t.Log(err)
}
}()
client, err := torrent.NewClient(&torrent.Config{
DataDir: filepath.Join(layout.BaseDir, "incomplete"),
DisableTrackers: true,
NoDHT: true,
DisableTCP: true,
DisableUTP: true,
})
cfg := torrent.NewDefaultClientConfig()
cfg.DataDir = filepath.Join(layout.BaseDir, "incomplete")
cfg.DisableTrackers = true
cfg.NoDHT = true
cfg.DisableTCP = true
cfg.DisableUTP = true
client, err := torrent.NewClient(cfg)
require.NoError(t, err)
defer client.Close()
tt, err := client.AddTorrent(layout.Metainfo)
@ -165,14 +165,13 @@ func TestDownloadOnDemand(t *testing.T) {
layout, err := newGreetingLayout()
require.NoError(t, err)
defer layout.Destroy()
cfg := torrent.Config{
DataDir: layout.Completed,
DisableTrackers: true,
NoDHT: true,
Seed: true,
ListenHost: torrent.LoopbackListenHost,
}
seeder, err := torrent.NewClient(&cfg)
cfg := torrent.NewDefaultClientConfig()
cfg.DataDir = layout.Completed
cfg.DisableTrackers = true
cfg.NoDHT = true
cfg.Seed = true
cfg.ListenHost = torrent.LoopbackListenHost
seeder, err := torrent.NewClient(cfg)
require.NoError(t, err)
defer seeder.Close()
testutil.ExportStatusWriter(seeder, "s")
@ -185,13 +184,13 @@ func TestDownloadOnDemand(t *testing.T) {
<-seederTorrent.GotInfo()
seederTorrent.VerifyData()
}()
leecher, err := torrent.NewClient(&torrent.Config{
DisableTrackers: true,
NoDHT: true,
DisableTCP: true,
DefaultStorage: storage.NewMMap(filepath.Join(layout.BaseDir, "download")),
ListenHost: torrent.LoopbackListenHost,
})
cfg = torrent.NewDefaultClientConfig()
cfg.DisableTrackers = true
cfg.NoDHT = true
cfg.DisableTCP = true
cfg.DefaultStorage = storage.NewMMap(filepath.Join(layout.BaseDir, "download"))
cfg.ListenHost = torrent.LoopbackListenHost
leecher, err := torrent.NewClient(cfg)
require.NoError(t, err)
testutil.ExportStatusWriter(leecher, "l")
defer leecher.Close()