Exemple #1
0
func main() {
	// Initialize new node with given name and cookie
	enode := node.NewNode("gonode@localhost", "123")

	// Allow node be available on 5588 port
	err := enode.Publish(5588)
	if err != nil {
		log.Printf("Cannot publish: %s", err)
		enode = nil
	}

	// Create channel to receive message when main process should be stopped
	completeChan := make(chan bool)

	// Initialize new instance of gonodeSrv structure which implements Process behaviour
	eSrv := new(gonodeSrv)

	// Spawn process with one arguments
	enode.Spawn(eSrv, completeChan)

	// Wait to stop
	<-completeChan

	return
}
Exemple #2
0
func main() {
	// Parse CLI flags
	flag.Parse()

	setup_logging()
	write_pid()

	log.Println("node started")

	// Initialize new node with given name and cookie
	enode := node.NewNode(NodeName, Cookie)

	// Allow node be available on EpmdPort port
	err = enode.Publish(EpmdPort)
	if err != nil {
		log.Fatalf("Cannot publish: %s", err)
	}

	// Create channel to receive message when main process should be stopped
	completeChan := make(chan bool)

	// Initialize new instance of srv structure which implements Process behaviour
	eSrv := new(srv)

	// Spawn process with one arguments
	enode.Spawn(eSrv, completeChan)

	// RPC
	if EnableRPC {
		// Create closure
		eClos := func(terms etf.List) (r etf.Term) {
			r = etf.Term(etf.Tuple{etf.Atom("gonode"), etf.Atom("reply"), len(terms)})
			return
		}

		// Provide it to call via RPC with `rpc:call(gonode@localhost, go_rpc, call, [as, qwe])`
		err = enode.RpcProvide("go_rpc", "call", eClos)
		if err != nil {
			log.Printf("Cannot provide function to RPC: %s", err)
		}
	}

	// Wait to stop
	<-completeChan

	log.Println("node finished")

	return
}
Exemple #3
0
func runNode() (enode *node.Node) {
	enode = node.NewNode(nodeName, nodeCookie)
	err := enode.Publish(nodePort)
	if err != nil {
		log.Printf("Cannot publish: %s", err)
		enode = nil
	}
	eSrv := new(eclusSrv)
	enode.Spawn(eSrv)

	eClos := func(terms etf.List) (r etf.Term) {
		r = etf.Term(etf.Tuple{etf.Atom("enode"), len(terms)})
		return
	}

	err = enode.RpcProvide("enode", "lambda", eClos)
	if err != nil {
		log.Printf("Cannot provide function to RPC: %s", err)
	}

	return
}
Exemple #4
0
func main() {
	// Initialize new node with given name and cookie
	enode := node.NewNode("gonode@localhost", "123")

	// Allow node be available on 5588 port
	err := enode.Publish(5588)
	if err != nil {
		log.Fatalf("Cannot publish: %s", err)
	}

	// Create channel to receive message when main process should be stopped
	completeChan := make(chan bool)

	// Initialize new instance of gonodeSrv structure which implements Process behaviour
	eSrv := new(gonodeSrv)

	// Spawn process with one arguments
	enode.Spawn(eSrv, completeChan)

	// RPC
	// Create closure
	eClos := func(terms etf.List) (r etf.Term) {
		r = etf.Term(etf.Tuple{etf.Atom("gonode"), etf.Atom("reply"), len(terms)})
		return
	}

	// Provide it to call via RPC with `rpc:call(gonode@localhost, go_rpc, call, [as, qwe])`
	err = enode.RpcProvide("go_rpc", "call", eClos)
	if err != nil {
		log.Printf("Cannot provide function to RPC: %s", err)
	}

	// Wait to stop
	<-completeChan

	return
}
Exemple #5
0
func NewRelay(basedir, name, cookie string) *Relay {
	return &Relay{basedir, node.NewNode(name, cookie), make(map[string]*hwfs.FS),
		make(chan struct{}, 1)}
}