예제 #1
0
func (_builder *Builder) Include(_entity *walker.Entity) os.Error {
	_entityPath := _entity.Path
	_entityKeyRaw, _error := hasher.HashString(_entityPath, _builder.treeHasher)
	if _error != nil {
		return _error
	}
	_entityKey := hex.EncodeToString(_entityKeyRaw)
	var _entityFingerprint string
	_entityFingerprint, _error = hasher.Fingerprint(_entity, _builder.treeHasher)
	if _error != nil {
		return _error
	}
	_leafKey := _entityKey[:_builder.depth*_builder.fanout]
	_leaf := _builder.leafs[_leafKey]
	if _leaf == nil {
		_leafNode := _builder.tree.Root()
		for _level := uint(0); _level < _builder.depth; _level++ {
			_leafName := _leafKey[_level*_builder.fanout : (_level+1)*_builder.fanout]
			_leafNode1 := _leafNode.Select(_leafName)
			if _leafNode1 == nil {
				_leafNode1, _error = _leafNode.Include(_leafName)
				if _error != nil {
					return _error
				}
			}
			_leafNode = _leafNode1
		}
		_leaf = &treeLeaf{_leafNode, make(map[string]string, 4)}
		_builder.leafs[_leafKey] = _leaf
	}
	_leaf.node.Attach(_entityPath, _entityFingerprint)
	return nil
}
예제 #2
0
func (_node *Node) Fingerprint() (string, os.Error) {
	return hasher.Fingerprint(_node, _node.tree.hasher)
}
예제 #3
0
func (_tree *Tree) Fingerprint() (string, os.Error) {
	return hasher.Fingerprint(_tree, _tree.hasher)
}
예제 #4
0
func main() {

	var _configuration *configuration
	var _error os.Error

	_configuration, _error = configure()
	if _error != nil {
		abort(_error)
	}

	runtime.GOMAXPROCS(_configuration.goMaxProcs)

	if _configuration.goProfile {
		_file, _error := os.Create("/tmp/merekele.cpuprof")
		if _error != nil {
			abort(_error)
		}
		_error = pprof.StartCPUProfile(_file)
		if _error != nil {
			abort(_error)
		}
	}

	_builder := builder.New(nil, _configuration.treeHasher, _configuration.dataHasher, 4, 1)

	_errorHandler := func(_error walker.Error) {
		transcript.TraceWarning("failed: %s; ignoring...", _error.String())
	}

	_entityHandler := func(_entity *walker.Entity) {
		var _error os.Error
		if (_configuration.dataHasher != nil) && _entity.IsRegular() && _entity.IsOpen() {
			_, _error = _entity.HashData(_configuration.dataHasher)
			if _error != nil {
				_errorHandler(_error)
			}
		}
		_error = _builder.Include(_entity)
		if _error != nil {
			_errorHandler(_error)
		}
		_entity.Close()
	}

	transcript.TraceInformation("building merkel tree...")

	for _, _path := range _configuration.paths {
		walker.Walk(_path,
			func(_ *walker.Entity) (bool, bool) {
				return true, true
			},
			_entityHandler, _errorHandler)
	}

	transcript.TraceInformation("finalizing merkel tree...")

	var _tree *merkel.Tree
	_tree, _error = _builder.Finalize()
	if _error != nil {
		abort(_error)
	}

	if false {
		transcript.TraceInformation("writing merkel node data...")
		_tree.Visit(func(_node *merkel.Node) {
			var _error os.Error
			var _nodeFingerprint string
			_nodeFingerprint, _error = hasher.Fingerprint(_node, _configuration.treeHasher)
			if _error != nil {
				abort(_error)
			}
			var _nodeData interface{}
			_nodeData, _error = _node.Data()
			if _error != nil {
				abort(_error)
			}
			type _output struct {
				Fingerprint string
				Entity      interface{}
			}
			_error = output(&_output{_nodeFingerprint, _nodeData}, _configuration)
			if _error != nil {
				abort(_error)
			}
		})
	}

	if true {
		transcript.TraceInformation("writing tree data...")
		var _treeData interface{}
		_treeData, _error = _tree.Data()
		if _error != nil {
			abort(_error)
		}
		_error = output(_treeData, _configuration)
		if _error != nil {
			abort(_error)
		}
	}

	if _configuration.goProfile {
		pprof.StopCPUProfile()
		{
			_file, _error := os.Create("/tmp/merekele.memprof")
			if _error != nil {
				abort(_error)
			}
			_error = pprof.WriteHeapProfile(_file)
			if _error != nil {
				abort(_error)
			}
			_error = _file.Close()
			if _error != nil {
				abort(_error)
			}
		}
	}

	os.Exit(0)
}