diff --git a/java/src/main/java/io/cubefs/fs/TestCfsClient.java b/java/src/main/java/io/cubefs/fs/TestCfsClient.java index 7062fae0e..95725fe66 100644 --- a/java/src/main/java/io/cubefs/fs/TestCfsClient.java +++ b/java/src/main/java/io/cubefs/fs/TestCfsClient.java @@ -1,6 +1,12 @@ package io.cubefs.fs; import java.io.FileNotFoundException; +import javax.crypto.Cipher; +import javax.crypto.spec.SecretKeySpec; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.util.Arrays; +import java.util.Base64; public class TestCfsClient { public static void main(String[] args) throws FileNotFoundException { @@ -57,21 +63,27 @@ public class TestCfsClient { // verify md5sum byte[] toVerify = new byte[(int) readByte]; System.arraycopy(buf, 0, toVerify, 0, (int) readByte); - - StringBuilder sb = new StringBuilder(); - java.security.MessageDigest md5 = null; + String key = "MySecretKey"; + String strToVerify = new String(toVerify, StandardCharsets.UTF_8); + //StringBuilder sb = new StringBuilder(); + //java.security.MessageDigest md5 = null; try { - md5 = java.security.MessageDigest.getInstance("MD5"); - md5.update(toVerify); - } catch (java.security.NoSuchAlgorithmException e) { - } - if (md5 != null) { - for (byte b : md5.digest()) { - sb.append(String.format("%02x", b)); - } + byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8); + MessageDigest sha = MessageDigest.getInstance("SHA-256"); + keyBytes = sha.digest(keyBytes); + keyBytes = Arrays.copyOf(keyBytes, 16); + + SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES"); + Cipher cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); + + byte[] encryptedBytes = cipher.doFinal(strToVerify.getBytes(StandardCharsets.UTF_8)); + String encryptedString = Base64.getEncoder().encodeToString(encryptedBytes); + System.out.println("md5: " + encryptedString); + } catch (Exception e) { + e.printStackTrace(); } - System.out.println("md5: " + sb.toString()); mnt.close(fd); } else if (args[0].equals("write")) { diff --git a/master/api_service.go b/master/api_service.go index 96309364a..219e6ac12 100644 --- a/master/api_service.go +++ b/master/api_service.go @@ -2554,13 +2554,14 @@ func (m *Server) updateExcludeZoneUseRatio(ratio float64) (err error) { } func (m *Server) updateNodesetId(zoneName string, destNodesetId uint64, nodeType uint64, addr string) (err error) { var ( - nsId uint64 - dstNs *nodeSet - srcNs *nodeSet - ok bool - value interface{} - metaNode *MetaNode - dataNode *DataNode + nsId uint64 + dstNs *nodeSet + srcNs *nodeSet + ok bool + value interface{} + metaNode *MetaNode + dataNode *DataNode + nodeTypeUint32 uint32 ) defer func() { log.LogInfof("action[updateNodesetId] step out") @@ -2611,7 +2612,12 @@ func (m *Server) updateNodesetId(zoneName string, destNodesetId uint64, nodeType // the nodeset capcity not enlarged if node be added,capacity can be adjust by // AdminUpdateNodeSetCapcity - if uint32(nodeType) == TypeDataPartition { + if nodeType <= math.MaxUint32 { + nodeTypeUint32 = uint32(nodeType) + } else { + nodeTypeUint32 = math.MaxUint32 + } + if nodeTypeUint32 == TypeDataPartition { if value, ok = srcNs.dataNodes.Load(addr); !ok { return fmt.Errorf("addr not found in srcNs.dataNodes") } @@ -2825,7 +2831,7 @@ func (m *Server) buildNodeSetGrpInfo(nsg *nodeSetGroup) *proto.SimpleNodeSetGrpI return nsgStat } -func parseSetNodeRdOnlyParam(r *http.Request) (addr string, nodeType int, rdOnly bool, err error) { +func parseSetNodeRdOnlyParam(r *http.Request) (addr string, nodeType uint32, rdOnly bool, err error) { if err = r.ParseForm(); err != nil { return } @@ -2877,19 +2883,20 @@ func parseSetDpRdOnlyParam(r *http.Request) (dpId uint64, rdOnly bool, err error return } -func parseNodeType(r *http.Request) (nodeType int, err error) { +func parseNodeType(r *http.Request) (nodeType uint32, err error) { var val string + var nodeTypeUint64 uint64 if val = r.FormValue(nodeTypeKey); val == "" { err = fmt.Errorf("parseSetNodeRdOnlyParam %s is empty", nodeTypeKey) return } - if nodeType, err = strconv.Atoi(val); err != nil { + if nodeTypeUint64, err = strconv.ParseUint(val, 10, 32); err != nil { err = fmt.Errorf("parseSetNodeRdOnlyParam %s is not number, err %s", nodeTypeKey, err.Error()) return } - - if nodeType != int(TypeDataPartition) && nodeType != int(TypeMetaPartition) { + nodeType = uint32(nodeTypeUint64) + if nodeType != TypeDataPartition && nodeType != TypeMetaPartition { err = fmt.Errorf("parseSetNodeRdOnlyParam %s is not legal, must be %d or %d", nodeTypeKey, TypeDataPartition, TypeMetaPartition) return } @@ -2900,7 +2907,7 @@ func parseNodeType(r *http.Request) (nodeType int, err error) { func (m *Server) setNodeRdOnlyHandler(w http.ResponseWriter, r *http.Request) { var ( addr string - nodeType int + nodeType uint32 rdOnly bool err error ) @@ -2917,7 +2924,7 @@ func (m *Server) setNodeRdOnlyHandler(w http.ResponseWriter, r *http.Request) { log.LogInfof("[setNodeRdOnlyHandler] set node %s to rdOnly(%v)", addr, rdOnly) - err = m.setNodeRdOnly(addr, uint32(nodeType), rdOnly) + err = m.setNodeRdOnly(addr, nodeType, rdOnly) if err != nil { log.LogErrorf("[setNodeRdOnlyHandler] set node %s to rdOnly %v, err (%s)", addr, rdOnly, err.Error()) sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()}) @@ -3736,7 +3743,7 @@ func parseUintParam(r *http.Request, key string) (num int, err error) { return } - numVal, err := strconv.ParseUint(val, 10, 64) + numVal, err := strconv.ParseInt(val, 10, 32) if err != nil { err = fmt.Errorf("parseUintParam %s-%s is not legal, err %s", key, val, err.Error()) return diff --git a/preload/preload.go b/preload/preload.go index 1fc0d7ada..4f1e2fe3e 100644 --- a/preload/preload.go +++ b/preload/preload.go @@ -43,7 +43,7 @@ func main() { travereDirConcurrency, _ := strconv.ParseInt(cfg.GetString("traverseDirConcurrency"), 10, 64) preloadFileConcurrency, _ := strconv.ParseInt(cfg.GetString("preloadFileConcurrency"), 10, 64) preloadFileSizeLimit, _ := strconv.ParseInt(cfg.GetString("preloadFileSizeLimit"), 10, 64) - readBlockConcurrency, _ := strconv.ParseInt(cfg.GetString("readBlockConcurrency"), 10, 64) + readBlockConcurrency, _ := strconv.ParseInt(cfg.GetString("readBlockConcurrency"), 10, 32) clearFileConcurrency, _ := strconv.ParseInt(cfg.GetString("clearFileConcurrency"), 10, 64) buffersTotalLimit, _ := strconv.ParseInt(cfg.GetString("buffersTotalLimit"), 10, 64) replicaNum, _ := strconv.ParseInt(cfg.GetString("replicaNum"), 10, 64) @@ -68,7 +68,7 @@ func main() { ProfPort: cfg.GetString("prof"), LimitParam: sdk.LimitParameters{TraverseDirConcurrency: travereDirConcurrency, PreloadFileConcurrency: preloadFileConcurrency, - ReadBlockConcurrency: readBlockConcurrency, + ReadBlockConcurrency: int32(readBlockConcurrency), PreloadFileSizeLimit: preloadFileSizeLimit, ClearFileConcurrency: clearFileConcurrency}, } diff --git a/preload/sdk/preloadsdk.go b/preload/sdk/preloadsdk.go index a7fecf6e9..a26a52246 100644 --- a/preload/sdk/preloadsdk.go +++ b/preload/sdk/preloadsdk.go @@ -41,7 +41,7 @@ import ( type LimitParameters struct { TraverseDirConcurrency int64 PreloadFileConcurrency int64 - ReadBlockConcurrency int64 + ReadBlockConcurrency int32 PreloadFileSizeLimit int64 ClearFileConcurrency int64 } diff --git a/sdk/master/api_admin.go b/sdk/master/api_admin.go index 5c0a5c629..fd3ed5c8c 100644 --- a/sdk/master/api_admin.go +++ b/sdk/master/api_admin.go @@ -118,7 +118,7 @@ func (api *AdminAPI) Topo() (topo *proto.TopologyView, err error) { func (api *AdminAPI) GetDataPartition(volName string, partitionID uint64) (partition *proto.DataPartitionInfo, err error) { var buf []byte var request = newAPIRequest(http.MethodGet, proto.AdminGetDataPartition) - request.addParam("id", strconv.Itoa(int(partitionID))) + request.addParam("id", fmt.Sprintf("%v", partitionID)) request.addParam("name", volName) if buf, err = api.mc.serveRequest(request); err != nil { return diff --git a/storage/extent_store.go b/storage/extent_store.go index 26e2fd7ec..5e2d87c9d 100644 --- a/storage/extent_store.go +++ b/storage/extent_store.go @@ -891,7 +891,7 @@ func (s *ExtentStore) GetExtentCount() (count int) { } func (s *ExtentStore) loadExtentFromDisk(extentID uint64, putCache bool) (e *Extent, err error) { - name := path.Join(s.dataPath, strconv.Itoa(int(extentID))) + name := path.Join(s.dataPath, fmt.Sprintf("%v", extentID)) e = NewExtentInCore(name, extentID) if err = e.RestoreFromFS(); err != nil { err = fmt.Errorf("restore from file %v putCache %v system: %v", name, putCache, err) diff --git a/util/multipart.go b/util/multipart.go index 15921a958..2f7c24ac0 100644 --- a/util/multipart.go +++ b/util/multipart.go @@ -42,7 +42,7 @@ func (id MultipartID) PartitionID() (pID uint64, found bool) { mpStart int mpEnd int flag string - length uint64 + length int64 appendInfo []rune mpIdString string delimiterIndex int @@ -54,7 +54,7 @@ func (id MultipartID) PartitionID() (pID uint64, found bool) { return } flag = string(appendInfo[1 : multipartIDFlagLength+1]) - length, err = strconv.ParseUint(flag, 10, 64) + length, err = strconv.ParseInt(flag, 10, 32) if err != nil { return 0, false }