Enable add/remove routes after server starts#15
Enable add/remove routes after server starts#15yangchenyun wants to merge 10 commits intoinetaf:masterfrom
Conversation
- Use a map instead of slice to hold routes for each configuration - Use a lock to guard read / write to the routes - Issue a serial number for the route added in order to remove them later - Add/RemoveRoute is thread-safe
- returns null routeId to indicate a failed registration
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
|
I signed it! |
|
CLAs look good, thanks! |
- Add the test case for existing backends - Add the test case for add/remove route after server starts
|
All the renamings in this PR obscure the actual change you're trying to make. Can you split your changes into two parts, or refrain from renames for now? |
tcpproxy.go
Outdated
| // not found, this is an no-op. | ||
| // | ||
| // Both AddRoute and RemoveRoute is go-routine safe. | ||
| func (p *Proxy) RemoveRoute(ipPort string, routeId int) (err error) { |
There was a problem hiding this comment.
tcpproxy.go
Outdated
| // The ipPort is any valid net.Listen TCP address. | ||
| func (p *Proxy) AddRoute(ipPort string, dest Target) { | ||
| p.addRoute(ipPort, fixedTarget{dest}) | ||
| func (p *Proxy) AddRoute(ipPort string, dest Target) (routeId int) { |
There was a problem hiding this comment.
rebase to fix the case of these originally, rather than fixing it in a later commit in the series.
tcpproxy.go
Outdated
| stopACME bool // if true, AddSNIRoute doesn't add targets to acmeTargets. | ||
| } | ||
|
|
||
| func NewConfig() (cfg *config) { |
There was a problem hiding this comment.
needs docs.
and unname result parameter per https://github.com/golang/go/wiki/CodeReviewComments#named-result-parameters
but actually I'd just delete this and let the zero value of Config be useful. You can initialize the routes map as needed.
tcpproxy.go
Outdated
| // config contains the proxying state for one listener. | ||
| type config struct { | ||
| routes []route | ||
| sync.Mutex // protect r/w of routes |
There was a problem hiding this comment.
comment should be like:
mu sync.Mutex // guards following
x int
y int
and blank line before stuff that is no longer guarded by it.
|
I separated the test refactoring in a #16, and I would do rebase and squash after that is check in. |
|
Adding routes only works for an already registered ipPort. The stuff in done in tcpproxy.Start() - looping over configs and calling p.netListen() is not done again. For removal of a route, it would be nice to cancel onging connections for this route. This would require a map or list of ongoing connections for a route |
Also added two test helpers to simplify and complete existing tests: