@@ -33,7 +33,7 @@ import (
33
33
34
34
const (
35
35
removeTorrentChanBuffer = 1
36
- updateTorrentChanBuffer = 1000
36
+ updateTorrentChanBuffer = 2048
37
37
38
38
torrentPending = iota //2
39
39
torrentPaused
@@ -365,6 +365,7 @@ func (tm *TorrentManager) RemoveTorrent(input metainfo.Hash) error {
365
365
}
366
366
367
367
func (tm * TorrentManager ) UpdateTorrent (input interface {}) error {
368
+ //go func() {tm.updateTorrent <- input}()
368
369
tm .updateTorrent <- input
369
370
return nil
370
371
}
@@ -532,7 +533,7 @@ func (tm *TorrentManager) AddInfoHash(ih metainfo.Hash, BytesRequested int64) *T
532
533
} else if _ , err := os .Stat (torrentPath ); err == nil {
533
534
return tm .AddTorrent (torrentPath , BytesRequested )
534
535
}
535
- log .Debug ("Get torrent from infohash" , "InfoHash" , ih .HexString ())
536
+ // log.Info ("Get torrent from infohash", "InfoHash", ih.HexString())
536
537
537
538
spec := & torrent.TorrentSpec {
538
539
Trackers : [][]string {},
@@ -544,25 +545,25 @@ func (tm *TorrentManager) AddInfoHash(ih metainfo.Hash, BytesRequested int64) *T
544
545
for _ , tracker := range tm .trackers {
545
546
spec .Trackers = append (spec .Trackers , tracker )
546
547
}
547
- log .Trace ("Torrent specific info" , "spec" , spec )
548
+ // log.Info ("Torrent specific info", "spec", spec)
548
549
549
550
t , _ , err := tm .client .AddTorrentSpec (spec )
550
551
if err != nil {
551
552
return nil
552
553
}
553
554
tt := tm .CreateTorrent (t , BytesRequested , torrentPending , ih )
554
555
//tm.mu.Unlock()
555
- log .Trace ("Torrent is waiting for gotInfo" , "InfoHash" , ih .HexString ())
556
+ // log.Info ("Torrent is waiting for gotInfo", "InfoHash", ih.HexString())
556
557
return tt
557
558
}
558
559
559
560
// UpdateInfoHash ...
560
561
func (tm * TorrentManager ) UpdateInfoHash (ih metainfo.Hash , BytesRequested int64 ) {
561
562
log .Debug ("Update torrent" , "InfoHash" , ih , "bytes" , BytesRequested )
563
+ tm .lock .Lock ()
564
+ defer tm .lock .Unlock ()
562
565
if t , ok := tm .bytes [ih ]; ! ok || t < BytesRequested {
563
- tm .lock .Lock ()
564
566
tm .bytes [ih ] = BytesRequested
565
- tm .lock .Unlock ()
566
567
}
567
568
/*if t := tm.GetTorrent(ih); t != nil {
568
569
if BytesRequested < t.bytesRequested {
@@ -658,6 +659,7 @@ func NewTorrentManager(config *Config) *TorrentManager {
658
659
closeAll : make (chan struct {}),
659
660
removeTorrent : make (chan metainfo.Hash , removeTorrentChanBuffer ),
660
661
updateTorrent : make (chan interface {}, updateTorrentChanBuffer ),
662
+ //updateTorrent: make(chan interface{}),
661
663
}
662
664
663
665
if len (config .DefaultTrackers ) > 0 {
@@ -694,11 +696,12 @@ func (tm *TorrentManager) mainLoop() {
694
696
case msg := <- tm .updateTorrent :
695
697
meta := msg .(FlowControlMeta )
696
698
if meta .IsCreate {
699
+ //log.Info("TorrentManager", "newTorrent", meta.InfoHash.String())
700
+ //go tm.AddInfoHash(meta.InfoHash, int64(meta.BytesRequested))
697
701
counter := 0
698
- log .Debug ("TorrentManager" , "newTorrent" , meta .InfoHash .String ())
699
702
for {
700
703
if t := tm .AddInfoHash (meta .InfoHash , int64 (meta .BytesRequested )); t != nil {
701
- log .Debug ("Torrent success" , "hash" , meta .InfoHash , "request" , meta .BytesRequested )
704
+ log .Info ("Torrent success" , "hash" , meta .InfoHash , "request" , meta .BytesRequested )
702
705
break
703
706
} else {
704
707
if counter > 10 {
@@ -709,7 +712,7 @@ func (tm *TorrentManager) mainLoop() {
709
712
}
710
713
}
711
714
} else {
712
- log .Debug ("TorrentManager" , "updateTorrent" , meta .InfoHash .String (), "bytes" , meta .BytesRequested )
715
+ // log.Info ("TorrentManager", "updateTorrent", meta.InfoHash.String(), "bytes", meta.BytesRequested)
713
716
tm .UpdateInfoHash (meta .InfoHash , int64 (meta .BytesRequested ))
714
717
}
715
718
case <- tm .closeAll :
@@ -786,7 +789,7 @@ func (tm *TorrentManager) listenTorrentProgress() {
786
789
t .isBoosting = true
787
790
go func (t * Torrent ) {
788
791
defer t .BoostOff ()
789
- log .Debug ("Try to boost torrent" , "infohash" , t .infohash )
792
+ log .Info ("Try to boost torrent" , "infohash" , t .infohash )
790
793
if data , err := tm .boostFetcher .GetTorrent (t .infohash ); err == nil {
791
794
if t .Torrent .Info () != nil {
792
795
return
@@ -819,7 +822,9 @@ func (tm *TorrentManager) listenTorrentProgress() {
819
822
active_boost := 0
820
823
for _ , t := range activeTorrentsCandidate {
821
824
ih := t .Torrent .InfoHash ()
825
+ tm .lock .RLock ()
822
826
BytesRequested := tm .bytes [ih ]
827
+ tm .lock .RUnlock ()
823
828
if t .bytesRequested < BytesRequested {
824
829
t .bytesRequested = BytesRequested
825
830
t .bytesLimitation = GetLimitation (BytesRequested )
0 commit comments