aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2020-06-07 16:32:48 -0400
committerDeterminant <[email protected]>2020-06-07 16:32:48 -0400
commita973e36064786c54d050c64e665d78661e7883a7 (patch)
tree19e241068ebfd6b41b11fe874feea64a441a49ec /plugin
parent803878756eafc3f3c86198ad9f5a8893a63cf7df (diff)
new branch: denali-next
Diffstat (limited to 'plugin')
-rw-r--r--plugin/evm/vm.go20
1 files changed, 18 insertions, 2 deletions
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{"*"}))},
}
}