func(api*adminAPI)AddPeer(urlstring)(bool,error){server:=api.node.Server()ifserver==nil{returnfalse,ErrNodeStopped}node,err:=enode.Parse(enode.ValidSchemes,url)iferr!=nil{returnfalse,fmt.Errorf("invalid enode: %v",err)}server.AddPeer(node)returntrue,nil}// AddPeer requests connecting to a remote node, and also maintaining the new// connection at all times, even reconnecting if it is lost.
func(api*adminAPI)AddTrustedPeer(urlstring)(bool,error){server:=api.node.Server()ifserver==nil{returnfalse,ErrNodeStopped}node,err:=enode.Parse(enode.ValidSchemes,url)iferr!=nil{returnfalse,fmt.Errorf("invalid enode: %v",err)}server.AddTrustedPeer(node)returntrue,nil}// AddTrustedPeer allows a remote node to always connect, even if slots are full
func(api*AdminAPI)ExportChain(filestring,first*uint64,last*uint64)(bool,error){iffirst==nil&&last!=nil{returnfalse,errors.New("last cannot be specified without first")}iffirst!=nil&&last==nil{head:=api.eth.BlockChain().CurrentHeader().Number.Uint64()last=&head}if_,err:=os.Stat(file);err==nil{returnfalse,errors.New("location would overwrite an existing file")}out,err:=os.OpenFile(file,os.O_CREATE|os.O_WRONLY|os.O_TRUNC,0644)iferr!=nil{returnfalse,err}deferout.Close()varwriterio.Writer=outifstrings.HasSuffix(file,".gz"){writer=gzip.NewWriter(writer)deferwriter.(*gzip.Writer).Close()}iffirst!=nil{iferr:=api.eth.BlockChain().ExportN(writer,*first,*last);err!=nil{returnfalse,err}}elseiferr:=api.eth.BlockChain().Export(writer);err!=nil{returnfalse,err}returntrue,nil}// ExportChain exports the current blockchain into a local file,// or a range of blocks if first and last are non-nil.
func(api*AdminAPI)ImportChain(filestring)(bool,error){in,err:=os.Open(file)iferr!=nil{returnfalse,err}deferin.Close()varreaderio.Reader=inifstrings.HasSuffix(file,".gz"){ifreader,err=gzip.NewReader(reader);err!=nil{returnfalse,err}}stream:=rlp.NewStream(reader,0)blocks,index:=make([// ImportChain imports a blockchain from a local file.]*types.Block,0,2500),0forbatch:=0;;batch++{forlen(blocks)<cap(blocks){block:=new(types.Block)iferr:=stream.Decode(block);err==io.EOF{break}elseiferr!=nil{returnfalse,fmt.Errorf("block %d: failed to parse: %v",index,err)}blocks=append(blocks,block)index++}iflen(blocks)==0{break}ifhasAllBlocks(api.eth.BlockChain(),blocks){blocks=blocks[:0]continue}if_,err:=api.eth.BlockChain().InsertChain(blocks);err!=nil{returnfalse,fmt.Errorf("batch %d: failed to insert: %v",batch,err)}blocks=blocks[:0]}returntrue,nil}
func(api*AdminAPI)MaxPeers(nint)(bool,error){api.eth.handler.maxPeers=napi.eth.p2pServer.MaxPeers=nfori:=api.eth.handler.peers.len();i>n;i=api.eth.handler.peers.len(){p:=api.eth.handler.peers.WorstPeer()ifp==nil{break}api.eth.handler.removePeer(p.ID())}returntrue,nil}// MaxPeers sets the maximum peer limit for the protocol manager and the p2p server.
func(api*adminAPI)NodeInfo()(*p2p.NodeInfo,error){server:=api.node.Server()ifserver==nil{returnnil,ErrNodeStopped}returnserver.NodeInfo(),nil}// NodeInfo retrieves all the information we know about the host node at the// protocol granularity.
func(api*adminAPI)PeerEvents(ctxcontext.Context)(*rpc.Subscription,error){server:=api.node.Server()ifserver==nil{returnnil,ErrNodeStopped}notifier,supported:=rpc.NotifierFromContext(ctx)if!supported{returnnil,rpc.ErrNotificationsUnsupported}rpcSub:=notifier.CreateSubscription()gofunc(){events:=make(chan*p2p.PeerEvent)sub:=server.SubscribeEvents(events)defersub.Unsubscribe()for{select{caseevent:=<-events:notifier.Notify(rpcSub.ID,event)case<-sub.Err():returncase<-rpcSub.Err():returncase<-notifier.Closed():return}}}()returnrpcSub,nil}// PeerEvents creates an RPC subscription which receives peer events from the// node's p2p.Server
func(api*adminAPI)Peers()([// Peers retrieves all the information we know about each individual peer at the// protocol granularity.]*p2p.PeerInfo,error){server:=api.node.Server()ifserver==nil{returnnil,ErrNodeStopped}returnserver.PeersInfo(),nil}
func(api*adminAPI)RemovePeer(urlstring)(bool,error){server:=api.node.Server()ifserver==nil{returnfalse,ErrNodeStopped}node,err:=enode.Parse(enode.ValidSchemes,url)iferr!=nil{returnfalse,fmt.Errorf("invalid enode: %v",err)}server.RemovePeer(node)returntrue,nil}// RemovePeer disconnects from a remote node if the connection exists
func(api*adminAPI)RemoveTrustedPeer(urlstring)(bool,error){server:=api.node.Server()ifserver==nil{returnfalse,ErrNodeStopped}node,err:=enode.Parse(enode.ValidSchemes,url)iferr!=nil{returnfalse,fmt.Errorf("invalid enode: %v",err)}server.RemoveTrustedPeer(node)returntrue,nil}// RemoveTrustedPeer removes a remote node from the trusted peer set, but it// does not disconnect it automatically.
func(api*adminAPI)StartHTTP(host*string,port*int,cors*string,apis*string,vhosts*string)(bool,error){api.node.lock.Lock()deferapi.node.lock.Unlock()ifhost==nil{h:=DefaultHTTPHostifapi.node.config.HTTPHost!=""{h=api.node.config.HTTPHost}host=&h}ifport==nil{port=&api.node.config.HTTPPort}config:=httpConfig{CorsAllowedOrigins:api.node.config.HTTPCors,Vhosts:api.node.config.HTTPVirtualHosts,Modules:api.node.config.HTTPModules,rpcEndpointConfig:rpcEndpointConfig{batchItemLimit:api.node.config.BatchRequestLimit,batchResponseSizeLimit:api.node.config.BatchResponseMaxSize}}ifcors!=nil{config.CorsAllowedOrigins=nilfor_,origin:=// StartHTTP starts the HTTP RPC API server.rangestrings.Split(*cors,","){config.CorsAllowedOrigins=append(config.CorsAllowedOrigins,strings.TrimSpace(origin))}}ifvhosts!=nil{config.Vhosts=nilfor_,vhost:=rangestrings.Split(*host,","){config.Vhosts=append(config.Vhosts,strings.TrimSpace(vhost))}}ifapis!=nil{config.Modules=nilfor_,m:=rangestrings.Split(*apis,","){config.Modules=append(config.Modules,strings.TrimSpace(m))}}iferr:=api.node.http.setListenAddr(*host,*port);err!=nil{returnfalse,err}iferr:=api.node.http.enableRPC(api.node.rpcAPIs,config);err!=nil{returnfalse,err}iferr:=api.node.http.start();err!=nil{returnfalse,err}returntrue,nil}
func(api*adminAPI)StartRPC(host*string,port*int,cors*string,apis*string,vhosts*string)(bool,error){log.Warn("Deprecation warning","method","admin.StartRPC","use-instead","admin.StartHTTP")returnapi.StartHTTP(host,port,cors,apis,vhosts)}// StartRPC starts the HTTP RPC API server.// Deprecated: use StartHTTP instead.
func(api*adminAPI)StartWS(host*string,port*int,allowedOrigins*string,apis*string)(bool,error){api.node.lock.Lock()deferapi.node.lock.Unlock()ifhost==nil{h:=DefaultWSHostifapi.node.config.WSHost!=""{h=api.node.config.WSHost}host=&h}ifport==nil{port=&api.node.config.WSPort}config:=wsConfig{Modules:api.node.config.WSModules,Origins:api.node.config.WSOrigins,rpcEndpointConfig:rpcEndpointConfig{batchItemLimit:api.node.config.BatchRequestLimit,batchResponseSizeLimit:api.node.config.BatchResponseMaxSize}}ifapis!=nil{config.Modules=nilfor_,m:=// StartWS starts the websocket RPC API server.rangestrings.Split(*apis,","){config.Modules=append(config.Modules,strings.TrimSpace(m))}}ifallowedOrigins!=nil{config.Origins=nilfor_,origin:=rangestrings.Split(*allowedOrigins,","){config.Origins=append(config.Origins,strings.TrimSpace(origin))}}server:=api.node.wsServerForPort(*port,false)iferr:=server.setListenAddr(*host,*port);err!=nil{returnfalse,err}openApis,_:=api.node.getAPIs()iferr:=server.enableWS(openApis,config);err!=nil{returnfalse,err}iferr:=server.start();err!=nil{returnfalse,err}api.node.http.log.Info("WebSocket endpoint opened","url",api.node.WSEndpoint())returntrue,nil}
func(api*adminAPI)StopRPC()(bool,error){log.Warn("Deprecation warning","method","admin.StopRPC","use-instead","admin.StopHTTP")returnapi.StopHTTP()}// StopRPC shuts down the HTTP server.// Deprecated: use StopHTTP instead.