-
Notifications
You must be signed in to change notification settings - Fork 159
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
Enable add/remove routes after server starts #15
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Done. Thanks.
tcpproxy.go
Outdated
// | ||
// This is generally used as either the only rule (for simple TCP | ||
// proxies), or as the final fallback rule for an ipPort. | ||
// | ||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rebase to fix the case of these originally, rather than fixing it in a later commit in the series.
tcpproxy.go
Outdated
acmeTargets []Target // accumulates targets that should be probed for acme. | ||
stopACME bool // if true, AddSNIRoute doesn't add targets to acmeTargets. | ||
} | ||
|
||
func NewConfig() (cfg *config) { |
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.
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.
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.
Removed the constructor.
tcpproxy.go
Outdated
@@ -93,11 +94,19 @@ func equals(want string) Matcher { | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Done.
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: