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

fix: #182 #183

Merged
merged 1 commit into from
Sep 2, 2024
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
12 changes: 6 additions & 6 deletions node/put_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ func verifySignature(n *Node, account, ethAccount, message, signature string) ([
t, err := time.Parse(time.DateTime, message)
if err == nil {
if time.Now().After(t) {
return nil, http.StatusForbidden, errors.New("signature has expired")
return nil, http.StatusForbidden, errors.New("Signature has expired")
}
}
} else {
if isUnixTimestamp(timestamp) {
if time.Now().Unix() >= timestamp {
return nil, http.StatusForbidden, errors.New("signature has expired")
return nil, http.StatusForbidden, errors.New("Signature has expired")
}
} else if isUnixMillTimestamp(timestamp) {
if time.Now().UnixMilli() >= timestamp {
return nil, http.StatusForbidden, errors.New("signature has expired")
return nil, http.StatusForbidden, errors.New("Signature has expired")
}
}
}
Expand All @@ -116,22 +116,22 @@ func verifySignature(n *Node, account, ethAccount, message, signature string) ([
return nil, http.StatusBadRequest, err
}
if ethAccInSian != ethAccount {
return nil, http.StatusBadRequest, errors.New("ETH signature verification failed")
return nil, http.StatusBadRequest, errors.New("Signature verification failed")
}
pkey, err = sutils.ParsingPublickey(account)
if err != nil {
return nil, http.StatusBadRequest, err
}
if len(pkey) == 0 {
return nil, http.StatusBadRequest, errors.New("invalid account")
return nil, http.StatusBadRequest, errors.New("Invalid account")
}
} else {
pkey, err = n.VerifyAccountSignature(account, message, signature)
if err != nil {
return nil, http.StatusBadRequest, err
}
if len(pkey) == 0 {
return nil, http.StatusBadRequest, errors.New("invalid signature")
return nil, http.StatusBadRequest, errors.New("Invalid signature")
}
}

Expand Down
21 changes: 14 additions & 7 deletions node/put_chunks.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,12 @@ func checkSapce(n *Node, pkey []byte, territoryName string, contentLength int64,
if err.Error() == chain.ERR_Empty {
return http.StatusForbidden, errors.New(ERR_NoTerritory)
}
return http.StatusInternalServerError, errors.New(ERR_RpcFailed)
return http.StatusInternalServerError, errors.New(ERR_RPCConnection)
}

blockheight, err := n.QueryBlockNumber("")
if err != nil {
return http.StatusInternalServerError, errors.New(ERR_RpcFailed)
return http.StatusInternalServerError, errors.New(ERR_RPCConnection)
}

if uint32(territoryInfo.Deadline) < (blockheight + deadLine) {
Expand All @@ -686,7 +686,7 @@ func checkSapce(n *Node, pkey []byte, territoryName string, contentLength int64,

remainingSpace, err := strconv.ParseUint(territoryInfo.RemainingSpace.String(), 10, 64)
if err != nil {
return http.StatusInternalServerError, err
return http.StatusInternalServerError, errors.New(ERR_InternalServer)
}

countSegment := contentLength / sconfig.SegmentSize
Expand Down Expand Up @@ -767,18 +767,25 @@ func checkExpiredFiles(rootDir string) bool {
}

func checkDeOSSStatus(n *Node, c *gin.Context) bool {
respData := RespType{}
if n.GetBalances() <= 1 {
msg := `The gateway account balance is insufficient, please feedback to us:
respData.Code = http.StatusInternalServerError
respData.Msg = `The gateway account balance is insufficient, please feedback to us:
https://twitter.com/CESS_Storage
https://t.me/CESS_Storage_official
https://discord.gg/tkZ4gfrK`
c.JSON(http.StatusInternalServerError, msg)
c.JSON(http.StatusInternalServerError, respData)
return false
}

if !n.GetRpcState() {
c.JSON(http.StatusInternalServerError, "RPC connection failed, please try again later.")
return false
err := n.ReconnectRpc()
if err != nil {
respData.Code = http.StatusInternalServerError
respData.Msg = ERR_RPCConnection
c.JSON(http.StatusInternalServerError, respData)
return false
}
}
return true
}
Expand Down
20 changes: 15 additions & 5 deletions node/put_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
"time"

"github.com/CESSProject/DeOSS/common/coordinate"
"github.com/CESSProject/DeOSS/common/utils"
Expand Down Expand Up @@ -190,12 +192,20 @@ func saveObjectToFile(c *gin.Context, file string) (int64, int, error) {
}

func checkDuplicates(n *Node, fid string, pkey []byte) (DuplicateType, int, error) {
fmeta, err := n.QueryFile(fid, -1)
if err != nil {
if !errors.Is(err, chain.ERR_RPC_EMPTY_VALUE) {
return Duplicate0, http.StatusInternalServerError, err
var err error
var fmeta chain.FileMetadata
for i := 0; i < 3; i++ {
fmeta, err = n.QueryFile(fid, -1)
if err != nil {
if strings.Contains(err.Error(), chain.ERR_RPC_CONNECTION.Error()) {
time.Sleep(time.Second * 6)
continue
}
if !errors.Is(err, chain.ERR_RPC_EMPTY_VALUE) {
return Duplicate0, http.StatusInternalServerError, err
}
return Duplicate0, http.StatusOK, nil
}
return Duplicate0, http.StatusOK, nil
}
for _, v := range fmeta.Owner {
if sutils.CompareSlice(v.User[:], pkey) {
Expand Down
Loading
Loading