@@ -54,6 +54,7 @@ import (
5454 "github.com/ethereum/go-ethereum/rpc/comms"
5555 "github.com/ethereum/go-ethereum/rpc/shared"
5656 "github.com/ethereum/go-ethereum/rpc/useragent"
57+ rpc "github.com/ethereum/go-ethereum/rpc/v2"
5758 "github.com/ethereum/go-ethereum/whisper"
5859 "github.com/ethereum/go-ethereum/xeth"
5960)
@@ -300,6 +301,10 @@ var (
300301 Usage : "Filename for IPC socket/pipe" ,
301302 Value : DirectoryString {common .DefaultIpcPath ()},
302303 }
304+ IPCExperimental = cli.BoolFlag {
305+ Name : "ipcexp" ,
306+ Usage : "Enable the new RPC implementation" ,
307+ }
303308 ExecFlag = cli.StringFlag {
304309 Name : "exec" ,
305310 Usage : "Execute JavaScript statement (only in combination with console/attach)" ,
@@ -690,6 +695,7 @@ func MakeSystemNode(name, version string, extra []byte, ctx *cli.Context) *node.
690695 Fatalf ("Failed to register the Whisper service: %v" , err )
691696 }
692697 }
698+
693699 return stack
694700}
695701
@@ -773,17 +779,53 @@ func IpcSocketPath(ctx *cli.Context) (ipcpath string) {
773779 return
774780}
775781
776- // StartIPC starts a IPC JSON-RPC API server.
777782func StartIPC (stack * node.Node , ctx * cli.Context ) error {
778783 config := comms.IpcConfig {
779784 Endpoint : IpcSocketPath (ctx ),
780785 }
781786
782- initializer := func (conn net.Conn ) (comms.Stopper , shared.EthereumApi , error ) {
783- var ethereum * eth.Ethereum
784- if err := stack .Service (& ethereum ); err != nil {
785- return nil , nil , err
787+ var ethereum * eth.Ethereum
788+ if err := stack .Service (& ethereum ); err != nil {
789+ return err
790+ }
791+
792+ if ctx .GlobalIsSet (IPCExperimental .Name ) {
793+ listener , err := comms .CreateListener (config )
794+ if err != nil {
795+ return err
796+ }
797+
798+ server := rpc .NewServer ()
799+
800+ // register package API's this node provides
801+ offered := stack .RPCAPIs ()
802+ for _ , api := range offered {
803+ server .RegisterName (api .Namespace , api .Service )
804+ glog .V (logger .Debug ).Infof ("Register %T under namespace '%s' for IPC service\n " , api .Service , api .Namespace )
786805 }
806+
807+ web3 := NewPublicWeb3API (stack )
808+ server .RegisterName ("web3" , web3 )
809+ net := NewPublicNetAPI (stack .Server (), ethereum .NetVersion ())
810+ server .RegisterName ("net" , net )
811+
812+ go func () {
813+ glog .V (logger .Info ).Infof ("Start IPC server on %s\n " , config .Endpoint )
814+ for {
815+ conn , err := listener .Accept ()
816+ if err != nil {
817+ glog .V (logger .Error ).Infof ("Unable to accept connection - %v\n " , err )
818+ }
819+
820+ codec := rpc .NewJSONCodec (conn )
821+ go server .ServeCodec (codec )
822+ }
823+ }()
824+
825+ return nil
826+ }
827+
828+ initializer := func (conn net.Conn ) (comms.Stopper , shared.EthereumApi , error ) {
787829 fe := useragent .NewRemoteFrontend (conn , ethereum .AccountManager ())
788830 xeth := xeth .New (stack , fe )
789831 apis , err := api .ParseApiString (ctx .GlobalString (IPCApiFlag .Name ), codec .JSON , xeth , stack )
0 commit comments