Ejemplo n.º 1
0
func init() {
	// init NODE_BASE_PATH
	swarm.NODE_BASE_PATH = "/data/swarm/node1"

	// load global vars
	swarm.PreStart()

	TestIndexhash = GetIndexhash(TestFile)
	TestObjecthash = swarm.Sha1Hex([]byte(TestFile))
	TestBlockhash = swarm.Sha1Hex([]byte(TestBlock))
}
Ejemplo n.º 2
0
// For tests
// Get object hash from test file
func GetIndexhash(objectContent []byte) (objecthash string) {
	blockhashes := make([]string, 0)
	size := len(objectContent)
	var start int
	for start = 0; start <= size; start += swarm.BLOCK_SIZE {
		end := start + swarm.BLOCK_SIZE
		if end > size {
			end = size
		}
		block := objectContent[start:end]
		blockhash := swarm.Sha1Hex(block)
		blockhashes = append(blockhashes, blockhash)
		if end == size {
			break
		}
	}
	return swarm.Sha1Hex([]byte(strings.Join(blockhashes, "")))
}