// StartWS starts a websocket JSON-RPC API server. func StartWS(stack *node.Node, ctx *cli.Context) error { for _, api := range stack.APIs() { if adminApi, ok := api.Service.(*node.PrivateAdminAPI); ok { address := ctx.GlobalString(WSListenAddrFlag.Name) port := ctx.GlobalInt(WSAllowedDomainsFlag.Name) allowedDomains := ctx.GlobalString(WSAllowedDomainsFlag.Name) apiStr := "" if ctx.GlobalIsSet(WSApiFlag.Name) { apiStr = ctx.GlobalString(WSApiFlag.Name) } _, err := adminApi.StartWS(address, port, allowedDomains, apiStr) return err } } glog.V(logger.Error).Infof("Unable to start RPC-WS interface, could not find admin API") return errors.New("Unable to start RPC-WS interface") }
// NewInProcRPCClient will start a new RPC server for the given node and returns a client to interact with it. func NewInProcRPCClient(stack *node.Node) *inProcClient { server := rpc.NewServer() offered := stack.APIs() for _, api := range offered { server.RegisterName(api.Namespace, api.Service) } web3 := node.NewPublicWeb3API(stack) server.RegisterName("web3", web3) var ethereum *eth.Ethereum if err := stack.Service(ðereum); err == nil { net := eth.NewPublicNetAPI(stack.Server(), ethereum.NetVersion()) server.RegisterName("net", net) } else { glog.V(logger.Warn).Infof("%v\n", err) } buf := &buf{ requests: make(chan []byte), responses: make(chan []byte), } client := &inProcClient{ server: server, buf: buf, } go func() { server.ServeCodec(rpc.NewJSONCodec(client.buf)) }() return client }
func StartNode(stack *node.Node) { if err := stack.Start(); err != nil { Fatalf("Error starting protocol stack: %v", err) } go func() { sigc := make(chan os.Signal, 1) signal.Notify(sigc, os.Interrupt) defer signal.Stop(sigc) <-sigc glog.V(logger.Info).Infoln("Got interrupt, shutting down...") go stack.Stop() logger.Flush() for i := 10; i > 0; i-- { <-sigc if i > 1 { glog.V(logger.Info).Infoln("Already shutting down, please be patient.") glog.V(logger.Info).Infoln("Interrupt", i-1, "more times to induce panic.") } } glog.V(logger.Error).Infof("Force quitting: this might not end so well.") panic("boom") }() }
func StartIPC(stack *node.Node, ctx *cli.Context) error { var ethereum *eth.Ethereum if err := stack.Service(ðereum); err != nil { return err } endpoint := IPCSocketPath(ctx) listener, err := rpc.CreateIPCListener(endpoint) if err != nil { return err } server := rpc.NewServer() // register package API's this node provides offered := stack.APIs() for _, api := range offered { server.RegisterName(api.Namespace, api.Service) glog.V(logger.Debug).Infof("Register %T under namespace '%s' for IPC service\n", api.Service, api.Namespace) } go func() { glog.V(logger.Info).Infof("Start IPC server on %s\n", endpoint) for { conn, err := listener.Accept() if err != nil { glog.V(logger.Error).Infof("Unable to accept connection - %v\n", err) } codec := rpc.NewJSONCodec(conn) go server.ServeCodec(codec) } }() return nil }