Skip to content

Commit

Permalink
idleconn timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ls0f committed Aug 1, 2017
1 parent 3a8987a commit 3126d2d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cracker/proxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (hp *httpProxy) connect(w http.ResponseWriter, r *http.Request) {
host := r.Header.Get("DSTHOST")
port := r.Header.Get("DSTPORT")
addr := fmt.Sprintf("%s:%s", host, port)
remote, err := net.DialTimeout("tcp", addr, time.Duration(time.Second*timeout))
remote, err := net.DialTimeout("tcp", addr, time.Second*timeout)
if err != nil {
WriteHTTPError(w, fmt.Sprintf("could not connect to %s", addr))
return
Expand All @@ -191,7 +191,7 @@ func (hp *httpProxy) connect(w http.ResponseWriter, r *http.Request) {
go func() {
pc.Do()
g.Debugf("disconnect %s", remote.RemoteAddr().String())
<-time.After(time.Duration(time.Second * heartTTL))
<-time.After(time.Second * heartTTL)
hp.Lock()
g.Debugf("delete uuid:%s ... \n", proxyID)
delete(hp.proxyMap, proxyID)
Expand Down
9 changes: 5 additions & 4 deletions cracker/proxy/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var tr = &http.Transport{
DisableKeepAlives: false,
MaxIdleConnsPerHost: PerHostNum,
Proxy: http.ProxyFromEnvironment,
TLSHandshakeTimeout: time.Duration(time.Second * timeout / 2),
TLSHandshakeTimeout: time.Second * timeout / 2,
IdleConnTimeout: time.Second * 90,
}

func Init(cert string) {
Expand Down Expand Up @@ -68,7 +69,7 @@ func (c *localProxyConn) gen_sign(req *http.Request) {
}

func (c *localProxyConn) push(data []byte, typ string) error {
hc := &http.Client{Transport: tr, Timeout: time.Duration(time.Second * timeout)}
hc := &http.Client{Transport: tr, Timeout: time.Second * timeout}
buf := bufio.NewBuffer(data)
req, _ := http.NewRequest("POST", c.server+PUSH, buf)
c.gen_sign(req)
Expand All @@ -90,7 +91,7 @@ func (c *localProxyConn) push(data []byte, typ string) error {
}

func (c *localProxyConn) connect(dstHost, dstPort string) (uuid string, err error) {
hc := &http.Client{Transport: tr, Timeout: time.Duration(time.Second * timeout)}
hc := &http.Client{Transport: tr, Timeout: time.Second * timeout}
req, _ := http.NewRequest("GET", c.server+CONNECT, nil)
c.gen_sign(req)
req.Header.Set("DSTHOST", dstHost)
Expand Down Expand Up @@ -149,7 +150,7 @@ func (c *localProxyConn) alive() {
select {
case <-c.close:
return
case <-time.After(time.Duration(time.Second * heartTTL / 2)):
case <-time.After(time.Second * heartTTL / 2):
if err := c.push([]byte("alive"), HEART_TYP); err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion cracker/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (pc *proxyConn) Do() {

for {
select {
case <-time.After(time.Duration(time.Second * heartTTL)):
case <-time.After(time.Second * heartTTL):
return
case <-pc.close:
return
Expand Down

0 comments on commit 3126d2d

Please sign in to comment.