Example #1
0
// 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(&ethereum); 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
}
Example #2
0
// handleIPC is the RPC over IPC handler to accept inbound API requests and run
// them until termination is requested.
func (g *Geth) handleIPC() {
	for {
		conn, err := g.ipcSocket.Accept()
		if err != nil {
			log15.Debug("Unable to accept connection (shutting down?)", "error", err)
			return
		}
		go g.ipcServer.ServeCodec(rpc.NewJSONCodec(conn))
	}
}
Example #3
0
func StartIPC(stack *node.Node, ctx *cli.Context) error {
	var ethereum *eth.Ethereum
	if err := stack.Service(&ethereum); 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

}