VProxy now natively supports kcp, and built a self-defined protocol for kcp tunnel. You may use it in WebSocksProxyAgent and WebSocksProxyServer.
The protocol is abstracted. You may fill you own implementation as long as it supports all functionality of the abstracted protocol. The protocol is not integrated with kcp, you may use it on any arq protocols.
VProxy implements a tunnel protocol similar to http/2. And the protocol is not integrated with kcp, you may use it on any arq protocols.
- handshake: used to initiate the tunnel
- keepalive: used to check whether the tunnel is still valid
- keepalive ack: used to respond a keepalive message to keep the tunnel active
- SYN: used to start a connection inside the tunnel
- SYN-ACK: used to let client know server received the
SYN
message - PSH: used to send data between client and server
- FIN: used to tell another endpoint that the sender endpoint will not send any data in the connection
- PSH-FIN: (optional) used to tell another endpoint that the sender endpoint sends the last piece in the connection
- RST: used to close the connection discarding any data remaining
- shutdown: used to close the tunnel and all connections inside the tunnel
The states are divided into two parts.
First part is for the tunnel states:
- init: the client or server just initiated
- handshake_sent: handshake message is sent from client to server
- ready: handshake message is received by client from server, or server receives handshake message from client
- both endpoints may send
shutdown
message to close the tunnel with a reason in the message.
Second part is for the connection states:
- none: the connection is just created
- syn_sent: the client sends
SYN
to the server - established: the client receives
SYN_ACK
from server, or server receivesSYN
from client - fin_sent:
FIN
message sent - fin_recv:
FIN
message received - dead: the connection is dead but user code has not explicitly call
close(fd)
yet - real_closed: the fd is really closed by the client
- the client sends a HANDSHAKE frame to the server
- the server sends a HANDSHAKE-ACK frame to the client (now the tunnel established)
- the client sends a SYN frame to the server
- the server sends a SYN-ACK frame to the client (now the connection established)
- the client/server can send PSH frames to each other
- the client/server sends a FIN or PSH-FIN frame (now the connection on sender side transform into SYN_SENT, and transform into SYN_RECV on the reciever side)
- another endpoint sends FIN or PSH-FIN at some time
- when connection is established, both endpoints may send a RST frame to close the connection immediately
- when tunnel is established, both endpoints may send a shutdown frame to close the tunnel, as well as all connections inside the tunnel
VProxy implemented the protocol using a frame set similar to HTTP/2
.
An empty SETTINGS
frame.
A PING
frame with an integer.
A PING
frame with ack flag set and an integer same as which contained in the keepalive
message.
An empty (not standard, the frame.length is set to 0) Headers
frame.
An empty (not standard, the frame.length is set to 0) Headers
frame.
A Data
frame containing the pushed data in the payload.
A Data
frame without payload and with close_stream flag set.
A Data
frame with payload and with close_stream flag set.
An empty (not standard, the frame.length is set to 0) Headers
frame with close_stream flag set.
A GOAWAY
frame, with a string reason as the payload. The stream id
and error code
are not used.