aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephenButtolph <[email protected]>2020-06-07 17:58:22 -0400
committerStephenButtolph <[email protected]>2020-06-07 17:58:22 -0400
commit6a33e292321a38ad07bd4e19459896e5c8d532d1 (patch)
treec4305fd69f66488c1ac76ed9bdf038c96cb02b6c
parent72542f28d66678d2fa47ec6c1aeedc6c988ad409 (diff)
parent7661fa34f0682b326b336b026c8624e5e51166b8 (diff)
Merge remote-tracking branch 'origin/denali-next' into denaliv0.2.4
-rw-r--r--coreth.go2
-rw-r--r--plugin/evm/vm.go27
2 files changed, 24 insertions, 5 deletions
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 3171a6b..bd8f9a4 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"
@@ -335,6 +337,23 @@ 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.WriteHeader(404)
+ writer.Write([]byte("404 page not found\r\n"))
+}
+
+func newIPFilter(handler http.Handler) http.Handler {
+ return ipFilter{handler}
+}
+
// CreateHandlers makes new http handlers that can handle API calls
func (vm *VM) CreateHandlers() map[string]*commonEng.HTTPHandler {
handler := vm.chain.NewRPCHandler()
@@ -345,8 +364,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{"*"}))},
}
}
@@ -355,8 +374,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{"*"}))},
}
}