Skip to content

Commit

Permalink
meta record fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ucwong committed May 19, 2024
1 parent 353448e commit 5b04956
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 49 deletions.
45 changes: 7 additions & 38 deletions backend/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,27 +149,6 @@ func (tm *TorrentManager) blockCaculate(value int64) int64 {
}

func (tm *TorrentManager) register(t *torrent.Torrent, requested int64, ih string, spec *torrent.TorrentSpec) *caffe.Torrent {
/*tt := &Torrent{
Torrent: t,
//maxEstablishedConns: tm.maxEstablishedConns,
//minEstablishedConns: 1,
//currentConns: tm.maxEstablishedConns,
bytesRequested: requested,
//bytesLimitation: tm.getLimitation(requested),
//bytesCompleted: 0,
//bytesMissing: 0,
status: status,
infohash: ih,
filepath: filepath.Join(tm.TmpDataDir, ih),
cited: 0,
//weight: 1,
//loop: 0,
maxPieces: 0,
//isBoosting: false,
//fast: false,
start: mclock.Now(),
}*/

tt := caffe.NewTorrent(t, requested, ih, filepath.Join(tm.TmpDataDir, ih), tm.slot, spec)
tm.setTorrent(tt)

Expand All @@ -180,13 +159,6 @@ func (tm *TorrentManager) register(t *torrent.Torrent, requested int64, ih strin
}

func (tm *TorrentManager) getTorrent(ih string) *caffe.Torrent {
/*tm.lock.RLock()
defer tm.lock.RUnlock()
if torrent, ok := tm.torrents[ih]; ok {
return torrent
}
return nil*/

if torrent, ok := tm.torrents.Get(ih); ok {
return torrent
}
Expand Down Expand Up @@ -1103,9 +1075,8 @@ func (tm *TorrentManager) pendingLoop() {
func (tm *TorrentManager) meta(t *caffe.Torrent) error {
if b, err := bencode.Marshal(t.Torrent.Info()); err == nil {
if tm.kvdb != nil && tm.kvdb.Get([]byte(SEED_PRE+t.InfoHash())) == nil {
if err := t.WriteTorrent(); err == nil {
tm.kvdb.Set([]byte(SEED_PRE+t.InfoHash()), b)
}
go t.WriteTorrent()
tm.kvdb.Set([]byte(SEED_PRE+t.InfoHash()), b)
}
} else {
log.Error("Meta info marshal failed", "ih", t.InfoHash(), "err", err)
Expand All @@ -1114,18 +1085,16 @@ func (tm *TorrentManager) meta(t *caffe.Torrent) error {
}

if err := t.Start(); err != nil {
tm.Dropping(t.InfoHash())
log.Error("Nas start failed", "ih", t.InfoHash(), "err", err)
return err
}

if params.IsGood(t.InfoHash()) || tm.mode == params.FULL { //|| tm.colaList.Contains(t.InfoHash()) {
if params.IsGood(t.InfoHash()) || tm.mode == params.FULL || t.BytesRequested() > t.Length() {
t.SetBytesRequested(t.Length())
} else {
if t.BytesRequested() > t.Length() {
t.SetBytesRequested(t.Length())
}
}
tm.Running(t)
return nil

return tm.Running(t)
}

func (tm *TorrentManager) finish(t *caffe.Torrent) error {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ require (
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.3.0 // indirect
modernc.org/libc v1.50.6 // indirect
modernc.org/libc v1.50.7 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.8.0 // indirect
modernc.org/sqlite v1.29.9 // indirect
modernc.org/sqlite v1.29.10 // indirect
zombiezen.com/go/sqlite v1.3.0 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,8 @@ modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE=
modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ=
modernc.org/gc/v2 v2.4.1 h1:9cNzOqPyMJBvrUipmynX0ZohMhcxPtMccYgGOJdOiBw=
modernc.org/gc/v2 v2.4.1/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU=
modernc.org/libc v1.50.6 h1:72NPEFMyKP01RJrKXS2eLXv35UklKqlJZ1b9P7gSo6I=
modernc.org/libc v1.50.6/go.mod h1:8lr2m1THY5Z3ikGyUc3JhLEQg1oaIBz/AQixw8/eksQ=
modernc.org/libc v1.50.7 h1:25+61e/ZI1e53ynk8dvS/BvWie3lIJPR1KVlTdGkkCg=
modernc.org/libc v1.50.7/go.mod h1:8lr2m1THY5Z3ikGyUc3JhLEQg1oaIBz/AQixw8/eksQ=
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E=
Expand All @@ -820,8 +820,8 @@ modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc=
modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss=
modernc.org/sqlite v1.29.9 h1:9RhNMklxJs+1596GNuAX+O/6040bvOwacTxuFcRuQow=
modernc.org/sqlite v1.29.9/go.mod h1:ItX2a1OVGgNsFh6Dv60JQvGfJfTPHPVpV6DF59akYOA=
modernc.org/sqlite v1.29.10 h1:3u93dz83myFnMilBGCOLbr+HjklS6+5rJLx4q86RDAg=
modernc.org/sqlite v1.29.10/go.mod h1:ItX2a1OVGgNsFh6Dv60JQvGfJfTPHPVpV6DF59akYOA=
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
Expand Down
5 changes: 0 additions & 5 deletions peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func (peer *Peer) broadcast() error {
Hash: k.Interface().(string),
Size: v.Value().(uint64),
}
//log.Debug("Broadcast", "ih", k.(string), "size", v.(uint64))
if err := p2p.Send(peer.ws, params.QueryCode, &query); err != nil {
return err
}
Expand All @@ -182,10 +181,6 @@ func (peer *Peer) broadcast() error {
}
}

//for k, _ := range peer.host.FullSeed() {
// TODO
//}

return nil
}

Expand Down

0 comments on commit 5b04956

Please sign in to comment.