Documentation ¶
Index ¶
- Constants
- Variables
- func CreateTLSClient(ca string) (*tls.Config, error)
- func GetAuthCtx(ctx context.Context) string
- func GetReqID(ctx context.Context) string
- func GetXForwardedFor(ctx context.Context) string
- func IsBatch(raw []byte) bool
- func IsValidID(id json.RawMessage) bool
- func MaybeRecordErrorsInRPCRes(ctx context.Context, backendName string, reqs []*RPCReq, resBatch []*RPCRes)
- func MaybeRecordSpecialRPCError(ctx context.Context, backendName, method string, rpcErr *RPCErr)
- func ParseBatchRPCReq(body []byte) ([]json.RawMessage, error)
- func ParseKeyPair(crt, key string) (tls.Certificate, error)
- func ReadFromEnvOrConfig(value string) (string, error)
- func RecordBatchRPCError(ctx context.Context, backendName string, reqs []*RPCReq, err error)
- func RecordBatchRPCForward(ctx context.Context, backendName string, reqs []*RPCReq, source string)
- func RecordCacheHit(method string)
- func RecordCacheMiss(method string)
- func RecordRPCError(ctx context.Context, backendName, method string, err error)
- func RecordRPCForward(ctx context.Context, backendName, method, source string)
- func RecordRedisError(source string)
- func RecordRequestPayloadSize(ctx context.Context, payloadSize int)
- func RecordResponsePayloadSize(ctx context.Context, payloadSize int)
- func RecordUnserviceableRequest(ctx context.Context, source string)
- func RecordWSMessage(ctx context.Context, backendName, source string)
- func Start(config *Config) (func(), error)
- func ValidateRPCReq(req *RPCReq) error
- type Backend
- func (b *Backend) Forward(ctx context.Context, reqs []*RPCReq, isBatch bool) ([]*RPCRes, error)
- func (b *Backend) IsRateLimited() bool
- func (b *Backend) IsWSSaturated() bool
- func (b *Backend) Online() bool
- func (b *Backend) ProxyWS(clientConn *websocket.Conn, methodWhitelist *StringSet) (*WSProxier, error)
- type BackendConfig
- type BackendGroup
- type BackendGroupConfig
- type BackendGroupsConfig
- type BackendOpt
- func WithBasicAuth(username, password string) BackendOpt
- func WithMaxRPS(maxRPS int) BackendOpt
- func WithMaxResponseSize(size int64) BackendOpt
- func WithMaxRetries(retries int) BackendOpt
- func WithMaxWSConns(maxConns int) BackendOpt
- func WithOutOfServiceDuration(interval time.Duration) BackendOpt
- func WithProxydIP(ip string) BackendOpt
- func WithStrippedTrailingXFF() BackendOpt
- func WithTLSConfig(tlsConfig *tls.Config) BackendOpt
- func WithTimeout(timeout time.Duration) BackendOpt
- type BackendOptions
- type BackendsConfig
- type Cache
- type CacheConfig
- type Config
- type EthBlockNumberMethodHandler
- type EthCallMethodHandler
- type EthGasPriceMethodHandler
- type EthGetBlockByNumberMethodHandler
- type EthGetBlockRangeMethodHandler
- type EthLastValueCache
- type GetLatestBlockNumFn
- type GetLatestGasPriceFn
- type LimitedHTTPClient
- type LocalRateLimiter
- func (l *LocalRateLimiter) DecBackendWSConns(name string) error
- func (l *LocalRateLimiter) FlushBackendWSConns(names []string) error
- func (l *LocalRateLimiter) IncBackendRPS(name string) (int, error)
- func (l *LocalRateLimiter) IncBackendWSConns(name string, max int) (bool, error)
- func (l *LocalRateLimiter) IsBackendOnline(name string) (bool, error)
- func (l *LocalRateLimiter) SetBackendOffline(name string, duration time.Duration) error
- type MethodMappingsConfig
- type MetricsConfig
- type NoopRPCCache
- type RPCCache
- type RPCErr
- type RPCMethodHandler
- type RPCReq
- type RPCRes
- type RateLimiter
- type RedisConfig
- type RedisRateLimiter
- func (r *RedisRateLimiter) DecBackendWSConns(name string) error
- func (r *RedisRateLimiter) FlushBackendWSConns(names []string) error
- func (r *RedisRateLimiter) IncBackendRPS(name string) (int, error)
- func (r *RedisRateLimiter) IncBackendWSConns(name string, max int) (bool, error)
- func (r *RedisRateLimiter) IsBackendOnline(name string) (bool, error)
- func (r *RedisRateLimiter) SetBackendOffline(name string, duration time.Duration) error
- type Server
- func (s *Server) HandleHealthz(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleWS(w http.ResponseWriter, r *http.Request)
- func (s *Server) RPCListenAndServe(host string, port int) error
- func (s *Server) Shutdown()
- func (s *Server) WSListenAndServe(host string, port int) error
- type ServerConfig
- type StaticMethodHandler
- type StringSet
- type WSProxier
Constants ¶
View Source
const ( JSONRPCVersion = "2.0" JSONRPCErrorInternal = -32000 )
View Source
const ( MetricsNamespace = "proxyd" RPCRequestSourceHTTP = "http" RPCRequestSourceWS = "ws" BackendProxyd = "proxyd" SourceClient = "client" SourceBackend = "backend" MethodUnknown = "unknown" )
View Source
const ( ContextKeyAuth = "authorization" ContextKeyReqID = "req_id" ContextKeyXForwardedFor = "x_forwarded_for" MaxBatchRPCCalls = 100 )
View Source
const MaxConcurrentWSConnsScript = `` /* 351-byte string literal not displayed */
View Source
const MaxRPSScript = `` /* 130-byte string literal not displayed */
Variables ¶
View Source
var ( ErrParseErr = &RPCErr{ Code: -32700, Message: "parse error", HTTPErrorCode: 400, } ErrInternal = &RPCErr{ Code: JSONRPCErrorInternal, Message: "internal error", HTTPErrorCode: 500, } ErrMethodNotWhitelisted = &RPCErr{ Code: JSONRPCErrorInternal - 1, Message: "rpc method is not whitelisted", HTTPErrorCode: 403, } ErrBackendOffline = &RPCErr{ Code: JSONRPCErrorInternal - 10, Message: "backend offline", HTTPErrorCode: 503, } ErrNoBackends = &RPCErr{ Code: JSONRPCErrorInternal - 11, Message: "no backends available for method", HTTPErrorCode: 503, } ErrBackendOverCapacity = &RPCErr{ Code: JSONRPCErrorInternal - 12, Message: "backend is over capacity", HTTPErrorCode: 429, } ErrBackendBadResponse = &RPCErr{ Code: JSONRPCErrorInternal - 13, Message: "backend returned an invalid response", HTTPErrorCode: 500, } ErrTooManyBatchRequests = &RPCErr{ Code: JSONRPCErrorInternal - 14, Message: "too many RPC calls in batch request", } ErrGatewayTimeout = &RPCErr{ Code: JSONRPCErrorInternal - 15, Message: "gateway timeout", HTTPErrorCode: 504, } )
View Source
var MillisecondDurationBuckets = []float64{1, 10, 50, 100, 500, 1000, 5000, 10000, 100000}
View Source
var PayloadSizeBuckets = []float64{10, 50, 100, 500, 1000, 5000, 10000, 100000, 1000000}
Functions ¶
func GetAuthCtx ¶
func GetXForwardedFor ¶
func IsValidID ¶
func IsValidID(id json.RawMessage) bool
func ParseBatchRPCReq ¶
func ParseBatchRPCReq(body []byte) ([]json.RawMessage, error)
func ParseKeyPair ¶
func ParseKeyPair(crt, key string) (tls.Certificate, error)
func ReadFromEnvOrConfig ¶
func RecordBatchRPCError ¶
func RecordBatchRPCForward ¶
func RecordCacheHit ¶
func RecordCacheHit(method string)
func RecordCacheMiss ¶
func RecordCacheMiss(method string)
func RecordRPCError ¶
func RecordRPCForward ¶
func RecordRedisError ¶
func RecordRedisError(source string)
func RecordWSMessage ¶
func ValidateRPCReq ¶
Types ¶
type Backend ¶
type Backend struct { Name string // contains filtered or unexported fields }
func NewBackend ¶
func NewBackend( name string, rpcURL string, wsURL string, rateLimiter RateLimiter, rpcSemaphore *semaphore.Weighted, opts ...BackendOpt, ) *Backend
func (*Backend) IsRateLimited ¶
func (*Backend) IsWSSaturated ¶
type BackendConfig ¶
type BackendConfig struct { Username string `toml:"username"` Password string `toml:"password"` RPCURL string `toml:"rpc_url"` WSURL string `toml:"ws_url"` MaxRPS int `toml:"max_rps"` MaxWSConns int `toml:"max_ws_conns"` CAFile string `toml:"ca_file"` ClientCertFile string `toml:"client_cert_file"` ClientKeyFile string `toml:"client_key_file"` StripTrailingXFF bool `toml:"strip_trailing_xff"` }
type BackendGroup ¶
type BackendGroupConfig ¶
type BackendGroupConfig struct {
Backends []string `toml:"backends"`
}
type BackendGroupsConfig ¶
type BackendGroupsConfig map[string]*BackendGroupConfig
type BackendOpt ¶
type BackendOpt func(b *Backend)
func WithBasicAuth ¶
func WithBasicAuth(username, password string) BackendOpt
func WithMaxRPS ¶
func WithMaxRPS(maxRPS int) BackendOpt
func WithMaxResponseSize ¶
func WithMaxResponseSize(size int64) BackendOpt
func WithMaxRetries ¶
func WithMaxRetries(retries int) BackendOpt
func WithMaxWSConns ¶
func WithMaxWSConns(maxConns int) BackendOpt
func WithOutOfServiceDuration ¶
func WithOutOfServiceDuration(interval time.Duration) BackendOpt
func WithProxydIP ¶
func WithProxydIP(ip string) BackendOpt
func WithStrippedTrailingXFF ¶
func WithStrippedTrailingXFF() BackendOpt
func WithTLSConfig ¶
func WithTLSConfig(tlsConfig *tls.Config) BackendOpt
func WithTimeout ¶
func WithTimeout(timeout time.Duration) BackendOpt
type BackendOptions ¶
type BackendsConfig ¶
type BackendsConfig map[string]*BackendConfig
type CacheConfig ¶
type Config ¶
type Config struct { WSBackendGroup string `toml:"ws_backend_group"` Server ServerConfig `toml:"server"` Cache CacheConfig `toml:"cache"` Redis RedisConfig `toml:"redis"` Metrics MetricsConfig `toml:"metrics"` BackendOptions BackendOptions `toml:"backend"` Backends BackendsConfig `toml:"backends"` Authentication map[string]string `toml:"authentication"` BackendGroups BackendGroupsConfig `toml:"backend_groups"` RPCMethodMappings map[string]string `toml:"rpc_method_mappings"` WSMethodWhitelist []string `toml:"ws_method_whitelist"` }
type EthBlockNumberMethodHandler ¶
type EthBlockNumberMethodHandler struct {
// contains filtered or unexported fields
}
func (*EthBlockNumberMethodHandler) GetRPCMethod ¶
func (*EthBlockNumberMethodHandler) PutRPCMethod ¶
type EthCallMethodHandler ¶
type EthCallMethodHandler struct {
// contains filtered or unexported fields
}
func (*EthCallMethodHandler) GetRPCMethod ¶
func (*EthCallMethodHandler) PutRPCMethod ¶
type EthGasPriceMethodHandler ¶
type EthGasPriceMethodHandler struct {
// contains filtered or unexported fields
}
func (*EthGasPriceMethodHandler) GetRPCMethod ¶
func (*EthGasPriceMethodHandler) PutRPCMethod ¶
type EthGetBlockByNumberMethodHandler ¶
type EthGetBlockByNumberMethodHandler struct {
// contains filtered or unexported fields
}
func (*EthGetBlockByNumberMethodHandler) GetRPCMethod ¶
func (*EthGetBlockByNumberMethodHandler) PutRPCMethod ¶
type EthGetBlockRangeMethodHandler ¶
type EthGetBlockRangeMethodHandler struct {
// contains filtered or unexported fields
}
func (*EthGetBlockRangeMethodHandler) GetRPCMethod ¶
func (*EthGetBlockRangeMethodHandler) PutRPCMethod ¶
type EthLastValueCache ¶
type EthLastValueCache struct {
// contains filtered or unexported fields
}
func (*EthLastValueCache) Read ¶
func (h *EthLastValueCache) Read(ctx context.Context) (string, error)
func (*EthLastValueCache) Start ¶
func (h *EthLastValueCache) Start()
func (*EthLastValueCache) Stop ¶
func (h *EthLastValueCache) Stop()
type LimitedHTTPClient ¶
type LocalRateLimiter ¶
type LocalRateLimiter struct {
// contains filtered or unexported fields
}
func NewLocalRateLimiter ¶
func NewLocalRateLimiter() *LocalRateLimiter
func (*LocalRateLimiter) DecBackendWSConns ¶
func (l *LocalRateLimiter) DecBackendWSConns(name string) error
func (*LocalRateLimiter) FlushBackendWSConns ¶
func (l *LocalRateLimiter) FlushBackendWSConns(names []string) error
func (*LocalRateLimiter) IncBackendRPS ¶
func (l *LocalRateLimiter) IncBackendRPS(name string) (int, error)
func (*LocalRateLimiter) IncBackendWSConns ¶
func (l *LocalRateLimiter) IncBackendWSConns(name string, max int) (bool, error)
func (*LocalRateLimiter) IsBackendOnline ¶
func (l *LocalRateLimiter) IsBackendOnline(name string) (bool, error)
func (*LocalRateLimiter) SetBackendOffline ¶
func (l *LocalRateLimiter) SetBackendOffline(name string, duration time.Duration) error
type MethodMappingsConfig ¶
type MetricsConfig ¶
type RPCErr ¶
type RPCErr struct { Code int `json:"code"` Message string `json:"message"` HTTPErrorCode int `json:"-"` }
func ErrInvalidRequest ¶
type RPCMethodHandler ¶
type RPCReq ¶
type RPCReq struct { JSONRPC string `json:"jsonrpc"` Method string `json:"method"` Params json.RawMessage `json:"params"` ID json.RawMessage `json:"id"` }
func ParseRPCReq ¶
type RPCRes ¶
type RPCRes struct { JSONRPC string Result interface{} Error *RPCErr ID json.RawMessage }
func NewRPCErrorRes ¶
func NewRPCErrorRes(id json.RawMessage, err error) *RPCRes
func (*RPCRes) MarshalJSON ¶
type RateLimiter ¶
type RateLimiter interface { IsBackendOnline(name string) (bool, error) SetBackendOffline(name string, duration time.Duration) error IncBackendRPS(name string) (int, error) IncBackendWSConns(name string, max int) (bool, error) DecBackendWSConns(name string) error FlushBackendWSConns(names []string) error }
func NewRedisRateLimiter ¶
func NewRedisRateLimiter(url string) (RateLimiter, error)
type RedisConfig ¶
type RedisConfig struct {
URL string `toml:"url"`
}
type RedisRateLimiter ¶
type RedisRateLimiter struct {
// contains filtered or unexported fields
}
func (*RedisRateLimiter) DecBackendWSConns ¶
func (r *RedisRateLimiter) DecBackendWSConns(name string) error
func (*RedisRateLimiter) FlushBackendWSConns ¶
func (r *RedisRateLimiter) FlushBackendWSConns(names []string) error
func (*RedisRateLimiter) IncBackendRPS ¶
func (r *RedisRateLimiter) IncBackendRPS(name string) (int, error)
func (*RedisRateLimiter) IncBackendWSConns ¶
func (r *RedisRateLimiter) IncBackendWSConns(name string, max int) (bool, error)
func (*RedisRateLimiter) IsBackendOnline ¶
func (r *RedisRateLimiter) IsBackendOnline(name string) (bool, error)
func (*RedisRateLimiter) SetBackendOffline ¶
func (r *RedisRateLimiter) SetBackendOffline(name string, duration time.Duration) error
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) HandleHealthz ¶
func (s *Server) HandleHealthz(w http.ResponseWriter, r *http.Request)
type ServerConfig ¶
type ServerConfig struct { RPCHost string `toml:"rpc_host"` RPCPort int `toml:"rpc_port"` WSHost string `toml:"ws_host"` WSPort int `toml:"ws_port"` MaxBodySizeBytes int64 `toml:"max_body_size_bytes"` MaxConcurrentRPCs int64 `toml:"max_concurrent_rpcs"` // TimeoutSeconds specifies the maximum time spent serving an HTTP request. Note that isn't used for websocket connections TimeoutSeconds int `toml:"timeout_seconds"` MaxUpstreamBatchSize int `toml:"max_upstream_batch_size"` }
type StaticMethodHandler ¶
type StaticMethodHandler struct {
// contains filtered or unexported fields
}
func (*StaticMethodHandler) GetRPCMethod ¶
func (*StaticMethodHandler) PutRPCMethod ¶
type StringSet ¶
type StringSet struct {
// contains filtered or unexported fields
}
func NewStringSet ¶
func NewStringSet() *StringSet
func NewStringSetFromStrings ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.