Skip to content

Commit

Permalink
Merge pull request #2740 from v2fly/master
Browse files Browse the repository at this point in the history
merge v2fly
  • Loading branch information
kslr authored Sep 18, 2020
2 parents 9cb633a + e5d6603 commit 20926be
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 47 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: "CodeQL"

on:
push:
branches: [master]
paths:
- "**/*.go"
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
paths:
- "**/*.go"
schedule:
- cron: '0 0 * * 1'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['go']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
27 changes: 5 additions & 22 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ name: Linter
on:
push:
branches: [master]
paths:
- "**/*.go"
pull_request:
branches: [master]
types: [opened, synchronize, reopened]
paths:
- "**/*.go"

jobs:
lint:
Expand All @@ -19,29 +23,8 @@ jobs:
- name: Checkout codebase
uses: actions/checkout@v2

- name: Cache go module
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-

- name: Lint other files
if: ${{ always() }}
uses: github/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_ALL_CODEBASE: false
VALIDATE_BASH: false
VALIDATE_DOCKERFILE: false
VALIDATE_DOCKERFILE_HADOLINT: false
VALIDATE_GO: false
VALIDATE_JSON: false
VALIDATE_MD: false
VALIDATE_PROTOBUF: false

- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.31
args: --config=.github/linters/.golangci.yml
args: --config=.github/linters/.golangci.yml
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected].10
- uses: actions/[email protected].11
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
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"
Expand Down
12 changes: 3 additions & 9 deletions app/router/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,11 @@ func NewAttributeMatcher(code string) (*AttributeMatcher, error) {
}, nil
}

func (m *AttributeMatcher) Match(attrs map[string]interface{}) bool {
// Match implements attributes matching.
func (m *AttributeMatcher) Match(attrs map[string]string) bool {
attrsDict := new(starlark.Dict)
for key, value := range attrs {
var starValue starlark.Value
switch value := value.(type) {
case string:
starValue = starlark.String(value)
}
if starValue != nil {
attrsDict.SetKey(starlark.String(key), starValue)
}
attrsDict.SetKey(starlark.String(key), starlark.String(value))
}

predefined := make(starlark.StringDict)
Expand Down
2 changes: 1 addition & 1 deletion app/router/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func TestRoutingRule(t *testing.T) {
},
test: []ruleTest{
{
input: withContent(&session.Content{Protocol: "http/1.1", Attributes: map[string]interface{}{":path": "/test/1"}}),
input: withContent(&session.Content{Protocol: "http/1.1", Attributes: map[string]string{":path": "/test/1"}}),
output: true,
},
},
Expand Down
13 changes: 8 additions & 5 deletions common/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Outbound struct {
Gateway net.Address
}

// SniffingRequest controls the behavior of content sniffing.
type SniffingRequest struct {
OverrideDestinationForProtocol []string
Enabled bool
Expand All @@ -65,7 +66,7 @@ type Content struct {

SniffingRequest SniffingRequest

Attributes map[string]interface{}
Attributes map[string]string

SkipRoutePick bool
}
Expand All @@ -76,16 +77,18 @@ type Sockopt struct {
Mark int32
}

func (c *Content) SetAttribute(name string, value interface{}) {
// SetAttribute attachs additional string attributes to content.
func (c *Content) SetAttribute(name string, value string) {
if c.Attributes == nil {
c.Attributes = make(map[string]interface{})
c.Attributes = make(map[string]string)
}
c.Attributes[name] = value
}

func (c *Content) Attribute(name string) interface{} {
// Attribute retrieves additional string attributes from content.
func (c *Content) Attribute(name string) string {
if c.Attributes == nil {
return nil
return ""
}
return c.Attributes[name]
}
2 changes: 1 addition & 1 deletion core.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

var (
version = "4.28.0"
version = "4.28.2"
build = "Custom"
codename = "V2Fly, a community-driven edition of V2Ray."
intro = "A unified platform for anti-censorship."
Expand Down
4 changes: 2 additions & 2 deletions features/routing/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

// Context is a feature to store connection information for routing.
//
// v2ray:api:beta
// v2ray:api:stable
type Context interface {
// GetInboundTag returns the tag of the inbound the connection was from.
GetInboundTag() string
Expand Down Expand Up @@ -36,5 +36,5 @@ type Context interface {
GetUser() string

// GetAttributes returns extra attributes from the conneciont content.
GetAttributes() map[string]interface{}
GetAttributes() map[string]string
}
4 changes: 2 additions & 2 deletions features/routing/session/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ func (ctx *Context) GetProtocol() string {

// GetUser implements routing.Context.
func (ctx *Context) GetUser() string {
if ctx.Inbound == nil {
if ctx.Inbound == nil || ctx.Inbound.User == nil {
return ""
}
return ctx.Inbound.User.Email
}

// GetAttributes implements routing.Context.
func (ctx *Context) GetAttributes() map[string]interface{} {
func (ctx *Context) GetAttributes() map[string]string {
if ctx.Content == nil {
return nil
}
Expand Down
7 changes: 5 additions & 2 deletions proxy/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
}

cachedH2Mutex.Lock()
defer cachedH2Mutex.Unlock()
cachedConn, cachedConnFound := cachedH2Conns[dest]
cachedH2Mutex.Unlock()

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

cachedH2Mutex.Lock()
if cachedH2Conns == nil {
cachedH2Conns = make(map[net.Destination]h2Conn)
}
Expand All @@ -268,6 +270,7 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
rawConn: rawConn,
h2Conn: h2clientConn,
}
cachedH2Mutex.Unlock()

return proxyConn, err
default:
Expand Down
9 changes: 8 additions & 1 deletion proxy/vmess/encoding/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"hash"
"hash/fnv"
"io"
"os"
vmessaead "v2ray.com/core/proxy/vmess/aead"

"golang.org/x/crypto/chacha20poly1305"
Expand Down Expand Up @@ -62,6 +63,12 @@ func NewClientSession(idHash protocol.IDHash, ctx context.Context) *ClientSessio
}
}

if vmessAeadDisable, vmessAeadDisableFound := os.LookupEnv("V2RAY_VMESS_AEAD_DISABLED"); vmessAeadDisableFound {
if vmessAeadDisable == "true" {
session.isAEADRequest = false
}
}

copy(session.requestBodyKey[:], randomBytes[:16])
copy(session.requestBodyIV[:], randomBytes[16:32])
session.responseHeader = randomBytes[32]
Expand All @@ -71,7 +78,7 @@ func NewClientSession(idHash protocol.IDHash, ctx context.Context) *ClientSessio
} else {
BodyKey := sha256.Sum256(session.requestBodyKey[:])
copy(session.responseBodyKey[:], BodyKey[:16])
BodyIV := sha256.Sum256(session.requestBodyKey[:])
BodyIV := sha256.Sum256(session.requestBodyIV[:])
copy(session.responseBodyIV[:], BodyIV[:16])
}

Expand Down
2 changes: 1 addition & 1 deletion proxy/vmess/encoding/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func (s *ServerSession) EncodeResponseHeader(header *protocol.ResponseHeader, wr
} else {
BodyKey := sha256.Sum256(s.requestBodyKey[:])
copy(s.responseBodyKey[:], BodyKey[:16])
BodyIV := sha256.Sum256(s.requestBodyKey[:])
BodyIV := sha256.Sum256(s.requestBodyIV[:])
copy(s.responseBodyIV[:], BodyIV[:16])
}

Expand Down

0 comments on commit 20926be

Please sign in to comment.