From a973e36064786c54d050c64e665d78661e7883a7 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 7 Jun 2020 16:32:48 -0400 Subject: new branch: denali-next --- plugin/evm/vm.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'plugin/evm') diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 2dd0dd8..fbea1a3 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -327,6 +327,22 @@ func (vm *VM) LastAccepted() ids.ID { return vm.lastAccepted.ID() } +type ipFilter struct { + handler http.Handler +} + +func (ipf ipFilter) ServeHTTP(writer http.ResponseWriter, request *http.Request) { + if ips, _, err := net.SplitHostPort(request.RemoteAddr); err != nil && ips == "127.0.0.1" { + ipf.handler.ServeHTTP(writer, request) + return + } + writer.WriterHeader(404) +} + +func NewIPFilter(handler http.Handler) { + ipFilter{handler} +} + // CreateHandlers makes new http handlers that can handle API calls func (vm *VM) CreateHandlers() map[string]*commonEng.HTTPHandler { handler := vm.chain.NewRPCHandler() @@ -337,8 +353,8 @@ func (vm *VM) CreateHandlers() map[string]*commonEng.HTTPHandler { handler.RegisterName("debug", &DebugAPI{vm}) return map[string]*commonEng.HTTPHandler{ - "/rpc": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: handler}, - "/ws": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: handler.WebsocketHandler([]string{"*"})}, + "/rpc": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: NewIPFilter(handler)}, + "/ws": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: NewIPFilter(handler.WebsocketHandler([]string{"*"}))}, } } -- cgit v1.2.3-70-g09d2 From 4ba8654f8cefd069cd730a51ce516ad76931a354 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 7 Jun 2020 16:40:12 -0400 Subject: add the missing imports --- plugin/evm/vm.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'plugin/evm') diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index fbea1a3..c10e2b9 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -9,6 +9,8 @@ import ( "errors" "fmt" "math/big" + "net" + "net/http" "sync" "sync/atomic" "time" -- cgit v1.2.3-70-g09d2 From ab977c426fe8021275fc1c7fd6cdb80d42191886 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 7 Jun 2020 16:46:44 -0400 Subject: ... --- plugin/evm/vm.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'plugin/evm') diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index c10e2b9..57b2eda 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -338,11 +338,11 @@ func (ipf ipFilter) ServeHTTP(writer http.ResponseWriter, request *http.Request) ipf.handler.ServeHTTP(writer, request) return } - writer.WriterHeader(404) + writer.WriteHeader(404) } -func NewIPFilter(handler http.Handler) { - ipFilter{handler} +func newIPFilter(handler http.Handler) http.Handler { + return ipFilter{handler} } // CreateHandlers makes new http handlers that can handle API calls @@ -355,8 +355,8 @@ func (vm *VM) CreateHandlers() map[string]*commonEng.HTTPHandler { handler.RegisterName("debug", &DebugAPI{vm}) return map[string]*commonEng.HTTPHandler{ - "/rpc": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: NewIPFilter(handler)}, - "/ws": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: NewIPFilter(handler.WebsocketHandler([]string{"*"}))}, + "/rpc": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: newIPFilter(handler)}, + "/ws": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: newIPFilter(handler.WebsocketHandler([]string{"*"}))}, } } -- cgit v1.2.3-70-g09d2 From 298d08dbf8b74a32f7bb74e25cc5bf729c35a6da Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Sun, 7 Jun 2020 21:27:09 +0000 Subject: fix minor typo --- coreth.go | 2 +- plugin/evm/vm.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'plugin/evm') diff --git a/coreth.go b/coreth.go index 019f480..06399b9 100644 --- a/coreth.go +++ b/coreth.go @@ -90,7 +90,7 @@ func (self *ETHChain) PendingSize() (int, error) { } func (self *ETHChain) AddRemoteTxs(txs []*types.Transaction) []error { - return self.backend.TxPool().AddRemotesSync(txs) + return self.backend.TxPool().AddRemotes(txs) } func (self *ETHChain) AddLocalTxs(txs []*types.Transaction) []error { diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 57b2eda..929725d 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -334,11 +334,12 @@ type ipFilter struct { } func (ipf ipFilter) ServeHTTP(writer http.ResponseWriter, request *http.Request) { - if ips, _, err := net.SplitHostPort(request.RemoteAddr); err != nil && ips == "127.0.0.1" { + if ips, _, err := net.SplitHostPort(request.RemoteAddr); err == nil && ips == "127.0.0.1" { ipf.handler.ServeHTTP(writer, request) return } writer.WriteHeader(404) + writer.Write([]byte("404 page not found")) } func newIPFilter(handler http.Handler) http.Handler { -- cgit v1.2.3-70-g09d2 From 734e7686a684030e2b9f1179af7f560683f2e913 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 7 Jun 2020 17:32:22 -0400 Subject: ... --- plugin/evm/vm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugin/evm') diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 929725d..10a4854 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -339,7 +339,7 @@ func (ipf ipFilter) ServeHTTP(writer http.ResponseWriter, request *http.Request) return } writer.WriteHeader(404) - writer.Write([]byte("404 page not found")) + writer.Write([]byte("404 page not found\r\n")) } func newIPFilter(handler http.Handler) http.Handler { -- cgit v1.2.3-70-g09d2 From 7661fa34f0682b326b336b026c8624e5e51166b8 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 7 Jun 2020 17:56:50 -0400 Subject: add ipFilter to "static" RPC --- plugin/evm/vm.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugin/evm') diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 10a4854..fc4c971 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -366,8 +366,8 @@ func (vm *VM) CreateStaticHandlers() map[string]*commonEng.HTTPHandler { handler := rpc.NewServer() handler.RegisterName("static", &StaticService{}) return map[string]*commonEng.HTTPHandler{ - "/rpc": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: handler}, - "/ws": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: handler.WebsocketHandler([]string{"*"})}, + "/rpc": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: newIPFilter(handler)}, + "/ws": &commonEng.HTTPHandler{LockOptions: commonEng.NoLock, Handler: newIPFilter(handler.WebsocketHandler([]string{"*"}))}, } } -- cgit v1.2.3-70-g09d2