Skip to content

Commit

Permalink
Merge pull request #338 from CortexFoundation/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ucwong authored Mar 17, 2023
2 parents 34a0348 + 5944c8b commit 6240bfd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 2 additions & 4 deletions backend/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,7 @@ func (tm *TorrentManager) activeLoop() {
} else {
//atomic.AddInt32(&t.Cited(), -1)
t.CitedDec()
elapsed := time.Duration(mclock.Now()) - time.Duration(t.Birth())
log.Debug("Seed cited has been decreased", "ih", i, "cited", t.Cited(), "n", n, "status", t.Status(), "elapsed", common.PrettyDuration(elapsed))
log.Debug("Seed cited has been decreased", "ih", i, "cited", t.Cited(), "n", n, "status", t.Status(), "elapsed", common.PrettyDuration(time.Duration(mclock.Now())-time.Duration(t.Birth())))
}
} else {
return
Expand Down Expand Up @@ -1315,8 +1314,7 @@ func (tm *TorrentManager) GetFile(ctx context.Context, infohash, subpath string)
start := mclock.Now()
//if data, err = tm.fc.ReadFileContext(ctx, dir); err == nil {
if data, err = tm.fc.ReadFile(dir); err == nil {
elapsed := time.Duration(mclock.Now() - start)
log.Debug("Load data from file cache", "ih", infohash, "dir", dir, "elapsed", common.PrettyDuration(elapsed))
log.Debug("Load data from file cache", "ih", infohash, "dir", dir, "elapsed", common.PrettyDuration(time.Duration(mclock.Now()-start)))
}
} else {
data, err = os.ReadFile(dir)
Expand Down
18 changes: 9 additions & 9 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package torrentfs
import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -200,7 +199,7 @@ func New(config *params.Config, cache, compress, listen bool) (*TorrentFS, error
PeerInfo: func(id enode.ID) any {
inst.peerMu.RLock()
defer inst.peerMu.RUnlock()
if p := inst.peers[fmt.Sprintf("%x", id[:8])]; p != nil {
if p := inst.peers[id.String()]; p != nil {
if p.Info() != nil {
return map[string]any{
"version": p.version,
Expand Down Expand Up @@ -370,20 +369,19 @@ func (fs *TorrentFS) HandlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
tfsPeer.stop()
}()

return fs.runMessageLoop(tfsPeer, rw)
return fs.runMessageLoop(tfsPeer)
}

func (fs *TorrentFS) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
func (fs *TorrentFS) runMessageLoop(p *Peer) error {
for {
if err := fs.handleMsg(p, rw); err != nil {
if err := fs.handleMsg(p); err != nil {
return err
}
}
}

func (fs *TorrentFS) handleMsg(p *Peer, rw p2p.MsgReadWriter) error {
// fetch the next packet
packet, err := rw.ReadMsg()
func (fs *TorrentFS) handleMsg(p *Peer) error {
packet, err := p.ws.ReadMsg()
if err != nil {
log.Debug("message loop", "peer", p.peer.ID(), "err", err)
return err
Expand Down Expand Up @@ -434,6 +432,8 @@ func (fs *TorrentFS) handleMsg(p *Peer, rw p2p.MsgReadWriter) error {
return errors.New("invalid code")
}

// TODO

return nil
}

Expand Down Expand Up @@ -517,6 +517,7 @@ func (fs *TorrentFS) init() {
func (fs *TorrentFS) bitsflow(ctx context.Context, ih string, size uint64) error {
select {
case fs.callback <- types.NewBitsFlow(ih, size):
// TODO
case <-ctx.Done():
return ctx.Err()
case <-fs.closeAll:
Expand Down Expand Up @@ -626,7 +627,6 @@ func (fs *TorrentFS) GetFileWithSize(ctx context.Context, infohash string, rawSi
fs.wg.Add(1)
go func(ctx context.Context, ih string) {
defer fs.wg.Done()
//fs.wakeup(ctx, infohash, rawSize)
fs.wakeup(ctx, ih)
}(ctx, infohash)
//if fs.config.Mode == params.LAZY && params.IsGood(infohash) {
Expand Down
2 changes: 2 additions & 0 deletions params/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const (
StatusCode = 0
QueryCode = 1
MsgCode = 2
PollCode = 3
VoteCode = 4

PeerStateCycle = time.Second * 300

Expand Down

0 comments on commit 6240bfd

Please sign in to comment.