Skip to content

Commit 06541fc

Browse files
committed
finish inverse role server support for webtunnel: fix lint
1 parent b4f1aa5 commit 06541fc

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

transport/internet/request/roundtripperreverserserver/clicommand/generate_token_cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ var cmdGenerateToken = &base.Command{
7979

8080
if *genOut != "" {
8181
content := fmt.Sprintf("private: %s\npublic: %s\n", b64Priv, b64Pub)
82-
if err := os.WriteFile(*genOut, []byte(content), 0600); err != nil {
82+
if err := os.WriteFile(*genOut, []byte(content), 0o600); err != nil {
8383
base.Fatalf("failed to write tokens to file %q: %v", *genOut, err)
8484
}
8585
if _, err := fmt.Fprintf(os.Stdout, "wrote base64 tokens to %s\n", *genOut); err != nil {

transport/internet/tlsmirror/mirrorenrollment/httpenrollmentconfirmation/clientbuilder.go

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package httpenrollmentconfirmation
22

33
import (
4+
"context"
45
"encoding/base32"
56
"net"
67
"net/http"
78
"sync"
89
"time"
910

1011
"github.com/v2fly/v2ray-core/v5/common"
11-
"github.com/v2fly/v2ray-core/v5/common/signal/done"
1212
"github.com/v2fly/v2ray-core/v5/transport/internet/tlsmirror"
1313
"github.com/v2fly/v2ray-core/v5/transport/internet/tlsmirror/httponconnection"
1414
)
@@ -83,31 +83,16 @@ func (c *clientRoundtripper) roundTrip(request *http.Request) (*http.Response, e
8383
}
8484
defer c.currentConnLock.RUnlock()
8585

86-
timeoutTimer := time.NewTimer(30 * time.Second)
87-
defer timeoutTimer.Stop()
88-
89-
waitForConnection := done.New()
90-
91-
var resp *http.Response
92-
var error_resp_ error
93-
var err error
94-
95-
go func() {
96-
resp_, err_ := c.currentConn.RoundTrip(request)
97-
resp = resp_
98-
error_resp_ = err_
99-
waitForConnection.Close()
100-
}()
101-
102-
select {
103-
case <-timeoutTimer.C:
104-
err = newError("timeout during enrollment verification round trip")
105-
case <-waitForConnection.Wait():
106-
err = error_resp_
107-
}
86+
timeoutContext, _ := context.WithTimeout(context.Background(), time.Second*30)
87+
request = request.WithContext(timeoutContext)
10888

89+
resp, err := c.currentConn.RoundTrip(request)
10990
// Use the current connection to perform the round trip
11091
if err != nil {
92+
if resp != nil && resp.Body != nil {
93+
resp.Body.Close()
94+
}
95+
11196
defer func() {
11297
c.currentConnLock.RUnlock()
11398
c.currentConnLock.Lock()
@@ -140,7 +125,7 @@ func (c *clientRoundtripper) createNewConnection() error {
140125
c.currentConnInnerConn = conn
141126
c.currentConn, err = httponconnection.NewSingleConnectionHTTPTransport(conn, "h2")
142127
if err != nil {
143-
conn.Close() // Close the connection if transport creation fails
128+
_ = conn.Close() // Close the connection if transport creation fails
144129
return newError("failed to create HTTP transport: ", err)
145130
}
146131
return nil

0 commit comments

Comments
 (0)