Skip to content

Commit

Permalink
update sdk and p2p for v0.7.6 (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
AstaFrode committed Dec 25, 2023
1 parent 75bd3b4 commit 4c8cfce
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 48 deletions.
14 changes: 7 additions & 7 deletions cmd/cmd/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/CESSProject/DeOSS/configs"
"github.com/CESSProject/DeOSS/node"
sdkgo "github.com/CESSProject/cess-go-sdk"
cess "github.com/CESSProject/cess-go-sdk"
sconfig "github.com/CESSProject/cess-go-sdk/config"
"github.com/spf13/cobra"
)
Expand All @@ -33,19 +33,19 @@ func cmd_exit_func(cmd *cobra.Command, args []string) {
os.Exit(1)
}

n.SDK, err = sdkgo.New(
n.SDK, err = cess.New(
context.Background(),
sconfig.CharacterName_Deoss,
sdkgo.ConnectRpcAddrs(n.Confile.GetRpcAddr()),
sdkgo.Mnemonic(n.Confile.GetMnemonic()),
sdkgo.TransactionTimeout(configs.TimeOut_WaitBlock),
cess.Name(sconfig.CharacterName_Deoss),
cess.ConnectRpcAddrs(n.Confile.GetRpcAddr()),
cess.Mnemonic(n.Confile.GetMnemonic()),
cess.TransactionTimeout(configs.TimeOut_WaitBlock),
)
if err != nil {
log.Println(err)
os.Exit(1)
}

txhash, err := n.ExitDeoss()
txhash, err := n.ExitDeOSS()
if err != nil || txhash == "" {
log.Printf("[err] %v\n", err)
os.Exit(1)
Expand Down
20 changes: 10 additions & 10 deletions cmd/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/CESSProject/DeOSS/pkg/db"
"github.com/CESSProject/DeOSS/pkg/logger"
"github.com/CESSProject/DeOSS/pkg/utils"
sdkgo "github.com/CESSProject/cess-go-sdk"
cess "github.com/CESSProject/cess-go-sdk"
sconfig "github.com/CESSProject/cess-go-sdk/config"
"github.com/CESSProject/cess-go-sdk/core/pattern"
sutils "github.com/CESSProject/cess-go-sdk/core/utils"
Expand Down Expand Up @@ -92,12 +92,12 @@ func cmd_run_func(cmd *cobra.Command, args []string) {
}

// Build sdk
n.SDK, err = sdkgo.New(
n.SDK, err = cess.New(
ctx,
sconfig.CharacterName_Deoss,
sdkgo.ConnectRpcAddrs(n.GetRpcAddr()),
sdkgo.Mnemonic(n.GetMnemonic()),
sdkgo.TransactionTimeout(configs.TimeOut_WaitBlock),
cess.Name(sconfig.CharacterName_Deoss),
cess.ConnectRpcAddrs(n.GetRpcAddr()),
cess.Mnemonic(n.GetMnemonic()),
cess.TransactionTimeout(configs.TimeOut_WaitBlock),
)
if err != nil {
out.Err(err.Error())
Expand All @@ -107,7 +107,7 @@ func cmd_run_func(cmd *cobra.Command, args []string) {
n.P2P, err = p2pgo.New(
ctx,
p2pgo.ListenPort(n.GetP2pPort()),
p2pgo.Workspace(filepath.Join(n.GetWorkspace(), n.GetSignatureAcc(), n.GetSdkName())),
p2pgo.Workspace(filepath.Join(n.GetWorkspace(), n.GetSignatureAcc(), n.GetSDKName())),
p2pgo.BootPeers(n.GetBootNodes()),
p2pgo.ProtocolPrefix(protocolPrefix),
)
Expand Down Expand Up @@ -150,7 +150,7 @@ func cmd_run_func(cmd *cobra.Command, args []string) {
time.Sleep(time.Second * time.Duration(utils.Ternary(int64(syncSt.HighestBlock-syncSt.CurrentBlock)*6, 30)))
}

ossinfo, err := n.QueryDeossInfo(n.GetSignatureAccPulickey())
ossinfo, err := n.QueryDeOSSInfo(n.GetSignatureAccPulickey())
if err != nil {
if err.Error() == pattern.ERR_Empty {
registerFlag = true
Expand All @@ -161,7 +161,7 @@ func cmd_run_func(cmd *cobra.Command, args []string) {
}

if registerFlag {
_, err = n.RegisterDeoss(n.GetPeerPublickey(), n.GetDomainName())
_, err = n.RegisterDeOSS(n.GetPeerPublickey(), n.GetDomainName())
if err != nil {
out.Err(fmt.Sprintf("register deoss err: %v", err))
os.Exit(1)
Expand All @@ -171,7 +171,7 @@ func cmd_run_func(cmd *cobra.Command, args []string) {
newPeerid := n.GetPeerPublickey()
if !sutils.CompareSlice([]byte(string(ossinfo.Peerid[:])), newPeerid) ||
n.GetDomainName() != string(ossinfo.Domain) {
txhash, err := n.UpdateDeoss(string(newPeerid), n.GetDomainName())
txhash, err := n.UpdateDeOSS(string(newPeerid), n.GetDomainName())
if err != nil {
out.Err(fmt.Sprintf("[%s] update deoss err: %v", txhash, err))
os.Exit(1)
Expand Down
14 changes: 7 additions & 7 deletions cmd/cmd/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/CESSProject/DeOSS/configs"
"github.com/CESSProject/DeOSS/node"
sdkgo "github.com/CESSProject/cess-go-sdk"
cess "github.com/CESSProject/cess-go-sdk"
sconfig "github.com/CESSProject/cess-go-sdk/config"
"github.com/CESSProject/cess-go-sdk/core/pattern"
"github.com/btcsuite/btcutil/base58"
Expand All @@ -37,12 +37,12 @@ func cmd_stat_func(cmd *cobra.Command, args []string) {
os.Exit(1)
}

n.SDK, err = sdkgo.New(
n.SDK, err = cess.New(
context.Background(),
sconfig.CharacterName_Deoss,
sdkgo.ConnectRpcAddrs(n.Confile.GetRpcAddr()),
sdkgo.Mnemonic(n.Confile.GetMnemonic()),
sdkgo.TransactionTimeout(configs.TimeOut_WaitBlock),
cess.Name(sconfig.CharacterName_Deoss),
cess.ConnectRpcAddrs(n.Confile.GetRpcAddr()),
cess.Mnemonic(n.Confile.GetMnemonic()),
cess.TransactionTimeout(configs.TimeOut_WaitBlock),
)
if err != nil {
log.Println(err)
Expand All @@ -54,7 +54,7 @@ func cmd_stat_func(cmd *cobra.Command, args []string) {
log.Println(err)
os.Exit(1)
}
ossinfo, err := n.QueryDeossInfo(pubkey)
ossinfo, err := n.QueryDeOSSInfo(pubkey)
if err != nil {
if err.Error() == pattern.ERR_Empty {
log.Printf("[err] You are not registered as an oss role\n")
Expand Down
2 changes: 1 addition & 1 deletion configs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
// Name space
NameSpace = Name
// version
Version = Name + " " + "v0.3.4"
Version = Name + " " + "v0.3.5"
// description
Description = "Object storage service based on CESS network"
)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.20

require (
github.com/AstaFrode/go-libp2p v0.26.4-0.20231113143058-912296254d44
github.com/CESSProject/cess-go-sdk v0.3.21-0.20231124070841-63bee15bbc25
github.com/CESSProject/cess-go-sdk v0.4.11
github.com/CESSProject/go-keyring v0.0.0-20220614131247-ee3a8da30fde
github.com/CESSProject/p2p-go v0.2.6-0.20231127085809-61bf3338888b
github.com/CESSProject/p2p-go v0.2.8
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/cbergoon/merkletree v0.2.0
github.com/centrifuge/go-substrate-rpc-client/v4 v4.1.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ github.com/AstaFrode/go-peertaskqueue v0.8.2-0.20231108073729-990e433425a4/go.mo
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CESSProject/cess-go-sdk v0.3.21-0.20231124070841-63bee15bbc25 h1:vsGDRpU39knFBI3FcZe2HxEi4YoUiftHU2/JX9O0TcA=
github.com/CESSProject/cess-go-sdk v0.3.21-0.20231124070841-63bee15bbc25/go.mod h1:KWlHxDKfinyfEI3w7BqMqgo+oi7grsUVayDw/2NYSks=
github.com/CESSProject/cess-go-sdk v0.4.11 h1:LP9zwF4G5dl8s8nnNshuxF/zo5wOMyujLSR4x2WF7lQ=
github.com/CESSProject/cess-go-sdk v0.4.11/go.mod h1:0fPeRJ57+WooVOEMwynC4gYjWunXYMYN/+jAMvmCqAk=
github.com/CESSProject/go-keyring v0.0.0-20220614131247-ee3a8da30fde h1:5MDRjjtg6PEhqyVjupwaapN96cOZiddOGAYwKQeaTu0=
github.com/CESSProject/go-keyring v0.0.0-20220614131247-ee3a8da30fde/go.mod h1:RUXBd3ROP98MYepEEa0Y0l/T0vQlIKqFJxI/ocdnRLM=
github.com/CESSProject/p2p-go v0.2.6-0.20231127085809-61bf3338888b h1:mgOe7+QChOVMt360EUIkmSJq2/WcnwJ7G+pG/+bGM5M=
github.com/CESSProject/p2p-go v0.2.6-0.20231127085809-61bf3338888b/go.mod h1:SMwJt5Zpk98k+d2J5gsN+0Forr7MbqOYWbHLd3mBLrI=
github.com/CESSProject/p2p-go v0.2.8 h1:gmskWAxkkZlLh+pjBtcdP1iIJZZmup8mXDSPj8Co3i8=
github.com/CESSProject/p2p-go v0.2.8/go.mod h1:SMwJt5Zpk98k+d2J5gsN+0Forr7MbqOYWbHLd3mBLrI=
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/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
Expand Down
13 changes: 9 additions & 4 deletions node/discoverMgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ func (n *Node) findPeers(ch chan<- bool) {
}()
n.Discover("info", ">>>>> start findPeers <<<<<")
for {
err := n.findpeer()
if err != nil {
n.Discover("err", err.Error())
if n.findPeer.Load() > 10 {
n.findPeer.Store(0)
err := n.findpeer()
if err != nil {
n.Discover("err", err.Error())
}
}
time.Sleep(time.Second)
}
}

Expand Down Expand Up @@ -55,6 +57,9 @@ func (n *Node) recvPeers(ch chan<- bool) {
}
}
}
default:
n.findPeer.Add(1)
time.Sleep(time.Second)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions node/getHandle.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (n *Node) getHandle(c *gin.Context) {
}
// Query bucket list
if queryName == "*" {
bucketList, err := n.QueryAllBucketName(pkey)
bucketList, err := n.QueryAllBucketString(pkey)
if err != nil {
if err.Error() == pattern.ERR_Empty {
n.Query("err", fmt.Sprintf("[%s] Query [%s] bucket list: NotFount", clientIp, account))
Expand Down Expand Up @@ -319,7 +319,7 @@ func (n *Node) getHandle(c *gin.Context) {
}

fpath = filepath.Join(n.GetDirs().FileDir, queryName)
peerList, _ := n.QueryDeossPeerIdList()
peerList, _ := n.QueryAllDeOSSPeerId()
if len(peerList) > 0 {
for _, v := range peerList {
addr, ok := n.GetPeer(v)
Expand Down
3 changes: 3 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"path/filepath"
"sort"
"sync"
"sync/atomic"
"syscall"
"time"

Expand Down Expand Up @@ -62,6 +63,7 @@ type Node struct {
peersPath string
ufileDir string
dfileDir string
findPeer *atomic.Uint32
}

// New is used to build a node instance
Expand All @@ -76,6 +78,7 @@ func New() *Node {
peers: make(map[string]peer.AddrInfo, 0),
storagePeers: make(map[string]struct{}, 0),
blacklist: make(map[string]int64, 0),
findPeer: new(atomic.Uint32),
}
}

Expand Down
2 changes: 1 addition & 1 deletion node/postRestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (n *Node) postRestoreHandle(c *gin.Context) {

// verify the space is authorized
var flag bool
authAccs, _ := n.QuaryAuthorizedAccounts(pkey)
authAccs, _ := n.QueryAuthorizedAccounts(pkey)
for _, v := range authAccs {
if n.GetSignatureAcc() == v {
flag = true
Expand Down
12 changes: 9 additions & 3 deletions node/putHandle.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/CESSProject/DeOSS/pkg/utils"
"github.com/CESSProject/cess-go-sdk/core/pattern"
"github.com/CESSProject/cess-go-sdk/core/process"
sutils "github.com/CESSProject/cess-go-sdk/core/utils"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
Expand Down Expand Up @@ -111,8 +112,13 @@ func (n *Node) putHandle(c *gin.Context) {

// verify the space is authorized
var flag bool
authAccs, err := n.QuaryAuthorizedAccounts(pkey)
authAccs, err := n.QueryAuthorizedAccounts(pkey)
if err != nil {
if err.Error() == pattern.ERR_Empty {
n.Upfile("info", fmt.Sprintf("[%v] %v", clientIp, ERR_SpaceNotAuth))
c.JSON(http.StatusForbidden, ERR_SpaceNotAuth)
return
}
n.Upfile("info", fmt.Sprintf("[%v] %v", clientIp, err))
c.JSON(http.StatusInternalServerError, err.Error())
return
Expand All @@ -138,7 +144,7 @@ func (n *Node) putHandle(c *gin.Context) {
return
}
n.Upfile("info", fmt.Sprintf("[%v] create bucket [%v] successfully: %v", clientIp, bucketName, txHash))
if len(txHash) != pattern.FileHashLen {
if len(txHash) != (pattern.FileHashLen + 2) {
c.JSON(http.StatusOK, "bucket already exists")
} else {
c.JSON(http.StatusOK, map[string]string{"Block hash:": txHash})
Expand Down Expand Up @@ -301,7 +307,7 @@ func (n *Node) putHandle(c *gin.Context) {
return
}

segmentInfo, roothash, err := n.ShardedEncryptionProcessing(fpath, cipher)
segmentInfo, roothash, err := process.ShardedEncryptionProcessing(fpath, cipher)
if err != nil {
n.Upfile("err", fmt.Sprintf("[%v] %v", clientIp, err))
c.JSON(http.StatusInternalServerError, err.Error())
Expand Down
2 changes: 1 addition & 1 deletion node/sdkMgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (n *Node) sdkMgt(ch chan<- bool) {
}
n.SavePeer(addrInfo.ID.Pretty(), *addrInfo)
}
sminerList, err := n.QuerySminerList()
sminerList, err := n.QueryAllSminerAccount()
if err != nil {
continue
}
Expand Down
13 changes: 12 additions & 1 deletion node/syncFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (n *Node) syncFiles(ch chan<- bool) {
continue
}

ossinfo, err = n.QueryDeossInfo(pubkey)
ossinfo, err = n.QueryDeOSSInfo(pubkey)
if err != nil {
n.Log("err", err.Error())
continue
Expand Down Expand Up @@ -167,6 +167,17 @@ func (n *Node) noticeBlocks(ch chan<- bool) {
continue
}

acid, err := cid.Parse(mycid)
if err != nil {
n.Block("err", fmt.Sprintf("[cid.Parse(%s)] %v", mycid, err))
continue
}

ok, err := n.GetBlockstore().Has(context.Background(), acid)
if err == nil && ok {
continue
}

buf, err := n.GetLocalDataFromBlock(mycid)
if err != nil {
n.Block("err", fmt.Sprintf("[GetLocalDataFromBlock] [%v] %v", mycid, err))
Expand Down
4 changes: 2 additions & 2 deletions node/taskMgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (n *Node) TaskMgt() {
ch_notifyBlocks = make(chan bool, 1)
)

sminerList, err := n.QuerySminerList()
sminerList, err := n.QueryAllSminerAccount()
if err == nil {
for i := 0; i < len(sminerList); i++ {
minerinfo, err := n.QueryStorageMiner(sminerList[i][:])
Expand Down Expand Up @@ -102,7 +102,7 @@ func (n *Node) connectChain() error {
if !n.GetChainState() {
n.Log("err", fmt.Sprintf("[%s] %v", n.GetCurrentRpcAddr(), pattern.ERR_RPC_CONNECTION))
out.Err(fmt.Sprintf("[%s] %v", n.GetCurrentRpcAddr(), pattern.ERR_RPC_CONNECTION))
err = n.Reconnect()
err = n.ReconnectRPC()
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions node/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/CESSProject/DeOSS/pkg/utils"
"github.com/CESSProject/cess-go-sdk/core/pattern"
"github.com/CESSProject/cess-go-sdk/core/process"
sutils "github.com/CESSProject/cess-go-sdk/core/utils"
"github.com/mr-tron/base58"
"github.com/pkg/errors"
Expand Down Expand Up @@ -163,7 +164,7 @@ func (n *Node) trackFile(trackfile string) error {
}

// verify the space is authorized
authAccs, err := n.QuaryAuthorizedAccounts(recordFile.Owner)
authAccs, err := n.QueryAuthorizedAccounts(recordFile.Owner)
if err != nil {
if err.Error() != pattern.ERR_Empty {
return errors.Wrapf(err, "[%s] [QuaryAuthorizedAccount]", roothash)
Expand Down Expand Up @@ -254,7 +255,7 @@ func (n *Node) trackFile(trackfile string) error {
}

if recordFile.SegmentInfo == nil {
resegmentInfo, reHash, err := n.ShardedEncryptionProcessing(filepath.Join(n.GetDirs().FileDir, roothash), "")
resegmentInfo, reHash, err := process.ShardedEncryptionProcessing(filepath.Join(n.GetDirs().FileDir, roothash), "")
if err != nil {
return errors.Wrapf(err, "[ShardedEncryptionProcessing]")
}
Expand All @@ -264,7 +265,7 @@ func (n *Node) trackFile(trackfile string) error {
recordFile.SegmentInfo = resegmentInfo
}

n.storageData(recordFile.Roothash, recordFile.SegmentInfo, storageOrder.CompleteInfo)
n.storageData(recordFile.Roothash, recordFile.SegmentInfo, storageOrder.CompleteList)
time.Sleep(time.Minute * 2)
}
}
Expand Down

0 comments on commit 4c8cfce

Please sign in to comment.