Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node: allow websocket and HTTP on the same port #20810

Merged
merged 56 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
0ee8a31
errors in comments for http.go
renaynay Feb 28, 2020
b8aaf24
consistency
renaynay Feb 28, 2020
7b81c6c
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay Mar 1, 2020
8911212
correcting typos in documentation for subscription.go
renaynay Mar 1, 2020
94e2d2a
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay Mar 11, 2020
1a1aaaf
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay Mar 12, 2020
1f7c7d0
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay Mar 16, 2020
1fc5827
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay Mar 16, 2020
a3204ee
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay Mar 23, 2020
aef6981
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay Mar 23, 2020
991237a
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay Mar 24, 2020
e13d78d
dirty functional implementation, some tests broken, some commented out
renaynay Mar 24, 2020
6becdde
added space
renaynay Mar 24, 2020
46eb11c
handler stack creation moved from rpc to node pkg
renaynay Mar 24, 2020
62bb958
fixed retesteth
renaynay Mar 24, 2020
fdff70c
fixed some TODOs
renaynay Mar 24, 2020
5eb0146
moved whitelist generation and api registration into separate method
renaynay Mar 24, 2020
307f70b
Merge pull request #3 from renaynay/handle-ws-only-if-specified
renaynay Mar 24, 2020
631488c
Merge pull request #2 from renaynay/handler-stack
renaynay Mar 24, 2020
339ba89
move handler creation to pkg node, remove deprecated function
renaynay Mar 25, 2020
8adb2f2
updating retesteth.go to remove adding the ws handler
renaynay Mar 25, 2020
eced2db
remove gzip file
renaynay Mar 25, 2020
74cd4f2
dont overwrite registering apis
renaynay Mar 25, 2020
8766f6a
removing some unnecessary whitespace
renaynay Mar 25, 2020
a87383b
fixed merge conflict
renaynay Mar 25, 2020
3131d6e
Merge pull request #4 from renaynay/node-handles-handler-creation
renaynay Mar 25, 2020
3de74d2
fixed some errors related to crashing travis build
renaynay Mar 25, 2020
a305f5a
removing unnecessary function
renaynay Mar 25, 2020
440ccbe
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay Mar 26, 2020
ba2c128
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay Mar 27, 2020
c8c18ba
fixed a typo in graphql service
renaynay Mar 27, 2020
04bae1d
Merge branch 'master' into multiplex-ws-rpc
renaynay Mar 27, 2020
4605994
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay Mar 27, 2020
2321f64
Merge branch 'master' into multiplex-ws-rpc
renaynay Mar 27, 2020
142b5f7
some docs
renaynay Mar 30, 2020
ef49e55
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay Mar 30, 2020
2538a69
Merge branch 'master' into multiplex-ws-rpc
renaynay Mar 30, 2020
a08ccfe
graphql works with new http server setup (#7)
renaynay Mar 30, 2020
aab171f
Matches the startup process of websocket server to that of http serve…
renaynay Mar 30, 2020
bdd1091
using rpc.CheckTimeouts instead of duplicate timeout check
renaynay Mar 30, 2020
51c6d69
Tests for handling websocket and http requests on the same server (#6)
renaynay Mar 30, 2020
03172fa
fixed incorrect call to register apis from whitelist in clef/main.go
renaynay Mar 30, 2020
9651389
added error check
renaynay Mar 30, 2020
4261aea
fixed import issue
renaynay Mar 30, 2020
c4f6bfc
removed some unnecessary whitespace
renaynay Mar 30, 2020
f9f85c4
removed some todos and fixed comment according to martins suggestion
renaynay Mar 30, 2020
e4d31d2
fixed using a port thats already in use for a test
renaynay Mar 31, 2020
1772c8c
move http endpoint startup from rpc to node pkg (#9)
renaynay Mar 31, 2020
7ce555d
removed todos and changed http port in test once again to check travi…
renaynay Mar 31, 2020
6e135ec
tests were attempting to restart server, fixed
renaynay Mar 31, 2020
19f658d
deleting whitespace and re-ordering args for test function
renaynay Apr 8, 2020
eebca1d
removed unnecessary channel / goroutine from ws and http tests
renaynay Apr 8, 2020
4e71c2a
cmd/geth: fix whitespace
fjl Apr 8, 2020
1fb1018
cmd/clef: fix whitespace
fjl Apr 8, 2020
1751298
cmd/clef: fix lint
fjl Apr 8, 2020
97d89ca
cmd/geth: fix lint
fjl Apr 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
graphql works with new http server setup (#7)
  • Loading branch information
renaynay committed Mar 30, 2020
commit a08ccfe8e6334592b91327a997b72a405fbcdb25
48 changes: 38 additions & 10 deletions graphql/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import (
"fmt"
"net"
"net/http"
"time"

"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"
"github.com/graph-gophers/graphql-go"
Expand Down Expand Up @@ -60,19 +62,45 @@ func (s *Service) APIs() []rpc.API { return nil }
// Start is called after all services have been constructed and the networking
// layer was also initialized to spawn any goroutines required by the service.
func (s *Service) Start(server *p2p.Server) error {
//var err error
//s.handler, err = newHandler(s.backend)
//if err != nil {
// return err
//}
//if s.listener, err = net.Listen("tcp", s.endpoint); err != nil {
// return err
//}
//go rpc.NewHTTPServer(s.cors, s.vhosts, s.timeouts, s.handler, []string{}).Serve(s.listener)
//log.Info("GraphQL endpoint opened", "url", fmt.Sprintf("http://%s", s.endpoint))
var err error
s.handler, err = newHandler(s.backend)
if err != nil {
return err
}
if s.listener, err = net.Listen("tcp", s.endpoint); err != nil {
return err
}
// create handler stack and wrap the graphql handler
handler := node.NewHTTPHandlerStack(s.handler, s.cors, s.vhosts)
// make sure timeout values are meaningful
registerTimeouts(&s.timeouts)
// create http server
httpSrv := &http.Server{
Handler: handler,
ReadTimeout: s.timeouts.ReadTimeout,
WriteTimeout: s.timeouts.WriteTimeout,
IdleTimeout: s.timeouts.IdleTimeout,
}
go httpSrv.Serve(s.listener)
log.Info("GraphQL endpoint opened", "url", fmt.Sprintf("http://%s", s.endpoint))
return nil
}

func registerTimeouts(timeouts *rpc.HTTPTimeouts){
if timeouts.ReadTimeout < time.Second {
log.Warn("Sanitizing invalid HTTP read timeout", "provided", timeouts.ReadTimeout, "updated", rpc.DefaultHTTPTimeouts.ReadTimeout)
timeouts.ReadTimeout = rpc.DefaultHTTPTimeouts.ReadTimeout
}
if timeouts.WriteTimeout < time.Second {
log.Warn("Sanitizing invalid HTTP write timeout", "provided", timeouts.WriteTimeout, "updated", rpc.DefaultHTTPTimeouts.WriteTimeout)
timeouts.WriteTimeout = rpc.DefaultHTTPTimeouts.WriteTimeout
}
if timeouts.IdleTimeout < time.Second {
log.Warn("Sanitizing invalid HTTP idle timeout", "provided", timeouts.IdleTimeout, "updated", rpc.DefaultHTTPTimeouts.IdleTimeout)
timeouts.IdleTimeout = rpc.DefaultHTTPTimeouts.IdleTimeout
}
}

// newHandler returns a new `http.Handler` that will answer GraphQL queries.
// It additionally exports an interactive query browser on the / endpoint.
func newHandler(backend ethapi.Backend) (http.Handler, error) {
Expand Down
3 changes: 1 addition & 2 deletions node/rpcstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ import (
"sync"

"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
"github.com/rs/cors"
)

// NewHTTPHandlerStack returns wrapped http-related handlers
func NewHTTPHandlerStack(srv *rpc.Server, cors []string, vhosts []string) http.Handler {
func NewHTTPHandlerStack(srv http.Handler, cors []string, vhosts []string) http.Handler {
// Wrap the CORS-handler within a host-handler
handler := newCorsHandler(srv, cors)
handler = newVHostHandler(vhosts, handler)
Expand Down