Skip to content

Commit 14fc0a3

Browse files
authored
Merge pull request #252 from CortexFoundation/dev
Dev 2 Master branch
2 parents 5865575 + b524246 commit 14fc0a3

File tree

3 files changed

+86
-91
lines changed

3 files changed

+86
-91
lines changed

solution/Makefile

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,37 @@ PLUGINS_DIR = $(shell pwd)/plugins
99
#CORTEXPATH = $(shell pwd)/../build/_workspace
1010

1111
all:
12-
build/env.sh go get -tags remote -v ./...
12+
#build/env.sh go get -tags remote -v ./...
1313
$(MAKE) -C ${LIB_CUCKOO_DIR}
1414
build/env.sh go build -buildmode=plugin -o ${PLUGINS_DIR}/cuda_helper.so ./miner/libcuckoo/cuda_helper.go
1515
#build/env.sh go build -buildmode=plugin -o ${PLUGINS_DIR}/opencl_helper.so ./miner/libcuckoo/opencl_helper.go
1616
build/env.sh go build -buildmode=plugin -o ${PLUGINS_DIR}/cpu_helper.so ./miner/libcuckoo/cpu_helper.go
17-
build/env.sh go build -o build/bin/cortex_miner ./cmd/miner
17+
#build/env.sh go build -o build/bin/cortex_miner ./cmd/miner
1818

1919
cuda-miner:
20-
build/env.sh go get -tags remote -v ./...
20+
#build/env.sh go get -tags remote -v ./...
2121
$(MAKE) -C ${LIB_CUCKOO_DIR} cuda
2222
build/env.sh go build -buildmode=plugin -o ${PLUGINS_DIR}/cuda_helper.so ./miner/libcuckoo/cuda_helper.go
23-
build/env.sh go build -o build/bin/cortex_miner ./cmd/miner
23+
#build/env.sh go build -o build/bin/cortex_miner ./cmd/miner
2424
@echo "Done building."
2525

26-
opencl-miner:
27-
build/env.sh go get -tags remote -v ./...
28-
$(MAKE) -C ${LIB_CUCKOO_DIR} opencl
29-
build/env.sh go build -buildmode=plugin -o ${PLUGINS_DIR}/opencl_helper.so ./miner/libcuckoo/opencl_helper.go
30-
build/env.sh go build -o build/bin/cortex_miner ./cmd/miner
31-
@echo "Done building."
26+
#opencl-miner:
27+
# build/env.sh go get -tags remote -v ./...
28+
# $(MAKE) -C ${LIB_CUCKOO_DIR} opencl
29+
# build/env.sh go build -buildmode=plugin -o ${PLUGINS_DIR}/opencl_helper.so ./miner/libcuckoo/opencl_helper.go
30+
#build/env.sh go build -o build/bin/cortex_miner ./cmd/miner
31+
# @echo "Done building."
3232

3333
cpu-miner:
34-
build/env.sh go get -tags remote -v ./...
34+
#build/env.sh go get -tags remote -v ./...
3535
$(MAKE) -C ${LIB_CUCKOO_DIR} cpu
3636
build/env.sh go build -buildmode=plugin -o ${PLUGINS_DIR}/cpu_helper.so ./miner/libcuckoo/cpu_helper.go
37-
build/env.sh go build -o build/bin/cortex_miner ./cmd/miner
37+
#build/env.sh go build -o build/bin/cortex_miner ./cmd/miner
3838
@echo "Done building."
3939

4040
clean:
41-
rm -rf miner/libcuckoo/*.o miner/libcuckoo/*.a
41+
$(MAKE) -C ${LIB_CUCKOO_DIR} clean
42+
#rm -rf miner/libcuckoo/*.o miner/libcuckoo/*.a
4243
rm -fr build/_workspace/pkg $(CBIN)/* $(PLUGINS_DIR)/*
4344
build/env.sh go clean -cache
4445

torrentfs/monitor.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,9 @@ func (m *Monitor) parseBlockTorrentInfo(b *Block) error {
522522
}
523523
}
524524
elapsed := time.Duration(mclock.Now()) - time.Duration(start)
525-
log.Debug("Transactions scanning", "count", len(b.Txs), "number", b.Number, "elapsed", common.PrettyDuration(elapsed))
525+
if len(b.Txs) > 0 {
526+
log.Debug("Transactions scanning", "count", len(b.Txs), "number", b.Number, "elapsed", common.PrettyDuration(elapsed))
527+
}
526528
}
527529

528530
return nil
@@ -729,24 +731,20 @@ if m.lastNumber > 256 {
729731
func (m *Monitor) listenLatestBlock() {
730732
defer m.wg.Done()
731733
timer := time.NewTimer(time.Second * defaultTimerInterval)
732-
//progress := uint64(0)
734+
progress := uint64(0)
733735
for {
734736
select {
735737
case <-timer.C:
736-
m.syncLastBlock()
738+
progress = m.syncLastBlock()
737739
// Aviod sync in full mode, fresh interval may be less.
738-
/*if progress > batch {
739-
timer.Reset(time.Millisecond * 100)
740-
} else if progress > batch/2 {
741-
timer.Reset(time.Millisecond * 500)
742-
} else if progress > batch/4 {
743-
timer.Reset(time.Millisecond * 1000)
740+
if progress > batch {
741+
timer.Reset(time.Millisecond * 10)
744742
} else if progress > 6 {
745-
timer.Reset(time.Millisecond * 2000)
743+
timer.Reset(time.Millisecond * 1000)
746744
} else {
747-
timer.Reset(time.Millisecond * 5000)
748-
}*/
749-
timer.Reset(time.Second * defaultTimerInterval)
745+
timer.Reset(time.Millisecond * 2000)
746+
}
747+
//timer.Reset(time.Second * defaultTimerInterval)
750748
case <-m.exitCh:
751749
log.Info("Block listener stopped")
752750
return
@@ -880,7 +878,7 @@ func (m *Monitor) syncLastBlock() uint64 {
880878
if minNumber > 5 {
881879
minNumber = minNumber - 5
882880
}
883-
log.Info("Torrent scanning ... ...", "from", minNumber, "to", maxNumber, "current", uint64(currentNumber), "range", uint64(maxNumber-minNumber), "behind", uint64(currentNumber)-maxNumber, "progress", float64(maxNumber)/float64(currentNumber))
881+
log.Debug("Torrent scanning ... ...", "from", minNumber, "to", maxNumber, "current", uint64(currentNumber), "range", uint64(maxNumber-minNumber), "behind", uint64(currentNumber)-maxNumber, "progress", float64(maxNumber)/float64(currentNumber))
884882
} else {
885883
return 0
886884
}
@@ -900,11 +898,13 @@ func (m *Monitor) syncLastBlock() uint64 {
900898
return 0
901899
}
902900
//m.taskCh <- rpcBlock
903-
m.deal(rpcBlock)
901+
if err := m.deal(rpcBlock); err != nil {
902+
return 0
903+
}
904904
}
905905
elapsed := time.Duration(mclock.Now()) - time.Duration(start)
906906
m.lastNumber = maxNumber
907-
log.Info("Torrent scan finished", "from", minNumber, "to", maxNumber, "current", uint64(currentNumber), "progress", float64(maxNumber)/float64(currentNumber), "last", m.lastNumber, "elasped", elapsed)
907+
log.Info("Torrent scan finished", "from", minNumber, "to", maxNumber, "range", uint64(maxNumber-minNumber), "current", uint64(currentNumber), "progress", float64(maxNumber)/float64(currentNumber), "last", m.lastNumber, "elasped", elapsed, "bps", float64(maxNumber-minNumber)*1000*1000*1000/float64(elapsed))
908908
return uint64(maxNumber - minNumber)
909909
}
910910

torrentfs/torrentClient.go

Lines changed: 56 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/anacrolix/torrent/metainfo"
2929
"github.com/anacrolix/torrent/mmap_span"
3030
"github.com/anacrolix/torrent/storage"
31+
//lru "github.com/hashicorp/golang-lru"
3132
//"github.com/anacrolix/dht/v2"
3233
)
3334

@@ -111,14 +112,12 @@ func (t *Torrent) ReloadFile(files []string, datas [][]byte, tm *TorrentManager)
111112
/*for _, tracker := range tm.trackers {
112113
spec.Trackers = append(spec.Trackers, tracker)
113114
}*/
114-
torrent, _, err := tm.client.AddTorrentSpec(spec)
115-
if err != nil {
116-
return
115+
if torrent, _, err := tm.client.AddTorrentSpec(spec); err == nil {
116+
<-torrent.GotInfo()
117+
torrent.VerifyData()
118+
t.Torrent = torrent
119+
t.Pause()
117120
}
118-
<-torrent.GotInfo()
119-
torrent.VerifyData()
120-
t.Torrent = torrent
121-
t.Pause()
122121
}
123122

124123
func (t *Torrent) ReloadTorrent(data []byte, tm *TorrentManager) {
@@ -146,14 +145,12 @@ func (t *Torrent) ReloadTorrent(data []byte, tm *TorrentManager) {
146145
spec.Trackers = append(spec.Trackers, tracker)
147146
}*/
148147
spec.Trackers = append(spec.Trackers, tm.trackers...)
149-
torrent, _, err := tm.client.AddTorrentSpec(spec)
150-
if err != nil {
151-
return
148+
if torrent, _, err := tm.client.AddTorrentSpec(spec); err == nil {
149+
<-torrent.GotInfo()
150+
torrent.VerifyData()
151+
t.Torrent = torrent
152+
t.Pause()
152153
}
153-
<-torrent.GotInfo()
154-
torrent.VerifyData()
155-
t.Torrent = torrent
156-
t.Pause()
157154
}
158155

159156
/*func (t *Torrent) GetFile(subpath string) ([]byte, error) {
@@ -181,32 +178,30 @@ func (t *Torrent) IsAvailable() bool {
181178
return false
182179
}
183180

184-
func (t *Torrent) HasTorrent() bool {
185-
return t.status != torrentPending
186-
}
181+
//func (t *Torrent) HasTorrent() bool {
182+
// return t.status != torrentPending
183+
//}
187184

188185
func (t *Torrent) WriteTorrent() {
189-
f, err := os.Create(path.Join(t.filepath, "torrent"))
190-
if err != nil {
191-
return
192-
}
193-
defer f.Close()
194-
log.Debug("Write torrent file", "path", t.filepath)
195-
if err := t.Metainfo().Write(f); err != nil {
196-
log.Error("Error while write torrent file", "error", err)
197-
return
198-
}
186+
if f, err := os.Create(path.Join(t.filepath, "torrent")); err == nil {
187+
defer f.Close()
188+
log.Debug("Write torrent file", "path", t.filepath)
189+
if err := t.Metainfo().Write(f); err != nil {
190+
log.Error("Error while write torrent file", "error", err)
191+
return
192+
}
199193

200-
t.Pause()
194+
t.Pause()
195+
}
201196
}
202197

203198
func (t *Torrent) SeedInQueue() {
199+
t.status = torrentSeedingInQueue
204200
if t.currentConns != 0 {
205201
t.currentConns = 0
206202
t.Torrent.SetMaxEstablishedConns(0)
207203
}
208204
t.Torrent.CancelPieces(0, t.Torrent.NumPieces())
209-
t.status = torrentSeedingInQueue
210205
}
211206

212207
func (t *Torrent) BoostOff() {
@@ -217,14 +212,13 @@ func (t *Torrent) Seed() {
217212
if t.status == torrentSeeding {
218213
return
219214
}
220-
215+
t.status = torrentSeeding
221216
if t.currentConns == 0 {
222217
t.currentConns = t.maxEstablishedConns
223218
t.Torrent.SetMaxEstablishedConns(t.currentConns)
224219
}
225220

226221
t.Torrent.DownloadAll()
227-
t.status = torrentSeeding
228222
log.Info("Download success, seeding(s)", "hash", t.InfoHash(), "size", common.StorageSize(t.BytesCompleted()), "files", len(t.Files()), "pieces", t.Torrent.NumPieces(), "seg", len(t.Torrent.PieceStateRuns()), "cited", t.cited)
229223
}
230224

@@ -239,9 +233,9 @@ func (t *Torrent) Pause() {
239233
t.Torrent.SetMaxEstablishedConns(0)
240234
}
241235
if t.status != torrentPaused {
236+
t.status = torrentPaused
242237
t.maxPieces = 0
243238
t.Torrent.CancelPieces(0, t.Torrent.NumPieces())
244-
t.status = torrentPaused
245239
}
246240
}
247241

@@ -327,11 +321,11 @@ func (tm *TorrentManager) CreateTorrent(t *torrent.Torrent, requested int64, sta
327321
func (tm *TorrentManager) GetTorrent(ih metainfo.Hash) *Torrent {
328322
tm.lock.RLock()
329323
defer tm.lock.RUnlock()
330-
torrent, ok := tm.torrents[ih]
331-
if !ok {
324+
if torrent, ok := tm.torrents[ih]; !ok {
332325
return nil
326+
} else {
327+
return torrent
333328
}
334-
return torrent
335329
}
336330

337331
func (tm *TorrentManager) SetTorrent(ih metainfo.Hash, torrent *Torrent) {
@@ -389,6 +383,7 @@ func GetMagnetURI(infohash metainfo.Hash) string {
389383

390384
func (tm *TorrentManager) UpdateDynamicTrackers(trackers []string) {
391385
tm.lock.Lock()
386+
defer tm.lock.Unlock()
392387
if len(tm.trackers) == 0 {
393388
tm.trackers = append(tm.trackers, trackers)
394389
} else if len(tm.trackers) == 1 {
@@ -401,8 +396,6 @@ func (tm *TorrentManager) UpdateDynamicTrackers(trackers []string) {
401396
for _, t := range tm.pendingTorrents {
402397
t.AddTrackers(newTrackers)
403398
}
404-
405-
tm.lock.Unlock()
406399
}
407400

408401
func (tm *TorrentManager) SetTrackers(trackers []string) {
@@ -496,36 +489,32 @@ func (tm *TorrentManager) AddTorrent(filePath string, BytesRequested int64) *Tor
496489
// spec.Trackers = append(spec.Trackers, tracker)
497490
//}
498491
spec.Trackers = append(spec.Trackers, tm.trackers...)
499-
t, _, err := tm.client.AddTorrentSpec(spec)
500-
if err != nil {
501-
return nil
492+
if t, _, err := tm.client.AddTorrentSpec(spec); err == nil {
493+
//var ss []string
494+
//slices.MakeInto(&ss, mi.Nodes)
495+
//tm.client.AddDHTNodes(ss)
496+
<-t.GotInfo()
497+
t.VerifyData()
498+
torrent := tm.CreateTorrent(t, BytesRequested, torrentPending, ih)
499+
torrent.Pause() //SeedInQueue()
500+
return torrent
502501
}
503-
//var ss []string
504-
//slices.MakeInto(&ss, mi.Nodes)
505-
//tm.client.AddDHTNodes(ss)
506-
<-t.GotInfo()
507-
t.VerifyData()
508-
torrent := tm.CreateTorrent(t, BytesRequested, torrentPending, ih)
509-
torrent.Pause() //SeedInQueue()
510-
return torrent
511502
} else {
512503
spec.Storage = storage.NewFile(TmpDir)
513504
/*for _, tracker := range tm.trackers {
514505
spec.Trackers = append(spec.Trackers, tracker)
515506
}*/
516507
spec.Trackers = append(spec.Trackers, tm.trackers...)
517-
t, _, err := tm.client.AddTorrentSpec(spec)
518-
if err != nil {
519-
return nil
508+
if t, _, err := tm.client.AddTorrentSpec(spec); err == nil {
509+
//var ss []string
510+
//slices.MakeInto(&ss, mi.Nodes)
511+
//tm.client.AddDHTNodes(ss)
512+
<-t.GotInfo()
513+
t.VerifyData()
514+
torrent := tm.CreateTorrent(t, BytesRequested, torrentPending, ih)
515+
torrent.Pause()
516+
return torrent
520517
}
521-
//var ss []string
522-
//slices.MakeInto(&ss, mi.Nodes)
523-
//tm.client.AddDHTNodes(ss)
524-
<-t.GotInfo()
525-
t.VerifyData()
526-
torrent := tm.CreateTorrent(t, BytesRequested, torrentPending, ih)
527-
torrent.Pause()
528-
return torrent
529518
}
530519
return nil
531520
}
@@ -847,7 +836,6 @@ func (tm *TorrentManager) listenTorrentProgress() {
847836
path.Join(defaultTmpFilePath, t.InfoHash()),
848837
path.Join(tm.DataDir, t.InfoHash()),
849838
)
850-
851839
if err != nil {
852840
//log.Warn("Seeding path error", "hash", t.Torrent.InfoHash(), "size", t.bytesCompleted, "miss", t.bytesMissing, "loop", log_counter)
853841
err = os.Remove(
@@ -954,6 +942,7 @@ func (tm *TorrentManager) listenTorrentProgress() {
954942

955943
if len(activeTorrents) <= tm.maxActiveTask {
956944
for _, t := range activeTorrents {
945+
//log.Info("Active torrent", "hash", t.Torrent.InfoHash().String(), "request", t.bytesRequested, "complete", t.bytesCompleted)
957946
t.Run()
958947
active_running += 1
959948
}
@@ -964,8 +953,13 @@ func (tm *TorrentManager) listenTorrentProgress() {
964953
active_running += 1
965954
}
966955
for i := tm.maxActiveTask; i < len(activeTorrents); i++ {
967-
activeTorrents[i].Pause()
968-
active_paused += 1
956+
if activeTorrents[i].bytesRequested > activeTorrents[i].bytesCompleted {
957+
activeTorrents[i].Run()
958+
active_running += 1
959+
} else {
960+
activeTorrents[i].Pause()
961+
active_paused += 1
962+
}
969963
}
970964
}
971965

0 commit comments

Comments
 (0)