Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTTPUpgrade transport #2727

Merged
merged 1 commit into from Oct 27, 2023
Merged

Conversation

xiaokangwang
Copy link
Contributor

@xiaokangwang xiaokangwang commented Oct 27, 2023

This is a reduced version of WebSocket transport that does not require actually implementing/using Websocket protocol itself. It sends http upgrade header to WebSocket and then use the upgraded http1.1 connection directly, cutting unnecessary overhead and protocol complexity of WebSocket.

This design is inspired by https://www.usenix.org/conference/foci20/presentation/frolov and based on WebTunnel Implementation.

Server Config Example, when hide behind nginx that deals with tls:

{
  "log": {
    "error": {
      "level": "Debug",
      "type": "Console"
    },
    "access": {
      "type": "None"
    }
  },
  "outbounds": [
    {
      "protocol": "freedom"
    }
  ],
  "inbounds": [
    {
      "protocol": "vmess",
      "settings": {
        "users": [
          "1234"
        ]
      },
      "listen": "127.0.0.1",
      "port": 1234,
      "streamSettings": {
        "transport": "httpupgrade",
        "transportSettings": {
          "host": "XXXX",
          "path": "XXXX"
        }
      }
    }
  ]
}

Client Config Example:

{
  "log": {
    "error": {
      "level": "Debug",
      "type": "Console"
    },
    "access": {
      "type": "None"
    }
  },
  "outbounds": [
    {
      "protocol": "vmess",
      "settings": {
        "port": 443,
        "uuid": "XXXX",
        "address": "XXXX"
      },
      "streamSettings": {
        "transport": "httpupgrade",
        "transportSettings": {
          "host": "XXXX",
          "path": "XXXX"
        },
        "security": "tls",
        "securitySettings": {
          "serverName": "XXXX",
          "allowInsecure": false,
          "nextProtocol": [
            "http/1.1"
          ]
        }
      }
    }
  ],
  "inbounds": [
    {
      "protocol": "socks",
      "settings": {
        "udpEnabled": true,
        "address": "127.0.0.1",
        "packetEncoding": "Packet"
      },
      "port": 1080
    }
  ]
}

@codecov-commenter
Copy link

codecov-commenter commented Oct 27, 2023

Codecov Report

Attention: 125 lines in your changes are missing coverage. Please review.

Comparison is base (cb84b28) 37.79% compared to head (1eefcd3) 37.68%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2727      +/-   ##
==========================================
- Coverage   37.79%   37.68%   -0.12%     
==========================================
  Files         654      659       +5     
  Lines       38723    38873     +150     
==========================================
+ Hits        14636    14649      +13     
- Misses      22477    22607     +130     
- Partials     1610     1617       +7     
Files Coverage Δ
transport/internet/httpupgrade/errors.generated.go 0.00% <0.00%> (ø)
transport/internet/httpupgrade/httpupgrade.go 25.00% <25.00%> (ø)
transport/internet/httpupgrade/dialer.go 6.66% <6.66%> (ø)
transport/internet/httpupgrade/config.pb.go 30.76% <30.76%> (ø)
transport/internet/httpupgrade/hub.go 4.08% <4.08%> (ø)

... and 7 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xiaokangwang xiaokangwang merged commit 1eefcd3 into v2fly:master Oct 27, 2023
39 of 40 checks passed
@freedmanop
Copy link

freedmanop commented Jan 16, 2024

客户端照你的写法不能用,可以说详细一点吗

@DDCHlsq
Copy link

DDCHlsq commented Mar 8, 2024

实测能用,延迟比 gRPC 传输略高,比 ws 低,但是速度是 gRPC 的 3 倍(GIA线路,本地千兆测试),

@CrazyBoyFeng
Copy link

@freedmanop 我估计你是用 v4 的模式载入的配置文件。httpupgrade 目前只提供了 v5 格式的配置接入:

./v2ray run -c config.json -format jsonv5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants