Skip to content

Conversation

buck54321
Copy link
Member

@buck54321 buck54321 commented Sep 17, 2019

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.

@buck54321 buck54321 mentioned this pull request Sep 28, 2019
@buck54321 buck54321 marked this pull request as ready for review September 30, 2019 12:08
@buck54321 buck54321 force-pushed the comms branch 3 times, most recently from bd98cca to 7824eea Compare October 6, 2019 12:33
Copy link
Member

@chappjc chappjc left a 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.

Copy link
Member

@chappjc chappjc left a 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)
Copy link
Member

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

Copy link
Member

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.

default:
log.Warnf("RPCClient outgoing message channel is blocking. disconnecting")
c.disconnect()
}
Copy link
Member

@chappjc chappjc Oct 15, 2019

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.

Copy link
Member Author

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.

Copy link
Member

@chappjc chappjc left a 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.
@chappjc chappjc merged commit 32692e7 into decred:master Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Communication Hub
3 participants