}
type Client struct {
- noUpload bool
- dataDir string
- halfOpenLimit int
- peerID [20]byte
- listeners []net.Listener
- utpSock *utp.Socket
- disableTrackers bool
- dHT *dht.Server
- disableUTP bool
- disableTCP bool
- ipBlockList *iplist.IPList
- bannedTorrents map[InfoHash]struct{}
- _configDir string
- config Config
- pruneTimer *time.Timer
- extensionBytes peerExtensionBytes
+ halfOpenLimit int
+ peerID [20]byte
+ listeners []net.Listener
+ utpSock *utp.Socket
+ dHT *dht.Server
+ ipBlockList *iplist.IPList
+ bannedTorrents map[InfoHash]struct{}
+ config Config
+ pruneTimer *time.Timer
+ extensionBytes peerExtensionBytes
// Set of addresses that have our client ID. This intentionally will
// include ourselves if we end up trying to connect to our own address
// through legitimate channels.
}
func (cl *Client) configDir() string {
- if cl._configDir == "" {
+ if cl.config.ConfigDir == "" {
return filepath.Join(os.Getenv("HOME"), ".config/torrent")
}
- return cl._configDir
+ return cl.config.ConfigDir
}
func (cl *Client) ConfigDir() string {
}
}()
cl = &Client{
- noUpload: cfg.NoUpload,
- disableTrackers: cfg.DisableTrackers,
- halfOpenLimit: socketsPerTorrent,
- dataDir: cfg.DataDir,
- disableUTP: cfg.DisableUTP,
- disableTCP: cfg.DisableTCP,
- _configDir: cfg.ConfigDir,
- config: *cfg,
+ halfOpenLimit: socketsPerTorrent,
+ config: *cfg,
torrentDataOpener: func(md *metainfo.Info) data.Data {
return filePkg.TorrentData(md, cfg.DataDir)
},
}
return cfg.ListenAddr
}
- if !cl.disableTCP {
+ if !cl.config.DisableTCP {
var l net.Listener
l, err = net.Listen("tcp", listenAddr())
if err != nil {
cl.listeners = append(cl.listeners, l)
go cl.acceptConnections(l, false)
}
- if !cl.disableUTP {
+ if !cl.config.DisableUTP {
cl.utpSock, err = utp.NewSocket(listenAddr())
if err != nil {
return
// Initiate connections via TCP and UTP simultaneously. Use the first one
// that succeeds.
left := 0
- if !me.disableUTP {
+ if !me.config.DisableUTP {
left++
}
- if !me.disableTCP {
+ if !me.config.DisableTCP {
left++
}
resCh := make(chan dialResult, left)
- if !me.disableUTP {
+ if !me.config.DisableUTP {
go doDial(me.dialUTP, resCh, true, addr, t)
}
- if !me.disableTCP {
+ if !me.config.DisableTCP {
go doDial(me.dialTCP, resCh, false, addr, t)
}
var res dialResult
"v": extendedHandshakeClientVersion,
// No upload queue is implemented yet.
"reqq": func() int {
- if me.noUpload {
+ if me.config.NoUpload {
// No need to look strange if it costs us nothing.
return 250
} else {
case pp.Interested:
c.PeerInterested = true
// TODO: This should be done from a dedicated unchoking routine.
- if me.noUpload {
+ if me.config.NoUpload {
break
}
c.Unchoke()
case pp.Have:
me.peerGotPiece(t, c, int(msg.Index))
case pp.Request:
- if me.noUpload {
+ if me.config.NoUpload {
break
}
if c.PeerRequests == nil {
}
func (me *Client) wantConns(t *torrent) bool {
- if me.noUpload && !t.needData() {
+ if me.config.NoUpload && !t.needData() {
return false
}
if t.numGoodConns() >= socketsPerTorrent {
}
// If the client intends to upload, it needs to know what state pieces are
// in.
- if !cl.noUpload {
+ if !cl.config.NoUpload {
// Queue all pieces for hashing. This is done sequentially to avoid
// spamming goroutines.
for _, p := range t.Pieces {
t.pruneTimer = time.AfterFunc(0, func() {
cl.pruneConnectionsUnlocked(T.torrent)
})
- if !cl.disableTrackers {
+ if !cl.config.DisableTrackers {
go cl.announceTorrentTrackers(T.torrent)
}
if cl.dHT != nil {
me.replenishConnRequests(t, conn)
}
}
- if t.haveAllPieces() && me.noUpload {
+ if t.haveAllPieces() && me.config.NoUpload {
t.ceaseNetworking()
}
me.event.Broadcast()