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 BackendRateLimiter
- 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 LocalBackendRateLimiter
- func (l *LocalBackendRateLimiter) DecBackendWSConns(name string) error
- func (l *LocalBackendRateLimiter) FlushBackendWSConns(names []string) error
- func (l *LocalBackendRateLimiter) IncBackendRPS(name string) (int, error)
- func (l *LocalBackendRateLimiter) IncBackendWSConns(name string, max int) (bool, error)
- func (l *LocalBackendRateLimiter) IsBackendOnline(name string) (bool, error)
- func (l *LocalBackendRateLimiter) SetBackendOffline(name string, duration time.Duration) error
- type MethodMappingsConfig
- type MetricsConfig
- type NoopRPCCache
- type RPCCache
- type RPCErr
- type RPCMethodHandler
- type RPCReq
- type RPCRes
- type RateLimitConfig
- type RedisBackendRateLimiter
- func (r *RedisBackendRateLimiter) DecBackendWSConns(name string) error
- func (r *RedisBackendRateLimiter) FlushBackendWSConns(names []string) error
- func (r *RedisBackendRateLimiter) IncBackendRPS(name string) (int, error)
- func (r *RedisBackendRateLimiter) IncBackendWSConns(name string, max int) (bool, error)
- func (r *RedisBackendRateLimiter) IsBackendOnline(name string) (bool, error)
- func (r *RedisBackendRateLimiter) SetBackendOffline(name string, duration time.Duration) error
- type RedisConfig
- 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 ServerRateLimiter
- 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, } ErrOverRateLimit = &RPCErr{ Code: JSONRPCErrorInternal - 16, Message: "rate limited", HTTPErrorCode: 429, } ErrBackendUnexpectedJSONRPC = errors.New("backend returned an unexpected JSON-RPC response") )
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 BackendRateLimiter, 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 BackendRateLimiter ¶
type BackendRateLimiter 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) (BackendRateLimiter, error)
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"` RateLimit RateLimitConfig `toml:"rate_limit"` 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 LocalBackendRateLimiter ¶
type LocalBackendRateLimiter struct {
// contains filtered or unexported fields
}
func NewLocalBackendRateLimiter ¶
func NewLocalBackendRateLimiter() *LocalBackendRateLimiter
func (*LocalBackendRateLimiter) DecBackendWSConns ¶
func (l *LocalBackendRateLimiter) DecBackendWSConns(name string) error
func (*LocalBackendRateLimiter) FlushBackendWSConns ¶
func (l *LocalBackendRateLimiter) FlushBackendWSConns(names []string) error
func (*LocalBackendRateLimiter) IncBackendRPS ¶
func (l *LocalBackendRateLimiter) IncBackendRPS(name string) (int, error)
func (*LocalBackendRateLimiter) IncBackendWSConns ¶
func (l *LocalBackendRateLimiter) IncBackendWSConns(name string, max int) (bool, error)
func (*LocalBackendRateLimiter) IsBackendOnline ¶
func (l *LocalBackendRateLimiter) IsBackendOnline(name string) (bool, error)
func (*LocalBackendRateLimiter) SetBackendOffline ¶
func (l *LocalBackendRateLimiter) 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 NewRPCRes ¶
func NewRPCRes(id json.RawMessage, result interface{}) *RPCRes
func (*RPCRes) MarshalJSON ¶
type RateLimitConfig ¶
type RedisBackendRateLimiter ¶
type RedisBackendRateLimiter struct {
// contains filtered or unexported fields
}
func (*RedisBackendRateLimiter) DecBackendWSConns ¶
func (r *RedisBackendRateLimiter) DecBackendWSConns(name string) error
func (*RedisBackendRateLimiter) FlushBackendWSConns ¶
func (r *RedisBackendRateLimiter) FlushBackendWSConns(names []string) error
func (*RedisBackendRateLimiter) IncBackendRPS ¶
func (r *RedisBackendRateLimiter) IncBackendRPS(name string) (int, error)
func (*RedisBackendRateLimiter) IncBackendWSConns ¶
func (r *RedisBackendRateLimiter) IncBackendWSConns(name string, max int) (bool, error)
func (*RedisBackendRateLimiter) IsBackendOnline ¶
func (r *RedisBackendRateLimiter) IsBackendOnline(name string) (bool, error)
func (*RedisBackendRateLimiter) SetBackendOffline ¶
func (r *RedisBackendRateLimiter) SetBackendOffline(name string, duration time.Duration) error
type RedisConfig ¶
type RedisConfig struct {
URL string `toml:"url"`
}
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer( backendGroups map[string]*BackendGroup, wsBackendGroup *BackendGroup, wsMethodWhitelist *StringSet, rpcMethodMappings map[string]string, maxBodySize int64, authenticatedPaths map[string]string, timeout time.Duration, maxUpstreamBatchSize int, cache RPCCache, rateLimitConfig RateLimitConfig, enableRequestLog bool, maxRequestBodyLogLen int, ) (*Server, error)
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"` EnableRequestLog bool `toml:"enable_request_log"` MaxRequestBodyLogLen int `toml:"max_request_body_log_len"` }
type ServerRateLimiter ¶
type ServerRateLimiter struct { }
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.