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

update bs #119

Merged
merged 1 commit into from
Nov 21, 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
23 changes: 10 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module github.com/CESSProject/DeOSS
go 1.20

require (
github.com/AstaFrode/go-libp2p v0.26.4-0.20231025094835-732a19c0bd0b
github.com/CESSProject/cess-go-sdk v0.3.21-0.20231110033426-453245bdc270
github.com/AstaFrode/go-libp2p v0.26.4-0.20231113143058-912296254d44
github.com/CESSProject/cess-go-sdk v0.3.21-0.20231114061951-fc77d8141ff0
github.com/CESSProject/go-keyring v0.0.0-20220614131247-ee3a8da30fde
github.com/CESSProject/p2p-go v0.2.6-0.20231110024714-6f709106eff6
github.com/CESSProject/p2p-go v0.2.6-0.20231117060004-cbb4a2e1792e
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 All @@ -15,6 +15,8 @@ require (
github.com/gin-gonic/gin v1.9.0
github.com/google/uuid v1.3.1
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef
github.com/ipfs/go-block-format v0.1.2
github.com/ipfs/go-cid v0.4.1
github.com/jedib0t/go-pretty/v6 v6.4.6
github.com/mr-tron/base58 v1.2.0
github.com/multiformats/go-multiaddr v0.11.0
Expand All @@ -25,17 +27,17 @@ require (
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.4
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a
github.com/vedhavyas/go-subkey/v2 v2.0.0
go.uber.org/zap v1.25.0
golang.org/x/crypto v0.14.0
golang.org/x/time v0.1.0
)

require (
github.com/AstaFrode/boxo v0.12.1-0.20231109082032-75fa153a39f3 // indirect
github.com/AstaFrode/go-libp2p-gostream v0.5.1-0.20231109095351-8050802a5d8b // indirect
github.com/AstaFrode/go-libp2p-grpc v0.1.1-0.20231109100113-0af9e902e45f // indirect
github.com/AstaFrode/go-libp2p-kad-dht v0.23.1-0.20231109074947-0279c8612966 // indirect
github.com/AstaFrode/go-libp2p-kbucket v0.5.1-0.20231109065217-dde6a45fa7ce // indirect
github.com/AstaFrode/boxo v0.12.1-0.20231117024608-7d5a75b69cdd // indirect
github.com/AstaFrode/go-libp2p-kad-dht v0.23.1-0.20231117020818-8d3fc0a486ad // indirect
github.com/AstaFrode/go-libp2p-kbucket v0.5.1-0.20231113151623-a45fff026283 // indirect
github.com/AstaFrode/go-libp2p-record v0.2.1-0.20231113144445-2b6ba1a2d403 // indirect
github.com/AstaFrode/go-peertaskqueue v0.8.2-0.20231108073729-990e433425a4 // indirect
github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
Expand Down Expand Up @@ -88,9 +90,6 @@ require (
github.com/huin/goupnp v1.2.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
github.com/ipfs/boxo v0.12.0 // indirect
github.com/ipfs/go-block-format v0.1.2 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
github.com/ipfs/go-ipfs-delay v0.0.1 // indirect
github.com/ipfs/go-ipfs-pq v0.0.3 // indirect
Expand All @@ -112,9 +111,7 @@ require (
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
github.com/libp2p/go-libp2p v0.26.4 // indirect
github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect
github.com/libp2p/go-libp2p-record v0.2.0 // indirect
github.com/libp2p/go-msgio v0.3.0 // indirect
github.com/libp2p/go-nat v0.1.0 // indirect
github.com/libp2p/go-netroute v0.2.1 // indirect
Expand Down
39 changes: 16 additions & 23 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,27 @@ dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBr
dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4=
dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU=
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
github.com/AstaFrode/boxo v0.12.1-0.20231109082032-75fa153a39f3 h1:eq7ocr4tA1vcvha6M5xSI/m6VVCneTR/tyFiVKIR7WI=
github.com/AstaFrode/boxo v0.12.1-0.20231109082032-75fa153a39f3/go.mod h1:V/cKqKfQBA04KQpA4dGpq4mwCBwT+e/fjyDDc2GT2gg=
github.com/AstaFrode/go-libp2p v0.26.4-0.20231025094835-732a19c0bd0b h1:4P16QVGgl7PulDFuDe67fUdPX4vls+/NL5yhuKHkv9k=
github.com/AstaFrode/go-libp2p v0.26.4-0.20231025094835-732a19c0bd0b/go.mod h1:RO0J/gHHqO0Wq16nM2Yv0byy9Z9cDBJ8VTzulots0kA=
github.com/AstaFrode/go-libp2p-gostream v0.5.1-0.20231109095351-8050802a5d8b h1:lOrOZr59T2tm+zkL8P0LKFmeI7tkNoW9dsJrrmCbwfk=
github.com/AstaFrode/go-libp2p-gostream v0.5.1-0.20231109095351-8050802a5d8b/go.mod h1:Wr9fDyJqrv8ATO/U+T6vtfiLYUutgi1/KJ1e6wkGDaA=
github.com/AstaFrode/go-libp2p-grpc v0.1.1-0.20231109100113-0af9e902e45f h1:W56eKv7chba4rcsokT66QJ1s4mMRFGvhbMXGPxK1fUo=
github.com/AstaFrode/go-libp2p-grpc v0.1.1-0.20231109100113-0af9e902e45f/go.mod h1:ngjEwR1IGTv20MwIvpMp12UNLbRwXq91a7TPW6m+2Mc=
github.com/AstaFrode/go-libp2p-kad-dht v0.23.1-0.20231109074947-0279c8612966 h1:4mqVjrugCK9HBInKBLJwqilar1y7LI7xT899MxzbHdA=
github.com/AstaFrode/go-libp2p-kad-dht v0.23.1-0.20231109074947-0279c8612966/go.mod h1:+DMTKOz/+WkZNaxdWDgrMQTt5d+x3QaK2eP1s7pmAL0=
github.com/AstaFrode/go-libp2p-kbucket v0.5.1-0.20231109065217-dde6a45fa7ce h1:LLSgCayG2gME+5XjK+oY5hS9nUhtff1+sw5tEzTGByU=
github.com/AstaFrode/go-libp2p-kbucket v0.5.1-0.20231109065217-dde6a45fa7ce/go.mod h1:guRAEj5PdSnmhX3xlfLFlcT2vI5sCItAZHNSapKkO6c=
github.com/AstaFrode/boxo v0.12.1-0.20231117024608-7d5a75b69cdd h1:HO6x4gA7nBUXhJ+cN6Oxq+5vb+QMGR6h1POpXj8O+iw=
github.com/AstaFrode/boxo v0.12.1-0.20231117024608-7d5a75b69cdd/go.mod h1:QAAe9MHNnh7pV9yZPDjzUeS2XFsJcZL1SVX/wwtOg/A=
github.com/AstaFrode/go-libp2p v0.26.4-0.20231113143058-912296254d44 h1:+cpQP/8OZDq7X5y45KsHC3Ndowwh0QFZImqXNLSVK1w=
github.com/AstaFrode/go-libp2p v0.26.4-0.20231113143058-912296254d44/go.mod h1:IwZXqQxpbAHV7orIa90XeCUGMKtzJnopON5gS1Avs/U=
github.com/AstaFrode/go-libp2p-kad-dht v0.23.1-0.20231117020818-8d3fc0a486ad h1:Ny8LSef08eEznNWPDsVxUlPBMlacgRcpUl+blucM2xs=
github.com/AstaFrode/go-libp2p-kad-dht v0.23.1-0.20231117020818-8d3fc0a486ad/go.mod h1:a3ag0Ke6hZseS0N2drhZwPcvtHbi67x+5xBNQmdRSNA=
github.com/AstaFrode/go-libp2p-kbucket v0.5.1-0.20231113151623-a45fff026283 h1:g3+4j9aH1s2bfMlLJ8SMe/+r0eGcEE2idGpVAz1nKk0=
github.com/AstaFrode/go-libp2p-kbucket v0.5.1-0.20231113151623-a45fff026283/go.mod h1:/ShEGW/hKSDSGKbDmBgCS6xGs5wBSURBBhIVrpU/2mo=
github.com/AstaFrode/go-libp2p-record v0.2.1-0.20231113144445-2b6ba1a2d403 h1:Mx/F2BYfwj8bLUiAK9IbdRgQHG6Ka3RE1FUysHNMT7o=
github.com/AstaFrode/go-libp2p-record v0.2.1-0.20231113144445-2b6ba1a2d403/go.mod h1:jyCMqtI9dzUu/2NToXCMQR4x+l+v+vqw3+S+QTOW1rg=
github.com/AstaFrode/go-peertaskqueue v0.8.2-0.20231108073729-990e433425a4 h1:fuOv9I6pz+zZZgRU9TYCYP2wd0iXh4wsZCdzunmDDGg=
github.com/AstaFrode/go-peertaskqueue v0.8.2-0.20231108073729-990e433425a4/go.mod h1:0YcQDsyTRKBTK9yE22DQgiwQndGFvenqMvD6Spkxl28=
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.20231110033426-453245bdc270 h1:ait40MYXw5eW26Uv5l9SWNLz+VHjp4+fxR3aNYxBz+g=
github.com/CESSProject/cess-go-sdk v0.3.21-0.20231110033426-453245bdc270/go.mod h1:KWlHxDKfinyfEI3w7BqMqgo+oi7grsUVayDw/2NYSks=
github.com/CESSProject/cess-go-sdk v0.3.21-0.20231114061951-fc77d8141ff0 h1:WelCunG4c8Ohmb4/ZiEzmJ9LCiU6cNSDMPxZb35ioGU=
github.com/CESSProject/cess-go-sdk v0.3.21-0.20231114061951-fc77d8141ff0/go.mod h1:KWlHxDKfinyfEI3w7BqMqgo+oi7grsUVayDw/2NYSks=
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.20231110024714-6f709106eff6 h1:TijSRt99nur0rt76KEpQlSLNOvnw0J5JeSHT/6QJhY8=
github.com/CESSProject/p2p-go v0.2.6-0.20231110024714-6f709106eff6/go.mod h1:0st7f0wgjxb6Y9IDq97pzF1+NPmsfLzjZEpaOKsdo2Q=
github.com/CESSProject/p2p-go v0.2.6-0.20231117060004-cbb4a2e1792e h1:r+SJZzcxb3so7W/6/98HGtT0BoB3YcK5Kf2uTp0q9Uc=
github.com/CESSProject/p2p-go v0.2.6-0.20231117060004-cbb4a2e1792e/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 Expand Up @@ -350,8 +348,6 @@ github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7P
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
github.com/ipfs/boxo v0.12.0 h1:AXHg/1ONZdRQHQLgG5JHsSC3XoE4DjCAMgK+asZvUcQ=
github.com/ipfs/boxo v0.12.0/go.mod h1:xAnfiU6PtxWCnRqu7dcXQ10bB5/kvI1kXRotuGqGBhg=
github.com/ipfs/go-block-format v0.1.2 h1:GAjkfhVx1f4YTODS6Esrj1wt2HhrtwTnhEr+DyPUaJo=
github.com/ipfs/go-block-format v0.1.2/go.mod h1:mACVcrxarQKstUU3Yf/RdwbC4DzPV6++rO2a3d+a/KE=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down Expand Up @@ -433,13 +429,8 @@ github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38y
github.com/libp2p/go-cidranger v1.1.0/go.mod h1:KWZTfSr+r9qEo9OkI9/SIEeAtw+NNoU0dXIXt15Okic=
github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM=
github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro=
github.com/libp2p/go-libp2p v0.26.4 h1:VA9ChjN0n1BwwfU/dqx4Zj9ezXtIxGk8FyJPwFONqxs=
github.com/libp2p/go-libp2p v0.26.4/go.mod h1:x75BN32YbwuY0Awm2Uix4d4KOz+/4piInkp4Wr3yOo8=
github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s=
github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w=
github.com/libp2p/go-libp2p-record v0.2.0 h1:oiNUOCWno2BFuxt3my4i1frNrt7PerzB3queqa1NkQ0=
github.com/libp2p/go-libp2p-record v0.2.0/go.mod h1:I+3zMkvvg5m2OcSdoL0KPljyJyvNDFGKX7QdlpYUcwk=
github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA=
github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=
github.com/libp2p/go-nat v0.1.0 h1:MfVsH6DLcpa04Xr+p8hmVRG4juse0s3J8HyNWYHffXg=
Expand Down Expand Up @@ -690,6 +681,8 @@ github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX
github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/vedhavyas/go-subkey v1.0.4 h1:QwjBZx4w7qXC2lmqol2jJfhaNXPI9BsgLZiMiCwqGDU=
github.com/vedhavyas/go-subkey v1.0.4/go.mod h1:aOIil/KS9hJlnr9ZSQKSoXdu/MbnkCxG4x9IOlLsMtI=
github.com/vedhavyas/go-subkey/v2 v2.0.0 h1:LemDIsrVtRSOkp0FA8HxP6ynfKjeOj3BY2U9UNfeDMA=
github.com/vedhavyas/go-subkey/v2 v2.0.0/go.mod h1:95aZ+XDCWAUUynjlmi7BtPExjXgXxByE0WfBwbmIRH4=
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0 h1:GDDkbFiaK8jsSDJfjId/PEGEShv6ugrt4kYsC5UIDaQ=
Expand Down
69 changes: 69 additions & 0 deletions node/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
jwt "github.com/dgrijalva/jwt-go"
"github.com/mr-tron/base58"
"github.com/pkg/errors"
"github.com/vedhavyas/go-subkey/v2/sr25519"
)

// VerifyToken is used to parse and verify token
Expand Down Expand Up @@ -108,6 +109,74 @@ func (n *Node) verifySignature(account, message, signature string) ([]byte, erro
return nil, errors.New("signature verification failed")
}

// VerifyToken is used to parse and verify token
func (n *Node) verifyJsSignature(account, message, signature string) ([]byte, error) {
if account == "" || signature == "" {
return nil, errors.New("no identity authentication information")
}
pkey, err := sutils.ParsingPublickey(account)
if err != nil {
return nil, err
}

ss58, err := sutils.EncodePublicKeyAsSubstrateAccount(pkey)
if err != nil {
return nil, err
}

verkr, _ := keyring.FromURI(ss58, keyring.NetSubstrate{})

sign_bytes, err := base58.Decode(signature)
if err != nil {
if strings.Contains(err.Error(), "zero length") {
return nil, errors.New("empty signature")
}
return nil, errors.New("signature not encoded with base58")
}

if len(sign_bytes) != 64 {
return nil, errors.New("wrong signature length")
}

var sign_array [64]byte
for i := 0; i < 64; i++ {
sign_array[i] = sign_bytes[i]
}

// Verify signature
ok := verkr.Verify(verkr.SigningContext([]byte("<Bytes>"+message+"</Bytes>")), sign_array)
if ok {
return pkey, nil
}
return nil, errors.New("signature verification failed")
}

// VerifyToken is used to parse and verify token
func (n *Node) verifySR25519Signature(account, message, signature string) ([]byte, error) {
if account == "" || signature == "" {
return nil, errors.New("no identity authentication information")
}

pkey, err := sutils.ParsingPublickey(account)
if err != nil {
return nil, err
}

pub, err := sr25519.Scheme{}.FromPublicKey(pkey)
if err != nil {
return pkey, err
}
sign_bytes, err := base58.Decode(signature)
if err != nil {
return pkey, err
}
ok := pub.Verify([]byte(message), sign_bytes)
if !ok {
return pkey, errors.New("signature verification failed")
}
return pkey, nil
}

func (n *Node) AccessControl(account string) bool {
if account == "" {
return false
Expand Down
2 changes: 0 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@ func (n *Node) DelFromBlacklist(peerid string) {
}

func (n *Node) RebuildDirs() {
os.RemoveAll(n.GetDirs().FileDir)
os.RemoveAll(n.GetDirs().ServiceTagDir)
os.RemoveAll(n.GetDirs().TmpDir)
os.RemoveAll(filepath.Join(n.Workspace(), configs.Db))
os.RemoveAll(filepath.Join(n.Workspace(), configs.Log))
Expand Down
72 changes: 36 additions & 36 deletions node/putHandle.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,25 +267,25 @@ func (n *Node) putHandle(c *gin.Context) {
return
}

// for i := 0; i < len(segmentInfo); i++ {
// for j := 0; j < len(segmentInfo[i].FragmentHash); j++ {
// mycid, err := n.FidToCid(filepath.Base(segmentInfo[i].FragmentHash[j]))
// n.Upfile("info", fmt.Sprintf("[%v] my cid from hash-1: %v ,%v", clientIp, mycid, err))
// }
// }
for i := 0; i < len(segmentInfo); i++ {
for j := 0; j < len(segmentInfo[i].FragmentHash); j++ {
mycid, err := n.FidToCid(filepath.Base(segmentInfo[i].FragmentHash[j]))
n.Upfile("info", fmt.Sprintf("[%v] my cid from hash-1: %v ,%v", clientIp, mycid, err))
}
}

// n.Upfile("info", fmt.Sprintf("[%v] segmentInfo: %v", clientIp, segmentInfo))
// savedCid, err := n.saveToBlockStore(segmentInfo)
// if err != nil {
// n.Upfile("err", fmt.Sprintf("[%v] %v", clientIp, err))
// c.JSON(http.StatusInternalServerError, err.Error())
// return
// }
n.Upfile("info", fmt.Sprintf("[%v] segmentInfo: %v", clientIp, segmentInfo))
savedCid, err := n.saveToBlockStore(segmentInfo)
if err != nil {
n.Upfile("err", fmt.Sprintf("[%v] %v", clientIp, err))
c.JSON(http.StatusInternalServerError, err.Error())
return
}

// n.Upfile("info", fmt.Sprintf("[%v] save successed cids: %v", clientIp, savedCid))
n.Upfile("info", fmt.Sprintf("[%v] save successed cids: %v", clientIp, savedCid))

// for i := 0; i < len(savedCid); i++ {
// buf, err := n.GetDataFromBlock(savedCid[i])
// buf, err := n.GetDataFromBlock(n.GetCtxQueryFromCtxCancel(), savedCid[i])
// if err != nil {
// n.Upfile("err", fmt.Sprintf("[%v] get data from %v failed", clientIp, savedCid[i]))
// } else {
Expand Down Expand Up @@ -443,24 +443,24 @@ func (n *Node) deduplication(pkey []byte, segmentInfo []pattern.SegmentDataInfo,
return false, nil
}

// func (n *Node) saveToBlockStore(segmentInfo []pattern.SegmentDataInfo) ([]string, error) {
// var err error
// var buf []byte
// var savedCid = make([]string, 0)
// for _, segment := range segmentInfo {
// for _, fragment := range segment.FragmentHash {
// buf, err = os.ReadFile(fragment)
// if err != nil {
// return savedCid, err
// }
// aCid, err := n.SaveAndNotifyDataBlock(buf)
// if err != nil {
// n.Upfile("err", fmt.Sprintf("save %v to block failed", fragment))
// } else {
// n.Upfile("info", fmt.Sprintf("save %v to block suc: %v", fragment, aCid.String()))
// savedCid = append(savedCid, aCid.String())
// }
// }
// }
// return savedCid, nil
// }
func (n *Node) saveToBlockStore(segmentInfo []pattern.SegmentDataInfo) ([]string, error) {
var err error
var buf []byte
var savedCid = make([]string, 0)
for _, segment := range segmentInfo {
for _, fragment := range segment.FragmentHash {
buf, err = os.ReadFile(fragment)
if err != nil {
return savedCid, err
}
aCid, err := n.SaveAndNotifyDataBlock(buf)
if err != nil {
n.Upfile("err", fmt.Sprintf("save %v to block failed", fragment))
} else {
n.Upfile("info", fmt.Sprintf("save %v to block suc: %v", fragment, aCid.String()))
savedCid = append(savedCid, aCid.String())
}
}
}
return savedCid, nil
}
Loading