├── version └── version.go ├── funding.json ├── aggregator ├── keys.go ├── node.go └── errors.go ├── middleware ├── plugins │ ├── plugins.go │ ├── load_balance.go │ ├── cors.go │ ├── requests_validator.go │ ├── http_proxy.go │ └── safety.go └── middleware.go ├── proxy ├── http_proxy.go └── pool.go ├── utils ├── crypto_test.go └── crypto.go ├── cmd └── aggregator │ ├── commands │ ├── init.go │ ├── root.go │ └── run.go │ └── main.go ├── .gitignore ├── notify └── notify.go ├── safety └── safety.go ├── Makefile ├── Dockerfile ├── loadbalance ├── selectors.go └── wr.go ├── client └── httpclient.go ├── run.sh ├── server ├── server.go └── manage_server.go ├── README.md ├── rpc ├── session.go └── jsonrpc.go ├── go.mod ├── log └── logger.go ├── config └── config.go ├── go.sum └── LICENSE /version/version.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | var ( 4 | Version string 5 | ) 6 | -------------------------------------------------------------------------------- /funding.json: -------------------------------------------------------------------------------- 1 | { 2 | "opRetro": { 3 | "projectId": "0xc8baf94c13404f1f5f1fb13de286c052bae58919ca80fd2be5d61312be096b35" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /aggregator/keys.go: -------------------------------------------------------------------------------- 1 | package aggregator 2 | 3 | var ( 4 | KeyDbConfig = []byte("config") 5 | 6 | KeyDbDeniedReceiver = []byte("denied-receiver") 7 | ) 8 | -------------------------------------------------------------------------------- /middleware/plugins/plugins.go: -------------------------------------------------------------------------------- 1 | package plugins 2 | 3 | import "github.com/BlockPILabs/aggregator/log" 4 | 5 | var ( 6 | logger = log.Module("plugins") 7 | ) 8 | -------------------------------------------------------------------------------- /proxy/http_proxy.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import "github.com/valyala/fasthttp" 4 | 5 | type HttpProxy struct { 6 | clients []*fasthttp.Client 7 | } 8 | 9 | func (p *HttpProxy) getClient() *fasthttp.Client { 10 | if p.clients == nil { 11 | return nil 12 | 13 | } 14 | return p.clients[0] 15 | } 16 | -------------------------------------------------------------------------------- /utils/crypto_test.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import "testing" 4 | 5 | func TestDecode(t *testing.T) { 6 | DecodeTx("0x02f875822019018505a569a280850ca18d4e808252089468349009458626e35da0eea9cb583b3c828bb815872386f26fc1000080c080a06efc84d692ebb0a04912f73bcb0ba0d7cd44df6d6c2261d07df439af707212f2a04cd68168788c55426761d7ad70d789c12eda66685a6e99a35a90c386e165fa85") 7 | } 8 | -------------------------------------------------------------------------------- /cmd/aggregator/commands/init.go: -------------------------------------------------------------------------------- 1 | package commands 2 | 3 | import ( 4 | "github.com/urfave/cli/v2" 5 | ) 6 | 7 | func InitCommand() *cli.Command { 8 | return &cli.Command{ 9 | Name: "init", 10 | Flags: []cli.Flag{}, 11 | Before: func(context *cli.Context) error { 12 | return nil 13 | }, 14 | Action: func(cli *cli.Context) error { 15 | 16 | return nil 17 | }, 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /aggregator/node.go: -------------------------------------------------------------------------------- 1 | package aggregator 2 | 3 | import "net/url" 4 | 5 | type Node struct { 6 | Name string `json:"name"` 7 | Endpoint string `json:"endpoint"` 8 | Weight int64 `json:"weight"` 9 | ReadOnly bool `json:"read_only"` 10 | Disabled bool `json:"disabled"` 11 | } 12 | 13 | func (node *Node) Host() string { 14 | _url, _ := url.Parse(node.Endpoint) 15 | return _url.Host + ":443" 16 | } 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | .DS_Store 3 | .idea/ 4 | *.exe 5 | *.exe~ 6 | *.dll 7 | *.so 8 | *.dylib 9 | 10 | # Test binary, built with `go test -c` 11 | *.test 12 | 13 | # Output of the go coverage tool, specifically when used with LiteIDE 14 | *.out 15 | 16 | # Dependency directories (remove the comment below to include it) 17 | # vendor/ 18 | build/ 19 | safety/*test* 20 | safety/*.json 21 | safety/*.txt -------------------------------------------------------------------------------- /notify/notify.go: -------------------------------------------------------------------------------- 1 | package notify 2 | 3 | import ( 4 | gonotify "github.com/martinlindhe/notify" 5 | "strings" 6 | ) 7 | 8 | func Send(title string, lines ...string) { 9 | gonotify.Notify("BlockPI RPC Aggregator", title, strings.Join(lines, "\n"), "") 10 | } 11 | 12 | func SendNotice(lines ...string) { 13 | Send("Notice: Aggregator Notice", lines...) 14 | } 15 | 16 | func SendError(lines ...string) { 17 | Send("Alert: An error occurred", lines...) 18 | } 19 | -------------------------------------------------------------------------------- /aggregator/errors.go: -------------------------------------------------------------------------------- 1 | package aggregator 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type Error struct { 8 | Code int 9 | Message string 10 | } 11 | 12 | func (err *Error) Error() string { 13 | return fmt.Sprintf("[%d]%s", err.Code, err.Message) 14 | } 15 | 16 | func NewError(code int, msg string) *Error { 17 | return &Error{Code: code, Message: msg} 18 | } 19 | 20 | var ( 21 | ErrServerError = NewError(-32000, "server error") 22 | ErrInvalidRequest = NewError(-32600, "invalid request") 23 | ErrInvalidMethod = NewError(-32601, "invalid method") 24 | ErrInvalidChain = NewError(-32601, "invalid chain") 25 | ErrMustReturn = NewError(10000, "must return") 26 | ErrDenyRequest = NewError(-32602, "deny request") 27 | ) 28 | -------------------------------------------------------------------------------- /utils/crypto.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "github.com/ethereum/go-ethereum/common" 5 | "github.com/ethereum/go-ethereum/core/types" 6 | ) 7 | 8 | func DecodeTx(hexTx string) (*types.Transaction, error) { 9 | rawTx := common.FromHex(hexTx) 10 | tx := new(types.Transaction) 11 | err := tx.UnmarshalBinary(rawTx) 12 | if err != nil { 13 | return nil, err 14 | } 15 | 16 | //txType := tx.Type() 17 | 18 | //signer := &types.HomesteadSigner{} 19 | 20 | //signer := types.NewEIP155Signer(tx.ChainId()) 21 | // 22 | //addr, err := types.Sender(signer, tx) 23 | //if err != nil { 24 | // return nil, err 25 | //} 26 | // 27 | //hexAddr := addr.Hex() 28 | //fmt.Println(txType, hexAddr) 29 | 30 | return tx, nil 31 | } 32 | -------------------------------------------------------------------------------- /safety/safety.go: -------------------------------------------------------------------------------- 1 | package safety 2 | 3 | import ( 4 | "crypto/md5" 5 | "crypto/sha256" 6 | "encoding/hex" 7 | "strings" 8 | ) 9 | 10 | func GoPlusAddress(address string) string { 11 | address = strings.ToLower(address) + "gopluslabs" 12 | sha256b := sha256.Sum256([]byte(address)) 13 | sha256hash := hex.EncodeToString(sha256b[0:]) 14 | return sha256hash 15 | } 16 | 17 | func RpcHubAddress(address string) string { 18 | address = strings.ToLower(address) + "rpchub" 19 | md5b := md5.Sum([]byte(address)) 20 | md5hash := hex.EncodeToString(md5b[0:]) 21 | return md5hash 22 | } 23 | 24 | func SlowMistAddress(address string) string { 25 | address = strings.ToLower(address) + "SlowMist" 26 | md5b := md5.Sum([]byte(address)) 27 | md5hash := hex.EncodeToString(md5b[0:]) 28 | return md5hash 29 | } 30 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | VERSION := $(shell git describe --tags --always) 2 | CONFIG_URL := https://cfg.rpchub.io/agg/op-default.json 3 | 4 | GOLDFLAGS := -X github.com/BlockPILabs/aggregator/version.Version=$(VERSION) 5 | GO_OPLDFLAGS := -X github.com/BlockPILabs/aggregator/config.DefaultConfigUrl=$(CONFIG_URL) 6 | GOFLAGS = -ldflags "$(GOLDFLAGS)" 7 | 8 | 9 | all: build 10 | 11 | .PHONY: build 12 | build: 13 | CGO_ENABLED=0 go build -ldflags "$(GOLDFLAGS)" -o ./build/ ./cmd/aggregator 14 | build-op: 15 | CGO_ENABLED=0 go build -ldflags "$(GOLDFLAGS) $(GO_OPLDFLAGS)" -o ./build/ ./cmd/aggregator 16 | #build-windows: 17 | # CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build $(GOFLAGS) -o ./build/ ./cmd/aggregator 18 | #build-mac: 19 | # CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build $(GOFLAGS) -o ./build/ ./cmd/aggregator 20 | clean: 21 | rm -rf build/* 22 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Stage 1: Build the Go application 2 | FROM golang:1.19 AS builder 3 | 4 | # Set the working directory 5 | WORKDIR /app 6 | 7 | # Copy the Go Modules manifests 8 | COPY go.mod go.sum ./ 9 | 10 | # Download Go modules 11 | RUN go mod download 12 | 13 | # Copy the source code 14 | COPY . . 15 | 16 | # Build the application 17 | RUN go build -o /app/aggregator ./cmd/aggregator 18 | 19 | # Stage 2: Create a minimal runtime image 20 | FROM golang:1.19 21 | 22 | # Set the working directory 23 | WORKDIR /app 24 | 25 | # Copy the built binary from the builder stage 26 | COPY --from=builder /app/aggregator /app/aggregator 27 | 28 | # Make the binary executable 29 | RUN chmod +x ./aggregator 30 | 31 | # Expose the port that the application listens on (if applicable) 32 | EXPOSE 8012 33 | 34 | # Command to run the application 35 | CMD ["./aggregator/aggregator"] 36 | -------------------------------------------------------------------------------- /cmd/aggregator/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "github.com/BlockPILabs/aggregator/cmd/aggregator/commands" 7 | "github.com/BlockPILabs/aggregator/version" 8 | "os" 9 | "time" 10 | 11 | "github.com/gogf/gf/v2/os/gfile" 12 | ) 13 | 14 | func main() { 15 | println(version.Version) 16 | 17 | time.Local = time.UTC 18 | initPath() 19 | 20 | app := commands.RootApp() 21 | err := app.Run(os.Args) 22 | if err != nil { 23 | panic(err) 24 | } 25 | 26 | } 27 | 28 | func initPath() { 29 | dir, err := gfile.Home(".rpchub/aggregator") 30 | if err != nil { 31 | panic(err) 32 | } 33 | 34 | if !gfile.Exists(dir) { 35 | err = os.MkdirAll(dir, 0700) 36 | if err != nil { 37 | panic(err) 38 | } 39 | } 40 | 41 | if !gfile.IsDir(dir) { 42 | panic(errors.New(fmt.Sprintf("%s is not a dir", dir))) 43 | } 44 | 45 | err = os.Chdir(dir) 46 | if err != nil { 47 | panic(err) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /loadbalance/selectors.go: -------------------------------------------------------------------------------- 1 | package loadbalance 2 | 3 | import ( 4 | "github.com/BlockPILabs/aggregator/aggregator" 5 | "github.com/BlockPILabs/aggregator/config" 6 | "github.com/BlockPILabs/aggregator/log" 7 | "sync" 8 | ) 9 | 10 | var ( 11 | _selectors = map[string]*WrSelector{} 12 | _mutex sync.Mutex 13 | logger = log.Module("load-balance") 14 | ) 15 | 16 | func SetNodes(chain string, nodes []aggregator.Node) { 17 | _mutex.Lock() 18 | defer _mutex.Unlock() 19 | 20 | selector := &WrSelector{} 21 | selector.SetNodes(nodes) 22 | _selectors[chain] = selector 23 | } 24 | 25 | func NextNode(chain string) *aggregator.Node { 26 | _mutex.Lock() 27 | defer _mutex.Unlock() 28 | 29 | selector := _selectors[chain] 30 | if selector != nil { 31 | return selector.NextNode() 32 | } 33 | 34 | return nil 35 | } 36 | 37 | func LoadFromConfig() { 38 | for chain, nodes := range config.Default().Nodes { 39 | logger.Info("New load balancer", "chain", chain, "nodes", len(nodes)) 40 | SetNodes(chain, nodes) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /client/httpclient.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "github.com/valyala/fasthttp" 5 | "github.com/valyala/fasthttp/fasthttpproxy" 6 | "strings" 7 | "time" 8 | ) 9 | 10 | type Client struct { 11 | client fasthttp.Client 12 | timeout int64 13 | maxRetries int64 14 | proxy string 15 | } 16 | 17 | func DefaultClient() *Client { 18 | return NewClient(30, "") 19 | } 20 | 21 | func NewClient(timeout int64, proxy string) *Client { 22 | cli := &Client{ 23 | client: fasthttp.Client{ 24 | MaxConnsPerHost: 65000, 25 | //Dial: func(addr string) (net.Conn, error) { 26 | // return nil, nil 27 | //}, 28 | }, 29 | timeout: timeout, 30 | proxy: proxy, 31 | } 32 | if proxy != "" { 33 | if strings.HasPrefix(proxy, "socks5://") { 34 | cli.client.Dial = fasthttpproxy.FasthttpSocksDialer(proxy) 35 | } else { 36 | cli.client.Dial = fasthttpproxy.FasthttpHTTPDialer(proxy) 37 | } 38 | } 39 | return cli 40 | } 41 | 42 | func (cli *Client) Do(req *fasthttp.Request, resp *fasthttp.Response) error { 43 | return cli.client.DoTimeout(req, resp, time.Second*time.Duration(cli.timeout)) 44 | } 45 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Define variables 4 | IMAGE_NAME="my-aggregator-image" 5 | CONTAINER_NAME="aggregator-container" 6 | HOST_PORT=8012 7 | CONTAINER_PORT=8012 8 | 9 | # Navigate to the project root directory 10 | cd "$(dirname "$0")" 11 | 12 | # Stop and remove any existing container with the same name 13 | if [ "$(docker ps -q -f name=$CONTAINER_NAME)" ]; then 14 | echo "Stopping existing container..." 15 | docker stop $CONTAINER_NAME 16 | fi 17 | 18 | if [ "$(docker ps -aq -f name=$CONTAINER_NAME)" ]; then 19 | echo "Removing existing container..." 20 | docker rm $CONTAINER_NAME 21 | fi 22 | 23 | # Remove the old image 24 | if [ "$(docker images -q $IMAGE_NAME)" ]; then 25 | echo "Removing old Docker image..." 26 | docker rmi $IMAGE_NAME 27 | fi 28 | 29 | # Build the Docker image 30 | echo "Building Docker image..." 31 | docker build -t $IMAGE_NAME . 32 | 33 | # Run the Docker container 34 | echo "Running Docker container..." 35 | docker run -d -p $HOST_PORT:$CONTAINER_PORT --name $CONTAINER_NAME $IMAGE_NAME 36 | 37 | # Display running containers 38 | docker ps 39 | 40 | echo "Aggregator is now running on port $HOST_PORT" 41 | -------------------------------------------------------------------------------- /cmd/aggregator/commands/root.go: -------------------------------------------------------------------------------- 1 | package commands 2 | 3 | import ( 4 | "errors" 5 | "github.com/urfave/cli/v2" 6 | "os" 7 | ) 8 | 9 | func RootApp() *cli.App { 10 | runCmd := RunCommand() 11 | cmd := &cli.App{ 12 | Name: "aggregator", 13 | Usage: "RPCHub aggregator", 14 | Flags: runCmd.Flags, 15 | EnableBashCompletion: true, 16 | BashComplete: cli.DefaultAppComplete, 17 | Before: func(cli *cli.Context) error { 18 | if err := initConfig(cli); err != nil { 19 | return err 20 | } 21 | return nil 22 | }, 23 | Action: func(cli *cli.Context) error { 24 | return runCommand(cli, "run", os.Args[1:]...) 25 | }, 26 | Commands: []*cli.Command{ 27 | runCmd, 28 | InitCommand(), 29 | }, 30 | } 31 | return cmd 32 | } 33 | 34 | func runCommand(app *cli.Context, cmd string, args ...string) error { 35 | args = append([]string{app.App.Name, cmd}, args...) 36 | 37 | subCommand := app.App.Command(cmd) 38 | if subCommand == nil { 39 | return errors.New("not sub command : " + cmd) 40 | } 41 | 42 | subCommand.SkipFlagParsing = true 43 | subCommand.Flags = []cli.Flag{} 44 | return subCommand.Run(app) 45 | } 46 | 47 | func initConfig(cli *cli.Context) error { 48 | //viper.SetConfigFile(cli.String(config.FlagConfigFile.Name)) 49 | 50 | //return config.LoadConfig() 51 | return nil 52 | } 53 | -------------------------------------------------------------------------------- /cmd/aggregator/commands/run.go: -------------------------------------------------------------------------------- 1 | package commands 2 | 3 | import ( 4 | "github.com/BlockPILabs/aggregator/config" 5 | "github.com/BlockPILabs/aggregator/loadbalance" 6 | "github.com/BlockPILabs/aggregator/middleware" 7 | "github.com/BlockPILabs/aggregator/middleware/plugins" 8 | "github.com/BlockPILabs/aggregator/server" 9 | "github.com/urfave/cli/v2" 10 | "golang.org/x/sync/errgroup" 11 | ) 12 | 13 | func RunCommand() *cli.Command { 14 | return &cli.Command{ 15 | Name: "run", 16 | Aliases: []string{"start"}, 17 | Flags: append([]cli.Flag{}, InitCommand().Flags...), 18 | Before: func(cli *cli.Context) error { 19 | err := runCommand(cli, "init") 20 | if err != nil { 21 | return err 22 | } 23 | 24 | config.Load() 25 | 26 | loadbalance.LoadFromConfig() 27 | 28 | middleware.Append( 29 | plugins.NewRequestValidatorMiddleware(), 30 | plugins.NewSafetyMiddleware(), 31 | plugins.NewLoadBalanceMiddleware(), 32 | plugins.NewHttpProxyMiddleware(), 33 | plugins.NewCorsMiddleware(), 34 | ) 35 | 36 | return nil 37 | }, 38 | Action: func(context *cli.Context) error { 39 | wg := errgroup.Group{} 40 | wg.Go(func() error { 41 | return server.NewManageServer() 42 | }) 43 | wg.Go(func() error { 44 | return server.NewServer() 45 | }) 46 | return wg.Wait() 47 | }, 48 | Subcommands: []*cli.Command{}, 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /loadbalance/wr.go: -------------------------------------------------------------------------------- 1 | package loadbalance 2 | 3 | import ( 4 | "github.com/BlockPILabs/aggregator/aggregator" 5 | "github.com/BlockPILabs/aggregator/notify" 6 | "math/rand" 7 | "sync" 8 | ) 9 | 10 | // WrSelector weighted-random selector 11 | type WrSelector struct { 12 | nodes []aggregator.Node 13 | sumWeight int64 14 | 15 | mutex sync.Mutex 16 | } 17 | 18 | func (s *WrSelector) SetNodes(nodes []aggregator.Node) { 19 | s.mutex.Lock() 20 | defer s.mutex.Unlock() 21 | 22 | var nodesSelected []aggregator.Node 23 | var sumWeight int64 = 0 24 | for _, node := range nodes { 25 | if !node.Disabled { 26 | if node.Weight > 0 && len(node.Endpoint) > 0 { 27 | sumWeight += node.Weight 28 | nodesSelected = append(nodesSelected, node) 29 | } else { 30 | notify.SendError("load balance: node is not selected", node.Name, node.Endpoint) 31 | } 32 | } else { 33 | logger.Warn("Node is disabled", "node", node.Name, "endpoint", node.Endpoint) 34 | } 35 | } 36 | s.nodes = nodesSelected 37 | s.sumWeight = sumWeight 38 | } 39 | 40 | func (s *WrSelector) NextNode() *aggregator.Node { 41 | s.mutex.Lock() 42 | defer s.mutex.Unlock() 43 | 44 | if s.sumWeight > 0 { 45 | w := rand.Int63n(s.sumWeight) 46 | var weight int64 = 0 47 | for _, node := range s.nodes { 48 | //if !node.Disabled { 49 | weight += node.Weight 50 | if weight >= w { 51 | return &node 52 | } 53 | //} 54 | } 55 | } 56 | return nil 57 | } 58 | -------------------------------------------------------------------------------- /middleware/plugins/load_balance.go: -------------------------------------------------------------------------------- 1 | package plugins 2 | 3 | import ( 4 | "github.com/BlockPILabs/aggregator/aggregator" 5 | "github.com/BlockPILabs/aggregator/loadbalance" 6 | "github.com/BlockPILabs/aggregator/middleware" 7 | "github.com/BlockPILabs/aggregator/rpc" 8 | "github.com/valyala/fasthttp" 9 | ) 10 | 11 | type LoadBalanceMiddleware struct { 12 | nextMiddleware middleware.Middleware 13 | enabled bool 14 | } 15 | 16 | func NewLoadBalanceMiddleware() *LoadBalanceMiddleware { 17 | return &LoadBalanceMiddleware{enabled: true} 18 | } 19 | 20 | func (m *LoadBalanceMiddleware) Name() string { 21 | return "LoadBalanceMiddleware" 22 | } 23 | 24 | func (m *LoadBalanceMiddleware) Enabled() bool { 25 | return m.enabled 26 | } 27 | 28 | func (m *LoadBalanceMiddleware) Next() middleware.Middleware { 29 | return m.nextMiddleware 30 | } 31 | 32 | func (m *LoadBalanceMiddleware) SetNext(middleware middleware.Middleware) { 33 | m.nextMiddleware = middleware 34 | } 35 | 36 | func (m *LoadBalanceMiddleware) OnRequest(session *rpc.Session) error { 37 | node := loadbalance.NextNode(session.Chain) 38 | if node == nil { 39 | return aggregator.ErrServerError 40 | } 41 | session.NodeName = node.Name 42 | //logger.Debug("load balance", "sid", session.SId(), "node", node.Name) 43 | if ctx, ok := session.RequestCtx.(*fasthttp.RequestCtx); ok { 44 | ctx.Request.SetRequestURI(node.Endpoint) 45 | } 46 | return nil 47 | } 48 | 49 | func (m *LoadBalanceMiddleware) OnProcess(session *rpc.Session) error { 50 | return nil 51 | } 52 | 53 | func (m *LoadBalanceMiddleware) OnResponse(session *rpc.Session) error { 54 | return nil 55 | } 56 | -------------------------------------------------------------------------------- /middleware/plugins/cors.go: -------------------------------------------------------------------------------- 1 | package plugins 2 | 3 | import ( 4 | "github.com/BlockPILabs/aggregator/middleware" 5 | "github.com/BlockPILabs/aggregator/rpc" 6 | "github.com/valyala/fasthttp" 7 | ) 8 | 9 | type CorsMiddleware struct { 10 | nextMiddleware middleware.Middleware 11 | enabled bool 12 | } 13 | 14 | func NewCorsMiddleware() *CorsMiddleware { 15 | return &CorsMiddleware{enabled: true} 16 | } 17 | 18 | func (m *CorsMiddleware) Name() string { 19 | return "CorsMiddleware" 20 | } 21 | 22 | func (m *CorsMiddleware) Enabled() bool { 23 | return m.enabled 24 | } 25 | 26 | func (m *CorsMiddleware) Next() middleware.Middleware { 27 | return m.nextMiddleware 28 | } 29 | 30 | func (m *CorsMiddleware) SetNext(middleware middleware.Middleware) { 31 | m.nextMiddleware = middleware 32 | } 33 | 34 | func (m *CorsMiddleware) OnRequest(session *rpc.Session) error { 35 | return nil 36 | } 37 | 38 | func (m *CorsMiddleware) OnProcess(session *rpc.Session) error { 39 | return nil 40 | } 41 | 42 | func (m *CorsMiddleware) OnResponse(session *rpc.Session) error { 43 | if ctx, ok := session.RequestCtx.(*fasthttp.RequestCtx); ok { 44 | if session.Method == "OPTIONS" { 45 | ctx.Response.Reset() 46 | ctx.Response.Header.Set("Access-Control-Max-Age", "86400") 47 | } 48 | ctx.Response.Header.Set("Access-Control-Allow-Origin", "*") 49 | ctx.Response.Header.Set("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS") 50 | ctx.Response.Header.Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Token, Authorization") 51 | ctx.Response.Header.Set("Access-Control-Allow-Credentials", "true") 52 | 53 | ctx.Response.Header.Set("X-Relay-Node", session.NodeName) 54 | 55 | ctx.SetStatusCode(fasthttp.StatusOK) 56 | } 57 | return nil 58 | } 59 | -------------------------------------------------------------------------------- /server/server.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "github.com/BlockPILabs/aggregator/config" 5 | "github.com/BlockPILabs/aggregator/log" 6 | "github.com/BlockPILabs/aggregator/middleware" 7 | "github.com/BlockPILabs/aggregator/notify" 8 | "github.com/BlockPILabs/aggregator/rpc" 9 | "github.com/valyala/fasthttp" 10 | ) 11 | 12 | var ( 13 | logger = log.Module("server") 14 | ) 15 | 16 | var requestHandler = func(ctx *fasthttp.RequestCtx) { 17 | defer func() { 18 | if err := recover(); err != nil { 19 | logger.Error("error", "msg", err) 20 | } 21 | }() 22 | 23 | var err error 24 | 25 | session := &rpc.Session{RequestCtx: ctx} 26 | err = session.Init() 27 | if err != nil { 28 | ctx.Error(string(session.NewJsonRpcError(err).Marshal()), fasthttp.StatusOK) 29 | return 30 | } 31 | for { 32 | session.Tries++ 33 | err = middleware.OnRequest(session) 34 | if err != nil { 35 | if session.IsMaxRetriesExceeded() { 36 | ctx.Error(string(session.NewJsonRpcError(err).Marshal()), fasthttp.StatusOK) 37 | return 38 | } 39 | continue 40 | } 41 | 42 | err = middleware.OnProcess(session) 43 | if err != nil { 44 | if session.IsMaxRetriesExceeded() { 45 | ctx.Error(string(session.NewJsonRpcError(err).Marshal()), fasthttp.StatusOK) 46 | return 47 | } 48 | continue 49 | } 50 | 51 | err = middleware.OnResponse(session) 52 | if err != nil { 53 | if session.IsMaxRetriesExceeded() { 54 | ctx.Error(string(session.NewJsonRpcError(err).Marshal()), fasthttp.StatusOK) 55 | return 56 | } 57 | continue 58 | } 59 | return 60 | } 61 | } 62 | 63 | func NewServer() error { 64 | var err error 65 | addr := ":8011" 66 | logger.Info("Starting proxy server", "addr", addr) 67 | 68 | for _, chain := range config.Chains() { 69 | logger.Info("Registered RPC", "endpoint", "http://localhost:8011/"+chain) 70 | } 71 | 72 | s := &fasthttp.Server{ 73 | Handler: fasthttp.CompressHandlerLevel(requestHandler, 6), 74 | MaxRequestBodySize: fasthttp.DefaultMaxRequestBodySize * 10, 75 | } 76 | 77 | err = s.ListenAndServe(addr) 78 | if err != nil { 79 | notify.SendError("Error start aggregator server.", err.Error()) 80 | return err 81 | } 82 | return nil 83 | } 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RPCHub Aggregator 2 | 3 | RPCHub is an RPC aggregator that offers you the fastest and most robust RPC services by integrating your owned nodes, private and public endpoints. 4 | 5 | RPCHub is an open-source software that allows you to customize your own strategy configurations. 6 | 7 | With customized configurations, RPCHub is able to achieve to make the RPC service to be scalable, exclusive, stable, low-cost, and high-performance. 8 | 9 | Configurations are stored and utilized locally to best protect your privacy. 10 | 11 | 12 | ## Installation 13 | Download the last release [here](https://github.com/BlockPILabs/aggregator/releases) 14 | 15 | ## Building from source 16 | ```shell 17 | git clone https://github.com/BlockPILabs/aggregator.git 18 | cd aggregator 19 | make 20 | ``` 21 | To start the aggregator, the following command can be run: 22 | ```shell 23 | build/aggregator 24 | ``` 25 | ## Configuration 26 | Default password is `123456`. 27 | 28 | Visit https://ag-cfg.rpchub.io/ to configure the aggregator. See the [documents](https://docs.rpchub.io/) for more details. 29 | 30 | Get current configuration by using command, replace `` to what you set or using the default password: 31 | ```shell 32 | curl -u rpchub: 'http://localhost:8012/config' 33 | ``` 34 | To update the configuration, the following command can be run: 35 | ```shell 36 | curl -u rpchub: -X POST 'http://localhost:8012/config' --header 'Content-Type: application/json' --data-raw '{"password":"123456","request_timeout":30,"max_retries":3,"nodes":{"arbitrum":[{"name":"blockpi-public-arbitrum","endpoint":"https://arbitrum.blockpi.network/v1/rpc/public","weight":90,"read_only":false,"disabled":false},{"name":"arbitrum-official","endpoint":"https://arb1.arbitrum.io/rpc","weight":10,"read_only":false,"disabled":false}],"bsc":[{"name":"blockpi-public-bsc","endpoint":"https://bsc.blockpi.network/v1/rpc/public","weight":100,"read_only":false,"disabled":false}]},"phishing_db":["https://cfg.rpchub.io/agg/scam-addresses.json"],"phishing_db_update_interval":3600}' 37 | ``` 38 | 39 | ## Reset configuration 40 | 1. Stop the aggregator. 41 | 2. Delete the configuration directory `rm -rf $HOME/.rpchub/aggregator/`. 42 | 3. Restart the aggregator -------------------------------------------------------------------------------- /middleware/middleware.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "github.com/BlockPILabs/aggregator/aggregator" 5 | "github.com/BlockPILabs/aggregator/log" 6 | "github.com/BlockPILabs/aggregator/rpc" 7 | ) 8 | 9 | var ( 10 | middlewareChain []Middleware 11 | logger = log.Module("middleware") 12 | ) 13 | 14 | type Middleware interface { 15 | Name() string 16 | 17 | Next() Middleware 18 | SetNext(next Middleware) 19 | 20 | Enabled() bool 21 | 22 | OnRequest(session *rpc.Session) error 23 | OnProcess(session *rpc.Session) error 24 | OnResponse(session *rpc.Session) error 25 | } 26 | 27 | func Append(middlewares ...Middleware) { 28 | for _, mw := range middlewares { 29 | if middlewareChain != nil && len(middlewareChain) > 0 { 30 | middlewareChain[len(middlewareChain)-1].SetNext(mw) 31 | } 32 | 33 | middlewareChain = append(middlewareChain, mw) 34 | } 35 | } 36 | 37 | func First() Middleware { 38 | if len(middlewareChain) > 0 { 39 | return middlewareChain[0] 40 | } 41 | return nil 42 | } 43 | 44 | func OnRequest(session *rpc.Session) error { 45 | mw := First() 46 | for mw != nil { 47 | err := mw.OnRequest(session) 48 | if err != nil { 49 | if err == aggregator.ErrMustReturn { 50 | return nil 51 | } 52 | logger.Error("an error occurred", "sid", session.SId(), "middleware", mw.Name(), "error", err) 53 | return err 54 | } 55 | mw = mw.Next() 56 | } 57 | return nil 58 | } 59 | 60 | func OnProcess(session *rpc.Session) error { 61 | mw := First() 62 | for mw != nil { 63 | err := mw.OnProcess(session) 64 | if err != nil { 65 | if err == aggregator.ErrMustReturn { 66 | return nil 67 | } 68 | logger.Error("an error occurred", "sid", session.SId(), "middleware", mw.Name(), "error", err) 69 | return err 70 | } 71 | mw = mw.Next() 72 | } 73 | return nil 74 | } 75 | 76 | func OnResponse(session *rpc.Session) error { 77 | mw := First() 78 | for mw != nil { 79 | err := mw.OnResponse(session) 80 | if err != nil { 81 | if err == aggregator.ErrMustReturn { 82 | return nil 83 | } 84 | logger.Error("an error occurred", "sid", session.SId(), "middleware", mw.Name(), "error", err) 85 | return err 86 | } 87 | mw = mw.Next() 88 | } 89 | return nil 90 | } 91 | -------------------------------------------------------------------------------- /middleware/plugins/requests_validator.go: -------------------------------------------------------------------------------- 1 | package plugins 2 | 3 | import ( 4 | "github.com/BlockPILabs/aggregator/aggregator" 5 | "github.com/BlockPILabs/aggregator/middleware" 6 | "github.com/BlockPILabs/aggregator/rpc" 7 | "strings" 8 | ) 9 | 10 | var ( 11 | defaultWriteMethods = []string{ 12 | strings.ToLower("_call"), 13 | strings.ToLower("_sendRawTransaction"), 14 | strings.ToLower("_sendTransaction"), 15 | strings.ToLower("_sendTransactionAsFeePayer"), 16 | } 17 | ) 18 | 19 | type RequestValidatorMiddleware struct { 20 | nextMiddleware middleware.Middleware 21 | enabled bool 22 | } 23 | 24 | func NewRequestValidatorMiddleware() *RequestValidatorMiddleware { 25 | return &RequestValidatorMiddleware{enabled: true} 26 | } 27 | 28 | func (m *RequestValidatorMiddleware) Name() string { 29 | return "RequestValidatorMiddleware" 30 | } 31 | 32 | func (m *RequestValidatorMiddleware) Enabled() bool { 33 | return m.enabled 34 | } 35 | 36 | func (m *RequestValidatorMiddleware) Next() middleware.Middleware { 37 | return m.nextMiddleware 38 | } 39 | 40 | func (m *RequestValidatorMiddleware) SetNext(middleware middleware.Middleware) { 41 | m.nextMiddleware = middleware 42 | } 43 | 44 | func (m *RequestValidatorMiddleware) OnRequest(session *rpc.Session) error { 45 | 46 | if session.Method == "OPTIONS" { 47 | return aggregator.ErrMustReturn 48 | } 49 | 50 | //if session.Method != "POST" { 51 | // return aggregator.ErrInvalidMethod 52 | //} 53 | 54 | session.IsWriteRpcMethod = m.isWriteMethod(session.RpcMethod()) 55 | 56 | return nil 57 | } 58 | 59 | func (m *RequestValidatorMiddleware) OnProcess(session *rpc.Session) error { 60 | if session.Method == "OPTIONS" { 61 | //if ctx, ok := session.RequestCtx.(*fasthttp.RequestCtx); ok { 62 | // 63 | //} 64 | 65 | return aggregator.ErrMustReturn 66 | } 67 | return nil 68 | } 69 | 70 | func (m *RequestValidatorMiddleware) OnResponse(session *rpc.Session) error { 71 | return nil 72 | } 73 | 74 | func (m *RequestValidatorMiddleware) isWriteMethod(method string) bool { 75 | if len(method) > 0 { 76 | method := strings.ToLower(method) 77 | for _, m := range defaultWriteMethods { 78 | if strings.HasSuffix(method, m) { 79 | return true 80 | } 81 | } 82 | } 83 | return false 84 | } 85 | -------------------------------------------------------------------------------- /rpc/session.go: -------------------------------------------------------------------------------- 1 | package rpc 2 | 3 | import ( 4 | "fmt" 5 | "github.com/BlockPILabs/aggregator/aggregator" 6 | "github.com/BlockPILabs/aggregator/config" 7 | "github.com/valyala/fasthttp" 8 | "strings" 9 | "sync" 10 | "sync/atomic" 11 | ) 12 | 13 | var _id int64 = 0 14 | 15 | type Session struct { 16 | once sync.Once 17 | sId any 18 | RequestCtx any 19 | Method string 20 | Path string 21 | Chain string 22 | Request *JsonRpcRequest 23 | RawRequest []byte 24 | Cfg config.Config 25 | 26 | Tries int 27 | NodeName string 28 | IsWriteRpcMethod bool 29 | 30 | //Tx *types.Transaction 31 | } 32 | 33 | func (s *Session) Init() error { 34 | var err error 35 | 36 | s.once.Do(func() { 37 | s.sId = atomic.AddInt64(&_id, 1) 38 | s.Cfg = config.Clone() 39 | if ctx, ok := s.RequestCtx.(*fasthttp.RequestCtx); ok { 40 | s.Method = string(ctx.Method()) 41 | s.Path = string(ctx.URI().Path()) 42 | s.RawRequest = ctx.Request.Body() 43 | 44 | ss := strings.Split(s.Path, "/") 45 | if len(ss) != 2 { 46 | err = aggregator.ErrInvalidRequest 47 | return 48 | } 49 | s.Chain = strings.Trim(ss[1], " ") 50 | s.Request = MustUnmarshalJsonRpcRequest(ctx.Request.Body()) 51 | } 52 | 53 | if !s.Cfg.HasChain(s.Chain) { 54 | err = aggregator.ErrInvalidChain 55 | return 56 | } 57 | }) 58 | 59 | return err 60 | } 61 | 62 | func (s *Session) SId() string { 63 | return fmt.Sprintf("s-%016d", s.sId) 64 | } 65 | 66 | func (s *Session) Id() any { 67 | var id any = 1 68 | if s.Request != nil { 69 | id = s.Request.Id 70 | } 71 | return id 72 | } 73 | 74 | func (s *Session) IsMaxRetriesExceeded() bool { 75 | return s.Tries >= s.Cfg.MaxRetries 76 | } 77 | 78 | func (s *Session) RpcMethod() string { 79 | if s.Request != nil { 80 | return s.Request.Method 81 | } 82 | return "" 83 | } 84 | 85 | func (s *Session) RpcParams() interface{} { 86 | if s.Request != nil { 87 | return s.Request.Params 88 | } 89 | return nil 90 | } 91 | 92 | func (s *Session) NewJsonRpcError(err error) *JsonRpcResponse { 93 | id := s.Id() 94 | if agErr, ok := err.(*aggregator.Error); ok { 95 | return Error(id, agErr.Code, agErr.Message) 96 | } 97 | return ErrorInvalidRequest(id, err.Error()) 98 | } 99 | -------------------------------------------------------------------------------- /rpc/jsonrpc.go: -------------------------------------------------------------------------------- 1 | package rpc 2 | 3 | import ( 4 | "encoding/json" 5 | ) 6 | 7 | type JsonRpcRequest struct { 8 | Id any `json:"id"` 9 | JSONRpc string `json:"jsonrpc,omitempty"` 10 | Method string `json:"method"` 11 | Params interface{} `json:"params,omitempty"` 12 | } 13 | 14 | type JsonRpcResponse struct { 15 | Id any `json:"id"` 16 | JSONRpc string `json:"jsonrpc,omitempty"` 17 | Error *JsonRpcResponseError `json:"error,omitempty"` 18 | Result interface{} `json:"result,omitempty"` 19 | } 20 | 21 | func (r *JsonRpcResponse) Marshal() []byte { 22 | data, _ := json.Marshal(r) 23 | return data 24 | } 25 | 26 | type JsonRpcResponseError struct { 27 | Code int `json:"code"` 28 | Message string `json:"message"` 29 | Data any `json:"data"` 30 | } 31 | 32 | func NewJsonRpcResponseError(code int, message string, data any) *JsonRpcResponseError { 33 | return &JsonRpcResponseError{ 34 | Code: code, 35 | Message: message, 36 | Data: data, 37 | } 38 | } 39 | 40 | func NewJsonRpcResponse(id any, result any, err *JsonRpcResponseError) *JsonRpcResponse { 41 | return &JsonRpcResponse{ 42 | Id: id, 43 | JSONRpc: "2.0", 44 | Error: err, 45 | Result: result, 46 | } 47 | } 48 | 49 | func Error(id any, code int, msg string) *JsonRpcResponse { 50 | return NewJsonRpcResponse(id, nil, NewJsonRpcResponseError(code, msg, nil)) 51 | } 52 | 53 | func ErrorServerError(id any, msg string) *JsonRpcResponse { 54 | return NewJsonRpcResponse(id, nil, NewJsonRpcResponseError(-32000, msg, nil)) 55 | } 56 | 57 | func ErrorInvalidRequest(id any, msg string) *JsonRpcResponse { 58 | return NewJsonRpcResponse(id, nil, NewJsonRpcResponseError(-32600, msg, nil)) 59 | } 60 | 61 | func ErrorMethodNotFound(id any, msg string) *JsonRpcResponse { 62 | return NewJsonRpcResponse(id, nil, NewJsonRpcResponseError(-32601, msg, nil)) 63 | } 64 | 65 | func ErrorInvalidParams(id any, msg string) *JsonRpcResponse { 66 | return NewJsonRpcResponse(id, nil, NewJsonRpcResponseError(-32602, msg, nil)) 67 | } 68 | 69 | func MustUnmarshalJsonRpcRequest(data []byte) *JsonRpcRequest { 70 | req := &JsonRpcRequest{} 71 | err := json.Unmarshal(data, req) 72 | if err != nil { 73 | return nil 74 | } 75 | return req 76 | } 77 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/BlockPILabs/aggregator 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/ethereum/go-ethereum v1.10.25 7 | github.com/fasthttp/router v1.4.12 8 | github.com/gogf/gf/v2 v2.2.0 9 | github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac 10 | github.com/magiconair/properties v1.8.6 11 | github.com/martinlindhe/notify v0.0.0-20181008203735-20632c9a275a 12 | github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 13 | github.com/urfave/cli/v2 v2.19.2 14 | github.com/valyala/fasthttp v1.40.0 15 | golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0 16 | ) 17 | 18 | require ( 19 | github.com/andybalholm/brotli v1.0.4 // indirect 20 | github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect 21 | github.com/cespare/xxhash/v2 v2.1.2 // indirect 22 | github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect 23 | github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb // indirect 24 | github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect 25 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect 26 | github.com/fsnotify/fsnotify v1.5.4 // indirect 27 | github.com/go-logr/logr v1.2.3 // indirect 28 | github.com/go-logr/stdr v1.2.2 // indirect 29 | github.com/go-redis/redis/v8 v8.11.5 // indirect 30 | github.com/go-stack/stack v1.8.1 // indirect 31 | github.com/golang/snappy v0.0.4 // indirect 32 | github.com/google/go-cmp v0.5.8 // indirect 33 | github.com/klauspost/compress v1.15.11 // indirect 34 | github.com/mattn/go-colorable v0.1.12 // indirect 35 | github.com/mattn/go-isatty v0.0.14 // indirect 36 | github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect 37 | github.com/russross/blackfriday/v2 v2.1.0 // indirect 38 | github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d // indirect 39 | github.com/stretchr/testify v1.8.0 // indirect 40 | github.com/valyala/bytebufferpool v1.0.0 // indirect 41 | github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect 42 | go.opentelemetry.io/otel v1.7.0 // indirect 43 | go.opentelemetry.io/otel/sdk v1.7.0 // indirect 44 | go.opentelemetry.io/otel/trace v1.7.0 // indirect 45 | golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect 46 | golang.org/x/net v0.0.0-20220607020251-c690dde0001d // indirect 47 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect 48 | golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 // indirect 49 | gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2 // indirect 50 | ) 51 | -------------------------------------------------------------------------------- /middleware/plugins/http_proxy.go: -------------------------------------------------------------------------------- 1 | package plugins 2 | 3 | import ( 4 | "github.com/BlockPILabs/aggregator/client" 5 | "github.com/BlockPILabs/aggregator/log" 6 | "github.com/BlockPILabs/aggregator/middleware" 7 | "github.com/BlockPILabs/aggregator/rpc" 8 | "github.com/valyala/fasthttp" 9 | "sync" 10 | "time" 11 | ) 12 | 13 | type HttpProxyMiddleware struct { 14 | nextMiddleware middleware.Middleware 15 | enabled bool 16 | client *client.Client 17 | clientCreatedAt time.Time 18 | clientRenew time.Duration 19 | mu sync.Mutex 20 | } 21 | 22 | func NewHttpProxyMiddleware() *HttpProxyMiddleware { 23 | return &HttpProxyMiddleware{ 24 | enabled: true, 25 | clientRenew: time.Second * 60, 26 | mu: sync.Mutex{}, 27 | } 28 | } 29 | 30 | func (m *HttpProxyMiddleware) Name() string { 31 | return "HttpProxyMiddleware" 32 | } 33 | 34 | func (m *HttpProxyMiddleware) Enabled() bool { 35 | return m.enabled 36 | } 37 | 38 | func (m *HttpProxyMiddleware) Next() middleware.Middleware { 39 | return m.nextMiddleware 40 | } 41 | 42 | func (m *HttpProxyMiddleware) SetNext(middleware middleware.Middleware) { 43 | m.nextMiddleware = middleware 44 | } 45 | 46 | func (m *HttpProxyMiddleware) OnRequest(session *rpc.Session) error { 47 | return nil 48 | } 49 | 50 | func (m *HttpProxyMiddleware) OnProcess(session *rpc.Session) error { 51 | if ctx, ok := session.RequestCtx.(*fasthttp.RequestCtx); ok { 52 | logger.Debug("relay rpc -> "+session.RpcMethod(), "sid", session.SId(), "node", session.NodeName, "isTx", session.IsWriteRpcMethod, "tries", session.Tries) 53 | err := m.GetClient(session).Do(&ctx.Request, &ctx.Response) 54 | //if ctx, ok := session.RequestCtx.(*fasthttp.RequestCtx); ok { 55 | // ctx.Response.Header.Set("Access-Control-Max-Age", "86400") 56 | // ctx.Response.Header.Set("Access-Control-Allow-Origin", "*") 57 | // ctx.Response.Header.Set("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS") 58 | // ctx.Response.Header.Set("Access-Control-Allow-Credentials", "true") 59 | // ctx.Response.Header.Set("X-Do-Node", session.NodeName) 60 | //} 61 | 62 | shouldDisableEndpoint := false 63 | if err != nil { 64 | log.Error(err.Error(), "node", session.NodeName) 65 | shouldDisableEndpoint = true 66 | } 67 | 68 | statusCode := ctx.Response.StatusCode() 69 | if statusCode/100 != 2 { 70 | log.Error("error status code", "code", statusCode, "node", session.NodeName) 71 | shouldDisableEndpoint = true 72 | } 73 | 74 | if shouldDisableEndpoint { 75 | //todo disable endpoint 76 | } 77 | 78 | return err 79 | } 80 | 81 | return nil 82 | } 83 | 84 | func (m *HttpProxyMiddleware) OnResponse(session *rpc.Session) error { 85 | return nil 86 | } 87 | 88 | func (m *HttpProxyMiddleware) GetClient(session *rpc.Session) *client.Client { 89 | m.mu.Lock() 90 | defer m.mu.Unlock() 91 | 92 | if time.Since(m.clientCreatedAt) <= m.clientRenew { 93 | if m.client != nil { 94 | return m.client 95 | } 96 | } 97 | 98 | //log.Debug("renew proxy http client") 99 | m.client = client.NewClient(session.Cfg.RequestTimeout, session.Cfg.Proxy) 100 | m.clientCreatedAt = time.Now() 101 | 102 | return m.client 103 | } 104 | -------------------------------------------------------------------------------- /server/manage_server.go: -------------------------------------------------------------------------------- 1 | package server 2 | 3 | import ( 4 | "bytes" 5 | "encoding/base64" 6 | "encoding/json" 7 | "github.com/BlockPILabs/aggregator/config" 8 | "github.com/BlockPILabs/aggregator/loadbalance" 9 | "github.com/BlockPILabs/aggregator/notify" 10 | "github.com/fasthttp/router" 11 | "github.com/valyala/fasthttp" 12 | "net/http" 13 | ) 14 | 15 | var basicAuthPrefix = []byte("Basic ") 16 | 17 | func rootHandler(ctx *fasthttp.RequestCtx) { 18 | ctx.WriteString("hello!") 19 | } 20 | 21 | func statusHandler(ctx *fasthttp.RequestCtx) { 22 | st := map[string]any{} 23 | st["mrt"] = config.Default().Mrt 24 | data, _ := json.Marshal(st) 25 | ctx.Response.Header.Set("Content-Type", "application/json") 26 | ctx.Write(data) 27 | } 28 | 29 | func routeConfigHandler(ctx *fasthttp.RequestCtx) { 30 | data, _ := json.Marshal(config.Default()) 31 | ctx.Response.Header.Set("Content-Type", "application/json") 32 | ctx.Write(data) 33 | } 34 | 35 | func routeUpdateConfigHandler(ctx *fasthttp.RequestCtx) { 36 | cfg := config.Config{} 37 | err := json.Unmarshal(ctx.Request.Body(), &cfg) 38 | if err != nil { 39 | ctx.Error("error parse config", fasthttp.StatusInternalServerError) 40 | return 41 | } 42 | 43 | defaultCfg := config.Default() 44 | cfg.Mrt = defaultCfg.Mrt 45 | 46 | dbs := defaultCfg.AuthorityDB 47 | for i := 0; i < len(dbs); i++ { 48 | for _, adb2 := range cfg.AuthorityDB { 49 | if dbs[i].Name == adb2.Name { 50 | dbs[i].Enable = adb2.Enable 51 | } 52 | } 53 | } 54 | 55 | cfg.AuthorityDB = dbs 56 | 57 | config.SetDefault(&cfg) 58 | loadbalance.LoadFromConfig() 59 | 60 | config.Save() 61 | 62 | data, _ := json.Marshal(cfg) 63 | ctx.Response.Header.Set("Content-Type", "application/json") 64 | ctx.Write(data) 65 | } 66 | 67 | func routeRestoreConfigHandler(ctx *fasthttp.RequestCtx) { 68 | config.LoadDefault() 69 | 70 | } 71 | 72 | func NewManageServer() error { 73 | r := router.New() 74 | r.PanicHandler = func(ctx *fasthttp.RequestCtx, err interface{}) { 75 | ctx.Error("Internal server error", fasthttp.StatusInternalServerError) 76 | } 77 | 78 | r.GET("/", rootHandler) 79 | r.GET("/status", statusHandler) 80 | r.GET("/config", routeConfigHandler) 81 | r.POST("/config", routeUpdateConfigHandler) 82 | r.POST("/config/restore", routeRestoreConfigHandler) 83 | 84 | addr := ":8012" 85 | logger.Info("Starting management server", "addr", addr) 86 | server := fasthttp.Server{ 87 | Name: "", 88 | Handler: func(ctx *fasthttp.RequestCtx) { 89 | ctx.Response.Header.Set("Access-Control-Allow-Origin", "*") 90 | ctx.Response.Header.Set("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS") 91 | ctx.Response.Header.Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Token, Authorization") 92 | ctx.Response.Header.Set("Access-Control-Allow-Credentials", "true") 93 | 94 | if string(ctx.Method()) == "OPTIONS" { 95 | ctx.Response.Header.Set("Access-Control-Max-Age", "86400") 96 | ctx.SetStatusCode(http.StatusOK) 97 | ctx.SetBodyString("ok") 98 | return 99 | } 100 | path := string(ctx.Request.URI().Path()) 101 | if path == "/status" { 102 | r.Handler(ctx) 103 | return 104 | } 105 | 106 | auth := ctx.Request.Header.Peek("Authorization") 107 | if bytes.HasPrefix(auth, basicAuthPrefix) { 108 | payload, err := base64.StdEncoding.DecodeString(string(auth[len(basicAuthPrefix):])) 109 | if err == nil { 110 | pair := bytes.SplitN(payload, []byte(":"), 2) 111 | if len(pair) == 2 && bytes.Equal(pair[0], []byte("rpchub")) && bytes.Equal(pair[1], []byte(config.Default().Password)) { 112 | config.Default().Mrt += 1 113 | config.Save() 114 | r.Handler(ctx) 115 | return 116 | } 117 | } 118 | } 119 | ctx.Error("Unauthorized", fasthttp.StatusUnauthorized) 120 | }, 121 | } 122 | err := server.ListenAndServe(addr) 123 | if err != nil { 124 | notify.SendError("Error start manage server.", err.Error()) 125 | return err 126 | } 127 | return nil 128 | } 129 | -------------------------------------------------------------------------------- /log/logger.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "github.com/inconshreveable/log15" 7 | "sync" 8 | ) 9 | 10 | type Logger interface { 11 | log15.Logger 12 | Trace(msg string, ctx ...interface{}) 13 | NewLogger(ctx ...interface{}) Logger 14 | SetLevel(lvl log15.Lvl) Logger 15 | SetLevelString(lvlString string) Logger 16 | NewContextLogger(c context.Context, ctx ...interface{}) (context.Context, Logger) 17 | } 18 | 19 | type loggerCtx struct { 20 | } 21 | 22 | type logger struct { 23 | log15.Logger 24 | } 25 | 26 | func (l *logger) GetHandler() log15.Handler { 27 | return l.Logger.GetHandler() 28 | } 29 | 30 | func (l *logger) SetHandler(h log15.Handler) { 31 | l.Logger.SetHandler(h) 32 | } 33 | func (l *logger) NewLogger(ctx ...interface{}) Logger { 34 | return &logger{Logger: l.Logger.New(ctx...)} 35 | } 36 | func (l *logger) NewContextLogger(c context.Context, ctx ...interface{}) (context.Context, Logger) { 37 | nl := l.NewLogger(ctx...) 38 | return WithContext(c, nl), nl 39 | } 40 | func (l *logger) SetLevel(lvl log15.Lvl) Logger { 41 | l.SetHandler(log15.LvlFilterHandler(lvl, l.GetHandler())) 42 | return l 43 | } 44 | func (l *logger) SetLevelString(lvlString string) Logger { 45 | lvl, err := log15.LvlFromString(lvlString) 46 | if err != nil { 47 | return l 48 | } 49 | return l.SetLevel(lvl) 50 | } 51 | func (l *logger) New(ctx ...interface{}) log15.Logger { 52 | return l.NewLogger(ctx...) 53 | } 54 | 55 | func (l *logger) Trace(msg string, ctx ...interface{}) { 56 | l.Logger.Error(msg, ctx...) 57 | } 58 | 59 | var root *logger 60 | var moduleLogs sync.Map 61 | 62 | func init() { 63 | root = &logger{Logger: log15.Root()} 64 | root.SetLevelString("debug") 65 | } 66 | 67 | func Module(module string) Logger { 68 | if module == "root" { 69 | return Root() 70 | } 71 | logI, ok := moduleLogs.Load(module) 72 | if !ok { 73 | log := newModule(module) 74 | moduleLogs.Store(module, log) 75 | return log 76 | } 77 | log, ok := logI.(Logger) 78 | if !ok { 79 | log = newModule(module) 80 | moduleLogs.Store(module, log) 81 | return log 82 | } 83 | return log 84 | } 85 | 86 | func Module15(module string) log15.Logger { 87 | return log15.New("module", module) 88 | } 89 | 90 | func newModule(module string) Logger { 91 | log := Root().NewLogger("module", module) 92 | return log 93 | } 94 | 95 | // New returns a new logger with the given context. 96 | // New is a convenient alias for Root().New 97 | func New(ctx ...interface{}) Logger { 98 | return root.New(ctx...).(*logger) 99 | } 100 | 101 | // Root returns the root logger 102 | func Root() Logger { 103 | return root 104 | } 105 | 106 | // Debug is a convenient alias for Root().Debug 107 | func Debug(msg string, ctx ...interface{}) { 108 | root.Debug(msg, ctx...) 109 | } 110 | 111 | // Info is a convenient alias for Root().Info 112 | func Info(msg string, ctx ...interface{}) { 113 | root.Info(msg, ctx...) 114 | } 115 | 116 | // Warn is a convenient alias for Root().Warn 117 | func Warn(msg string, ctx ...interface{}) { 118 | root.Warn(msg, ctx...) 119 | } 120 | 121 | // Error is a convenient alias for Root().Error 122 | func Error(msg string, ctx ...interface{}) { 123 | root.Error(msg, ctx...) 124 | } 125 | 126 | // Crit is a convenient alias for Root().Crit 127 | func Crit(msg string, ctx ...interface{}) { 128 | root.Crit(msg, ctx...) 129 | } 130 | 131 | // Trace is a convenient alias for Root().Trace 132 | func Trace(msg string, ctx ...interface{}) { 133 | root.Trace(msg, ctx...) 134 | } 135 | 136 | func StackError(msg string, ctx error) { 137 | root.Error(fmt.Sprintf("%s => error : %+v", msg, ctx)) 138 | } 139 | func SetHandler(h log15.Handler) { 140 | root.SetHandler(h) 141 | } 142 | 143 | func GetHandler() log15.Handler { 144 | return root.GetHandler() 145 | } 146 | 147 | func SetLevel(lvl log15.Lvl) Logger { 148 | return Root().SetLevel(lvl) 149 | } 150 | func SetLevelString(lvlString string) Logger { 151 | return Root().SetLevelString(lvlString) 152 | } 153 | 154 | // WithContext context log 155 | func WithContext(ctx context.Context, l Logger) context.Context { 156 | if l == nil { 157 | l = Root() 158 | } 159 | k := loggerCtx{} 160 | ctx = context.WithValue(ctx, k, l) 161 | return ctx 162 | } 163 | -------------------------------------------------------------------------------- /proxy/pool.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | // 4 | //import ( 5 | // "errors" 6 | // "sync" 7 | //) 8 | // 9 | //var ( 10 | // errFactoryNotHelp = errors.New("factory is not able to fill the pool") 11 | // errInvalidCapacitySetting = errors.New("invalid capacity settings") 12 | //) 13 | // 14 | //type chanPool struct { 15 | // // mutex makes the chanPool woking with goroutine safely 16 | // mutex sync.RWMutex 17 | // 18 | // // reverseProxyChan chan of getting the *ReverseProxy and putting it back 19 | // reverseProxyChan chan *HttpProxy 20 | // 21 | // // factory is factory method to generate ReverseProxy 22 | // // this can be customized 23 | // factory Factory 24 | //} 25 | // 26 | //// Factory the generator to creat ReverseProxy 27 | //type Factory func(string) (*HttpProxy, error) 28 | // 29 | //// NewChanPool to new a pool with some params 30 | //func NewChanPool(initialCap, maxCap int, factory Factory) (Pool, error) { 31 | // if initialCap < 0 || maxCap <= 0 || initialCap > maxCap { 32 | // return nil, errInvalidCapacitySetting 33 | // } 34 | // 35 | // // initialize the chanPool 36 | // pool := &chanPool{ 37 | // mutex: sync.RWMutex{}, 38 | // reverseProxyChan: make(chan *HttpProxy, maxCap), 39 | // factory: factory, 40 | // } 41 | // 42 | // // create initial connections, if something goes wrong, 43 | // // just close the pool error out. 44 | // for i := 0; i < initialCap; i++ { 45 | // proxy, err := factory("") 46 | // if err != nil { 47 | // proxy.Close() 48 | // return nil, errFactoryNotHelp 49 | // } 50 | // pool.reverseProxyChan <- proxy 51 | // } 52 | // 53 | // return pool, nil 54 | //} 55 | // 56 | //// getConnsAndFactory ... get a copy of chanPool's reverseProxyChan and factory 57 | //func (p *chanPool) getConnsAndFactory() (chan *HttpProxy, Factory) { 58 | // p.mutex.RLock() 59 | // reverseProxyChan, factory := p.reverseProxyChan, p.factory 60 | // p.mutex.RUnlock() 61 | // return reverseProxyChan, factory 62 | //} 63 | // 64 | //// Close close the pool 65 | //func (p *chanPool) Close() { 66 | // p.mutex.Lock() 67 | // reverseProxyChan := p.reverseProxyChan 68 | // p.reverseProxyChan = nil 69 | // p.factory = nil 70 | // p.mutex.Unlock() 71 | // 72 | // if reverseProxyChan == nil { 73 | // return 74 | // } 75 | // 76 | // close(reverseProxyChan) 77 | // for proxy := range reverseProxyChan { 78 | // proxy.Close() 79 | // } 80 | //} 81 | // 82 | //// Get a *ReverseProxy from pool, it will get an error while 83 | //// reverseProxyChan is nil or pool has been closed 84 | //func (p *chanPool) Get(addr string) (*HttpProxy, error) { 85 | // // reverseProxyChan, factory := p.getConnsAndFactory() 86 | // // if reverseProxyChan == nil { 87 | // // return nil, ErrClosed 88 | // // } 89 | // 90 | // if p.reverseProxyChan == nil { 91 | // return nil, errClosed 92 | // } 93 | // 94 | // // wrap our connections with out custom net.Conn implementation (wrapConn 95 | // // method) that puts the connection back to the pool if it's closed. 96 | // select { 97 | // case proxy := <-p.reverseProxyChan: 98 | // // FIXME: judge empty proxy correctly 99 | // if &proxy == nil { 100 | // return nil, errClosed 101 | // } 102 | // return proxy.SetClient(addr), nil 103 | // default: 104 | // proxy, err := p.factory(addr) 105 | // if err != nil { 106 | // return nil, err 107 | // } 108 | // return proxy, nil 109 | // } 110 | //} 111 | // 112 | //// Put ... put a *ReverseProxy object back into chanPool 113 | //func (p *chanPool) Put(proxy *HttpProxy) error { 114 | // if proxy == nil { 115 | // return errors.New("proxy is nil. rejecting") 116 | // } 117 | // 118 | // // p.mutex.RLock() 119 | // // defer p.mutex.RUnlock() 120 | // 121 | // if p.reverseProxyChan == nil { 122 | // // pool is closed, close passed connection 123 | // proxy.Close() 124 | // return nil 125 | // } 126 | // 127 | // // put the resource back into the pool. If the pool is full, this will 128 | // // block and the default case will be executed. 129 | // select { 130 | // case p.reverseProxyChan <- proxy: 131 | // return nil 132 | // default: 133 | // // pool is full, close passed connection 134 | // proxy.Close() 135 | // return nil 136 | // } 137 | //} 138 | // 139 | //// Len get chanPool channel length 140 | //func (p *chanPool) Len() int { 141 | // reverseProxyChan, _ := p.getConnsAndFactory() 142 | // return len(reverseProxyChan) 143 | //} 144 | -------------------------------------------------------------------------------- /config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "github.com/BlockPILabs/aggregator/aggregator" 8 | "github.com/BlockPILabs/aggregator/log" 9 | "github.com/BlockPILabs/aggregator/notify" 10 | "github.com/syndtr/goleveldb/leveldb" 11 | leveldbErrors "github.com/syndtr/goleveldb/leveldb/errors" 12 | "github.com/valyala/fasthttp" 13 | "sort" 14 | "sync" 15 | "time" 16 | ) 17 | 18 | var ( 19 | logger = log.Module("config") 20 | locker = sync.Mutex{} 21 | DefaultConfigUrl = "https://cfg.rpchub.io/agg/default.json" 22 | defaultPhishingDb = "https://cfg.rpchub.io/agg/scam-addresses.json" 23 | 24 | _Config = &Config{ 25 | Password: "123456", 26 | RequestTimeout: 30, 27 | MaxRetries: 3, 28 | PhishingDb: []string{defaultPhishingDb}, 29 | PhishingDbUpdateInterval: 3600, 30 | } 31 | ) 32 | 33 | type Config struct { 34 | Password string `json:"password,omitempty"` 35 | Proxy string `json:"proxy,omitempty"` 36 | RequestTimeout int64 `json:"request_timeout,omitempty"` 37 | MaxRetries int `json:"max_retries,omitempty"` 38 | Nodes map[string][]aggregator.Node `json:"nodes"` 39 | PhishingDb []string `json:"phishing_db"` 40 | PhishingDbUpdateInterval int64 `json:"phishing_db_update_interval"` 41 | Mrt int64 `json:"mrt"` 42 | AuthorityDB []AuthorityDB `json:"authority_db"` 43 | } 44 | 45 | type AuthorityDB struct { 46 | Name string `json:"name"` 47 | Url string `json:"url"` 48 | Enable bool `json:"enable"` 49 | } 50 | 51 | func (c Config) HasChain(chain string) bool { 52 | if len(chain) > 0 { 53 | if v, ok := c.Nodes[chain]; ok { 54 | if len(v) > 0 { 55 | return true 56 | } 57 | } 58 | } 59 | return false 60 | } 61 | 62 | func Clone() Config { 63 | locker.Lock() 64 | defer locker.Unlock() 65 | 66 | cfg := *_Config 67 | cfg.Nodes = map[string][]aggregator.Node{} 68 | 69 | for key, nodes := range _Config.Nodes { 70 | cfg.Nodes[key] = []aggregator.Node{} 71 | for _, node := range nodes { 72 | cfg.Nodes[key] = append(cfg.Nodes[key], node) 73 | } 74 | } 75 | return cfg 76 | } 77 | 78 | func Default() *Config { 79 | locker.Lock() 80 | defer locker.Unlock() 81 | 82 | return _Config 83 | } 84 | 85 | func SetDefault(cfg *Config) { 86 | locker.Lock() 87 | defer locker.Unlock() 88 | 89 | _Config = cfg 90 | } 91 | 92 | func LoadDefault() *Config { 93 | var cfg *Config 94 | 95 | retries := 0 96 | for { 97 | statusCode, data, err := (&fasthttp.Client{}).GetTimeout(nil, DefaultConfigUrl, time.Second*5) 98 | if err == nil && statusCode == 200 { 99 | err = json.Unmarshal(data, &cfg) 100 | if err == nil { 101 | logger.Info("Load default config success") 102 | break 103 | } 104 | } 105 | if err != nil || statusCode != 200 { 106 | retries++ 107 | errStr := "" 108 | if err != nil { 109 | errStr = err.Error() 110 | } 111 | logger.Error("Load default config failed", "statusCode", statusCode, "error", errStr, "retries", retries) 112 | 113 | if retries >= 5 { 114 | notify.SendError("Load default Config failed", fmt.Sprintf("Status Code: %d\nError: %s", statusCode, errStr)) 115 | logger.Warn("Load default config failed, See the documents for more details [https://docs.rpchub.io/]") 116 | break 117 | } else { 118 | time.Sleep(time.Second * 3) 119 | } 120 | } 121 | } 122 | 123 | return cfg 124 | } 125 | 126 | func Load() error { 127 | cfg := LoadDefault() 128 | 129 | db, err := leveldb.OpenFile("data/db", nil) 130 | if err != nil { 131 | logger.Error("Load Config failed", "error", err.Error()) 132 | notify.SendError("Load Config failed", err.Error()) 133 | return err 134 | } 135 | defer db.Close() 136 | 137 | data, err := db.Get(aggregator.KeyDbConfig, nil) 138 | if err != nil && !errors.Is(err, leveldbErrors.ErrNotFound) { 139 | logger.Error("Load Config failed", "error", err.Error()) 140 | notify.SendError("Load Config failed", err.Error()) 141 | return err 142 | } 143 | 144 | var cfgLocal *Config 145 | if data != nil { 146 | err = json.Unmarshal(data, &cfgLocal) 147 | if err != nil { 148 | logger.Error("Load Config failed", "error", err.Error()) 149 | notify.SendError("Load Config failed", err.Error()) 150 | return err 151 | } 152 | 153 | if cfg != nil { 154 | for k, v := range cfg.Nodes { 155 | if cfgLocal.Nodes[k] == nil { 156 | cfgLocal.Nodes[k] = v 157 | } 158 | } 159 | 160 | dbs := cfg.AuthorityDB 161 | for i := 0; i < len(dbs); i++ { 162 | for _, adbLocal := range cfgLocal.AuthorityDB { 163 | if dbs[i].Name == adbLocal.Name { 164 | dbs[i].Enable = adbLocal.Enable 165 | } 166 | } 167 | } 168 | cfgLocal.AuthorityDB = dbs 169 | } 170 | } 171 | 172 | if cfgLocal != nil { 173 | _Config = cfgLocal 174 | } else { 175 | _Config = cfg 176 | } 177 | 178 | data, _ = json.Marshal(_Config) 179 | err = db.Put(aggregator.KeyDbConfig, data, nil) 180 | 181 | return err 182 | } 183 | 184 | func Save() error { 185 | db, err := leveldb.OpenFile("data/db", nil) 186 | if err != nil { 187 | logger.Error("Save Config failed", "error", err.Error()) 188 | notify.SendError("Save Config failed", err.Error()) 189 | return err 190 | } 191 | defer db.Close() 192 | 193 | data, err := json.Marshal(Default()) 194 | if err != nil { 195 | logger.Error("Save Config failed", "error", err.Error()) 196 | notify.SendError("Save Config failed", err.Error()) 197 | return err 198 | } 199 | 200 | err = db.Put(aggregator.KeyDbConfig, data, nil) 201 | if err != nil { 202 | logger.Error("Save Config failed", "error", err.Error()) 203 | notify.SendError("Save Config failed", err.Error()) 204 | return err 205 | } 206 | 207 | return nil 208 | } 209 | 210 | func Chains() []string { 211 | var chains []string 212 | for key, _ := range Default().Nodes { 213 | chains = append(chains, key) 214 | } 215 | sort.Strings(chains) 216 | return chains 217 | } 218 | -------------------------------------------------------------------------------- /middleware/plugins/safety.go: -------------------------------------------------------------------------------- 1 | package plugins 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/BlockPILabs/aggregator/aggregator" 6 | "github.com/BlockPILabs/aggregator/client" 7 | "github.com/BlockPILabs/aggregator/config" 8 | "github.com/BlockPILabs/aggregator/log" 9 | "github.com/BlockPILabs/aggregator/middleware" 10 | "github.com/BlockPILabs/aggregator/notify" 11 | "github.com/BlockPILabs/aggregator/rpc" 12 | "github.com/BlockPILabs/aggregator/safety" 13 | "github.com/BlockPILabs/aggregator/utils" 14 | "github.com/valyala/fasthttp" 15 | "strings" 16 | "sync" 17 | "time" 18 | ) 19 | 20 | var ( 21 | phishingAddressMap map[string]*phishingAddress 22 | authorityPhishingAddressMap = map[string]map[string]*phishingAddress{} 23 | mu = sync.Mutex{} 24 | lastUpdateAt time.Time 25 | ) 26 | 27 | type SafetyMiddleware struct { 28 | nextMiddleware middleware.Middleware 29 | enabled bool 30 | } 31 | 32 | type phishingAddress struct { 33 | Address string 34 | Description string 35 | Reporter string 36 | } 37 | 38 | func NewSafetyMiddleware() *SafetyMiddleware { 39 | m := &SafetyMiddleware{enabled: true} 40 | m.updatePhishingDb() 41 | m.updateAuthorityPhishingDb() 42 | go func() { 43 | for { 44 | if time.Since(lastUpdateAt) > time.Second*time.Duration(config.Default().PhishingDbUpdateInterval) { 45 | m.updatePhishingDb() 46 | m.updateAuthorityPhishingDb() 47 | } 48 | time.Sleep(time.Second * 10) 49 | } 50 | }() 51 | 52 | return m 53 | } 54 | 55 | func (m *SafetyMiddleware) Name() string { 56 | return "SafetyMiddleware" 57 | } 58 | 59 | func (m *SafetyMiddleware) Enabled() bool { 60 | return m.enabled 61 | } 62 | 63 | func (m *SafetyMiddleware) Next() middleware.Middleware { 64 | return m.nextMiddleware 65 | } 66 | 67 | func (m *SafetyMiddleware) SetNext(middleware middleware.Middleware) { 68 | m.nextMiddleware = middleware 69 | } 70 | 71 | func (m *SafetyMiddleware) OnRequest(session *rpc.Session) error { 72 | if session.IsWriteRpcMethod { 73 | params := session.RpcParams() 74 | //logger.Debug("new tx", "method", session.RpcMethod()) 75 | rpcMethod := session.RpcMethod() 76 | rpcMethod = strings.ToLower(rpcMethod[strings.Index(rpcMethod, "_"):]) 77 | 78 | targetAddress := "" 79 | 80 | switch rpcMethod { 81 | case strings.ToLower("_sendRawTransaction"): 82 | rawTx, ok := params.([]interface{})[0].(string) 83 | if !ok { 84 | return nil 85 | } 86 | tx, err := utils.DecodeTx(rawTx) 87 | if err != nil { 88 | logger.Warn("Unable to decode tx") 89 | notify.SendNotice("Unable to decode tx") 90 | } else { 91 | targetAddress = tx.To().Hex() 92 | //phishing, pha := m.isPhishingAddress(receiver) 93 | //if phishing { 94 | // notify.SendError("Transaction is denied", receiver, pha.Description) 95 | // logger.Error("transaction is denied", "Receiver", receiver, "Reason", pha.Description) 96 | // return aggregator.ErrDenyRequest 97 | //} 98 | //session.ChainId = tx.ChainId().Int64() 99 | //session.Tx = tx 100 | } 101 | case strings.ToLower("_call"): 102 | targetAddress = params.([]interface{})[0].(map[string]interface{})["to"].(string) 103 | case strings.ToLower("_sendTransaction"): 104 | targetAddress = params.([]interface{})[0].(map[string]interface{})["to"].(string) 105 | case strings.ToLower("_sendTransactionAsFeePayer"): 106 | //targetAddress = params.([]interface{})[0].(map[string]interface{})["to"].(string) 107 | } 108 | 109 | if len(targetAddress) != 0 { 110 | phishing, pha := m.isPhishingAddress(targetAddress) 111 | if phishing { 112 | reporter := "" 113 | if len(pha.Reporter) > 0 { 114 | reporter = "Reporter: " + pha.Reporter 115 | } 116 | notify.Send("Option denied - scam address", m.shortAddress(targetAddress), reporter) 117 | logger.Error("Option denied", "target", targetAddress, "Reason", pha.Description, "reporter", pha.Reporter) 118 | return aggregator.ErrDenyRequest 119 | } 120 | } 121 | 122 | } 123 | return nil 124 | } 125 | 126 | func (m *SafetyMiddleware) OnProcess(session *rpc.Session) error { 127 | return nil 128 | } 129 | 130 | func (m *SafetyMiddleware) OnResponse(session *rpc.Session) error { 131 | return nil 132 | } 133 | 134 | func (m *SafetyMiddleware) shortAddress(address string) string { 135 | length := len(address) 136 | if length > 10 { 137 | return address[0:6] + "..." + address[length-4:] 138 | } 139 | return address 140 | } 141 | 142 | func (m *SafetyMiddleware) updateAuthorityPhishingDb() { 143 | cfg := config.Clone() 144 | cli := client.NewClient(cfg.RequestTimeout, cfg.Proxy) 145 | for _, adb := range cfg.AuthorityDB { 146 | if !adb.Enable { 147 | logger.Warn("Authority phishing db not enable", "provider", adb.Name) 148 | continue 149 | } 150 | logger.Info("Updating authority phishing db", "provider", adb.Name) 151 | req := &fasthttp.Request{} 152 | resp := &fasthttp.Response{} 153 | req.Header.SetMethod(fasthttp.MethodGet) 154 | req.Header.Set("Accept-Encoding", "gzip,deflate,br") 155 | req.SetRequestURI(adb.Url) 156 | 157 | err := cli.Do(req, resp) 158 | if err != nil { 159 | log.Error("Phishing db update failed", "url", adb.Url, "err", err) 160 | continue 161 | } 162 | result := map[string]string{} 163 | body, _ := resp.BodyUncompressed() 164 | err = json.Unmarshal(body, &result) 165 | 166 | addrMap := map[string]*phishingAddress{} 167 | for addr, desc := range result { 168 | pha := &phishingAddress{ 169 | Address: strings.ToLower(addr), 170 | Description: desc, 171 | Reporter: adb.Name, 172 | } 173 | 174 | addrMap[addr] = pha 175 | } 176 | logger.Info("Updated authority phishing db", "addresses", len(addrMap)) 177 | authorityPhishingAddressMap[adb.Name] = addrMap 178 | 179 | } 180 | } 181 | 182 | func (m *SafetyMiddleware) updatePhishingDb() { 183 | cfg := config.Clone() 184 | if cfg.PhishingDb == nil || len(cfg.PhishingDb) == 0 { 185 | return 186 | } 187 | 188 | cli := client.NewClient(cfg.RequestTimeout, cfg.Proxy) 189 | req := &fasthttp.Request{} 190 | resp := &fasthttp.Response{} 191 | req.Header.Set("Accept-Encoding", "gzip,deflate,br") 192 | 193 | hasError := false 194 | 195 | addrMap := map[string]*phishingAddress{} 196 | for _, dbUrl := range cfg.PhishingDb { 197 | logger.Info("Updating phishing db", "url", dbUrl) 198 | 199 | func() { 200 | defer func() { 201 | if err := recover(); err != nil { 202 | logger.Error("Error update phishing db", "err", err) 203 | } 204 | }() 205 | 206 | req.SetRequestURI(dbUrl) 207 | req.Header.SetMethod(fasthttp.MethodGet) 208 | err := cli.Do(req, resp) 209 | if err != nil { 210 | log.Error("Phishing db update failed", "url", dbUrl, "err", err) 211 | hasError = true 212 | return 213 | } 214 | result := map[string]string{} 215 | body, _ := resp.BodyUncompressed() 216 | err = json.Unmarshal(body, &result) 217 | if err != nil { 218 | log.Error("Phishing db update failed", "url", dbUrl, "err", err) 219 | return 220 | } 221 | 222 | for addr, desc := range result { 223 | pha := &phishingAddress{ 224 | Address: strings.ToLower(addr), 225 | Description: desc, 226 | } 227 | addrMap[addr] = pha 228 | } 229 | 230 | }() 231 | } 232 | 233 | mu.Lock() 234 | defer mu.Unlock() 235 | phishingAddressMap = addrMap 236 | 237 | count := len(phishingAddressMap) 238 | logger.Info("Updated phishing db", "addresses", count) 239 | 240 | if !hasError { 241 | lastUpdateAt = time.Now() 242 | } 243 | } 244 | 245 | func (m *SafetyMiddleware) isPhishingAddress(address string) (bool, *phishingAddress) { 246 | mu.Lock() 247 | defer mu.Unlock() 248 | address = strings.ToLower(address) 249 | 250 | var isPhishingAddress bool 251 | 252 | var descs = map[string]string{} 253 | var reporters []string 254 | 255 | pha, exist := phishingAddressMap[address] 256 | if exist { 257 | isPhishingAddress = true 258 | descs[pha.Description] = pha.Description 259 | if len(pha.Reporter) > 0 { 260 | reporters = append(reporters, pha.Reporter) 261 | } 262 | } 263 | 264 | for provider, phaMap := range authorityPhishingAddressMap { 265 | var hash string 266 | switch provider { 267 | case "goplus": 268 | hash = safety.RpcHubAddress(safety.GoPlusAddress(address)) 269 | case "slowmist": 270 | hash = safety.RpcHubAddress(safety.SlowMistAddress(address)) 271 | } 272 | 273 | if len(hash) > 0 { 274 | pha, exist = phaMap[hash] 275 | if exist { 276 | descs[pha.Description] = pha.Description 277 | if len(pha.Reporter) > 0 { 278 | reporters = append(reporters, pha.Reporter) 279 | } 280 | isPhishingAddress = true 281 | } 282 | } 283 | } 284 | 285 | if isPhishingAddress { 286 | var desc []string 287 | for k, _ := range descs { 288 | desc = append(desc, k) 289 | } 290 | 291 | return true, &phishingAddress{ 292 | Address: address, 293 | Description: strings.TrimSpace(strings.Join(desc, ", ")), 294 | Reporter: strings.TrimSpace(strings.Join(reporters, ", ")), 295 | } 296 | } 297 | 298 | return false, nil 299 | } 300 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= 2 | github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= 3 | github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= 4 | github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o= 5 | github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= 6 | github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= 7 | github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k= 8 | github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= 9 | github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= 10 | github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= 11 | github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 12 | github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= 13 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= 14 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= 15 | github.com/clbanning/mxj/v2 v2.5.5 h1:oT81vUeEiQQ/DcHbzSytRngP6Ky9O+L+0Bw0zSJag9E= 16 | github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s= 17 | github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= 18 | github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 19 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 20 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 21 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 22 | github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb h1:6S+TKObz6+Io2c8IOkcbK4Sz7nj6RpEVU7TkvmsZZcw= 23 | github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb/go.mod h1:wf3nKtOnQqCp7kp9xB7hHnNlZ6m3NoiOxjrB9hFRq4Y= 24 | github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0= 25 | github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= 26 | github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc= 27 | github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= 28 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= 29 | github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= 30 | github.com/ethereum/go-ethereum v1.10.25 h1:5dFrKJDnYf8L6/5o42abCE6a9yJm9cs4EJVRyYMr55s= 31 | github.com/ethereum/go-ethereum v1.10.25/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg= 32 | github.com/fasthttp/router v1.4.12 h1:QEgK+UKARaC1bAzJgnIhdUMay6nwp+YFq6VGPlyKN1o= 33 | github.com/fasthttp/router v1.4.12/go.mod h1:41Qdc4Z4T2pWVVtATHCnoUnOtxdBoeKEYJTXhHwbxCQ= 34 | github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= 35 | github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= 36 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 37 | github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= 38 | github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= 39 | github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= 40 | github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 41 | github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= 42 | github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 43 | github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= 44 | github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 45 | github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= 46 | github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= 47 | github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= 48 | github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= 49 | github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= 50 | github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= 51 | github.com/gogf/gf/v2 v2.2.0 h1:J1b+ORVr9GQyuvb7PlQq07IfU2Qe89zN2gJXXu8nBb0= 52 | github.com/gogf/gf/v2 v2.2.0/go.mod h1:thvkyb43RWUu/m05sRm4CbH9r7t7/FrW2M56L9Ystwk= 53 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 54 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 55 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 56 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 57 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 58 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 59 | github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= 60 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 61 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 62 | github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= 63 | github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 64 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 65 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 66 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 67 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 68 | github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= 69 | github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= 70 | github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 71 | github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= 72 | github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 73 | github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= 74 | github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 75 | github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0= 76 | github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78= 77 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= 78 | github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= 79 | github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac h1:n1DqxAo4oWPMvH1+v+DLYlMCecgumhhgnxAPdqDIFHI= 80 | github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac/go.mod h1:cOaXtrgN4ScfRrD9Bre7U1thNq5RtJ8ZoP4iXVGRj6o= 81 | github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= 82 | github.com/klauspost/compress v1.15.11 h1:Lcadnb3RKGin4FYM/orgq0qde+nc15E5Cbqg4B9Sx9c= 83 | github.com/klauspost/compress v1.15.11/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= 84 | github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= 85 | github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= 86 | github.com/martinlindhe/notify v0.0.0-20181008203735-20632c9a275a h1:nQcAxLK581HrmqF0TVy2GC3iFjB8X+aWGtxQ/t2uyGE= 87 | github.com/martinlindhe/notify v0.0.0-20181008203735-20632c9a275a/go.mod h1:zL1p4SieQ27ZZ4V4KdVYdEcSkVl1OwNoi8xI1r5hJkc= 88 | github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= 89 | github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= 90 | github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= 91 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 92 | github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= 93 | github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= 94 | github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= 95 | github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= 96 | github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ= 97 | github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U= 98 | github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= 99 | github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= 100 | github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= 101 | github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= 102 | github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= 103 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 104 | github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= 105 | github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= 106 | github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= 107 | github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= 108 | github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= 109 | github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= 110 | github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= 111 | github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= 112 | github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= 113 | github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= 114 | github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= 115 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 116 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 117 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 118 | github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA= 119 | github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= 120 | github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 121 | github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d h1:Q+gqLBOPkFGHyCJxXMRqtUgUbTjI8/Ze8vu8GGyNFwo= 122 | github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4= 123 | github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU= 124 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 125 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 126 | github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= 127 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 128 | github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= 129 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 130 | github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= 131 | github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= 132 | github.com/tklauser/go-sysconf v0.3.5 h1:uu3Xl4nkLzQfXNsWn15rPc/HQCJKObbt1dKJeWp3vU4= 133 | github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA= 134 | github.com/urfave/cli/v2 v2.19.2 h1:eXu5089gqqiDQKSnFW+H/FhjrxRGztwSxlTsVK7IuqQ= 135 | github.com/urfave/cli/v2 v2.19.2/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI= 136 | github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= 137 | github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= 138 | github.com/valyala/fasthttp v1.40.0 h1:CRq/00MfruPGFLTQKY8b+8SfdK60TxNztjRMnH0t1Yc= 139 | github.com/valyala/fasthttp v1.40.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I= 140 | github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= 141 | github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= 142 | github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= 143 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 144 | github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= 145 | go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM= 146 | go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk= 147 | go.opentelemetry.io/otel/sdk v1.7.0 h1:4OmStpcKVOfvDOgCt7UriAPtKolwIhxpnSNI/yK+1B0= 148 | go.opentelemetry.io/otel/sdk v1.7.0/go.mod h1:uTEOTwaqIVuTGiJN7ii13Ibp75wJmYUDe374q6cZwUU= 149 | go.opentelemetry.io/otel/trace v1.7.0 h1:O37Iogk1lEkMRXewVtZ1BBTVn5JEp8GrJvP92bJqC6o= 150 | go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48yyE4TNvoHqU= 151 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 152 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 153 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 154 | golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE= 155 | golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= 156 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 157 | golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 158 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 159 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 160 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 161 | golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 162 | golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 163 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 164 | golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= 165 | golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 166 | golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 167 | golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= 168 | golang.org/x/net v0.0.0-20220607020251-c690dde0001d h1:4SFsTMi4UahlKoloni7L4eYzhFRifURQLw+yv0QDCx8= 169 | golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 170 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 171 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 172 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 173 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 174 | golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0 h1:cu5kTvlzcw1Q5S9f5ip1/cpiB4nXvw1XYzFPGgzLUOY= 175 | golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 176 | golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 177 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 178 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 179 | golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 180 | golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 181 | golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 182 | golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 183 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 184 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 185 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 186 | golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 187 | golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 188 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 189 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 190 | golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 191 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 192 | golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 193 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 194 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 195 | golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 196 | golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 197 | golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 198 | golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 199 | golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 200 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= 201 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 202 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 203 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 204 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 205 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 206 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 207 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 208 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 209 | golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y= 210 | golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0= 211 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 212 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 213 | golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= 214 | golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= 215 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 216 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 217 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 218 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 219 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 220 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 221 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 222 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 223 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 224 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 225 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 226 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 227 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 228 | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= 229 | gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2 h1:MZF6J7CV6s/h0HBkfqebrYfKCVEo5iN+wzE4QhV3Evo= 230 | gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2/go.mod h1:s1Sn2yZos05Qfs7NKt867Xe18emOmtsO3eAKbDaon0o= 231 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= 232 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= 233 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 234 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 235 | gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 236 | gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 237 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 238 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 239 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 240 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 241 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 242 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------