Coder Social home page Coder Social logo

iceonsun / rsock Goto Github PK

View Code? Open in Web Editor NEW
246.0 11.0 36.0 4.3 MB

The best companion of kcptun

Home Page: https://github.com/iceonsun/rsock/wiki/rsock%E7%AE%80%E4%BB%8B%E4%BB%A5%E5%8F%8A%E5%8E%9F%E7%90%86

CMake 0.98% C++ 38.50% Shell 0.61% C 59.23% Makefile 0.68%
kcptun tcp raw-socket udp shadowsocks faketcp accelerate libpcap libuv winpcap libnet cross-platform

rsock's Introduction

Build Status Build status Downloads


Introduction

中文请点击这里.

rsock is neither accelerator, nor vpn. It merely turns a udp connection into multiple fake tcp connections, or multiple normal udp connections or both. It's very similar with udp because it's not reliable and has no flow control, timeout retransmission algorithms, etc. It's cross platform. It's supposed to used together with kcptun or other udp client with ARQ. The purpose of rsock is that prevent qos to udp from ISP if any. It supports Windows, Mac and Linux. To see introduction and usage of kcptun click here . And shadowsocks, click here .

REPEAT: Data transfer of rsock is NOT reliable. Reliable data tranfer should be taked care of by app level(kcptun).

The following picture brifely shows principles

Installation

There are precompiled binaries for 64bit Linux, 64bit Mac and x86/x64 windows. They can be downloaded from here.

For Windows users, you have to install winpcap first. winpcap

For other platforms, you can download source code and compile it by yourself. Compilation guide is here

Quick start

Server

Remember to add firewall rule if firewall enabled.

Take Linux as an exmaple:

# port=10000
# while [ $port -le 10010 ]
do
sudo ufw allow $port
port=$[ $port + 1]
done

It means allow client connects to server from port 10000 to 10010. (rsock use port range 10001-10010 by default. If you want to change the default value, please check Parameter Explanation section.)

sudo ./server_rsock_Linux -t 127.0.0.1:9999

Parameter explanation:

127.0.0.1:9999, target address,aka address of kcptun server working on.

Client

Take mac as an example:

sudo ./client_rsock_Darwin --taddr=x.x.x.x -l 127.0.0.1:30000

Parameter explanation:

-t x.x.x.x , Address of rsock server。Attention. This is different from server. It only contains ip.

-l , local listened udp address, aka target address of kcptun client(the address specified by -t).

NOTE

  1. If rsock doesn't work, you have to check whether your NIC supoorts winpcap. And routers may also filter packets, especially when you use Windows.

  2. For Windows users, speed is far slow than rsock on mac/Linux. (500-800KB/s during my test) e.g. On Mac/Linux, rsock can support to watch 1080P youtube video smoothly. For windows users, rsock can only support 720P youtube video.

Exit

ps axu|grep rsock

sudo kill -SIGUSR1 pid # pid is id of rsock. It's 72294 in image above.

Parameters in detail


	-t, --taddr=[addr]		target address. e.g. 8.8.8.8:88,7.7.7.7. Required.
	-l, --ludp=[addr]		local listened udp address. Only valid for client. Required by client.
	-d, --dev=[device]		name of network interface card of Internet.e.g,eth0, en0. rsock can auto detect right device to work on. Use this when the default can't work.
	-h, --help			Display help menu. Not available now.
	-f				json config file
	--lcapIp=[ip]			Internet IP. Can omit the -d if this parameter sepcified. rsock can auto detect right device to work on. Use this when the default can't work.
	--unPath			Local unix domain socket. Not available now.
	-p, --ports=[...]		tcp/udp port list for rsock server. e.g.10001,10010(2 ports); 10001-10010(11 ports); 80,443,10001-10010(12 ports). **NO** white spaces allowed. Default value: 10001-10010
	--duration=[timeSec]		Time for app connection to persist if no data is transfered in the app connection. unit: seconds. defalt 30s
	--hash=[hashKey]		Not for encryption. Only for judgement if data belong to rsock. REPEAT: rsock don't encrypt data. Encryption is done by kcptun.
	--type=[tcp|udp|all]		type of communication. One of tcp, udp or all. Default is tcp.
	--daemon=[1|0]			Run as daemon. 1 yes. 0 no. default 1.
	-v				verbose mode. (Better not change default value. There is an unsolved bug that will cause slow speed right now)
	--log=[path/to/log]		Directory of log. Will create if not exist. Default: /var/log/rsock
	--cap_timeout			timeout of libpcap. Don't change this value if know what it really means.

Principle

  1. Server listens on some ports. (tcp 10001-10010, 10 ports by default)
  2. Client connects to all of server ports.
  3. For each of communications, client send data by libnet to one of server ports, which should have been connected.
  4. Server receive data by libpcap. It's same for server to send data to client. Now they make communication.
  5. For application, local_ip:app_udp_port and server_ip:app_udp_port make a connection。If no data flows thourgh this connection for a period of time(default 30s), it will be closed.
  6. When client receive rst or fin, it will close that real network connection and reconnect to server.

Disadvantage

Under tcp mode, since we don't send/recv data from socket, it will send an ack with 0 length, telling peer next seq it expects. This due to standard. And that will waste bandwith.

Comparison

Comparing objects:rsock, kcptun

Server test environment

digitalocean NY vps. 1G RAM

Client test environment 1. digitalocean Singaport vps.

rsock(tcp only, 11 ports). 1.25M

rsock(udp only, 11 ports). 1.5M

rsock(doc/tcp and udp, 11 ports each. 1.1M

kcptun. The fastest, around 1.5MB.

Client test environment 1. China telecom with 100Mb downloading and 10Mb upload speed.

rsock(tcp only, 11 ports). 1.4M

rsock(udp only, 11 ports. 1.7M

rsock(udp and tcp, 11 ports each)900K. I've tested twice. The speed is slower.

kcptun. extremely fast. Around 2MB.

note: There is no evidence that more ports rsock use, the faster it is. It's mainly determined by your bandwith.

Conclusion

rsock only has 70%-90% speed of kcptun.

Note

If you find no network connection, please check if rsock and kcptun still running.

You can run flowing commands to check:

ps axu|egrep 'kcptun|rsock'

It is strongly recommended that kcptun server and rsock server run in background. For kcptun server, run

nohup sudo -u nobody ./server_linux_amd64 -r ":port1" -l ":port2" -mode fast2 -key aKey >/dev/null 2>&1 &

For rsock server, only need to specify parameter --daemon=1

If servers run normally, try to restart kcptun client(turn shadowsocks on/off, this will restart kcptun).

rsock DOES NOT encrypt data. Encrption happens in app level(kcptun).

Other projects

udp2raw-tunnel

kcptun-raw

icmptunnel

TODO

  1. Refactor code.

  2. Add randomize port listening.

  3. Add idle mode. Don't repeatedly connect to server if no data for a period.

  4. Add other fake conn. e.g. ICMP, DNS.

rsock's People

Contributors

iceonsun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rsock's Issues

need some help for rsock client

Hello,
需要一些使用上的帮助。

以mac为例:

sudo ./client_rsock_Darwin --taddr=x.x.x.x -l 127.0.0.1:30000

参数解释:
-t x.x.x.x,替换成rsock服务器端地址。注意,这里和服务器端不一样:无需指定端口。
-l 127.0.0.1:30000 是本地监听的udp端口。即kcptun客户端的目标地址(kcptun中-t 参数对应的地址)。
  • 梯子被墙了 TCP 回程,然后用上了 KCPTUN,然后在 KCPTUN 的 issue 中看到了 rsock, 使用中有些问题。

  • server 端在 docker 里跑的 SS 和 KCPTUN,只暴露了 udp 端口,然后 rsock 是应该监听这个 暴露的 udp 端口吧。我理解是 SS ==> KCPTUN ==> RSOCKS

  • client 端暴露了 SS 端口,我理解是 我把流量发给 SS 端口,进docker 后 SS 发给 KCPTUN,KCPTUN 再发给 server。那用 RSOCKS 客户端应该插在哪。是我要把 KCPTUN 的 remote address 改成本地,然后发给指定端端口,然后 RSOCKS -l 本地:指定端口 这样吗?

即kcptun客户端的目标地址(kcptun中-t 参数对应的地址)。

尤其这里把我看懵逼了,kcptun 客户端参数里没有 -t,只有 -r,可是 -r 监听的是 VPS:PORT,萌新瞬间就懵了,请教下该怎么玩儿。

CentOs 上报错 Assertion `p.targetCapInt != 0' failed

我明明已经安装了 libuv-devel libpcap-devel libnet-devel,但是运行时仍然报错,不知道这个错误代表什么意思,以及要怎么解决?

Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:libuv-devel-1.19.2-1.el7.x86_64                                                                                                    1/3
  Installing : 14:libpcap-devel-1.5.3-11.el7.x86_64                                                                                                 2/3
  Installing : libnet-devel-1.1.6-7.el7.x86_64                                                                                                      3/3
  Verifying  : libnet-devel-1.1.6-7.el7.x86_64                                                                                                      1/3
  Verifying  : 14:libpcap-devel-1.5.3-11.el7.x86_64                                                                                                 2/3
  Verifying  : 1:libuv-devel-1.19.2-1.el7.x86_64                                                                                                    3/3

Installed:
  libnet-devel.x86_64 0:1.1.6-7.el7                libpcap-devel.x86_64 14:1.5.3-11.el7                libuv-devel.x86_64 1:1.19.2-1.el7

Complete!
[root@jpb ~]# ./server_rsock_Linux -t 0.0.0.0:21048
dev name: eth0
dev: eth0, ipv4: 20.26.6.8
server_rsock_Linux: /Users/robert/workspace/cpp/CLIon/rSock/bean/RConfig.cpp:219: static void RConfig::CheckValidation(const RConfig&): Assertion `p.targetCapInt != 0' failed.
Aborted
[root@jpb ~]#

在VPC网络的云平台中,rsock工作异常

云平台上ifconfig命令看不到公网网卡,使用rsock+kcptun能看到客户端到到服务器的连接不断的再增加,但kcptun没有收到数据。
本地不断报错:
2018-08-16 13:47:26.928 ERROR [3792] [INetGroup::childConnErrCb@140] remove conn tcp:10.68..:55966-140.143..:10010, key: 924506782 err: -1
2018-08-16 13:47:26.993 ERROR [3792] [INetGroup::handleMessage@153] closing conn: tcp:10.68..:55966-140.143..:10010, key: 924506782
2018-08-16 13:47:26.994 ERROR [3792] [CConnErrHandler::OnNetConnErr@23] conn tcp:src:10.68.., sp:55966, dst:140.143.., dp: 10010, seq:1263199529, ack: 1263199335, flag: 16, err, reconnect it
2018-08-16 13:47:10.498 ERROR [3792] [NetConnKeepAlive::OnFlush@139] keepalive timeout, key: 923916971
服务器端只显示
2018-08-16 13:48:13.430 DEBUG [13444] [TcpAckPool::AddInfoFromPeer@28] Add tcpInfo: tcp:src:172.21.., sp:10004, dst:101.230.., dp: 40468, seq:3143514337, ack: 3203679237, flag: 18

服务器端使用的命令:
nohup ./server_linux_amd64 -t "172.21..:3389" -l "127.0.0.1:4000" -mode fast2 > kcptun.out 2>&1 &
./server_rsock_Linux -t 127.0.0.1:4000

https://s33.postimg.cc/org7tzlvz/QQ_20180816135316.png

报文中掺杂额外字节

hi,我正在开发一个基于kcp的应用,使用rsock做隧道,发现rsock会塞一段“不是我发送的字节”到udp包中。

客户端macos,服务端linux,版本均为20180613_03

tcpdump抓包发现,偶尔会有一段我没有发送的字节掺杂到报文中:

每一行是一次抓到的多余报文,特征很明显:

f268b10bd0083eed1700b6bc82180c30f129d9000000b6db1a370000000000

f268b10bd0083eed1700b6bc82180c30f129e400000045e318370000000000

f268b10bd0083eed1700b6bc82180c30f129f200000083e517370000000000

f268b10bd0083eed1700b6bc82180c30f1290101000019e719370000000000

f268b10bd0083eed170089aac51cc4d6d8a510000000a5e9895e0000000000

你们看下是否需要我提供tcpdump文件?或者说这段报文是有什么特殊用途的,需要我应用层单独处理?

server_rsock_Darwin for macOS Illegal instruction.

server_rsock_Darwin 在我 14mid 的 MBP 运行没问题,但在 12later 的 Mac Mini 上发生 Illegal instruction 错误。
你编译的时候应该加 -march=x86-64 参数。这样就可以限定架构指令集,而不是本机最大优化。最大优化完其它老机器不一定能用了。

windows client can not run

E:\rsock>client_rsock_Windows.exe -t 104.x.x.x --ludp=127.0.0.1:2001
Assertion failed: p.selfCapInt != 0, file c:\projects\myproject\bean\rconfig.cpp, line 221

修改wiki里面的编译指南

sudo apt-get install g++ libuv1-dev libnet libpcap #note!It's libuv1-dev

有劳作者修改成

sudo apt-get install g++ libuv1-dev libnet1-dev libpcap-dev

windows客户端运行问题(ss+kcptun+rsock)

黑窗口中运行client_rsock_Windows -t x.x.x.x -l 127.0.0.1:688
然后停在
2018-08-18 18:05:34.976 DEBUG [16712] [TcpAckPool::AddInfoFromPeer@28] Add tcpInfo: tcp:src:10.0.0.xx, sp:49982, dst:xxx.xx.xx.xx:, dp: 10010, seq:3424839963, ack: 116318266, flag: 18
2018-08-18 18:05:34.976 DEBUG [17556] [INetGroup::AddNetConn@88] Add INetConn: tcp:10.0.0.xx:49982-xx.xx.xx.xx:10010, key: 924500798
2018-08-18 18:05:34.980 DEBUG [17556] [ClientGroup::Init@46] client, listening on udp: 127.0.0.1:688
(光标闪烁)
请问大佬们这算是成功运行了吗?然后需要做什么呢。
另:-l后的地址是我shadowsocks中的服务器地址和服务器端口,经过kcptun处理后变成127.0.0.1:688,这样做是正确的吗?提前谢过

双边混肴么

这是双边混肴么?假设sever为linux,client为windows,都要同时运行吗,再加上比如kcp就2个sever和client同时都要一起运行么,那client为安卓呢

请问如何修复 "pcap init failed"?

安装号rsock后我使用以下命令
/opt/rsock/./server_rsock_Linux --dev=venet0 --taddr=127.0.0.1:32227 --ports=12221-12225
dev: venet0, ipv4: 127.0.0.1
Run in background. pid: 8226
但是在ps aux看不到进程,查看日志如下
2018-06-28 22:38:08.633 ERROR [8226] [RCap::doInit@108] init failed: arptype 65535 not supported by libpcap - falling back to cooked socket
2018-06-28 22:38:08.633 ERROR [8226] [ISockApp::doInit@211] pcap init failed
2018-06-28 22:38:08.633 DEBUG [8226] [ISockApp::Close@275]

组件安装了 libuv libnet libpcap libdnet gcc gcc-c++

如何给ss的udp转发呢

想给ss的udp做转发 被运营商限速1mibs。。
SS端口3388

服务端sudo ./server_rsock_Linux -d ens18 -t 127.0.0.1:3388

客户端sudo ./client_rsock_Linux -d eth0 --taddr=远程ip -l 127.0.0.1:30000

客户端udp连30000端口 连不上哈哈 是不支持吗 还是我命令打错了

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.