-
Notifications
You must be signed in to change notification settings - Fork 21k
node: allow websocket and HTTP on the same port #20810
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
Merged
Merged
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
0ee8a31
errors in comments for http.go
renaynay b8aaf24
consistency
renaynay 7b81c6c
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay 8911212
correcting typos in documentation for subscription.go
renaynay 94e2d2a
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay 1a1aaaf
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay 1f7c7d0
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay 1fc5827
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay a3204ee
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay aef6981
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay 991237a
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay e13d78d
dirty functional implementation, some tests broken, some commented out
renaynay 6becdde
added space
renaynay 46eb11c
handler stack creation moved from rpc to node pkg
renaynay 62bb958
fixed retesteth
renaynay fdff70c
fixed some TODOs
renaynay 5eb0146
moved whitelist generation and api registration into separate method
renaynay 307f70b
Merge pull request #3 from renaynay/handle-ws-only-if-specified
renaynay 631488c
Merge pull request #2 from renaynay/handler-stack
renaynay 339ba89
move handler creation to pkg node, remove deprecated function
renaynay 8adb2f2
updating retesteth.go to remove adding the ws handler
renaynay eced2db
remove gzip file
renaynay 74cd4f2
dont overwrite registering apis
renaynay 8766f6a
removing some unnecessary whitespace
renaynay a87383b
fixed merge conflict
renaynay 3131d6e
Merge pull request #4 from renaynay/node-handles-handler-creation
renaynay 3de74d2
fixed some errors related to crashing travis build
renaynay a305f5a
removing unnecessary function
renaynay 440ccbe
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay ba2c128
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay c8c18ba
fixed a typo in graphql service
renaynay 04bae1d
Merge branch 'master' into multiplex-ws-rpc
renaynay 4605994
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay 2321f64
Merge branch 'master' into multiplex-ws-rpc
renaynay 142b5f7
some docs
renaynay ef49e55
Merge branch 'master' of github.com:ethereum/go-ethereum
renaynay 2538a69
Merge branch 'master' into multiplex-ws-rpc
renaynay a08ccfe
graphql works with new http server setup (#7)
renaynay aab171f
Matches the startup process of websocket server to that of http serve…
renaynay bdd1091
using rpc.CheckTimeouts instead of duplicate timeout check
renaynay 51c6d69
Tests for handling websocket and http requests on the same server (#6)
renaynay 03172fa
fixed incorrect call to register apis from whitelist in clef/main.go
renaynay 9651389
added error check
renaynay 4261aea
fixed import issue
renaynay c4f6bfc
removed some unnecessary whitespace
renaynay f9f85c4
removed some todos and fixed comment according to martins suggestion
renaynay e4d31d2
fixed using a port thats already in use for a test
renaynay 1772c8c
move http endpoint startup from rpc to node pkg (#9)
renaynay 7ce555d
removed todos and changed http port in test once again to check travi…
renaynay 6e135ec
tests were attempting to restart server, fixed
renaynay 19f658d
deleting whitespace and re-ordering args for test function
renaynay eebca1d
removed unnecessary channel / goroutine from ws and http tests
renaynay 4e71c2a
cmd/geth: fix whitespace
fjl 1fb1018
cmd/clef: fix whitespace
fjl 1751298
cmd/clef: fix lint
fjl 97d89ca
cmd/geth: fix lint
fjl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2018 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package node | ||
|
||
import ( | ||
"net" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
) | ||
|
||
// StartHTTPEndpoint starts the HTTP RPC endpoint. | ||
func StartHTTPEndpoint(endpoint string, timeouts rpc.HTTPTimeouts, handler http.Handler) (net.Listener, error) { | ||
// start the HTTP listener | ||
var ( | ||
listener net.Listener | ||
err error | ||
) | ||
if listener, err = net.Listen("tcp", endpoint); err != nil { | ||
return nil, err | ||
} | ||
// make sure timeout values are meaningful | ||
CheckTimeouts(&timeouts) | ||
// Bundle and start the HTTP server | ||
httpSrv := &http.Server{ | ||
Handler: handler, | ||
ReadTimeout: timeouts.ReadTimeout, | ||
WriteTimeout: timeouts.WriteTimeout, | ||
IdleTimeout: timeouts.IdleTimeout, | ||
} | ||
go httpSrv.Serve(listener) | ||
return listener, err | ||
} | ||
|
||
// startWSEndpoint starts a websocket endpoint. | ||
func startWSEndpoint(endpoint string, handler http.Handler) (net.Listener, error) { | ||
// start the HTTP listener | ||
var ( | ||
listener net.Listener | ||
err error | ||
) | ||
if listener, err = net.Listen("tcp", endpoint); err != nil { | ||
return nil, err | ||
} | ||
wsSrv := &http.Server{Handler: handler} | ||
go wsSrv.Serve(listener) | ||
return listener, err | ||
} | ||
|
||
// checkModuleAvailability checks that all names given in modules are actually | ||
// available API services. It assumes that the MetadataApi module ("rpc") is always available; | ||
// the registration of this "rpc" module happens in NewServer() and is thus common to all endpoints. | ||
func checkModuleAvailability(modules []string, apis []rpc.API) (bad, available []string) { | ||
availableSet := make(map[string]struct{}) | ||
for _, api := range apis { | ||
if _, ok := availableSet[api.Namespace]; !ok { | ||
availableSet[api.Namespace] = struct{}{} | ||
available = append(available, api.Namespace) | ||
} | ||
} | ||
for _, name := range modules { | ||
if _, ok := availableSet[name]; !ok && name != rpc.MetadataApi { | ||
bad = append(bad, name) | ||
} | ||
} | ||
return bad, available | ||
} | ||
|
||
// CheckTimeouts ensures that timeout values are meaningful | ||
func CheckTimeouts(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 | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.