Skip to content

Commit

Permalink
getlantern/lantern#2196 Added support for MinQOS configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Jan 27, 2015
1 parent 16c4258 commit fe75e67
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/github.com/getlantern/flashlight/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type Client struct {
// WriteTimeout: (optional) timeout for write ops
WriteTimeout time.Duration

// MinQOS: (optional) the minimum QOS to require from proxies.
MinQOS int

priorCfg *ClientConfig
priorTrustedCAs *x509.CertPool
cfgMutex sync.RWMutex
Expand Down Expand Up @@ -73,6 +76,8 @@ func (client *Client) Configure(cfg *ClientConfig) {
log.Debugf("Client configuration initialized")
}

log.Debugf("Requiring minimum QOS of %d", cfg.MinQOS)
client.MinQOS = cfg.MinQOS
bal := client.initBalancer(cfg)
client.initReverseProxy(bal, cfg.DumpHeaders)
client.initNatty(cfg)
Expand Down
1 change: 1 addition & 0 deletions src/github.com/getlantern/flashlight/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (

// ClientConfig captures configuration information for a Client
type ClientConfig struct {
MinQOS int
DumpHeaders bool // whether or not to dump headers of requests and responses
FrontedServers []*FrontedServerInfo
ChainedServers map[string]*ChainedServerInfo
Expand Down
8 changes: 4 additions & 4 deletions src/github.com/getlantern/flashlight/client/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (client *Client) intercept(resp http.ResponseWriter, req *http.Request) {
addr := hostIncludingPort(req, 443)

// Establish outbound connection
connOut, err := client.getBalancer().DialQOS("tcp", addr, targetQOS(req))
connOut, err := client.getBalancer().DialQOS("tcp", addr, client.targetQOS(req))
if err != nil {
respondBadGateway(clientConn, fmt.Sprintf("Unable to handle CONNECT request: %s", err))
return
Expand All @@ -55,8 +55,8 @@ func (client *Client) intercept(resp http.ResponseWriter, req *http.Request) {
}

// targetQOS determines the target quality of service given the X-Flashlight-QOS
// header if available, else returns 0.
func targetQOS(req *http.Request) int {
// header if available, else returns MinQOS.
func (client *Client) targetQOS(req *http.Request) int {
requestedQOS := req.Header.Get(XFlashlightQOS)
if requestedQOS != "" {
rqos, err := strconv.Atoi(requestedQOS)
Expand All @@ -65,7 +65,7 @@ func targetQOS(req *http.Request) int {
}
}

return 0
return client.MinQOS
}

// pipeData pipes data between the client and proxy connections. It's also
Expand Down
1 change: 1 addition & 0 deletions src/github.com/getlantern/flashlight/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ func (cfg Config) doFetchCloudConfig(proxyAddr string) ([]byte, error) {
}
defer resp.Body.Close()
if resp.StatusCode == 304 {
log.Debugf("Config unchanged in cloud")
return nil, nil
} else if resp.StatusCode != 200 {
return nil, fmt.Errorf("Unexpected response status: %d", resp.StatusCode)
Expand Down

0 comments on commit fe75e67

Please sign in to comment.