Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base discover3 #134

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
31 changes: 25 additions & 6 deletions node/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package node

import (
"fmt"
"time"

"github.com/CESSProject/cess-bucket/pkg/utils"
)
Expand All @@ -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
}
}
}
19 changes: 12 additions & 7 deletions node/spaceMgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions node/stagMgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down