Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchenyun committed Apr 11, 2018
1 parent a64c39c commit 08e1ca7
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions tcpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,13 @@ func equals(want string) Matcher {
// config contains the proxying state for one listener.
type config struct {
sync.Mutex // protect w of routes
nextRouteID int
routes map[int]route
nextRouteID int

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) {
cfg = &config{}
cfg.routes = make(map[int]route)
cfg.nextRouteID = 1
return
}

// A route matches a connection to a target.
type route interface {
// match examines the initial bytes of a connection, looking for a
Expand All @@ -132,7 +126,10 @@ func (p *Proxy) configFor(ipPort string) *config {
p.configs = make(map[string]*config)
}
if p.configs[ipPort] == nil {
p.configs[ipPort] = newConfig()
cfg := &config{}
cfg.routes = make(map[int]route)
cfg.nextRouteID = 1
p.configs[ipPort] = cfg
}
return p.configs[ipPort]
}
Expand Down Expand Up @@ -173,10 +170,9 @@ func (p *Proxy) AddRoute(ipPort string, dest Target) (routeID int) {
// 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) {
func (p *Proxy) RemoveRoute(ipPort string, routeID int) {
cfg := p.configFor(ipPort)
cfg.routes[routeID] = nil
return
}

type fixedTarget struct {
Expand Down

0 comments on commit 08e1ca7

Please sign in to comment.