Пример #1
0
/*
Create a new model at the specified path for the given peer id. Will not
immediately update, must be explicitely called.
*/
func Create(root string, peerid string, storePath string) (*Model, error) {
	if root == "" || peerid == "" || storePath == "" {
		return nil, shared.ErrIllegalParameters
	}
	if !shared.IsTinzenite(root) {
		return nil, shared.ErrNotTinzenite
	}
	m := &Model{
		RootPath:     root,
		TrackedPaths: make(map[string]bool),
		StaticInfos:  make(map[string]staticinfo),
		SelfID:       peerid,
		StorePath:    storePath}
	return m, nil
}
Пример #2
0
/*
Create returns a struct that will allow to bootstrap to an existing Tinzenite
network. To actually start bootstrapping call Bootstrap.Start(address).

Path: the absolute path to the directory. localPeerName: the user defined name
of this peer. trusted: whether this should be a trusted peer or an encrypted
one. f: the callback to call once the bootstrap has successfully run.
*/
func Create(path, localPeerName string, trusted bool, f Success) (*Bootstrap, error) {
	if shared.IsTinzenite(path) {
		return nil, shared.ErrIsTinzenite
	}
	// build structure
	var err error
	if trusted {
		err = shared.MakeTinzeniteDir(path)
	} else {
		err = shared.MakeEncryptedDir(path)
	}
	// creation of structure error
	if err != nil {
		return nil, err
	}
	// create object
	boot := &Bootstrap{
		path:   path,
		onDone: f}
	boot.cInterface = createChanInterface(boot)
	channel, err := channel.Create(localPeerName, nil, boot.cInterface)
	if err != nil {
		return nil, err
	}
	boot.channel = channel
	// get address for peer
	address, err := boot.channel.Address()
	if err != nil {
		return nil, err
	}
	// make peer (at correct location!)
	peer, err := shared.CreatePeer(localPeerName, address, trusted)
	if err != nil {
		return nil, err
	}
	boot.peer = peer
	// bg stuff
	boot.wg.Add(1)
	boot.stop = make(chan bool, 1)
	go boot.run()
	return boot, nil
}