diff --git a/configs/system.go b/configs/system.go index 1483084..354b6aa 100644 --- a/configs/system.go +++ b/configs/system.go @@ -16,7 +16,7 @@ const ( // Name is the name of the program Name = "bucket" // version - Version = "v0.6.0" + Version = "v0.6.1" // Description is the description of the program Description = "Storage node implementation in CESS networks" // NameSpace is the cached namespace diff --git a/go.mod b/go.mod index 48e4fb7..4544fd3 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/CESSProject/cess-bucket go 1.19 require ( - github.com/CESSProject/cess-go-sdk v0.2.9 - github.com/CESSProject/p2p-go v0.0.37 + github.com/CESSProject/cess-go-sdk v0.3.0 + github.com/CESSProject/p2p-go v0.1.0 github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/bytedance/sonic v1.9.2 github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.13 diff --git a/go.sum b/go.sum index 617cd87..1fd08b8 100644 --- a/go.sum +++ b/go.sum @@ -48,8 +48,12 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/CESSProject/cess-go-sdk v0.2.9 h1:rbcJl1c80bb75718GBTND0vP7Sc+hlm4DIhe8etBOfY= github.com/CESSProject/cess-go-sdk v0.2.9/go.mod h1:ueHJuYJUNB8RrQUz5uWisCYO7jrQF/StI1TRXdZlMyM= +github.com/CESSProject/cess-go-sdk v0.3.0 h1:RElSOlA2fR9a74NRJ4j3lx/70K4w9v3GfRNksMnTjfY= +github.com/CESSProject/cess-go-sdk v0.3.0/go.mod h1:Xae8ekw4HLkePovcmITkTbsqZbsye3ftqGFimxD4DvM= github.com/CESSProject/p2p-go v0.0.37 h1:FYlTPWAKMmRW/HxzXH1FD1ueGIT8kkvGCJQK0YRlBms= github.com/CESSProject/p2p-go v0.0.37/go.mod h1:MmuZ2UfXnEJMZMhOCC4Ec5QQUJCT7j2yg3Xk/oZ16yw= +github.com/CESSProject/p2p-go v0.1.0 h1:0rOjG8hshY+X3f4cs/HDJnYEtDtFIjceLtAHkUjz4yU= +github.com/CESSProject/p2p-go v0.1.0/go.mod h1:MmuZ2UfXnEJMZMhOCC4Ec5QQUJCT7j2yg3Xk/oZ16yw= github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM= github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= diff --git a/node/discover.go b/node/discover.go index 6652e1b..babbe80 100644 --- a/node/discover.go +++ b/node/discover.go @@ -8,7 +8,7 @@ package node import ( - "fmt" + "time" "github.com/CESSProject/cess-bucket/pkg/utils" ) @@ -20,15 +20,34 @@ func (n *Node) discoverMgt(ch chan bool) { n.Pnc(utils.RecoverError(err)) } }() - - var peerid string n.Discover(">>>>> Start discoverMgt <<<<<") + tickDiscover := time.NewTicker(time.Minute * 5) + defer tickDiscover.Stop() + + var reset bool + var length int for { select { case discoverPeer := <-n.DiscoveredPeer(): - peerid = discoverPeer.ID.Pretty() - n.Discover(fmt.Sprintf("discovered: %s", peerid)) - n.SavePeer(peerid, discoverPeer) + if !reset { + reset = true + tickDiscover.Reset(time.Minute * 5) + } + n.SavePeer(discoverPeer.ID.Pretty(), discoverPeer) + case <-tickDiscover.C: + length = 0 + n.RouteTableFindPeers(len(n.peers) + 30) + default: + if reset { + if length != len(n.peers) { + length = len(n.peers) + allPeer := n.GetAllPeerId() + for _, v := range allPeer { + n.Discover(v) + } + } + } + reset = false } } } diff --git a/node/spaceMgt.go b/node/spaceMgt.go index e0001a9..f83dbd9 100644 --- a/node/spaceMgt.go +++ b/node/spaceMgt.go @@ -183,17 +183,22 @@ func (n *Node) requsetIdlefile() ([]byte, string, error) { for _, tee := range teelist { teePeerId = base58.Encode([]byte(string(tee.PeerId[:]))) addr, ok := n.GetPeer(teePeerId) - if ok { - err = n.Connect(n.GetRootCtx(), addr) + if !ok { + addr, err = n.DHTFindPeer(teePeerId) if err != nil { continue } - _, err = n.IdleReq(addr.ID, pattern.FragmentSize, pattern.BlockNumber, n.GetStakingPublickey(), sign) - if err != nil { - continue - } - return tee.ControllerAccount[:], teePeerId, nil } + + err = n.Connect(n.GetRootCtx(), addr) + if err != nil { + continue + } + _, err = n.IdleReq(addr.ID, pattern.FragmentSize, pattern.BlockNumber, n.GetStakingPublickey(), sign) + if err != nil { + continue + } + return tee.ControllerAccount[:], teePeerId, nil } return nil, teePeerId, err diff --git a/node/stagMgt.go b/node/stagMgt.go index 4531ff7..757a3c0 100644 --- a/node/stagMgt.go +++ b/node/stagMgt.go @@ -121,19 +121,16 @@ func (n *Node) calcFileTag() error { teePeerId := base58.Encode([]byte(string(t.PeerId[:]))) addr, ok := n.GetPeer(teePeerId) if !ok { - continue + addr, err = n.DHTFindPeer(teePeerId) + if err != nil { + continue + } } err = n.Connect(n.GetRootCtx(), addr) if err != nil { continue } - // id, err = peer.Decode(teePeerId) - // if err != nil { - // n.Stag("err", fmt.Sprintf("[peer.Decode:%s] err: %v", teePeerId, err)) - // continue - // } - n.Stag("info", fmt.Sprintf("Send fragment [%s] tag req to tee: %s", filepath.Base(f), teePeerId)) code, err = n.TagReq(addr.ID, filepath.Base(f), "", pattern.BlockNumber) if err != nil || code != 0 {