diff --git a/go.mod b/go.mod index 8aa6c0e0a6..23854d77e9 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.15 require ( github.com/Azure/azure-storage-blob-go v0.8.1-0.20191213204130-762620a866ba github.com/CortexFoundation/inference v1.0.2-0.20201224021922-b0ffbeb3641a - github.com/CortexFoundation/torrentfs v1.0.23-0.20201231051304-82ddc94679e2 + github.com/CortexFoundation/torrentfs v1.0.23-0.20210107061014-4ce882e6c1af github.com/VictoriaMetrics/fastcache v1.5.8-0.20200305212624-8835719dc76c github.com/aristanetworks/goarista v0.0.0-20200513152637-638451432ae4 github.com/arsham/figurine v1.0.1 @@ -24,7 +24,7 @@ require ( github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 github.com/google/gofuzz v1.0.0 github.com/gorilla/websocket v1.4.2 - github.com/hashicorp/golang-lru v0.5.5-0.20200511160909-eb529947af53 + github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d github.com/holiman/uint256 v1.1.1 github.com/huin/goupnp v1.0.0 github.com/influxdata/influxdb v1.8.0 diff --git a/go.sum b/go.sum index 4fa9723982..9f7094ca6c 100644 --- a/go.sum +++ b/go.sum @@ -55,8 +55,8 @@ github.com/CortexFoundation/torrentfs v1.0.13-0.20200623060705-ce027f43f2f8/go.m github.com/CortexFoundation/torrentfs v1.0.14-0.20200703071639-3fcabcabf274/go.mod h1:qnb3YlIJmuetVBtC6Lsejr0Xru+1DNmDCdTqnwy7lhk= github.com/CortexFoundation/torrentfs v1.0.20-0.20200810031954-d36d26f82fcc/go.mod h1:N5BsicP5ynjXIi/Npl/SRzlJ630n1PJV2sRj0Z0t2HA= github.com/CortexFoundation/torrentfs v1.0.22-0.20201126093427-f455d2481b9b/go.mod h1:lcAYtGEoWAeIhWH/JpXno34eNA17xslgwg6UBBd769U= -github.com/CortexFoundation/torrentfs v1.0.23-0.20201231051304-82ddc94679e2 h1:LYsw1PM1bO9P+k038HzNVwKOHH8YfqhptNOD5NpU+iI= -github.com/CortexFoundation/torrentfs v1.0.23-0.20201231051304-82ddc94679e2/go.mod h1:G3ayO+jjreBIvSJ/Ybeau4BAFr8C7xXxfCT14k3vueU= +github.com/CortexFoundation/torrentfs v1.0.23-0.20210107061014-4ce882e6c1af h1:REod3wU6mecnW9D26uiB+i23wJMBL/OUKe/pHTcFw/g= +github.com/CortexFoundation/torrentfs v1.0.23-0.20210107061014-4ce882e6c1af/go.mod h1:vlT2WiXsQzl+fMK8UVs+o7q6bkOc/vkKM4XtEnAtHcM= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/Julusian/godocdown v0.0.0-20170816220326-6d19f8ff2df8/go.mod h1:INZr5t32rG59/5xeltqoCJoNY7e5x/3xoY9WSWVWg74= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= @@ -174,8 +174,8 @@ github.com/anacrolix/torrent v1.15.1-0.20200504230043-cc5d2abe18e5/go.mod h1:QlO github.com/anacrolix/torrent v1.15.1-0.20200619022403-dd51e99b88cc/go.mod h1:wuopQPC5+/M+zHYvhcA2vp5UCTm9rUc+VqjyBa882Q8= github.com/anacrolix/torrent v1.15.1-0.20200715061614-dd906f8fa72e/go.mod h1:XWo/fJN1oKgcjgxM+pUZpvalHfqHDs27BY5mBZjIQWo= github.com/anacrolix/torrent v1.18.1-0.20201121024423-388e6899a15b/go.mod h1:nhOLTTTOcr5WnvNKJzHGKzyz5D8mujPIgdbRU2818v8= -github.com/anacrolix/torrent v1.19.3-0.20201230004348-29cc20ede998 h1:v+D+H7RR0wPqh0P8xQk1OAtsNxi/g0hoGN9tU4KyBEA= -github.com/anacrolix/torrent v1.19.3-0.20201230004348-29cc20ede998/go.mod h1:WjA5XIOm/3qWM8DUEhd5ACfD771/wsddW90nCAhCUOQ= +github.com/anacrolix/torrent v1.20.1-0.20210106225046-69a419882b51 h1:pyAW9ilVARFMamxraj6l0+X2O7ctYNzK2WPUfXqUKKo= +github.com/anacrolix/torrent v1.20.1-0.20210106225046-69a419882b51/go.mod h1:f/btzA0Ki6DT56yVGPbAN9n70wKeYjn22ikKkTaCFBs= github.com/anacrolix/upnp v0.1.1/go.mod h1:LXsbsp5h+WGN7YR+0A7iVXm5BL1LYryDev1zuJMWYQo= github.com/anacrolix/upnp v0.1.2-0.20200416075019-5e9378ed1425 h1:/Wi6l2ONI1FUFWN4cBwHOO90V4ylp4ud/eov6GUcVFk= github.com/anacrolix/upnp v0.1.2-0.20200416075019-5e9378ed1425/go.mod h1:Pz94W3kl8rf+wxH3IbCa9Sq+DTJr8OSbV2Q3/y51vYs= @@ -327,6 +327,8 @@ github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2 github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o= github.com/frankban/quicktest v1.9.0 h1:jfEA+Psfr/pHsRJYPpHiNu7PGJnGctNxvTaM3K1EyXk= github.com/frankban/quicktest v1.9.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y= +github.com/frankban/quicktest v1.11.3 h1:8sXhOn0uLys67V8EsXLc6eszDs8VXWxL3iRvebPhedY= +github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -421,6 +423,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= @@ -484,6 +488,8 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/golang-lru v0.5.5-0.20200511160909-eb529947af53 h1:mcyf48FjrlX8JRXvy5v3LPeXBv+Um6WvoKS+kknfgIk= github.com/hashicorp/golang-lru v0.5.5-0.20200511160909-eb529947af53/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d h1:dg1dEPuWpEqDnvIw251EVy4zlP8gWbsGj4BsUKCRpYs= +github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= @@ -560,6 +566,8 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= diff --git a/miner/worker.go b/miner/worker.go index 59cc4cfd07..4464650ba0 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -872,13 +872,6 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64) if parent.Time() >= uint64(timestamp) { timestamp = int64(parent.Time() + 1) } - // this will ensure we're not going off too far in the future - if now := time.Now().Unix(); timestamp > now+1 { - wait := time.Duration(timestamp-now) * time.Second - log.Info("Mining too far in the future", "wait", common.PrettyDuration(wait)) - time.Sleep(wait) - } - num := parent.Number() if num.Uint64() <= w.checkpoint && w.checkpoint > 0 { return diff --git a/vendor/github.com/CortexFoundation/torrentfs/chaindb.go b/vendor/github.com/CortexFoundation/torrentfs/chaindb.go index 648d577ff7..dc24d52ac5 100644 --- a/vendor/github.com/CortexFoundation/torrentfs/chaindb.go +++ b/vendor/github.com/CortexFoundation/torrentfs/chaindb.go @@ -94,6 +94,7 @@ func NewChainDB(config *Config) (*ChainDB, error) { //fs.rootCache, _ = lru.New(8) if err := fs.initBlockNumber(); err != nil { + log.Error("Init block error", "err", err) return nil, err } //if err := fs.initCheckPoint(); err != nil { @@ -103,13 +104,16 @@ func NewChainDB(config *Config) (*ChainDB, error) { // return nil, err //} if err := fs.initFiles(); err != nil { + log.Error("Init files error", "err", err) return nil, err } if err := fs.initMerkleTree(); err != nil { + log.Error("Init mkt error", "err", err) return nil, err } if err := fs.initID(); err != nil { + log.Error("Init node id error", "err", err) return nil, err } @@ -287,6 +291,12 @@ var ( ErrReadDataFromBoltDB = errors.New("bolt DB Read Error") ) +func uint64ToBytes(i uint64) []byte { + var buf [8]byte + binary.BigEndian.PutUint64(buf[:], i) + return buf[:] +} + func (fs *ChainDB) GetBlockByNumber(blockNum uint64) *types.Block { var block types.Block @@ -295,10 +305,7 @@ func (fs *ChainDB) GetBlockByNumber(blockNum uint64) *types.Block { if buk == nil { return ErrReadDataFromBoltDB } - k, err := json.Marshal(blockNum) - if err != nil { - return ErrReadDataFromBoltDB - } + k := uint64ToBytes(blockNum) v := buk.Get(k) @@ -323,19 +330,18 @@ func (fs *ChainDB) progress(f *types.FileInfo, init bool) (bool, error) { err := fs.db.Update(func(tx *bolt.Tx) error { buk, err := tx.CreateBucketIfNotExists([]byte("files_" + fs.version)) if err != nil { + log.Error("Progress bucket failed", "err", err) return err } - k, err := json.Marshal(f.Meta.InfoHash) - if err != nil { - return err - } + k := []byte(f.Meta.InfoHash) var v []byte bef := buk.Get(k) if bef == nil { update = true v, err = json.Marshal(f) if err != nil { + log.Error("Progress json failed", "err", err) return err } return buk.Put(k, v) @@ -357,10 +363,10 @@ func (fs *ChainDB) progress(f *types.FileInfo, init bool) (bool, error) { } } if insert { - log.Debug("New relate file found and progressing", "hash", info.Meta.InfoHash.String(), "old", info.ContractAddr, "new", f.ContractAddr, "relate", len(info.Relate), "init", init) + log.Debug("New relate file found and progressing", "hash", info.Meta.InfoHash, "old", info.ContractAddr, "new", f.ContractAddr, "relate", len(info.Relate), "init", init) f.Relate = append(f.Relate, *info.ContractAddr) } else { - log.Debug("Address changed and progressing", "hash", info.Meta.InfoHash.String(), "old", info.ContractAddr, "new", f.ContractAddr, "relate", len(info.Relate), "init", init) + log.Debug("Address changed and progressing", "hash", info.Meta.InfoHash, "old", info.ContractAddr, "new", f.ContractAddr, "relate", len(info.Relate), "init", init) } } v, err = json.Marshal(f) @@ -380,7 +386,7 @@ func (fs *ChainDB) progress(f *types.FileInfo, init bool) (bool, error) { if err != nil { return err } - log.Debug("New relate file found", "hash", info.Meta.InfoHash.String(), "old", info.ContractAddr, "new", f.ContractAddr, "r", len(info.Relate), "l", info.LeftSize, "r", len(f.Relate), "l", f.LeftSize, "init", init) + log.Debug("New relate file found", "hash", info.Meta.InfoHash, "old", info.ContractAddr, "new", f.ContractAddr, "r", len(info.Relate), "l", info.LeftSize, "r", len(f.Relate), "l", f.LeftSize, "init", init) f.Relate = info.Relate return buk.Put(k, v) } @@ -419,10 +425,7 @@ func (fs *ChainDB) AddBlock(b *types.Block) error { if err != nil { return err } - k, err := json.Marshal(b.Number) - if err != nil { - return err - } + k := uint64ToBytes(b.Number) return buk.Put(k, v) }); err == nil { @@ -501,8 +504,8 @@ func (fs *ChainDB) initFiles() error { for k, v := c.First(); k != nil; k, v = c.Next() { var x types.FileInfo - if err := json.Unmarshal(v, &x); err != nil { + log.Error("Json unmarshal error", "err", err) return err } fs.filesContractAddr[*x.ContractAddr] = &x diff --git a/vendor/github.com/CortexFoundation/torrentfs/default.go b/vendor/github.com/CortexFoundation/torrentfs/default.go index 59b7742c28..76e5c75263 100644 --- a/vendor/github.com/CortexFoundation/torrentfs/default.go +++ b/vendor/github.com/CortexFoundation/torrentfs/default.go @@ -71,5 +71,5 @@ const ( downloadWaitingTime = 2700 defaultBytesLimitation = 512 * 1024 defaultTmpPath = ".tmp" - version = "1" + version = "2" ) diff --git a/vendor/github.com/CortexFoundation/torrentfs/go.mod b/vendor/github.com/CortexFoundation/torrentfs/go.mod index 03095cf95b..cdb293676e 100644 --- a/vendor/github.com/CortexFoundation/torrentfs/go.mod +++ b/vendor/github.com/CortexFoundation/torrentfs/go.mod @@ -10,14 +10,14 @@ require ( github.com/anacrolix/log v0.7.1-0.20200604014615-c244de44fd2d github.com/anacrolix/missinggo/v2 v2.5.0 github.com/anacrolix/tagflag v1.1.1-0.20200411025953-9bb5209d56c2 - github.com/anacrolix/torrent v1.19.3-0.20201230004348-29cc20ede998 + github.com/anacrolix/torrent v1.20.1-0.20210106225046-69a419882b51 github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 github.com/davecgh/go-spew v1.1.1 github.com/dustin/go-humanize v1.0.0 github.com/edsrzf/mmap-go v1.0.0 github.com/fsnotify/fsnotify v1.4.9 github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 - github.com/hashicorp/golang-lru v0.5.5-0.20200511160909-eb529947af53 + github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d github.com/pborman/uuid v1.2.0 github.com/ucwong/golang-set v1.8.1-0.20200419153428-d7b0b1ac2d43 go.etcd.io/bbolt v1.3.6-0.20200807205753-f6be82302843 diff --git a/vendor/github.com/CortexFoundation/torrentfs/go.sum b/vendor/github.com/CortexFoundation/torrentfs/go.sum index a5091a7e8c..c744391993 100644 --- a/vendor/github.com/CortexFoundation/torrentfs/go.sum +++ b/vendor/github.com/CortexFoundation/torrentfs/go.sum @@ -159,8 +159,8 @@ github.com/anacrolix/torrent v1.11.0/go.mod h1:FwBai7SyOFlflvfEOaM88ag/jjcBWxTOq github.com/anacrolix/torrent v1.15.0/go.mod h1:MFc6KcbpAyfwGqOyRkdarUK9QnKA/FkVg0usFk1OQxU= github.com/anacrolix/torrent v1.15.1-0.20200504230043-cc5d2abe18e5/go.mod h1:QlOfgrCz5kbvhOz8M58dUwHY5SfZ9VbIvReZ0z0MdIk= github.com/anacrolix/torrent v1.15.1-0.20200619022403-dd51e99b88cc/go.mod h1:wuopQPC5+/M+zHYvhcA2vp5UCTm9rUc+VqjyBa882Q8= -github.com/anacrolix/torrent v1.19.3-0.20201230004348-29cc20ede998 h1:v+D+H7RR0wPqh0P8xQk1OAtsNxi/g0hoGN9tU4KyBEA= -github.com/anacrolix/torrent v1.19.3-0.20201230004348-29cc20ede998/go.mod h1:WjA5XIOm/3qWM8DUEhd5ACfD771/wsddW90nCAhCUOQ= +github.com/anacrolix/torrent v1.20.1-0.20210106225046-69a419882b51 h1:pyAW9ilVARFMamxraj6l0+X2O7ctYNzK2WPUfXqUKKo= +github.com/anacrolix/torrent v1.20.1-0.20210106225046-69a419882b51/go.mod h1:f/btzA0Ki6DT56yVGPbAN9n70wKeYjn22ikKkTaCFBs= github.com/anacrolix/upnp v0.1.1/go.mod h1:LXsbsp5h+WGN7YR+0A7iVXm5BL1LYryDev1zuJMWYQo= github.com/anacrolix/upnp v0.1.2-0.20200416075019-5e9378ed1425 h1:/Wi6l2ONI1FUFWN4cBwHOO90V4ylp4ud/eov6GUcVFk= github.com/anacrolix/upnp v0.1.2-0.20200416075019-5e9378ed1425/go.mod h1:Pz94W3kl8rf+wxH3IbCa9Sq+DTJr8OSbV2Q3/y51vYs= @@ -289,6 +289,8 @@ github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2 github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o= github.com/frankban/quicktest v1.9.0 h1:jfEA+Psfr/pHsRJYPpHiNu7PGJnGctNxvTaM3K1EyXk= github.com/frankban/quicktest v1.9.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y= +github.com/frankban/quicktest v1.11.3 h1:8sXhOn0uLys67V8EsXLc6eszDs8VXWxL3iRvebPhedY= +github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -372,6 +374,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -432,6 +436,8 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/golang-lru v0.5.5-0.20200511160909-eb529947af53 h1:mcyf48FjrlX8JRXvy5v3LPeXBv+Um6WvoKS+kknfgIk= github.com/hashicorp/golang-lru v0.5.5-0.20200511160909-eb529947af53/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d h1:dg1dEPuWpEqDnvIw251EVy4zlP8gWbsGj4BsUKCRpYs= +github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= @@ -501,6 +507,8 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= diff --git a/vendor/github.com/CortexFoundation/torrentfs/handler.go b/vendor/github.com/CortexFoundation/torrentfs/handler.go index 10aed7c137..9fb9855b1a 100644 --- a/vendor/github.com/CortexFoundation/torrentfs/handler.go +++ b/vendor/github.com/CortexFoundation/torrentfs/handler.go @@ -22,15 +22,6 @@ import ( "crypto/sha1" "errors" "fmt" - "github.com/CortexFoundation/CortexTheseus/common/mclock" - "github.com/CortexFoundation/torrentfs/compress" - "github.com/CortexFoundation/torrentfs/params" - "github.com/CortexFoundation/torrentfs/types" - "github.com/allegro/bigcache/v2" - "github.com/bradfitz/iter" - "github.com/edsrzf/mmap-go" - lru "github.com/hashicorp/golang-lru" - "golang.org/x/time/rate" "io" "io/ioutil" "math" @@ -41,8 +32,19 @@ import ( "time" "github.com/CortexFoundation/CortexTheseus/common" + "github.com/CortexFoundation/CortexTheseus/common/mclock" "github.com/CortexFoundation/CortexTheseus/log" "github.com/CortexFoundation/CortexTheseus/metrics" + "github.com/CortexFoundation/torrentfs/compress" + "github.com/CortexFoundation/torrentfs/params" + "github.com/CortexFoundation/torrentfs/types" + + "github.com/allegro/bigcache/v2" + "github.com/bradfitz/iter" + "github.com/edsrzf/mmap-go" + lru "github.com/hashicorp/golang-lru" + "golang.org/x/time/rate" + xlog "github.com/anacrolix/log" "github.com/anacrolix/torrent" "github.com/anacrolix/torrent/metainfo" @@ -83,10 +85,10 @@ var ( type TorrentManager struct { client *torrent.Client //bytes map[metainfo.Hash]int64 - torrents map[metainfo.Hash]*Torrent - seedingTorrents map[metainfo.Hash]*Torrent - activeTorrents map[metainfo.Hash]*Torrent - pendingTorrents map[metainfo.Hash]*Torrent + torrents map[string]*Torrent + seedingTorrents map[string]*Torrent + activeTorrents map[string]*Torrent + pendingTorrents map[string]*Torrent maxSeedTask int maxEstablishedConns int trackers [][]string @@ -120,15 +122,15 @@ func (tm *TorrentManager) getLimitation(value int64) int64 { return ((value + block - 1) / block) * block } -func (tm *TorrentManager) register(t *torrent.Torrent, requested int64, status int, ih metainfo.Hash, ch chan bool) *Torrent { +func (tm *TorrentManager) register(t *torrent.Torrent, requested int64, status int, ih string, ch chan bool) *Torrent { tt := &Torrent{ t, tm.maxEstablishedConns, 5, tm.maxEstablishedConns, requested, tm.getLimitation(requested), 0, 0, status, - ih.String(), - filepath.Join(tm.TmpDataDir, ih.String()), + ih, + filepath.Join(tm.TmpDataDir, ih), 0, 1, 0, 0, false, true, 0, ch, } tm.setTorrent(ih, tt) @@ -137,7 +139,7 @@ func (tm *TorrentManager) register(t *torrent.Torrent, requested int64, status i return tt } -func (tm *TorrentManager) getTorrent(ih metainfo.Hash) *Torrent { +func (tm *TorrentManager) getTorrent(ih string) *Torrent { tm.lock.RLock() defer tm.lock.RUnlock() if torrent, ok := tm.torrents[ih]; ok { @@ -146,7 +148,7 @@ func (tm *TorrentManager) getTorrent(ih metainfo.Hash) *Torrent { return nil } -func (tm *TorrentManager) setTorrent(ih metainfo.Hash, t *Torrent) { +func (tm *TorrentManager) setTorrent(ih string, t *Torrent) { tm.lock.Lock() defer tm.lock.Unlock() tm.torrents[ih] = t @@ -180,7 +182,7 @@ func (tm *TorrentManager) dropAll() { func (tm *TorrentManager) commit(ctx context.Context, hex string, request uint64, ch chan bool) error { log.Debug("Commit task", "ih", hex, "request", request, "ch", ch) task := types.FlowControlMeta{ - InfoHash: metainfo.NewHashFromHex(hex), + InfoHash: hex, BytesRequested: request, Ch: ch, } @@ -255,7 +257,7 @@ func (tm *TorrentManager) verifyTorrent(info *metainfo.Info, root string) error } //func (tm *TorrentManager) loadSpec(ih metainfo.Hash, filePath string, BytesRequested int64) *torrent.TorrentSpec { -func (tm *TorrentManager) loadSpec(ih metainfo.Hash, filePath string) *torrent.TorrentSpec { +func (tm *TorrentManager) loadSpec(ih string, filePath string) *torrent.TorrentSpec { if _, err := os.Stat(filePath); err != nil { return nil } @@ -267,17 +269,17 @@ func (tm *TorrentManager) loadSpec(ih metainfo.Hash, filePath string) *torrent.T spec := torrent.TorrentSpecFromMetaInfo(mi) - if ih != spec.InfoHash { - log.Warn("Info hash mismatch", "ih", ih.HexString(), "new", spec.InfoHash.HexString()) + if ih != spec.InfoHash.HexString() { + log.Warn("Info hash mismatch", "ih", ih, "new", spec.InfoHash) return nil } - TmpDir := filepath.Join(tm.TmpDataDir, ih.HexString()) - ExistDir := filepath.Join(tm.DataDir, ih.HexString()) + TmpDir := filepath.Join(tm.TmpDataDir, ih) + ExistDir := filepath.Join(tm.DataDir, ih) useExistDir := false if _, err := os.Stat(ExistDir); err == nil { - log.Debug("Seeding from existing file.", "ih", ih.HexString()) + log.Debug("Seeding from existing file.", "ih", ih) info, err := mi.UnmarshalInfo() if err != nil { log.Error("error unmarshalling info: ", "info", err) @@ -299,7 +301,7 @@ func (tm *TorrentManager) loadSpec(ih metainfo.Hash, filePath string) *torrent.T return spec } -func (tm *TorrentManager) addInfoHash(ih metainfo.Hash, BytesRequested int64, ch chan bool) *Torrent { +func (tm *TorrentManager) addInfoHash(ih string, BytesRequested int64, ch chan bool) *Torrent { log.Debug("Add seed", "ih", ih, "bytes", BytesRequested, "ch", ch) if t := tm.getTorrent(ih); t != nil { return t @@ -309,8 +311,8 @@ func (tm *TorrentManager) addInfoHash(ih metainfo.Hash, BytesRequested int64, ch return nil } - tmpTorrentPath := filepath.Join(tm.TmpDataDir, ih.HexString(), "torrent") - seedTorrentPath := filepath.Join(tm.DataDir, ih.HexString(), "torrent") + tmpTorrentPath := filepath.Join(tm.TmpDataDir, ih, "torrent") + seedTorrentPath := filepath.Join(tm.DataDir, ih, "torrent") var spec *torrent.TorrentSpec @@ -368,9 +370,9 @@ func (tm *TorrentManager) addInfoHash(ih metainfo.Hash, BytesRequested int64, ch }*/ if spec == nil { - tmpDataPath := filepath.Join(tm.TmpDataDir, ih.HexString()) + tmpDataPath := filepath.Join(tm.TmpDataDir, ih) spec = &torrent.TorrentSpec{ - InfoHash: ih, + InfoHash: metainfo.NewHashFromHex(ih), Storage: storage.NewFile(tmpDataPath), //Storage: storage.NewFileWithCompletion(tmpDataPath, storage.NewMapPieceCompletion()), } @@ -445,10 +447,10 @@ func NewTorrentManager(config *Config, fsid uint64, cache, compress bool) (*Torr torrentManager := &TorrentManager{ client: cl, - torrents: make(map[metainfo.Hash]*Torrent), - pendingTorrents: make(map[metainfo.Hash]*Torrent), - seedingTorrents: make(map[metainfo.Hash]*Torrent), - activeTorrents: make(map[metainfo.Hash]*Torrent), + torrents: make(map[string]*Torrent), + pendingTorrents: make(map[string]*Torrent), + seedingTorrents: make(map[string]*Torrent), + activeTorrents: make(map[string]*Torrent), //bytes: make(map[metainfo.Hash]int64), maxSeedTask: config.MaxSeedingNum, maxEstablishedConns: cfg.EstablishedConnsPerTorrent, @@ -525,7 +527,7 @@ func (tm *TorrentManager) seedingLoop() { for { select { case t := <-tm.seedingChan: - tm.seedingTorrents[t.Torrent.InfoHash()] = t + tm.seedingTorrents[t.Torrent.InfoHash().HexString()] = t s := t.Seed() if t.ch != nil { @@ -602,7 +604,7 @@ func (tm *TorrentManager) mainLoop() { //if _, ok := BadFiles[meta.InfoHash.HexString()]; ok { // continue //} - if IsBad(meta.InfoHash.HexString()) { + if IsBad(meta.InfoHash) { continue } bytes := int64(meta.BytesRequested) @@ -633,11 +635,11 @@ func (tm *TorrentManager) pendingLoop() { for { select { case t := <-tm.pendingChan: - tm.pendingTorrents[t.Torrent.InfoHash()] = t + tm.pendingTorrents[t.Torrent.InfoHash().HexString()] = t timer.Reset(0) case <-timer.C: for ih, t := range tm.pendingTorrents { - if _, ok := BadFiles[ih.String()]; ok { + if _, ok := BadFiles[ih]; ok { continue } t.loop++ @@ -689,9 +691,9 @@ func (tm *TorrentManager) pendingLoop() { } }*/ } else if tm.boost && (t.loop > 60 || (t.start == 0 && t.bytesRequested > 0)) { - log.Info("Boost seed", "ih", ih.String(), "loop", t.loop, "request", t.bytesRequested, "start", t.start) + log.Info("Boost seed", "ih", ih, "loop", t.loop, "request", t.bytesRequested, "start", t.start) t.loop = 0 - if data, err := tm.boostFetcher.FetchTorrent(ih.String()); err == nil { + if data, err := tm.boostFetcher.FetchTorrent(ih); err == nil { if t.Torrent.Info() != nil { continue } @@ -703,7 +705,7 @@ func (tm *TorrentManager) pendingLoop() { } else { if _, ok := GoodFiles[t.InfoHash()]; t.start == 0 && (ok || t.bytesRequested > 0 || tm.mode == FULL || t.loop > 600) { if ok { - log.Debug("Good file found in pending", "ih", common.HexToHash(ih.String())) + log.Debug("Good file found in pending", "ih", common.HexToHash(ih)) } t.AddTrackers(tm.trackers) t.start = mclock.Now() @@ -728,7 +730,7 @@ func (tm *TorrentManager) activeLoop() { counter++ select { case t := <-tm.activeChan: - tm.activeTorrents[t.Torrent.InfoHash()] = t + tm.activeTorrents[t.Torrent.InfoHash().HexString()] = t timer.Reset(0) case <-timer.C: log_counter++ @@ -769,7 +771,7 @@ func (tm *TorrentManager) activeLoop() { if t.bytesRequested == 0 { active_wait++ if log_counter%60 == 0 { - log.Debug("[Waiting]", "ih", ih.String(), "complete", common.StorageSize(t.bytesCompleted), "req", common.StorageSize(t.bytesRequested), "quota", common.StorageSize(t.bytesRequested), "limit", common.StorageSize(t.bytesLimitation), "total", common.StorageSize(t.BytesMissing()), "seg", len(t.Torrent.PieceStateRuns()), "peers", t.currentConns, "max", t.Torrent.NumPieces()) + log.Debug("[Waiting]", "ih", ih, "complete", common.StorageSize(t.bytesCompleted), "req", common.StorageSize(t.bytesRequested), "quota", common.StorageSize(t.bytesRequested), "limit", common.StorageSize(t.bytesLimitation), "total", common.StorageSize(t.BytesMissing()), "seg", len(t.Torrent.PieceStateRuns()), "peers", t.currentConns, "max", t.Torrent.NumPieces()) } continue } @@ -784,21 +786,21 @@ func (tm *TorrentManager) activeLoop() { if t.Finished() { //tm.lock.Lock() - if _, err := os.Stat(filepath.Join(tm.DataDir, ih.String())); err == nil { + if _, err := os.Stat(filepath.Join(tm.DataDir, ih)); err == nil { if len(tm.seedingChan) < cap(tm.seedingChan) { - log.Debug("Path exist", "ih", ih, "path", filepath.Join(tm.DataDir, ih.String())) + log.Debug("Path exist", "ih", ih, "path", filepath.Join(tm.DataDir, ih)) delete(tm.activeTorrents, ih) log.Trace("S <- A", "ih", ih) //, "elapsed", time.Duration(mclock.Now())-time.Duration(t.start)) tm.seedingChan <- t } } else { err := os.Symlink( - filepath.Join(defaultTmpPath, ih.String()), - filepath.Join(tm.DataDir, ih.String()), + filepath.Join(defaultTmpPath, ih), + filepath.Join(tm.DataDir, ih), ) if err != nil { err = os.Remove( - filepath.Join(tm.DataDir, ih.String()), + filepath.Join(tm.DataDir, ih), ) if err == nil { log.Debug("Fix path success", "ih", ih, "size", t.bytesCompleted, "miss", t.bytesMissing, "loop", log_counter) @@ -956,7 +958,7 @@ func (tm *TorrentManager) available(infohash string, rawSize uint64) (bool, uint return false, 0, 0, errors.New("Invalid infohash format") } - ih := metainfo.NewHashFromHex(strings.TrimPrefix(strings.ToLower(infohash), common.Prefix)) + ih := strings.TrimPrefix(strings.ToLower(infohash), common.Prefix) if t := tm.getTorrent(ih); t == nil { return false, 0, 0, ErrInactiveTorrent } else { @@ -992,7 +994,7 @@ func (tm *TorrentManager) getFile(infohash, subpath string) ([]byte, uint64, err if !common.IsHexAddress(infohash) { return nil, 0, errors.New("Invalid infohash format") } - ih := metainfo.NewHashFromHex(strings.TrimPrefix(strings.ToLower(infohash), common.Prefix)) + ih := strings.TrimPrefix(strings.ToLower(infohash), common.Prefix) if torrent := tm.getTorrent(ih); torrent == nil { return nil, 0, ErrInactiveTorrent diff --git a/vendor/github.com/CortexFoundation/torrentfs/sync.go b/vendor/github.com/CortexFoundation/torrentfs/sync.go index a518bacba1..8fc26db8a7 100644 --- a/vendor/github.com/CortexFoundation/torrentfs/sync.go +++ b/vendor/github.com/CortexFoundation/torrentfs/sync.go @@ -27,7 +27,6 @@ import ( "github.com/CortexFoundation/CortexTheseus/rpc" "github.com/CortexFoundation/torrentfs/params" "github.com/CortexFoundation/torrentfs/types" - "github.com/anacrolix/torrent/metainfo" lru "github.com/hashicorp/golang-lru" "math" "runtime" @@ -172,7 +171,7 @@ func (m *Monitor) indexCheck() error { } func (m *Monitor) indexInit() error { - fileMap := make(map[metainfo.Hash]*types.FileInfo) + fileMap := make(map[string]*types.FileInfo) for _, file := range m.fs.Files() { if f, ok := fileMap[file.Meta.InfoHash]; ok { if f.LeftSize > file.LeftSize { @@ -194,10 +193,10 @@ func (m *Monitor) indexInit() error { } capcity += bytesRequested log.Debug("File storage info", "addr", file.ContractAddr, "ih", file.Meta.InfoHash, "remain", common.StorageSize(file.LeftSize), "raw", common.StorageSize(file.Meta.RawSize), "request", common.StorageSize(bytesRequested)) - if u, p, err := m.fs.SetTorrent(file.Meta.InfoHash.HexString(), bytesRequested); u && err == nil { + if u, p, err := m.fs.SetTorrent(file.Meta.InfoHash, bytesRequested); u && err == nil { if m.mode != LAZY { - log.Debug("Search in sync parse download", "ih", file.Meta.InfoHash.HexString(), "request", p) - m.dl.Search(context.Background(), file.Meta.InfoHash.HexString(), p, nil) + log.Debug("Search in sync parse download", "ih", file.Meta.InfoHash, "request", p) + m.dl.Search(context.Background(), file.Meta.InfoHash, p, nil) } } if file.LeftSize == 0 { @@ -363,10 +362,10 @@ func (m *Monitor) parseFileMeta(tx *types.Transaction, meta *types.FileMeta, b * if update && op == 1 { log.Debug("Create new file", "ih", meta.InfoHash, "op", op) - if u, p, err := m.fs.SetTorrent(meta.InfoHash.HexString(), 0); u && err == nil { + if u, p, err := m.fs.SetTorrent(meta.InfoHash, 0); u && err == nil { if m.mode != LAZY { - log.Debug("Search in sync parse create", "ih", meta.InfoHash.HexString(), "request", p) - m.dl.Search(context.Background(), meta.InfoHash.HexString(), p, nil) + log.Debug("Search in sync parse create", "ih", meta.InfoHash, "request", p) + m.dl.Search(context.Background(), meta.InfoHash, p, nil) } } //m.dl.UpdateTorrent(context.Background(), types.FlowControlMeta{ @@ -429,10 +428,10 @@ func (m *Monitor) parseBlockTorrentInfo(b *types.Block) (bool, error) { } else { log.Debug("Data processing ...", "ih", file.Meta.InfoHash, "addr", (*tx.Recipient).String(), "remain", common.StorageSize(remainingSize), "request", common.StorageSize(bytesRequested), "raw", common.StorageSize(file.Meta.RawSize), "number", b.Number) } - if u, p, err := m.fs.SetTorrent(file.Meta.InfoHash.HexString(), bytesRequested); u && err == nil { + if u, p, err := m.fs.SetTorrent(file.Meta.InfoHash, bytesRequested); u && err == nil { if m.mode != LAZY { - log.Debug("Search in sync parse download", "ih", file.Meta.InfoHash.HexString(), "request", p) - m.dl.Search(context.Background(), file.Meta.InfoHash.HexString(), p, nil) + log.Debug("Search in sync parse download", "ih", file.Meta.InfoHash, "request", p) + m.dl.Search(context.Background(), file.Meta.InfoHash, p, nil) } } //m.dl.UpdateTorrent(context.Background(), types.FlowControlMeta{ diff --git a/vendor/github.com/CortexFoundation/torrentfs/torrent.go b/vendor/github.com/CortexFoundation/torrentfs/torrent.go index 5a6550050d..2395e5d243 100644 --- a/vendor/github.com/CortexFoundation/torrentfs/torrent.go +++ b/vendor/github.com/CortexFoundation/torrentfs/torrent.go @@ -18,12 +18,12 @@ package torrentfs import ( "bytes" - "github.com/CortexFoundation/CortexTheseus/common/mclock" "os" "path/filepath" "time" "github.com/CortexFoundation/CortexTheseus/common" + "github.com/CortexFoundation/CortexTheseus/common/mclock" "github.com/CortexFoundation/CortexTheseus/log" "github.com/anacrolix/torrent" "github.com/anacrolix/torrent/metainfo" diff --git a/vendor/github.com/CortexFoundation/torrentfs/types/common.go b/vendor/github.com/CortexFoundation/torrentfs/types/common.go index f65cf99103..b4dd035f94 100644 --- a/vendor/github.com/CortexFoundation/torrentfs/types/common.go +++ b/vendor/github.com/CortexFoundation/torrentfs/types/common.go @@ -24,7 +24,6 @@ import ( "github.com/CortexFoundation/CortexTheseus/common/hexutil" "github.com/CortexFoundation/CortexTheseus/rlp" "github.com/CortexFoundation/torrentfs/params" - "github.com/anacrolix/torrent/metainfo" ) const ( @@ -155,7 +154,7 @@ type receiptMarshaling struct { //go:generate gencodec -type FileMeta -out gen_filemeta_json.go type FileMeta struct { - InfoHash metainfo.Hash `json:"infoHash" gencodec:"required"` + InfoHash string `json:"infoHash" gencodec:"required"` // Name string `json:"Name" gencodec:"required"` // The raw size of the file counted in bytes RawSize uint64 `json:"rawSize" gencodec:"required"` @@ -168,7 +167,7 @@ type FileMeta struct { //} type FlowControlMeta struct { - InfoHash metainfo.Hash + InfoHash string BytesRequested uint64 //IsCreate bool Ch chan bool diff --git a/vendor/github.com/CortexFoundation/torrentfs/types/gen_filemeta_json.go b/vendor/github.com/CortexFoundation/torrentfs/types/gen_filemeta_json.go index 6dc72f3ef9..b5de3b6f66 100644 --- a/vendor/github.com/CortexFoundation/torrentfs/types/gen_filemeta_json.go +++ b/vendor/github.com/CortexFoundation/torrentfs/types/gen_filemeta_json.go @@ -5,15 +5,13 @@ package types import ( "encoding/json" "errors" - - "github.com/anacrolix/torrent/metainfo" ) // MarshalJSON marshals as JSON. func (f FileMeta) MarshalJSON() ([]byte, error) { type FileMeta struct { - InfoHash metainfo.Hash `json:"infoHash" gencodec:"required"` - RawSize uint64 `json:"rawSize" gencodec:"required"` + InfoHash string `json:"infoHash" gencodec:"required"` + RawSize uint64 `json:"rawSize" gencodec:"required"` } var enc FileMeta enc.InfoHash = f.InfoHash @@ -24,8 +22,8 @@ func (f FileMeta) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals from JSON. func (f *FileMeta) UnmarshalJSON(input []byte) error { type FileMeta struct { - InfoHash *metainfo.Hash `json:"infoHash" gencodec:"required"` - RawSize *uint64 `json:"rawSize" gencodec:"required"` + InfoHash *string `json:"infoHash" gencodec:"required"` + RawSize *uint64 `json:"rawSize" gencodec:"required"` } var dec FileMeta if err := json.Unmarshal(input, &dec); err != nil { diff --git a/vendor/github.com/CortexFoundation/torrentfs/types/infer_meta.go b/vendor/github.com/CortexFoundation/torrentfs/types/infer_meta.go index 767f8a2ad7..955d268e6a 100644 --- a/vendor/github.com/CortexFoundation/torrentfs/types/infer_meta.go +++ b/vendor/github.com/CortexFoundation/torrentfs/types/infer_meta.go @@ -4,10 +4,10 @@ import ( "encoding/json" "errors" "math/big" + "strings" "github.com/CortexFoundation/CortexTheseus/common" "github.com/CortexFoundation/CortexTheseus/rlp" - "github.com/anacrolix/torrent/metainfo" ) var ( @@ -26,7 +26,7 @@ type InferMeta interface { RawSize() uint64 // Gas() uint64 AuthorAddress() common.Address - InfoHash() metainfo.Hash + InfoHash() string Comment() string } @@ -66,19 +66,31 @@ type InputMeta struct { //RawBytes []byte `json:"RawBytes"` } -func (mm *ModelMeta) InfoHash() metainfo.Hash { - ih := metainfo.NewHashFromHex(mm.Hash.String()[2:]) - return ih +func (mm *ModelMeta) InfoHash() (ih string) { + if strings.HasPrefix(mm.Hash.String(), "0x") { + ih = mm.Hash.String()[2:] + } else { + ih = mm.Hash.String() + } + return } -func (mm *InputMeta) InfoHash() metainfo.Hash { - ih := metainfo.NewHashFromHex(mm.Hash.String()[2:]) - return ih +func (mm *InputMeta) InfoHash() (ih string) { + if strings.HasPrefix(mm.Hash.String(), "0x") { + ih = mm.Hash.String()[2:] + } else { + ih = mm.Hash.String() + } + return } -func (mm *Meta) InfoHash() metainfo.Hash { - ih := metainfo.NewHashFromHex(mm.Hash.String()[2:]) - return ih +func (mm *Meta) InfoHash() (ih string) { + if strings.HasPrefix(mm.Hash.String(), "0x") { + ih = mm.Hash.String()[2:] + } else { + ih = mm.Hash.String() + } + return } func (mm *ModelMeta) SetBlockNum(num big.Int) error { diff --git a/vendor/github.com/anacrolix/torrent/README.md b/vendor/github.com/anacrolix/torrent/README.md index e4be0c7251..0a36a80091 100644 --- a/vendor/github.com/anacrolix/torrent/README.md +++ b/vendor/github.com/anacrolix/torrent/README.md @@ -28,7 +28,7 @@ There are some small [examples](https://godoc.org/github.com/anacrolix/torrent#p ## Mentions - * @anacrolix and this repo are in [Console 32](https://console.substack.com/p/console-32). + * [@anacrolix](https://github.com/anacrolix) and this repo are in [Console 32](https://console.substack.com/p/console-32). ### Downstream projects diff --git a/vendor/github.com/anacrolix/torrent/config.go b/vendor/github.com/anacrolix/torrent/config.go index f4c0f17239..0cfde9d0b8 100644 --- a/vendor/github.com/anacrolix/torrent/config.go +++ b/vendor/github.com/anacrolix/torrent/config.go @@ -124,6 +124,10 @@ type ClientConfig struct { // Don't add connections that have the same peer ID as an existing // connection for a given Torrent. DropDuplicatePeerIds bool + // Drop peers that are complete if we are also complete and have no use for the peer. This is a + // bit of a special case, since a peer could also be useless if they're just not interested, or + // we don't intend to obtain all of a torrent's data. + DropMutuallyCompletePeers bool ConnTracker *conntrack.Instance @@ -170,6 +174,7 @@ func NewDefaultClientConfig() *ClientConfig { DownloadRateLimiter: unlimited, ConnTracker: conntrack.NewInstance(), DisableAcceptRateLimiting: true, + DropMutuallyCompletePeers: true, HeaderObfuscationPolicy: HeaderObfuscationPolicy{ Preferred: true, RequirePreferred: false, diff --git a/vendor/github.com/anacrolix/torrent/go.mod b/vendor/github.com/anacrolix/torrent/go.mod index 0e5ef41ab7..add797fadd 100644 --- a/vendor/github.com/anacrolix/torrent/go.mod +++ b/vendor/github.com/anacrolix/torrent/go.mod @@ -24,7 +24,7 @@ require ( github.com/dustin/go-humanize v1.0.0 github.com/edsrzf/mmap-go v1.0.0 github.com/elliotchance/orderedmap v1.3.0 - github.com/frankban/quicktest v1.9.0 + github.com/frankban/quicktest v1.11.3 github.com/fsnotify/fsnotify v1.4.9 github.com/golang/protobuf v1.4.3 // indirect github.com/golang/snappy v0.0.2 // indirect diff --git a/vendor/github.com/anacrolix/torrent/go.sum b/vendor/github.com/anacrolix/torrent/go.sum index 0e7018281e..1b560a5f5a 100644 --- a/vendor/github.com/anacrolix/torrent/go.sum +++ b/vendor/github.com/anacrolix/torrent/go.sum @@ -213,6 +213,8 @@ github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJn github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY= github.com/frankban/quicktest v1.9.0 h1:jfEA+Psfr/pHsRJYPpHiNu7PGJnGctNxvTaM3K1EyXk= github.com/frankban/quicktest v1.9.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y= +github.com/frankban/quicktest v1.11.3 h1:8sXhOn0uLys67V8EsXLc6eszDs8VXWxL3iRvebPhedY= +github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= @@ -287,6 +289,8 @@ github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -354,6 +358,8 @@ github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= diff --git a/vendor/github.com/anacrolix/torrent/metainfo/hash.go b/vendor/github.com/anacrolix/torrent/metainfo/hash.go index 41ee956613..b2bab751b6 100644 --- a/vendor/github.com/anacrolix/torrent/metainfo/hash.go +++ b/vendor/github.com/anacrolix/torrent/metainfo/hash.go @@ -2,6 +2,7 @@ package metainfo import ( "crypto/sha1" + "encoding" "encoding/hex" "fmt" ) @@ -11,7 +12,10 @@ const HashSize = 20 // 20-byte SHA1 hash used for info and pieces. type Hash [HashSize]byte -var _ fmt.Formatter = (*Hash)(nil) +var ( + _ fmt.Formatter = (*Hash)(nil) + _ encoding.TextUnmarshaler = (*Hash)(nil) +) func (h Hash) Format(f fmt.State, c rune) { // TODO: I can't figure out a nice way to just override the 'x' rune, since it's meaningless @@ -50,6 +54,10 @@ func (h *Hash) FromHexString(s string) (err error) { return } +func (h *Hash) UnmarshalText(b []byte) error { + return h.FromHexString(string(b)) +} + func NewHashFromHex(s string) (h Hash) { err := h.FromHexString(s) if err != nil { diff --git a/vendor/github.com/anacrolix/torrent/mse/mse.go b/vendor/github.com/anacrolix/torrent/mse/mse.go index b51a5aaf45..d4a0368e11 100644 --- a/vendor/github.com/anacrolix/torrent/mse/mse.go +++ b/vendor/github.com/anacrolix/torrent/mse/mse.go @@ -19,7 +19,6 @@ import ( "sync" "github.com/anacrolix/missinggo/perf" - "github.com/bradfitz/iter" ) const ( @@ -286,18 +285,22 @@ func (h *handshake) postWrite(b []byte) error { return nil } -func xor(dst, src []byte) (ret []byte) { - max := len(dst) - if max > len(src) { - max = len(src) - } - ret = make([]byte, 0, max) - for i := range iter.N(max) { - ret = append(ret, dst[i]^src[i]) +func xor(a, b []byte) (ret []byte) { + max := len(a) + if max > len(b) { + max = len(b) } + ret = make([]byte, max) + xorInPlace(ret, a, b) return } +func xorInPlace(dst, a, b []byte) { + for i := range dst { + dst[i] = a[i] ^ b[i] + } +} + func marshal(w io.Writer, data ...interface{}) (err error) { for _, data := range data { err = binary.Write(w, binary.BigEndian, data) @@ -438,9 +441,17 @@ func (h *handshake) receiverSteps() (ret io.ReadWriter, chosen CryptoMethod, err if err != nil { return } + expectedHash := hash(req3, h.s[:]) + eachHash := sha1.New() + var sum, xored [sha1.Size]byte err = ErrNoSecretKeyMatch h.skeys(func(skey []byte) bool { - if bytes.Equal(xor(hash(req2, skey), hash(req3, h.s[:])), b[:]) { + eachHash.Reset() + eachHash.Write(req2) + eachHash.Write(skey) + eachHash.Sum(sum[:0]) + xorInPlace(xored[:], sum[:], expectedHash) + if bytes.Equal(xored[:], b[:]) { h.skey = skey err = nil return false @@ -542,14 +553,28 @@ func InitiateHandshake(rw io.ReadWriter, skey []byte, initialPayload []byte, cry return h.Do() } -func ReceiveHandshake(rw io.ReadWriter, skeys SecretKeyIter, selectCrypto CryptoSelector) (ret io.ReadWriter, method CryptoMethod, err error) { +type HandshakeResult struct { + io.ReadWriter + CryptoMethod + error + SecretKey []byte +} + +func ReceiveHandshake(rw io.ReadWriter, skeys SecretKeyIter, selectCrypto CryptoSelector) (io.ReadWriter, CryptoMethod, error) { + res := ReceiveHandshakeEx(rw, skeys, selectCrypto) + return res.ReadWriter, res.CryptoMethod, res.error +} + +func ReceiveHandshakeEx(rw io.ReadWriter, skeys SecretKeyIter, selectCrypto CryptoSelector) (ret HandshakeResult) { h := handshake{ conn: rw, initer: false, skeys: skeys, chooseMethod: selectCrypto, } - return h.Do() + ret.ReadWriter, ret.CryptoMethod, ret.error = h.Do() + ret.SecretKey = h.skey + return } // A function that given a function, calls it with secret keys until it diff --git a/vendor/github.com/anacrolix/torrent/peer-impl.go b/vendor/github.com/anacrolix/torrent/peer-impl.go index 10a6d249f7..81ec26ef25 100644 --- a/vendor/github.com/anacrolix/torrent/peer-impl.go +++ b/vendor/github.com/anacrolix/torrent/peer-impl.go @@ -14,7 +14,7 @@ type peerImpl interface { // Return true if there's room for more activity. request(request) bool connectionFlags() string - _close() + onClose() _postCancel(request) onGotInfo(*metainfo.Info) drop() diff --git a/vendor/github.com/anacrolix/torrent/peerconn.go b/vendor/github.com/anacrolix/torrent/peerconn.go index e333d21372..43b66770d0 100644 --- a/vendor/github.com/anacrolix/torrent/peerconn.go +++ b/vendor/github.com/anacrolix/torrent/peerconn.go @@ -201,7 +201,7 @@ func (cn *peer) cumInterest() time.Duration { return ret } -func (cn *PeerConn) peerHasAllPieces() (all bool, known bool) { +func (cn *peer) peerHasAllPieces() (all bool, known bool) { if cn.peerSentHaveAll { return true, true } @@ -349,10 +349,10 @@ func (cn *peer) close() { } cn.discardPieceInclination() cn._pieceRequestOrder.Clear() - cn.peerImpl._close() + cn.peerImpl.onClose() } -func (cn *PeerConn) _close() { +func (cn *PeerConn) onClose() { if cn.pex.IsEnabled() { cn.pex.Close() } @@ -843,6 +843,7 @@ func (cn *PeerConn) peerPiecesChanged() { cn.updateRequests() } } + cn.t.maybeDropMutuallyCompletePeer(&cn.peer) } func (cn *PeerConn) raisePeerMinPieces(newMin pieceIndex) { @@ -860,6 +861,7 @@ func (cn *PeerConn) peerSentHave(piece pieceIndex) error { } cn.raisePeerMinPieces(piece + 1) cn._peerPieces.Set(bitmap.BitIndex(piece), true) + cn.t.maybeDropMutuallyCompletePeer(&cn.peer) if cn.updatePiecePriority(piece) { cn.updateRequests() } diff --git a/vendor/github.com/anacrolix/torrent/torrent.go b/vendor/github.com/anacrolix/torrent/torrent.go index 16d4a483c4..462dad1ed0 100644 --- a/vendor/github.com/anacrolix/torrent/torrent.go +++ b/vendor/github.com/anacrolix/torrent/torrent.go @@ -826,6 +826,26 @@ func (t *Torrent) havePiece(index pieceIndex) bool { return t.haveInfo() && t.pieceComplete(index) } +func (t *Torrent) maybeDropMutuallyCompletePeer( + // I'm not sure about taking peer here, not all peer implementations actually drop. Maybe that's okay? + p *peer, +) { + if !t.cl.config.DropMutuallyCompletePeers { + return + } + if !t.haveAllPieces() { + return + } + if all, known := p.peerHasAllPieces(); !(known && all) { + return + } + if p.useful() { + return + } + t.logger.WithDefaultLevel(log.Debug).Printf("dropping %v, which is mutually complete", p) + p.drop() +} + func (t *Torrent) haveChunk(r request) (ret bool) { // defer func() { // log.Println("have chunk", r, ret) @@ -1808,6 +1828,7 @@ func (t *Torrent) onPieceCompleted(piece pieceIndex) { t.cancelRequestsForPiece(piece) for conn := range t.conns { conn.have(piece) + t.maybeDropMutuallyCompletePeer(&conn.peer) } } diff --git a/vendor/github.com/anacrolix/torrent/webseed-peer.go b/vendor/github.com/anacrolix/torrent/webseed-peer.go index 4ed323725d..5b0cb824ad 100644 --- a/vendor/github.com/anacrolix/torrent/webseed-peer.go +++ b/vendor/github.com/anacrolix/torrent/webseed-peer.go @@ -61,14 +61,15 @@ func (ws *webseedPeer) connectionFlags() string { return "WS" } -// TODO: This is called when banning peers. Perhaps we want to be able to ban webseeds too. +// TODO: This is called when banning peers. Perhaps we want to be able to ban webseeds too. We could +// return bool if this is even possible, and if it isn't, skip to the next drop candidate. func (ws *webseedPeer) drop() {} func (ws *webseedPeer) updateRequests() { ws.peer.doRequestState() } -func (ws *webseedPeer) _close() {} +func (ws *webseedPeer) onClose() {} func (ws *webseedPeer) requestResultHandler(r request, webseedRequest webseed.Request) { result := <-webseedRequest.Result diff --git a/vendor/github.com/anacrolix/torrent/webtorrent/tracker_client.go b/vendor/github.com/anacrolix/torrent/webtorrent/tracker_client.go index 5af6c7c0df..c5aacaf25f 100644 --- a/vendor/github.com/anacrolix/torrent/webtorrent/tracker_client.go +++ b/vendor/github.com/anacrolix/torrent/webtorrent/tracker_client.go @@ -35,6 +35,7 @@ type TrackerClient struct { wsConn *websocket.Conn closed bool stats TrackerClientStats + pingTicker *time.Ticker } func (me *TrackerClient) Stats() TrackerClientStats { @@ -72,20 +73,37 @@ func (tc *TrackerClient) doWebsocket() error { return fmt.Errorf("dialing tracker: %w", err) } defer c.Close() - tc.Logger.WithDefaultLevel(log.Debug).Printf("dialed tracker %q", tc.Url) + tc.Logger.WithDefaultLevel(log.Info).Printf("connected") tc.mu.Lock() tc.wsConn = c tc.cond.Broadcast() tc.mu.Unlock() + tc.announceOffers() + closeChan := make(chan struct{}) + go func() { + for { + select { + case <-tc.pingTicker.C: + err := c.WriteMessage(websocket.PingMessage, []byte{}) + if err != nil { + return + } + case <-closeChan: + return + default: + } + } + }() err = tc.trackerReadLoop(tc.wsConn) + close(closeChan) tc.mu.Lock() - tc.closeUnusedOffers() c.Close() tc.mu.Unlock() return err } func (tc *TrackerClient) Run() error { + tc.pingTicker = time.NewTicker(60 * time.Second) tc.cond.L = &tc.mu tc.mu.Lock() for !tc.closed { @@ -111,11 +129,37 @@ func (tc *TrackerClient) Close() error { if tc.wsConn != nil { tc.wsConn.Close() } + tc.closeUnusedOffers() + tc.pingTicker.Stop() tc.mu.Unlock() tc.cond.Broadcast() return nil } +func (tc *TrackerClient) announceOffers() { + + // tc.Announce grabs a lock on tc.outboundOffers. It also handles the case where outboundOffers + // is nil. Take ownership of outboundOffers here. + tc.mu.Lock() + offers := tc.outboundOffers + tc.outboundOffers = nil + tc.mu.Unlock() + + if offers == nil { + return + } + + // Iterate over our locally-owned offers, close any existing "invalid" ones from before the + // socket reconnected, reannounce the infohash, adding it back into the tc.outboundOffers. + tc.Logger.WithDefaultLevel(log.Info).Printf("reannouncing %d infohashes after restart", len(offers)) + for _, offer := range offers { + // TODO: Capture the errors? Are we even in a position to do anything with them? + offer.peerConnection.Close() + // Use goroutine here to allow read loop to start and ensure the buffer drains. + go tc.Announce(tracker.Started, offer.infoHash) + } +} + func (tc *TrackerClient) closeUnusedOffers() { for _, offer := range tc.outboundOffers { offer.peerConnection.Close() @@ -139,6 +183,7 @@ func (tc *TrackerClient) Announce(event tracker.AnnounceEvent, infoHash [20]byte request, err := tc.GetAnnounceRequest(event, infoHash) if err != nil { + pc.Close() return fmt.Errorf("getting announce parameters: %w", err) } @@ -159,6 +204,7 @@ func (tc *TrackerClient) Announce(event tracker.AnnounceEvent, infoHash [20]byte data, err := json.Marshal(req) if err != nil { + pc.Close() return fmt.Errorf("marshalling request: %w", err) } diff --git a/vendor/github.com/anacrolix/torrent/webtorrent/tracker_protocol.go b/vendor/github.com/anacrolix/torrent/webtorrent/tracker_protocol.go index 167044a631..a63fe5a64d 100644 --- a/vendor/github.com/anacrolix/torrent/webtorrent/tracker_protocol.go +++ b/vendor/github.com/anacrolix/torrent/webtorrent/tracker_protocol.go @@ -12,7 +12,7 @@ type AnnounceRequest struct { Uploaded int64 `json:"uploaded"` Downloaded int64 `json:"downloaded"` Left int64 `json:"left"` - Event string `json:"event"` + Event string `json:"event,omitempty"` Action string `json:"action"` InfoHash string `json:"info_hash"` PeerID string `json:"peer_id"` diff --git a/vendor/github.com/hashicorp/golang-lru/lru.go b/vendor/github.com/hashicorp/golang-lru/lru.go index aa524338c3..9af03d4fc6 100644 --- a/vendor/github.com/hashicorp/golang-lru/lru.go +++ b/vendor/github.com/hashicorp/golang-lru/lru.go @@ -6,10 +6,17 @@ import ( "github.com/hashicorp/golang-lru/simplelru" ) +const ( + // DefaultEvictedBufferSize defines the default buffer size to store evicted key/val + DefaultEvictedBufferSize = 16 +) + // Cache is a thread-safe fixed size LRU cache. type Cache struct { - lru simplelru.LRUCache - lock sync.RWMutex + lru *simplelru.LRU + evictedKeys, evictedVals []interface{} + onEvictedCB func(k, v interface{}) + lock sync.RWMutex } // New creates an LRU of the given size. @@ -19,30 +26,63 @@ func New(size int) (*Cache, error) { // NewWithEvict constructs a fixed size cache with the given eviction // callback. -func NewWithEvict(size int, onEvicted func(key interface{}, value interface{})) (*Cache, error) { - lru, err := simplelru.NewLRU(size, simplelru.EvictCallback(onEvicted)) - if err != nil { - return nil, err +func NewWithEvict(size int, onEvicted func(key, value interface{})) (c *Cache, err error) { + // create a cache with default settings + c = &Cache{ + onEvictedCB: onEvicted, } - c := &Cache{ - lru: lru, + if onEvicted != nil { + c.initEvictBuffers() + onEvicted = c.onEvicted } - return c, nil + c.lru, err = simplelru.NewLRU(size, onEvicted) + return +} + +func (c *Cache) initEvictBuffers() { + c.evictedKeys = make([]interface{}, 0, DefaultEvictedBufferSize) + c.evictedVals = make([]interface{}, 0, DefaultEvictedBufferSize) +} + +// onEvicted save evicted key/val and sent in externally registered callback +// outside of critical section +func (c *Cache) onEvicted(k, v interface{}) { + c.evictedKeys = append(c.evictedKeys, k) + c.evictedVals = append(c.evictedVals, v) } // Purge is used to completely clear the cache. func (c *Cache) Purge() { + var ks, vs []interface{} c.lock.Lock() c.lru.Purge() + if c.onEvictedCB != nil && len(c.evictedKeys) > 0 { + ks, vs = c.evictedKeys, c.evictedVals + c.initEvictBuffers() + } c.lock.Unlock() + // invoke callback outside of critical section + if c.onEvictedCB != nil { + for i := 0; i < len(ks); i++ { + c.onEvictedCB(ks[i], vs[i]) + } + } } // Add adds a value to the cache. Returns true if an eviction occurred. func (c *Cache) Add(key, value interface{}) (evicted bool) { + var k, v interface{} c.lock.Lock() evicted = c.lru.Add(key, value) + if c.onEvictedCB != nil && evicted { + k, v = c.evictedKeys[0], c.evictedVals[0] + c.evictedKeys, c.evictedVals = c.evictedKeys[:0], c.evictedVals[:0] + } c.lock.Unlock() - return evicted + if c.onEvictedCB != nil && evicted { + c.onEvictedCB(k, v) + } + return } // Get looks up a key's value from the cache. @@ -75,13 +115,21 @@ func (c *Cache) Peek(key interface{}) (value interface{}, ok bool) { // recent-ness or deleting it for being stale, and if not, adds the value. // Returns whether found and whether an eviction occurred. func (c *Cache) ContainsOrAdd(key, value interface{}) (ok, evicted bool) { + var k, v interface{} c.lock.Lock() - defer c.lock.Unlock() - if c.lru.Contains(key) { + c.lock.Unlock() return true, false } evicted = c.lru.Add(key, value) + if c.onEvictedCB != nil && evicted { + k, v = c.evictedKeys[0], c.evictedVals[0] + c.evictedKeys, c.evictedVals = c.evictedKeys[:0], c.evictedVals[:0] + } + c.lock.Unlock() + if c.onEvictedCB != nil && evicted { + c.onEvictedCB(k, v) + } return false, evicted } @@ -89,47 +137,80 @@ func (c *Cache) ContainsOrAdd(key, value interface{}) (ok, evicted bool) { // recent-ness or deleting it for being stale, and if not, adds the value. // Returns whether found and whether an eviction occurred. func (c *Cache) PeekOrAdd(key, value interface{}) (previous interface{}, ok, evicted bool) { + var k, v interface{} c.lock.Lock() - defer c.lock.Unlock() - previous, ok = c.lru.Peek(key) if ok { + c.lock.Unlock() return previous, true, false } - evicted = c.lru.Add(key, value) + if c.onEvictedCB != nil && evicted { + k, v = c.evictedKeys[0], c.evictedVals[0] + c.evictedKeys, c.evictedVals = c.evictedKeys[:0], c.evictedVals[:0] + } + c.lock.Unlock() + if c.onEvictedCB != nil && evicted { + c.onEvictedCB(k, v) + } return nil, false, evicted } // Remove removes the provided key from the cache. func (c *Cache) Remove(key interface{}) (present bool) { + var k, v interface{} c.lock.Lock() present = c.lru.Remove(key) + if c.onEvictedCB != nil && present { + k, v = c.evictedKeys[0], c.evictedVals[0] + c.evictedKeys, c.evictedVals = c.evictedKeys[:0], c.evictedVals[:0] + } c.lock.Unlock() + if c.onEvictedCB != nil && present { + c.onEvicted(k, v) + } return } // Resize changes the cache size. func (c *Cache) Resize(size int) (evicted int) { + var ks, vs []interface{} c.lock.Lock() evicted = c.lru.Resize(size) + if c.onEvictedCB != nil && evicted > 0 { + ks, vs = c.evictedKeys, c.evictedVals + c.initEvictBuffers() + } c.lock.Unlock() + if c.onEvictedCB != nil && evicted > 0 { + for i := 0; i < len(ks); i++ { + c.onEvictedCB(ks[i], vs[i]) + } + } return evicted } // RemoveOldest removes the oldest item from the cache. func (c *Cache) RemoveOldest() (key, value interface{}, ok bool) { + var k, v interface{} c.lock.Lock() key, value, ok = c.lru.RemoveOldest() + if c.onEvictedCB != nil && ok { + k, v = c.evictedKeys[0], c.evictedVals[0] + c.evictedKeys, c.evictedVals = c.evictedKeys[:0], c.evictedVals[:0] + } c.lock.Unlock() + if c.onEvictedCB != nil && ok { + c.onEvictedCB(k, v) + } return } // GetOldest returns the oldest entry func (c *Cache) GetOldest() (key, value interface{}, ok bool) { - c.lock.Lock() + c.lock.RLock() key, value, ok = c.lru.GetOldest() - c.lock.Unlock() + c.lock.RUnlock() return } diff --git a/vendor/github.com/kr/pretty/formatter.go b/vendor/github.com/kr/pretty/formatter.go index df61d8d19e..bf4b598d06 100644 --- a/vendor/github.com/kr/pretty/formatter.go +++ b/vendor/github.com/kr/pretty/formatter.go @@ -37,7 +37,7 @@ func (fo formatter) passThrough(f fmt.State, c rune) { s := "%" for i := 0; i < 128; i++ { if f.Flag(i) { - s += string(i) + s += string(rune(i)) } } if w, ok := f.Width(); ok { diff --git a/vendor/modules.txt b/vendor/modules.txt index 3061496eea..868ee62e1e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -13,7 +13,7 @@ github.com/CortexFoundation/cvm-runtime/kernel ## explicit github.com/CortexFoundation/inference github.com/CortexFoundation/inference/synapse -# github.com/CortexFoundation/torrentfs v1.0.23-0.20201231051304-82ddc94679e2 +# github.com/CortexFoundation/torrentfs v1.0.23-0.20210107061014-4ce882e6c1af ## explicit github.com/CortexFoundation/torrentfs github.com/CortexFoundation/torrentfs/compress @@ -70,7 +70,7 @@ github.com/anacrolix/stm/rate github.com/anacrolix/stm/stmutil # github.com/anacrolix/sync v0.2.0 github.com/anacrolix/sync -# github.com/anacrolix/torrent v1.19.3-0.20201230004348-29cc20ede998 +# github.com/anacrolix/torrent v1.20.1-0.20210106225046-69a419882b51 github.com/anacrolix/torrent github.com/anacrolix/torrent/bencode github.com/anacrolix/torrent/common @@ -224,7 +224,7 @@ github.com/google/uuid # github.com/gorilla/websocket v1.4.2 ## explicit github.com/gorilla/websocket -# github.com/hashicorp/golang-lru v0.5.5-0.20200511160909-eb529947af53 +# github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d ## explicit github.com/hashicorp/golang-lru github.com/hashicorp/golang-lru/simplelru @@ -258,7 +258,7 @@ github.com/jmespath/go-jmespath # github.com/julienschmidt/httprouter v1.3.0 ## explicit github.com/julienschmidt/httprouter -# github.com/kr/pretty v0.2.0 +# github.com/kr/pretty v0.2.1 github.com/kr/pretty # github.com/kr/text v0.1.0 github.com/kr/text