MCPcopy Create free account
hub / github.com/Super-long/ChubbyGo / makeCheckSum

Method makeCheckSum

BaseServer/fileSystem.go:155–176  ·  view source on GitHub ↗

* * @brief: 基于FileSystemNode生成一个新的CheckSum; 其实保证随机性就ok了;我这种生成方式最大程度与文件有关 * @notes: 大费周章的生成这样一个数是否有必要呢?虽然用的也不多 * @!!!!!: 完全想错了;我们需要一个以文件内容生成的校验和,这样才可以在不同的节点都执行成功 */ *func (Fsn *FileSystemNode) makeCheckSum() uint64 { var res uint64 // step1: 取对象地址的值 // AddressValue可以获取对象的地址的64位整数具体的值 p := re

()

Source from the content-addressed store, hash-verified

153 * 显然instanceSeq最小值为1,checksum也不可能是0,所以ClientInstanceSeq和ClientInstanceSeq可以使用0作为无效值
154 */
155func (Fsn *FileSystemNode) makeCheckSum() uint64 {
156 // 生成20位字符串,每一位都是16进制的数字
157 hash := sha1.New()
158 hash.Write([]byte(Fsn.nowPath))
159 sha1Res := hash.Sum(nil)
160
161 var res uint64 = 0
162
163 for i := 0; i < 14; i++ {
164 res = res | (uint64(sha1Res[i]) << (4*i))
165 }
166
167 //[63,56][55,0]
168
169 res = res | Fsn.instanceSeq << 57
170
171 res = res | uint64(len(Fsn.next) << 59)
172
173 res = res | uint64(len(Fsn.nextNameCache) << 61)
174
175 return res
176}
177
178/*
179 * @brief: Type:创建的文件的类型;name:文件名称;后面则是文件初始的操作权限

Callers 3

InsertMethod · 0.95
InitRootFunction · 0.95
DeleteMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected