mirror of https://github.com/poanetwork/gecko.git
Merge branch 'master' into TS_health
This commit is contained in:
commit
b333fbe2a5
|
@ -7,6 +7,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -28,30 +29,40 @@ var (
|
||||||
|
|
||||||
// Server maintains the HTTP router
|
// Server maintains the HTTP router
|
||||||
type Server struct {
|
type Server struct {
|
||||||
log logging.Logger
|
log logging.Logger
|
||||||
factory logging.Factory
|
factory logging.Factory
|
||||||
router *router
|
router *router
|
||||||
portURL string
|
listenAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize creates the API server at the provided port
|
// Initialize creates the API server at the provided host and port
|
||||||
func (s *Server) Initialize(log logging.Logger, factory logging.Factory, port uint16) {
|
func (s *Server) Initialize(log logging.Logger, factory logging.Factory, host string, port uint16) {
|
||||||
s.log = log
|
s.log = log
|
||||||
s.factory = factory
|
s.factory = factory
|
||||||
s.portURL = fmt.Sprintf(":%d", port)
|
s.listenAddress = fmt.Sprintf("%s:%d", host, port)
|
||||||
s.router = newRouter()
|
s.router = newRouter()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch starts the API server
|
// Dispatch starts the API server
|
||||||
func (s *Server) Dispatch() error {
|
func (s *Server) Dispatch() error {
|
||||||
handler := cors.Default().Handler(s.router)
|
handler := cors.Default().Handler(s.router)
|
||||||
return http.ListenAndServe(s.portURL, handler)
|
listener, err := net.Listen("tcp", s.listenAddress)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.log.Info("API server listening on %q", s.listenAddress)
|
||||||
|
return http.Serve(listener, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DispatchTLS starts the API server with the provided TLS certificate
|
// DispatchTLS starts the API server with the provided TLS certificate
|
||||||
func (s *Server) DispatchTLS(certFile, keyFile string) error {
|
func (s *Server) DispatchTLS(certFile, keyFile string) error {
|
||||||
handler := cors.Default().Handler(s.router)
|
handler := cors.Default().Handler(s.router)
|
||||||
return http.ListenAndServeTLS(s.portURL, certFile, keyFile, handler)
|
listener, err := net.Listen("tcp", s.listenAddress)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.log.Info("API server listening on %q", s.listenAddress)
|
||||||
|
return http.ServeTLS(listener, handler, certFile, keyFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterChain registers the API endpoints associated with this chain That
|
// RegisterChain registers the API endpoints associated with this chain That
|
||||||
|
|
|
@ -30,7 +30,7 @@ func (s *Service) Call(_ *http.Request, args *Args, reply *Reply) error {
|
||||||
|
|
||||||
func TestCall(t *testing.T) {
|
func TestCall(t *testing.T) {
|
||||||
s := Server{}
|
s := Server{}
|
||||||
s.Initialize(logging.NoLog{}, logging.NoFactory{}, 8080)
|
s.Initialize(logging.NoLog{}, logging.NoFactory{}, "localhost", 8080)
|
||||||
|
|
||||||
serv := &Service{}
|
serv := &Service{}
|
||||||
newServer := rpc.NewServer()
|
newServer := rpc.NewServer()
|
||||||
|
|
|
@ -93,6 +93,7 @@ func init() {
|
||||||
consensusIP := fs.String("public-ip", "", "Public IP of this node")
|
consensusIP := fs.String("public-ip", "", "Public IP of this node")
|
||||||
|
|
||||||
// HTTP Server:
|
// HTTP Server:
|
||||||
|
httpHost := fs.String("http-host", "", "Address of the HTTP server")
|
||||||
httpPort := fs.Uint("http-port", 9650, "Port of the HTTP server")
|
httpPort := fs.Uint("http-port", 9650, "Port of the HTTP server")
|
||||||
fs.BoolVar(&Config.EnableHTTPS, "http-tls-enabled", false, "Upgrade the HTTP server to HTTPs")
|
fs.BoolVar(&Config.EnableHTTPS, "http-tls-enabled", false, "Upgrade the HTTP server to HTTPs")
|
||||||
fs.StringVar(&Config.HTTPSKeyFile, "http-tls-key-file", "", "TLS private key file for the HTTPs server")
|
fs.StringVar(&Config.HTTPSKeyFile, "http-tls-key-file", "", "TLS private key file for the HTTPs server")
|
||||||
|
@ -270,6 +271,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTP:
|
// HTTP:
|
||||||
|
Config.HTTPHost = *httpHost
|
||||||
Config.HTTPPort = uint16(*httpPort)
|
Config.HTTPPort = uint16(*httpPort)
|
||||||
|
|
||||||
// Logging:
|
// Logging:
|
||||||
|
|
|
@ -42,6 +42,7 @@ type Config struct {
|
||||||
BootstrapPeers []*Peer
|
BootstrapPeers []*Peer
|
||||||
|
|
||||||
// HTTP configuration
|
// HTTP configuration
|
||||||
|
HTTPHost string
|
||||||
HTTPPort uint16
|
HTTPPort uint16
|
||||||
EnableHTTPS bool
|
EnableHTTPS bool
|
||||||
HTTPSKeyFile string
|
HTTPSKeyFile string
|
||||||
|
|
|
@ -479,7 +479,7 @@ func (n *Node) initChains() error {
|
||||||
func (n *Node) initAPIServer() {
|
func (n *Node) initAPIServer() {
|
||||||
n.Log.Info("Initializing API server")
|
n.Log.Info("Initializing API server")
|
||||||
|
|
||||||
n.APIServer.Initialize(n.Log, n.LogFactory, n.Config.HTTPPort)
|
n.APIServer.Initialize(n.Log, n.LogFactory, n.Config.HTTPHost, n.Config.HTTPPort)
|
||||||
|
|
||||||
go n.Log.RecoverAndPanic(func() {
|
go n.Log.RecoverAndPanic(func() {
|
||||||
if n.Config.EnableHTTPS {
|
if n.Config.EnableHTTPS {
|
||||||
|
|
|
@ -36,7 +36,7 @@ type AtomicTx interface {
|
||||||
// AtomicBlock being accepted results in the transaction contained in the
|
// AtomicBlock being accepted results in the transaction contained in the
|
||||||
// block to be accepted and committed to the chain.
|
// block to be accepted and committed to the chain.
|
||||||
type AtomicBlock struct {
|
type AtomicBlock struct {
|
||||||
SingleDecisionBlock `serialize:"true"`
|
CommonDecisionBlock `serialize:"true"`
|
||||||
|
|
||||||
Tx AtomicTx `serialize:"true"`
|
Tx AtomicTx `serialize:"true"`
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ type AtomicBlock struct {
|
||||||
|
|
||||||
// initialize this block
|
// initialize this block
|
||||||
func (ab *AtomicBlock) initialize(vm *VM, bytes []byte) error {
|
func (ab *AtomicBlock) initialize(vm *VM, bytes []byte) error {
|
||||||
if err := ab.SingleDecisionBlock.initialize(vm, bytes); err != nil {
|
if err := ab.CommonDecisionBlock.initialize(vm, bytes); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return ab.Tx.initialize(vm)
|
return ab.Tx.initialize(vm)
|
||||||
|
@ -123,9 +123,6 @@ func (ab *AtomicBlock) Accept() {
|
||||||
ab.onAcceptFunc()
|
ab.onAcceptFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
parent := ab.parentBlock()
|
|
||||||
// remove this block and its parent from memory
|
|
||||||
parent.free()
|
|
||||||
ab.free()
|
ab.free()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,11 +130,9 @@ func (ab *AtomicBlock) Accept() {
|
||||||
// decision block, has ID [parentID].
|
// decision block, has ID [parentID].
|
||||||
func (vm *VM) newAtomicBlock(parentID ids.ID, tx AtomicTx) (*AtomicBlock, error) {
|
func (vm *VM) newAtomicBlock(parentID ids.ID, tx AtomicTx) (*AtomicBlock, error) {
|
||||||
ab := &AtomicBlock{
|
ab := &AtomicBlock{
|
||||||
SingleDecisionBlock: SingleDecisionBlock{CommonDecisionBlock: CommonDecisionBlock{
|
CommonDecisionBlock: CommonDecisionBlock{CommonBlock: CommonBlock{
|
||||||
CommonBlock: CommonBlock{
|
Block: core.NewBlock(parentID),
|
||||||
Block: core.NewBlock(parentID),
|
vm: vm,
|
||||||
vm: vm,
|
|
||||||
},
|
|
||||||
}},
|
}},
|
||||||
Tx: tx,
|
Tx: tx,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue