proxy

package
v0.0.0-...-e46861f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNodeProviderProxy

func NewNodeProviderProxy(config NodeProviderConfig) (*httputil.ReverseProxy, error)

Types

type Config

type Config struct {
	Proxy              ProxyConfig
	Targets            []NodeProviderConfig
	HealthChecks       HealthCheckConfig
	HealthcheckManager *HealthCheckManager
}

This struct is temporary. It's about to keep the input interface clean and simple.

type HealthCheckConfig

type HealthCheckConfig struct {
	Interval         time.Duration `yaml:"interval"`
	Timeout          time.Duration `yaml:"timeout"`
	FailureThreshold uint          `yaml:"failureThreshold"`
	SuccessThreshold uint          `yaml:"successThreshold"`
}

type HealthCheckManager

type HealthCheckManager struct {
	// contains filtered or unexported fields
}

func NewHealthCheckManager

func NewHealthCheckManager(config HealthCheckManagerConfig) (*HealthCheckManager, error)

func (*HealthCheckManager) IsHealthy

func (h *HealthCheckManager) IsHealthy(name string) bool

func (*HealthCheckManager) Start

func (*HealthCheckManager) Stop

type HealthCheckManagerConfig

type HealthCheckManagerConfig struct {
	Targets []NodeProviderConfig
	Config  HealthCheckConfig
	Logger  *slog.Logger
}

type HealthChecker

type HealthChecker struct {
	// contains filtered or unexported fields
}

func NewHealthChecker

func NewHealthChecker(config HealthCheckerConfig) (*HealthChecker, error)

func (*HealthChecker) BlockNumber

func (h *HealthChecker) BlockNumber() uint64

func (*HealthChecker) CheckAndSetHealth

func (h *HealthChecker) CheckAndSetHealth()

CheckAndSetHealth makes the following calls - `eth_blockNumber` - to get the latest block reported by the node - `eth_call` - to get the gas limit And sets the health status based on the responses.

func (*HealthChecker) GasLimit

func (h *HealthChecker) GasLimit() uint64

func (*HealthChecker) IsHealthy

func (h *HealthChecker) IsHealthy() bool

func (*HealthChecker) Name

func (h *HealthChecker) Name() string

func (*HealthChecker) Start

func (h *HealthChecker) Start(c context.Context)

func (*HealthChecker) Stop

func (h *HealthChecker) Stop(_ context.Context) error

type HealthCheckerConfig

type HealthCheckerConfig struct {
	URL    string
	Name   string // identifier imported from RPC gateway config
	Logger *slog.Logger

	// How often to check health.
	Interval time.Duration `yaml:"healthcheckInterval"`

	// How long to wait for responses before failing
	Timeout time.Duration `yaml:"healthcheckTimeout"`

	// Try FailureThreshold times before marking as unhealthy
	FailureThreshold uint `yaml:"healthcheckInterval"`

	// Minimum consecutive successes required to mark as healthy
	SuccessThreshold uint `yaml:"healthcheckInterval"`
}

type JSONRPCResponse

type JSONRPCResponse struct {
	Jsonrpc string `json:"jsonrpc"`
	ID      int    `json:"id"`
	Result  string `json:"result"`
}

type NodeProvider

type NodeProvider struct {
	Config NodeProviderConfig
	Proxy  *httputil.ReverseProxy
}

func NewNodeProvider

func NewNodeProvider(config NodeProviderConfig) (*NodeProvider, error)

func (*NodeProvider) Name

func (n *NodeProvider) Name() string

func (*NodeProvider) ServeHTTP

func (n *NodeProvider) ServeHTTP(w http.ResponseWriter, r *http.Request)

type NodeProviderConfig

type NodeProviderConfig struct {
	Name       string                       `yaml:"name"`
	Connection NodeProviderConnectionConfig `yaml:"connection"`
}

type NodeProviderConnectionConfig

type NodeProviderConnectionConfig struct {
	HTTP NodeProviderConnectionHTTPConfig `yaml:"http"`
}

type NodeProviderConnectionHTTPConfig

type NodeProviderConnectionHTTPConfig struct {
	URL         string `yaml:"url"`
	Compression bool   `yaml:"compression"`
}

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

func NewProxy

func NewProxy(config Config) (*Proxy, error)

func (*Proxy) HasNodeProviderFailed

func (p *Proxy) HasNodeProviderFailed(statusCode int) bool

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ProxyConfig

type ProxyConfig struct {
	Port            string        `yaml:"port"`
	UpstreamTimeout time.Duration `yaml:"upstreamTimeout"`
}

type ReponseWriter

type ReponseWriter struct {
	// contains filtered or unexported fields
}

func NewResponseWriter

func NewResponseWriter() *ReponseWriter

func (*ReponseWriter) Header

func (p *ReponseWriter) Header() http.Header

func (*ReponseWriter) Write

func (p *ReponseWriter) Write(b []byte) (int, error)

func (*ReponseWriter) WriteHeader

func (p *ReponseWriter) WriteHeader(statusCode int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL