Skip to content

Commit a66709c

Browse files
oweidxiaokangwang
authored andcommitted
Create EN-US version of muxcool.md
1 parent d3190b0 commit a66709c

File tree

1 file changed

+114
-2
lines changed

1 file changed

+114
-2
lines changed
Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,115 @@
1-
# Mux.Cool
1+
# Mux.Cool Protocol
22

3-
The documentation for this page is missing. Please submit a [pull request](https://github.com/v2fly/v2fly-github-io/pulls) or refer to the Chinese documentation.
3+
Mux.Cool protocol is a multiplexing transport protocol used to transmit multiple independent data streams within a single established data stream.
4+
5+
## Version
6+
7+
Current version is 1 Beta.
8+
9+
## Dependencies
10+
11+
### Underlying Protocol
12+
13+
Mux.Cool must run on top of an established reliable data stream.
14+
15+
## Communication Process
16+
17+
A Mux.Cool connection can transmit multiple sub-connections, each with an independent ID and state. The transmission process consists of frames, with each frame transmitting data for a specific sub-connection.
18+
19+
### Client Behavior
20+
21+
When a connection is needed and no existing connections are available, the client initiates a new connection to the server, referred to as the "main connection".
22+
23+
1. A main connection can be used to send multiple sub-connections. The client can independently determine the number of sub-connections the main connection can carry.
24+
2. For a new sub-connection, the client must send a `New` state to notify the server to establish the sub-connection, then use the `Keep` state to transmit data.
25+
3. When a sub-connection ends, the client sends an `End` state to notify the server to close the sub-connection.
26+
4. The client can decide when to close the main connection but must ensure the server maintains the connection simultaneously.
27+
5. The client can use the KeepAlive state to prevent the server from closing the main connection.
28+
29+
### Server Behavior
30+
31+
When the server receives a new sub-connection, it should handle it as a normal connection.
32+
33+
1. Upon receiving an `End` state, the server can close the upstream connection to the target address.
34+
2. In server responses, the same ID as the request must be used to transmit sub-connection data.
35+
3. The server cannot use the `New` state.
36+
4. The server can use the KeepAlive state to prevent the client from closing the main connection.
37+
38+
## Transport Format
39+
40+
Mux.Cool uses a symmetric transport format, meaning clients and servers send and receive data in the same format.
41+
42+
### Frame Format
43+
44+
| 2 bytes | L bytes | X bytes |
45+
|---------|---------|---------|
46+
| Metadata Length L | Metadata | Extra Data |
47+
48+
### Metadata
49+
50+
Metadata has several types, distinguished by state S. All metadata types include ID and Opt fields:
51+
52+
* ID: Unique identifier for the sub-connection
53+
* Opt:
54+
* D(0x01): Has extra data
55+
56+
When option Opt(D) is enabled, the extra data format is:
57+
58+
| 2 bytes | L bytes |
59+
|---------|---------|
60+
| Length L | Data |
61+
62+
#### New Sub-connection (New)
63+
64+
| 2 bytes | 1 byte | 1 byte | 1 byte | 2 bytes | 1 byte | X bytes |
65+
|---------|---------|---------|---------|---------|---------|---------|
66+
| ID | 0x01 | Option Opt | Network Type N | Port | Address Type T | Address A |
67+
68+
Where:
69+
70+
* Network Type N:
71+
* 0x01: TCP, indicating sub-connection traffic should be sent to target as TCP
72+
* 0x02: UDP, indicating sub-connection traffic should be sent to target as UDP
73+
* Address Type T:
74+
* 0x01: IPv4
75+
* 0x02: Domain name
76+
* 0x03: IPv6
77+
* Address A:
78+
* When T = 0x01: 4-byte IPv4 address
79+
* When T = 0x02: 1-byte length (L) + L-byte domain name
80+
* When T = 0x03: 16-byte IPv6 address
81+
82+
When creating a new sub-connection with Opt(D) enabled, the frame's data must be sent to the target host.
83+
84+
#### Keep Sub-connection (Keep)
85+
86+
| 2 bytes | 1 byte | 1 byte |
87+
|---------|---------|---------|
88+
| ID | 0x02 | Option Opt |
89+
90+
When keeping a sub-connection with Opt(D) enabled, the frame's data must be sent to the target host.
91+
92+
#### Close Sub-connection (End)
93+
94+
| 2 bytes | 1 byte | 1 byte |
95+
|---------|---------|---------|
96+
| ID | 0x03 | Option Opt |
97+
98+
When closing a sub-connection with Opt(D) enabled, the frame's data must be sent to the target host.
99+
100+
#### Keep Connection (KeepAlive)
101+
102+
| 2 bytes | 1 byte | 1 byte |
103+
|---------|---------|---------|
104+
| ID | 0x04 | Option Opt |
105+
106+
For keep-alive:
107+
108+
* When Opt(D) is enabled, the frame's data must be discarded
109+
* ID can be a random value
110+
111+
## Application
112+
113+
The Mux.Cool protocol is independent of the underlying protocol and can theoretically use any reliable stream connection to transmit Mux.Cool protocol data.
114+
115+
In destination-oriented protocols like Shadowsocks and VMess, a specified address must be included when establishing a connection. For compatibility, the Mux.Cool protocol specifies the address as "v1.mux.cool". When the main connection's target address matches this, forwarding proceeds in Mux.Cool mode; otherwise, traditional forwarding is used.

0 commit comments

Comments
 (0)