Skip to content

Commit 20926be

Browse files
authored
Merge pull request #2740 from v2fly/master
merge v2fly
2 parents 9cb633a + e5d6603 commit 20926be

File tree

12 files changed

+107
-47
lines changed

12 files changed

+107
-47
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [master]
6+
paths:
7+
- "**/*.go"
8+
pull_request:
9+
# The branches below must be a subset of the branches above
10+
branches: [master]
11+
paths:
12+
- "**/*.go"
13+
schedule:
14+
- cron: '0 0 * * 1'
15+
16+
jobs:
17+
analyze:
18+
name: Analyze
19+
runs-on: ubuntu-latest
20+
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
# Override automatic language detection by changing the below list
25+
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
26+
language: ['go']
27+
# Learn more...
28+
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
29+
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v2
33+
with:
34+
# We must fetch at least the immediate parents so that if this is
35+
# a pull request then we can checkout the head.
36+
fetch-depth: 2
37+
38+
# If this run was triggered by a pull request event, then checkout
39+
# the head of the pull request instead of the merge commit.
40+
- run: git checkout HEAD^2
41+
if: ${{ github.event_name == 'pull_request' }}
42+
43+
# Initializes the CodeQL tools for scanning.
44+
- name: Initialize CodeQL
45+
uses: github/codeql-action/init@v1
46+
with:
47+
languages: ${{ matrix.language }}
48+
# If you wish to specify custom queries, you can do so here or in a config file.
49+
# By default, queries listed here will override any specified in a config file.
50+
# Prefix the list here with "+" to use these queries and those in the config file.
51+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
52+
53+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54+
# If this step fails, then you should remove it and run the build manually (see below)
55+
- name: Autobuild
56+
uses: github/codeql-action/autobuild@v1
57+
58+
# ℹ️ Command-line programs to run using the OS shell.
59+
# 📚 https://git.io/JvXDl
60+
61+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62+
# and modify them (or add more) to build your code if your project
63+
# uses a compiled language
64+
65+
#- run: |
66+
# make bootstrap
67+
# make release
68+
69+
- name: Perform CodeQL Analysis
70+
uses: github/codeql-action/analyze@v1

.github/workflows/linter.yml

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ name: Linter
33
on:
44
push:
55
branches: [master]
6+
paths:
7+
- "**/*.go"
68
pull_request:
79
branches: [master]
810
types: [opened, synchronize, reopened]
11+
paths:
12+
- "**/*.go"
913

1014
jobs:
1115
lint:
@@ -19,29 +23,8 @@ jobs:
1923
- name: Checkout codebase
2024
uses: actions/checkout@v2
2125

22-
- name: Cache go module
23-
uses: actions/cache@v2
24-
with:
25-
path: ~/go/pkg/mod
26-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
27-
restore-keys: ${{ runner.os }}-go-
28-
29-
- name: Lint other files
30-
if: ${{ always() }}
31-
uses: github/[email protected]
32-
env:
33-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34-
VALIDATE_ALL_CODEBASE: false
35-
VALIDATE_BASH: false
36-
VALIDATE_DOCKERFILE: false
37-
VALIDATE_DOCKERFILE_HADOLINT: false
38-
VALIDATE_GO: false
39-
VALIDATE_JSON: false
40-
VALIDATE_MD: false
41-
VALIDATE_PROTOBUF: false
42-
4326
- name: golangci-lint
4427
uses: golangci/golangci-lint-action@v2
4528
with:
4629
version: v1.31
47-
args: --config=.github/linters/.golangci.yml
30+
args: --config=.github/linters/.golangci.yml

.github/workflows/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
stale:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/[email protected].10
11+
- uses: actions/[email protected].11
1212
with:
1313
repo-token: ${{ secrets.GITHUB_TOKEN }}
1414
stale-issue-message: "This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 5 days"

app/router/condition.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,11 @@ func NewAttributeMatcher(code string) (*AttributeMatcher, error) {
288288
}, nil
289289
}
290290

291-
func (m *AttributeMatcher) Match(attrs map[string]interface{}) bool {
291+
// Match implements attributes matching.
292+
func (m *AttributeMatcher) Match(attrs map[string]string) bool {
292293
attrsDict := new(starlark.Dict)
293294
for key, value := range attrs {
294-
var starValue starlark.Value
295-
switch value := value.(type) {
296-
case string:
297-
starValue = starlark.String(value)
298-
}
299-
if starValue != nil {
300-
attrsDict.SetKey(starlark.String(key), starValue)
301-
}
295+
attrsDict.SetKey(starlark.String(key), starlark.String(value))
302296
}
303297

304298
predefined := make(starlark.StringDict)

app/router/condition_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func TestRoutingRule(t *testing.T) {
313313
},
314314
test: []ruleTest{
315315
{
316-
input: withContent(&session.Content{Protocol: "http/1.1", Attributes: map[string]interface{}{":path": "/test/1"}}),
316+
input: withContent(&session.Content{Protocol: "http/1.1", Attributes: map[string]string{":path": "/test/1"}}),
317317
output: true,
318318
},
319319
},

common/session/session.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type Outbound struct {
5353
Gateway net.Address
5454
}
5555

56+
// SniffingRequest controls the behavior of content sniffing.
5657
type SniffingRequest struct {
5758
OverrideDestinationForProtocol []string
5859
Enabled bool
@@ -65,7 +66,7 @@ type Content struct {
6566

6667
SniffingRequest SniffingRequest
6768

68-
Attributes map[string]interface{}
69+
Attributes map[string]string
6970

7071
SkipRoutePick bool
7172
}
@@ -76,16 +77,18 @@ type Sockopt struct {
7677
Mark int32
7778
}
7879

79-
func (c *Content) SetAttribute(name string, value interface{}) {
80+
// SetAttribute attachs additional string attributes to content.
81+
func (c *Content) SetAttribute(name string, value string) {
8082
if c.Attributes == nil {
81-
c.Attributes = make(map[string]interface{})
83+
c.Attributes = make(map[string]string)
8284
}
8385
c.Attributes[name] = value
8486
}
8587

86-
func (c *Content) Attribute(name string) interface{} {
88+
// Attribute retrieves additional string attributes from content.
89+
func (c *Content) Attribute(name string) string {
8790
if c.Attributes == nil {
88-
return nil
91+
return ""
8992
}
9093
return c.Attributes[name]
9194
}

core.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
var (
22-
version = "4.28.0"
22+
version = "4.28.2"
2323
build = "Custom"
2424
codename = "V2Fly, a community-driven edition of V2Ray."
2525
intro = "A unified platform for anti-censorship."

features/routing/context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
// Context is a feature to store connection information for routing.
88
//
9-
// v2ray:api:beta
9+
// v2ray:api:stable
1010
type Context interface {
1111
// GetInboundTag returns the tag of the inbound the connection was from.
1212
GetInboundTag() string
@@ -36,5 +36,5 @@ type Context interface {
3636
GetUser() string
3737

3838
// GetAttributes returns extra attributes from the conneciont content.
39-
GetAttributes() map[string]interface{}
39+
GetAttributes() map[string]string
4040
}

features/routing/session/context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ func (ctx *Context) GetProtocol() string {
9595

9696
// GetUser implements routing.Context.
9797
func (ctx *Context) GetUser() string {
98-
if ctx.Inbound == nil {
98+
if ctx.Inbound == nil || ctx.Inbound.User == nil {
9999
return ""
100100
}
101101
return ctx.Inbound.User.Email
102102
}
103103

104104
// GetAttributes implements routing.Context.
105-
func (ctx *Context) GetAttributes() map[string]interface{} {
105+
func (ctx *Context) GetAttributes() map[string]string {
106106
if ctx.Content == nil {
107107
return nil
108108
}

proxy/http/client.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,10 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
210210
}
211211

212212
cachedH2Mutex.Lock()
213-
defer cachedH2Mutex.Unlock()
213+
cachedConn, cachedConnFound := cachedH2Conns[dest]
214+
cachedH2Mutex.Unlock()
214215

215-
if cachedConn, found := cachedH2Conns[dest]; found {
216+
if cachedConnFound {
216217
rc, cc := cachedConn.rawConn, cachedConn.h2Conn
217218
if cc.CanTakeNewRequest() {
218219
proxyConn, err := connectHTTP2(rc, cc)
@@ -260,6 +261,7 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
260261
return nil, err
261262
}
262263

264+
cachedH2Mutex.Lock()
263265
if cachedH2Conns == nil {
264266
cachedH2Conns = make(map[net.Destination]h2Conn)
265267
}
@@ -268,6 +270,7 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
268270
rawConn: rawConn,
269271
h2Conn: h2clientConn,
270272
}
273+
cachedH2Mutex.Unlock()
271274

272275
return proxyConn, err
273276
default:

0 commit comments

Comments
 (0)