-
Notifications
You must be signed in to change notification settings - Fork 126
server: add communication hub #33
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
Conversation
bd98cca
to
7824eea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the beginning of a review, but there is discussion going on now that it's relevant to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just nits really.
|
||
// Create an HTTP router, putting a couple of useful middlewares in place. | ||
mux := chi.NewRouter() | ||
mux.Use(middleware.RealIP) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mux.Use(middleware.RealIP) // TODO: make an option since a reverse proxy is needed with this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can revisit this. Real IP detection is precarious, and we've dealt with it a bit in dcrdata. But let's not hold this up because of it.
server/comms/wsclient.go
Outdated
default: | ||
log.Warnf("RPCClient outgoing message channel is blocking. disconnecting") | ||
c.disconnect() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you get a chance, could you please review the PR decred/dcrdata#1571?
Specifically, it's addressing an issue (one of a few) where a full channel was causing a disconnect, but it was not invalid to have a flood of messages in certain cases. The buffer really should be there just for performance, and should almost certainly not result in an error if it is backed up.
https://github.com/decred/dcrdata/pull/1571/files#diff-52517481ff8865495645ee67fb5a8a30R395-R418
I think that putting the send case with a case on the killed/closed channel should be sufficient, but I put a timer in case there's a bug that prevents one of the cases from being hit. But I believe if the outChan
is really going to block forever, it's because the client is shutdown. I think this is a safe approach as long as the goroutine that should be receiving on outChan
guarantees that the close
channel gets closed when it and the loop returns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a select for the quit
channel, but no timer or default
case for now. I think we just need to poke at it during load testing. I'll review decred/dcrdata#1571 too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just those typos and LGTM
Adds a websocket and http server as part of the new comms package. The server is currently only used for websockets at the /ws endpoint, but adding more endpoints is trivial. Websockets are done with gorilla. I'm using the go-chi package for http routing, which seems like overkill for a single endpoint, but will become more useful as the number grows. The server is pretty basic, but it does have small middleware stack and the ability to temporarily blacklist an IP address.
Resolves #6
Adds a websocket and http server as part of the new comms package. The server is currently only used for websockets at the /ws endpoint, but adding more endpoints is trivial.
Websockets are done with gorilla. I'm using the go-chi package for http routing, which seems like overkill for a single endpoint, but will become more useful as the number grows.
The server is pretty basic for now, but it does have a small useful middleware stack and the ability to temporarily blacklist an IP address.