235 Commits

Author SHA1 Message Date
wangyu-
8680b06882 Update README.zh-cn.md 2017-11-18 05:31:01 -08:00
wangyu-
57cce3a424 Update README.zh-cn.md 2017-11-18 05:30:23 -08:00
wangyu-
6ab4294bd9 Update README.zh-cn.md 2017-11-18 05:22:27 -08:00
wangyu-
ebdabb4598 Update README.zh-cn.md 2017-11-18 05:21:41 -08:00
wangyu-
c254545290 Update README.zh-cn.md 2017-11-18 01:14:33 -08:00
wangyu-
1301fdc96d Merge branch 'master' of https://github.com/wangyu-/UDPspeeder 2017-11-18 00:05:25 -06:00
wangyu-
f58dfe4fdd fixed a warn of last commit 2017-11-18 00:03:08 -06:00
wangyu-
3fd198a1e2 fixed a possible MTU issue when redundant num=0 2017-11-18 00:01:21 -06:00
wangyu-
017e851c2d Update README.md 2017-11-17 09:50:58 -08:00
wangyu-
2929eead0e Update README.md 2017-11-17 09:46:52 -08:00
wangyu-
e2c2f2dfec Update README.zh-cn.md 2017-11-17 09:12:30 -08:00
wangyu-
d0ebd67dbd Update README.md 2017-11-17 08:54:30 -08:00
wangyu-
211fcee8db Update README.zh-cn.md 2017-11-17 08:51:05 -08:00
wangyu-
6b4a2dfe21 increased timeout 2017-11-17 01:17:31 -06:00
wangyu-
65939eb9e7 Merge branch 'master' of https://github.com/wangyu-/UDPspeeder 2017-11-17 01:12:17 -06:00
wangyu-
9c00a2f3a6 increased timeout 2017-11-17 01:12:04 -06:00
wangyu-
4706e51fad Update README.zh-cn.md 2017-11-16 10:52:01 -08:00
wangyu-
c3786a91d8 Update README.zh-cn.md 2017-11-16 10:31:11 -08:00
wangyu-
680f127350 Update README.zh-cn.md 2017-11-16 10:28:57 -08:00
wangyu-
7713cf0c15 Update README.zh-cn.md 2017-11-16 10:18:16 -08:00
wangyu-
5024a02d20 Update README.zh-cn.md 2017-11-16 10:12:32 -08:00
wangyu-
f2d9deb2a3 Update README.zh-cn.md 2017-11-16 10:09:47 -08:00
wangyu-
c5c440245c Update README.zh-cn.md 2017-11-16 06:42:20 -08:00
wangyu-
c95e2db1af Update README.zh-cn.md 2017-11-16 06:41:26 -08:00
wangyu-
82a2b3cb9a Update README.zh-cn.md 2017-11-16 03:10:37 -08:00
wangyu-
8ecc696da5 Update README.zh-cn.md 2017-11-16 03:04:21 -08:00
wangyu-
6e6fc62fb8 Update README.zh-cn.md 2017-11-15 20:34:32 -08:00
wangyu-
ea03e5f8ec Update README.zh-cn.md 2017-11-15 20:33:21 -08:00
wangyu-
3be2642397 Update README.zh-cn.md 2017-11-15 20:31:47 -08:00
wangyu-
d05bcfc2f8 Update README.zh-cn.md 2017-11-15 20:28:48 -08:00
wangyu-
e50292bd4a Update README.zh-cn.md 2017-11-15 20:26:42 -08:00
wangyu-
363aec12d4 Update README.zh-cn.md 2017-11-12 20:40:01 -08:00
wangyu-
4364a7b789 Update README.zh-cn.md 2017-11-12 20:38:37 -08:00
wangyu-
17a42a1218 Update README.zh-cn.md 2017-11-11 14:33:20 -08:00
wangyu-
9152fef474 Update README.zh-cn.md 2017-11-11 14:29:46 -08:00
wangyu-
eb7406e6f3 Update README.zh-cn.md 2017-11-11 14:18:42 -08:00
wangyu-
296a84be3c Update README.zh-cn.md 2017-11-11 14:12:58 -08:00
wangyu-
69558ab16c Update README.zh-cn.md 2017-11-11 00:58:25 -08:00
wangyu-
37b7eb7282 Update README.zh-cn.md 2017-11-09 01:47:08 -08:00
wangyu-
4ca57cf656 Update README.zh-cn.md 2017-11-09 01:11:19 -08:00
wangyu-
1a744d69ea Update README.zh-cn.md 2017-11-08 15:59:24 -08:00
wangyu-
86b68697e1 Update README.zh-cn.md 2017-11-08 15:57:23 -08:00
wangyu-
63a2f923ab Update README.md 2017-11-08 15:54:54 -08:00
wangyu-
5774b478fc Update README.md 2017-11-08 15:54:12 -08:00
wangyu-
e91dcf6647 Update README.zh-cn.md 2017-11-08 15:50:31 -08:00
wangyu-
f6c97af854 Update README.md 2017-11-08 15:49:59 -08:00
wangyu-
2f097d720d changed a log 2017-11-08 03:59:36 -06:00
wangyu-
c6de39acc8 relax an assert 2017-11-08 03:53:13 -06:00
wangyu-
0f425a3a98 added version.txt 2017-11-08 03:38:23 -06:00
wangyu-
2cc560088b Update README.md 2017-11-07 02:58:34 -08:00
wangyu-
b83b21f2eb Merge branch 'master' of https://github.com/wangyu-/UDPspeeder 2017-11-07 03:55:01 -06:00
wangyu-
f526046846 do not drop packet in mode 1 2017-11-07 03:54:54 -06:00
wangyu-
1be5fb5fc1 Update README.zh-cn.md 2017-11-06 18:53:00 -08:00
wangyu-
27874aa413 changed parameter 2017-11-06 03:19:28 -06:00
wangyu-
fde2329528 Merge branch 'master' of https://github.com/wangyu-/UDPspeeder 2017-11-06 03:17:38 -06:00
wangyu-
30b78c1339 changed parameter 2017-11-06 03:17:34 -06:00
wangyu-
17a3074b34 Update README.zh-cn.md 2017-11-05 03:38:20 -08:00
wangyu-
cce7d18163 Update README.zh-cn.md 2017-11-04 21:50:37 -07:00
wangyu-
90029e1ea7 Update README.zh-cn.md 2017-11-03 22:50:24 -07:00
wangyu-
c26a4708ee Update README.zh-cn.md 2017-11-03 22:49:28 -07:00
wangyu-
fdbf4ab205 Update udpspeeder_openvpn.md 2017-11-03 22:46:33 -07:00
wangyu-
7ee72ee84c Update udpspeeder_openvpn.md 2017-11-03 22:45:39 -07:00
wangyu-
cac5f8271c Update README.zh-cn.md 2017-10-31 21:19:26 -07:00
wangyu-
219e8e2592 Update README.zh-cn.md 2017-10-31 21:18:33 -07:00
wangyu-
02b4d59500 Update README.zh-cn.md 2017-10-31 21:18:02 -07:00
wangyu-
894bf7cd0d Update README.zh-cn.md 2017-10-31 20:52:50 -07:00
wangyu-
a8cab43139 Update README.zh-cn.md 2017-10-31 20:52:31 -07:00
wangyu-
369a9d8e1b Update README.zh-cn.md 2017-10-31 20:51:39 -07:00
wangyu-
0f7894f42f revert last comit 2017-10-31 22:29:16 -05:00
wangyu-
d7daae25bf relax restriction for fec_data_num==1 2017-10-31 22:14:57 -05:00
wangyu-
d7271b74b4 Merge branch 'master' of https://github.com/wangyu-/UDPspeeder 2017-10-31 22:05:58 -05:00
wangyu-
1eeef14470 update log 2017-10-31 22:05:51 -05:00
wangyu-
9d30caffc9 Add files via upload 2017-11-01 10:35:01 +08:00
wangyu-
e50e383ede Delete ping_compare_cn.PNG 2017-10-31 19:34:47 -07:00
wangyu-
c73a197971 Update README.zh-cn.md 2017-10-31 19:31:24 -07:00
wangyu-
ba44617124 Add files via upload 2017-11-01 10:30:10 +08:00
wangyu-
19e718f0a3 new function tcp csum 2017-10-31 19:43:25 -05:00
wangyu-
bd323be9c4 fixed log 2017-10-30 20:29:04 -05:00
wangyu-
35a85e38ae fixed a missed continue 2017-10-30 11:23:37 -05:00
wangyu-
4871983b8f Update README.zh-cn.md 2017-10-30 08:40:17 -07:00
wangyu-
fec3c39cad Update README.zh-cn.md 2017-10-30 08:38:18 -07:00
wangyu-
4d55348a4d Update README.md 2017-10-30 08:35:41 -07:00
wangyu-
36eef02d8a Update README.md 2017-10-30 08:35:24 -07:00
wangyu-
3fd48dd20e Update README.md 2017-10-30 08:33:56 -07:00
wangyu-
766aa274d9 Update README.md 2017-10-30 08:33:36 -07:00
wangyu-
d961537682 Update udpspeeder_openvpn.md 2017-10-29 23:42:21 -07:00
wangyu-
4dcfe87bd3 Update README.zh-cn.md 2017-10-29 20:47:23 -07:00
wangyu-
2aa0ece465 Update README.md 2017-10-29 20:46:24 -07:00
wangyu-
05fd84b675 Update README.zh-cn.md 2017-10-29 03:41:28 -07:00
wangyu-
1e00ff7c87 add option keep-reconnect 2017-10-28 08:56:24 -05:00
wangyu-
c76818c6a8 trival 2017-10-28 07:44:25 -05:00
wangyu-
e3e2fe6d36 changed default sub-net 2017-10-28 06:48:24 -05:00
wangyu-
7cd87e7b59 trival 2017-10-28 04:36:37 -05:00
wangyu-
c3aae9579b refactor 2017-10-28 02:05:14 -05:00
wangyu-
d9f80781a2 changed --tun-dev to required argument 2017-10-28 01:45:50 -05:00
wangyu-
203604e1b5 Merge branch 'master' of https://github.com/wangyu-/UDPspeeder 2017-10-28 01:03:12 -05:00
wangyu-
5ac6e30c8e removed tun_dev.cpp and .h 2017-10-28 01:02:58 -05:00
wangyu-
6728d5a561 add dest ip restriction 2017-10-28 00:45:19 -05:00
wangyu-
f9eaae172f fixed typo 2017-10-27 23:19:08 -05:00
wangyu-
a0eeedb12a more log,more robust 2017-10-27 22:51:33 -05:00
wangyu-
324d34c87a Update README.zh-cn.md 2017-10-27 20:25:17 -07:00
wangyu-
1fe64b5689 Update README.zh-cn.md 2017-10-27 20:20:35 -07:00
wangyu-
d5e900e91c aloww len==fec_mtu 2017-10-27 21:16:59 -05:00
wangyu-
8e00273db4 just commit 2017-10-27 08:28:43 -05:00
wangyu-
73d68a2baf just commit 2017-10-27 05:23:46 -05:00
wangyu-
d1c88bbc07 implemented connection reject 2017-10-27 04:58:20 -05:00
wangyu-
caa8320743 implement dev tun 2017-10-27 00:03:35 -05:00
wangyu-
f64108867c fixed merge conflict 2017-10-26 09:49:46 -05:00
wangyu-
716e5458f9 Merge pull request #48 from bg6cq/master
typo fix
2017-10-26 22:34:48 +08:00
Zhang Huanjie
91c9a9e705 usage typo fix 2017-10-26 22:09:05 +08:00
Zhang Huanjie
e633b5b3ce typo fix 2017-10-26 21:59:47 +08:00
wangyu-
47d762958f refactor 2017-10-26 08:54:18 -05:00
wangyu-
0a34cb47ab refactor 2017-10-26 08:38:52 -05:00
wangyu-
cdba2f8c2c Update README.zh-cn.md 2017-10-26 01:23:24 -07:00
wangyu-
8f9deafce7 Update README.zh-cn.md 2017-10-26 01:21:59 -07:00
wangyu-
d6e445f220 Merge pull request #47 from Carmot/master
Minor memory issues fixed.
2017-10-26 14:43:00 +08:00
Jose Angel Gariburo
3d2ec1bdf2 fec.c is external so leaving it as it is.
Changed log output to 'log_warn'.
2017-10-26 08:29:04 +02:00
wangyu-
c0450160d6 trival 2017-10-26 00:31:21 -05:00
wangyu-
b23dd44aa7 Update README.md 2017-10-25 21:04:25 -07:00
wangyu-
fc540c6fe2 Update README.md 2017-10-25 21:01:08 -07:00
wangyu-
c0b57e66fd Update README.zh-cn.md 2017-10-25 11:35:15 -07:00
wangyu-
00f8ddf48e Update README.zh-cn.md 2017-10-25 11:22:04 -07:00
wangyu-
63cc9a3c5d Update README.zh-cn.md 2017-10-25 11:21:44 -07:00
wangyu-
47c5823f52 Update README.zh-cn.md 2017-10-25 11:16:22 -07:00
wangyu-
5351095f42 Update README.zh-cn.md 2017-10-25 11:15:45 -07:00
wangyu-
64b0420ff4 Update README.zh-cn.md 2017-10-25 10:33:08 -07:00
wangyu-
695b0e46a8 Update README.zh-cn.md 2017-10-25 10:24:08 -07:00
wangyu-
1798529d28 Update README.zh-cn.md 2017-10-25 10:22:51 -07:00
wangyu-
f50e0d4dc6 Update README.zh-cn.md 2017-10-25 09:57:18 -07:00
wangyu-
c0817fba47 Update README.zh-cn.md 2017-10-25 09:43:06 -07:00
wangyu-
0a6e9f500a Update README.zh-cn.md 2017-10-25 09:41:58 -07:00
Jose Angel Gariburo
c8fb35cf53 Minor memory issues fixed.
'u_long' variable name changed to 'u_dword'. It is not a good idea to name a variable as an existing type.
2017-10-25 17:48:22 +02:00
wangyu-
9d62ea410f Update README.zh-cn.md 2017-10-25 00:58:11 -07:00
wangyu-
d1c36cc197 Update README.zh-cn.md 2017-10-25 00:55:12 -07:00
wangyu-
a99791c98a Update README.zh-cn.md 2017-10-25 00:33:45 -07:00
wangyu-
0e1b86b237 Merge branch 'master' of https://github.com/wangyu-/UDPspeeder 2017-10-25 02:29:43 -05:00
wangyu-
a1cddaf671 change log 2017-10-25 02:29:11 -05:00
wangyu-
0f3a7cf3b6 Update README.zh-cn.md 2017-10-25 00:11:44 -07:00
wangyu-
a2f9afd369 Update README.zh-cn.md 2017-10-25 00:10:28 -07:00
wangyu-
7bb66e9ce7 Update README.md 2017-10-25 00:04:50 -07:00
wangyu-
8e7a8aed92 changed help page 2017-10-25 02:00:34 -05:00
wangyu-
696396cf79 change help page 2017-10-25 01:57:08 -05:00
wangyu-
e11141e036 help page 2017-10-25 01:45:35 -05:00
wangyu-
d6fc5dc072 implemented commands 2017-10-25 01:15:50 -05:00
wangyu-
4dd37700e6 add option fifo 2017-10-24 14:16:17 -05:00
wangyu-
cf08bb735d add log,changed a fatal to error 2017-10-24 04:06:37 -05:00
wangyu-
1ca82311ec qMerge branch 'master' of https://github.com/wangyu-/UDPspeeder 2017-10-24 04:04:13 -05:00
wangyu-
cdf74b780a Update README.zh-cn.md 2017-10-24 00:21:38 -07:00
wangyu-
9e54fc8a3b Update README.zh-cn.md 2017-10-24 00:18:30 -07:00
wangyu-
16efd9d4a1 Update README.zh-cn.md 2017-10-23 23:11:02 -07:00
wangyu-
597b28f05f Update README.zh-cn.md 2017-10-23 22:10:51 -07:00
wangyu-
5192438851 Update README.zh-cn.md 2017-10-23 22:07:16 -07:00
wangyu-
13084620e5 Update README.zh-cn.md 2017-10-23 22:06:33 -07:00
wangyu-
6a58f4d38c Update README.zh-cn.md 2017-10-23 22:03:43 -07:00
wangyu-
5b40129505 Update README.md 2017-10-23 22:02:39 -07:00
wangyu-
d20627f5c0 Update README.zh-cn.md 2017-10-23 21:59:40 -07:00
wangyu-
0c016e8013 Update README.zh-cn.md 2017-10-23 21:48:32 -07:00
wangyu-
0f5155051b Update README.zh-cn.md 2017-10-23 21:48:08 -07:00
wangyu-
bf7c0a5dc1 Update README.zh-cn.md 2017-10-23 21:36:51 -07:00
wangyu-
bfe3c9cb00 Update README.zh-cn.md 2017-10-23 21:34:54 -07:00
wangyu-
2ae70d49a2 Update README.zh-cn.md 2017-10-23 21:31:44 -07:00
wangyu-
67529a041b Update README.zh-cn.md 2017-10-23 21:26:39 -07:00
wangyu-
385aa66e15 Update README.zh-cn.md 2017-10-23 21:23:20 -07:00
wangyu-
20a5547b27 Update README.zh-cn.md 2017-10-23 07:09:46 -07:00
wangyu-
605787bdd6 Update README.zh-cn.md 2017-10-23 07:06:30 -07:00
wangyu-
7cf14a39c7 Update README.zh-cn.md 2017-10-23 07:04:35 -07:00
wangyu-
8b267f811b Update README.zh-cn.md 2017-10-23 07:03:41 -07:00
wangyu-
9714332658 Update udpspeeder_openvpn.md 2017-10-23 05:00:49 -07:00
wangyu-
30896c8110 Update udpspeeder_openvpn.md 2017-10-23 05:00:22 -07:00
wangyu-
9b1999ec11 Update udpspeeder_openvpn.md 2017-10-23 04:58:06 -07:00
wangyu-
e71e200f5b Update udpspeeder_openvpn.md 2017-10-23 04:57:01 -07:00
wangyu-
5391077b94 Update udpspeeder_openvpn.md 2017-10-23 04:56:28 -07:00
wangyu-
0a44043884 Update README.zh-cn.md 2017-10-22 22:18:00 -07:00
wangyu-
586eae7c34 Update udpspeeder_openvpn.md 2017-10-22 22:12:59 -07:00
wangyu-
841c387fcb Update udpspeeder_openvpn.md 2017-10-22 22:12:26 -07:00
wangyu-
592efb300a Update README.zh-cn.md 2017-10-22 21:43:59 -07:00
wangyu-
bd8cb2076d Update README.md 2017-10-22 18:22:53 -07:00
wangyu-
8ad40532bb Update README.md 2017-10-22 10:35:45 -07:00
wangyu-
ebb6cf1cea Add files via upload 2017-10-22 12:34:49 -05:00
wangyu-
3737491145 Update README.md 2017-10-22 08:41:55 -07:00
wangyu-
257f8231b7 Update udpspeeder_openvpn.md 2017-10-22 05:26:49 -07:00
wangyu-
3e7df45d24 fixed a typo 2017-10-21 20:21:16 -05:00
wangyu-
fd8deba3ed Update README.md 2017-10-21 17:30:51 -07:00
wangyu-
eda1360d56 Update README.md 2017-10-21 17:30:22 -07:00
wangyu-
39f2ead0af Merge branch 'master' of https://github.com/wangyu-/UDPspeeder 2017-10-21 11:09:51 -05:00
wangyu-
77b908a663 fix -q option 2017-10-21 10:59:49 -05:00
wangyu-
6d8904d144 Update README.zh-cn.md 2017-10-21 06:49:52 -07:00
wangyu-
be9d0270d1 Update README.zh-cn.md 2017-10-21 06:48:41 -07:00
wangyu-
a5612072ea Update README.zh-cn.md 2017-10-20 23:48:02 -07:00
wangyu-
aec423012c Update README.zh-cn.md 2017-10-20 23:45:27 -07:00
wangyu-
a8120dde23 Update README.zh-cn.md 2017-10-20 23:41:37 -07:00
wangyu-
0009531a6f Update README.zh-cn.md 2017-10-20 23:40:29 -07:00
wangyu-
06510d2e21 Update README.md 2017-10-20 22:15:44 -07:00
wangyu-
c4a84b5d66 Update README.md 2017-10-20 21:52:09 -07:00
wangyu-
1f366d56f8 Update README.md 2017-10-20 21:47:26 -07:00
wangyu-
43c6afbd16 Merge pull request #32 from heart4lor/patch-1
Update main.cpp
2017-10-20 22:42:14 -05:00
Sun Yongfei
5d6d904ff7 Update main.cpp 2017-10-21 11:27:39 +08:00
wangyu-
bbf202a438 Update README.zh-cn.md 2017-10-20 20:04:40 -07:00
wangyu-
27801fe6c0 Add files via upload 2017-10-20 06:34:36 -05:00
wangyu-
de173447ba Update README.zh-cn.md 2017-10-20 04:20:27 -07:00
wangyu-
cb352c911c Update README.zh-cn.md 2017-10-20 04:19:29 -07:00
wangyu-
0351bd0e59 Update README.zh-cn.md 2017-10-20 01:57:38 -07:00
wangyu-
15f77da7d9 Update README.zh-cn.md 2017-10-20 01:47:25 -07:00
wangyu-
bc92925b30 Update README.zh-cn.md 2017-10-20 01:46:30 -07:00
wangyu-
d9b8664709 Update README.zh-cn.md 2017-10-20 01:35:55 -07:00
wangyu-
e5e7c302d6 Update README.zh-cn.md 2017-10-20 00:49:24 -07:00
wangyu-
dc5c7c4e05 Update README.zh-cn.md 2017-10-20 00:47:04 -07:00
wangyu-
3db1b7c068 Update README.zh-cn.md 2017-10-19 23:35:23 -07:00
wangyu-
a0d23221a6 Update README.zh-cn.md 2017-10-19 23:17:09 -07:00
wangyu-
7dbd5b2575 Update README.zh-cn.md 2017-10-19 23:16:22 -07:00
wangyu-
a48e9a08d9 Update README.zh-cn.md 2017-10-19 23:11:34 -07:00
wangyu-
919a6022d0 Add files via upload 2017-10-20 01:08:28 -05:00
wangyu-
e158c3922e Update README.zh-cn.md 2017-10-19 21:54:41 -07:00
wangyu-
3ad201ba56 Update README.zh-cn.md 2017-10-19 21:52:37 -07:00
wangyu-
7adf9d7cde Update README.zh-cn.md 2017-10-19 21:32:58 -07:00
wangyu-
2d08c6f7ec Add files via upload 2017-10-19 23:32:19 -05:00
wangyu-
8b2957818a Update README.zh-cn.md 2017-10-19 21:30:06 -07:00
wangyu-
55516c16d5 Update README.zh-cn.md 2017-10-19 21:28:25 -07:00
wangyu-
2e52b163ec Add files via upload 2017-10-19 23:24:45 -05:00
wangyu-
34523fee11 Update README.md 2017-10-19 21:03:27 -07:00
wangyu-
e8fe62300d Update README.zh-cn.v1.md 2017-10-19 20:56:28 -07:00
wangyu-
dbed5c3e6b Add files via upload 2017-10-19 22:53:31 -05:00
wangyu-
5228a3c44d Update README.zh-cn.v1.md 2017-10-19 20:46:24 -07:00
wangyu-
0d4c59552f Update README.zh-cn.v1.md 2017-10-19 20:45:24 -07:00
wangyu-
43f8bb2367 Update README.zh-cn.v1.md 2017-10-19 20:42:35 -07:00
wangyu-
60aa420a99 Update README.zh-cn.md 2017-10-19 20:38:08 -07:00
wangyu-
9bd3707301 Update README.zh-cn.md 2017-10-19 20:31:02 -07:00
wangyu-
f99a84a5a0 Add files via upload 2017-10-19 22:25:40 -05:00
wangyu-
87972b8801 Create 11 2017-10-19 20:25:06 -07:00
wangyu-
adb3a8890f Update README.md 2017-10-19 20:17:26 -07:00
wangyu-
2b0e64d1ae just commit 2017-10-19 22:15:52 -05:00
wangyu-
d407af5bd1 just commit 2017-10-19 22:14:39 -05:00
wangyu-
df34c723bc Update README.md 2017-10-19 11:48:12 -07:00
wangyu-
f83075390b Add files via upload 2017-10-19 13:47:52 -05:00
wangyu-
bb88b2e6b6 Add files via upload 2017-10-19 13:44:34 -05:00
32 changed files with 2560 additions and 1692 deletions

View File

@@ -1,33 +1,52 @@
# UDPspeeder
Network Speed-Up Tool. Boost your Connection on a High Lantency High Packet-Loss Link by using Forward Error Correction.
When used alone,UDPspeeder speeds-up only udp connection.Nevertheless,if you used UDPspeeder + any UDP-based VPN together,you can speed-up any traffic(include tcp/udp/icmp)。
When used alone, UDPspeeder speeds-up only UDP connection. Nevertheless, if you used UDPspeeder + any UDP-based VPN together,
you can speed-up any traffic(include TCP/UDP/ICMP), currently OpenVPN/L2TP/ShadowVPN are confirmed to be supported。
![](/images/en/udpspeeder.PNG)
or
![image_vpn](/images/en/udpspeeder+openvpn.PNG)
![image_vpn](/images/en/udpspeeder+openvpn3.PNG)
Assume your local network to your server is lossy. Just establish a VPN connection to your server with UDPspeeder + any UDP-based VPN, access your server via this VPN connection, then your connection quality will be significantly improved. With well-tuned parameters , you can easily reduce IP or UDP/ICMP packet-loss-rate to less than 0.01% . Besides reducing packet-loss-rate, UDPspeeder can also significantly improve your TCP latency and TCP single-thread download speed.
[简体中文](/doc/README.zh-cn.md)(内容更丰富)
###### Note
You can use udp2raw with UDPspeeder together to get better speed on some ISP with UDP QoS(UDP throttling).
udp2raw's repo
https://github.com/wangyu-/udp2raw-tunnel
You can also try tinyFecVPN, a lightweight high-performance VPN with build-in FEC support:
tinyFecVPN's repo:
https://github.com/wangyu-/tinyFecVPN
[简体中文](/doc/README.md)
# Efficacy
tested on a link with 100ms latency and 10% packet loss at both direction
### Ping Packet Loss
![](/images/en/ping_compare3.PNG)
![](/images/en/ping_compare_mode1.png)
### SCP Copy Speed
![](/images/en/scp_compare2.PNG)
# Supported Platforms
Linux host (including desktop Linux,Android phone/tablet,OpenWRT router,or Raspberry PI).
Linux host (including desktop Linux,Android phone/tablet, OpenWRT router, or Raspberry PI).
For Windows and MacOS You can run UDPspeeder inside [this](https://github.com/wangyu-/udp2raw-tunnel/releases/download/20170918.0/lede-17.01.2-x86_virtual_machine_image_with_udp2raw_pre_installed.zip) 7.5mb virtual machine image.
For Windows and MacOS You can run UDPspeeder inside [this](https://github.com/wangyu-/udp2raw-tunnel/releases/download/20171108.0/lede-17.01.2-x86_virtual_machine_image.zip) 7.5mb virtual machine image.
# How does it work
UDPspeeder uses FEC(Forward Error Correction) to improve your connection's quality,at the cost of addtional bandwidth.The algorithm for FEC is called Reed-Solomon.
UDPspeeder uses FEC(Forward Error Correction) to reduce packet loss rate, at the cost of addtional bandwidth. The algorithm for FEC is called Reed-Solomon.
![image0](/images/en/fec.PNG)
### Reed-Solomon
@@ -53,23 +72,27 @@ Assume your server ip is 44.55.66.77, you have a service listening on udp port 7
```bash
# Run at server side:
./speederv2 -s -l0.0.0.0:4096 -r 127.0.0.1:7777 -f20:10
./speederv2 -s -l0.0.0.0:4096 -r 127.0.0.1:7777 -f20:10 -k "passwd"
# Run at client side
./speederv2 -c -l0.0.0.0:3333 -r44.55.66.77:4096 -f20:10
./speederv2 -c -l0.0.0.0:3333 -r44.55.66.77:4096 -f20:10 -k "passwd"
```
Now connecting to UDP port 3333 at the client side is equivalent to connecting to port 7777 at the server side,and the connection is boosted by UDPspeeder.
Now connecting to UDP port 3333 at the client side is equivalent to connecting to port 7777 at the server side, and the connection is boosted by UDPspeeder.
##### Note
`-f20:10` means sending 10 redundant packets for every 20 original packets.
`-k` enables simple XOR encryption
To run stably, pay attention to MTU. You can also try `--mode 0`,there will be no MTU problem in this mode.
# Advanced Topic
### Full Options
```
UDPspeeder V2
git version:f479ca2779 build date:Oct 19 2017 01:37:08
git version:8e7a8aed92 build date:Oct 25 2017 02:00:54
repository: https://github.com/wangyu-/UDPspeeder
usage:
@@ -80,13 +103,13 @@ common option,must be same on both sides:
-k,--key <string> key for simple xor encryption. if not set,xor is disabled
main options:
-f,--fec x:y forward error correction,send y redundant packets for every x packets
--timeout <number> how long could a packet be held in queue before doing fec,unit: ms
--mode <number> fec-mode,available values: 0,1 ; 0 cost less bandwidth,1 cost less latency
--timeout <number> how long could a packet be held in queue before doing fec,unit: ms,default :8ms
--mode <number> fec-mode,available values: 0,1 ; 0 cost less bandwidth,1 cost less latency(default)
--report <number> turn on send/recv report,and set a period for reporting,unit:s
advanced options:
--mtu <number> mtu. for mode 0,the program will split packet to segment smaller than mtu_value.
for mode 1,no packet will be split,the program just check if the mtu is exceed.
default value:1250
default value:1250
-j,--jitter <number> simulated jitter.randomly delay first packet for 0~<number> ms,default value:0.
do not use if you dont know what it means.
-i,--interval <number> scatter each fec group to a interval of <number> ms,to protect burst packet loss.
@@ -94,6 +117,9 @@ advanced options:
--random-drop <number> simulate packet loss ,unit:0.01%. default value: 0
--disable-obscure <number> disable obscure,to save a bit bandwidth and cpu
developer options:
--fifo <string> use a fifo(named pipe) for sending commands to the running program,so that you
can change fec encode parameters dynamically,check readme.md in repository for
supported commands.
-j ,--jitter jmin:jmax similiar to -j above,but create jitter randomly between jmin and jmax
-i,--interval imin:imax similiar to -i above,but scatter randomly between imin and imax
-q,--queue-len <number> max fec queue len,only for mode 0
@@ -103,12 +129,22 @@ developer options:
--disable-fec <number> completely disable fec,turn the program into a normal udp tunnel
--sock-buf <number> buf size for socket,>=10 and <=10240,unit:kbyte,default:1024
log and help options:
--log-level <number> 0:never 1:fatal 2:error 3:warn
--log-level <number> 0:never 1:fatal 2:error 3:warn
4:info (default) 5:debug 6:trace
--log-position enable file name,function name,line number in log
--disable-color disable log color
-h,--help print this help message
```
### Speed-Up any traffic with OpenVPN+UDPspeeder
#### `--fifo` option
Use a fifo(named pipe) for sending commands to the running program. For example `--fifo fifo.file`, you can use following commands to change parameters dynamically:
```
echo fec 19:9 > fifo.file
echo mtu 1100 > fifo.file
echo timeout 5 > fifo.file
echo queue-len 100 > fifo.file
echo mode 0 > fifo.file
```
### Speed-Up any traffic with OpenVPN + UDPspeeder
Check [UDPspeeder + openvpn config guide](/doc/udpspeeder_openvpn.md).

View File

@@ -15,12 +15,16 @@ int about_to_exit=0;
raw_mode_t raw_mode=mode_faketcp;
unordered_map<int, const char*> raw_mode_tostring = {{mode_faketcp, "faketcp"}, {mode_udp, "udp"}, {mode_icmp, "icmp"}};
int delay_capacity=0;
//static int random_number_fd=-1;
char iptables_rule[200]="";
//int is_client = 0, is_server = 0;
program_mode_t program_mode=unset_mode;//0 unset; 1client 2server
program_mode_t client_or_server=unset_mode;//0 unset; 1client 2server
working_mode_t working_mode=tunnel_mode;
int socket_buf_size=1024*1024;
@@ -256,6 +260,39 @@ unsigned short csum(const unsigned short *ptr,int nbytes) {
return(answer);
}
unsigned short tcp_csum(const pseudo_header & ph,const unsigned short *ptr,int nbytes) {//works both for big and little endian
register long sum;
unsigned short oddbyte;
register short answer;
sum=0;
unsigned short * tmp= (unsigned short *)&ph;
for(int i=0;i<6;i++)
{
sum+=*tmp++;
}
while(nbytes>1) {
sum+=*ptr++;
nbytes-=2;
}
if(nbytes==1) {
oddbyte=0;
*((u_char*)&oddbyte)=*(u_char*)ptr;
sum+=oddbyte;
}
sum = (sum>>16)+(sum & 0xffff);
sum = sum + (sum>>16);
answer=(short)~sum;
return(answer);
}
int set_buf_size(int fd,int socket_buf_size,int force_socket_buf)
{
if(force_socket_buf)
@@ -488,3 +525,100 @@ int round_up_div(int a,int b)
{
return (a+b-1)/b;
}
int create_fifo(char * file)
{
if(mkfifo (file, 0666)!=0)
{
if(errno==EEXIST)
{
mylog(log_warn,"warning fifo file %s exist\n",file);
}
else
{
mylog(log_fatal,"create fifo file %s failed\n",file);
myexit(-1);
}
}
int fifo_fd=open (file, O_RDWR);
if(fifo_fd<0)
{
mylog(log_fatal,"create fifo file %s failed\n",file);
myexit(-1);
}
struct stat st;
if (fstat(fifo_fd, &st)!=0)
{
mylog(log_fatal,"fstat failed for fifo file %s\n",file);
myexit(-1);
}
if(!S_ISFIFO(st.st_mode))
{
mylog(log_fatal,"%s is not a fifo\n",file);
myexit(-1);
}
setnonblocking(fifo_fd);
return fifo_fd;
}
int new_listen_socket(int &fd,u32_t ip,int port)
{
fd =socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
int yes = 1;
//setsockopt(udp_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
struct sockaddr_in local_me={0};
socklen_t slen = sizeof(sockaddr_in);
//memset(&local_me, 0, sizeof(local_me));
local_me.sin_family = AF_INET;
local_me.sin_port = htons(port);
local_me.sin_addr.s_addr = ip;
if (bind(fd, (struct sockaddr*) &local_me, slen) == -1) {
mylog(log_fatal,"socket bind error\n");
//perror("socket bind error");
myexit(1);
}
setnonblocking(fd);
set_buf_size(fd,socket_buf_size);
mylog(log_debug,"local_listen_fd=%d\n,",fd);
return 0;
}
int new_connected_socket(int &fd,u32_t ip,int port)
{
char ip_port[40];
sprintf(ip_port,"%s:%d",my_ntoa(ip),port);
struct sockaddr_in remote_addr_in = { 0 };
socklen_t slen = sizeof(sockaddr_in);
//memset(&remote_addr_in, 0, sizeof(remote_addr_in));
remote_addr_in.sin_family = AF_INET;
remote_addr_in.sin_port = htons(port);
remote_addr_in.sin_addr.s_addr = ip;
fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (fd < 0) {
mylog(log_warn, "[%s]create udp_fd error\n", ip_port);
return -1;
}
setnonblocking(fd);
set_buf_size(fd, socket_buf_size);
mylog(log_debug, "[%s]created new udp_fd %d\n", ip_port, fd);
int ret = connect(fd, (struct sockaddr *) &remote_addr_in, slen);
if (ret != 0) {
mylog(log_warn, "[%s]fd connect fail\n",ip_port);
close(fd);
return -1;
}
return 0;
}

View File

@@ -21,6 +21,7 @@
#include <sys/wait.h>
#include <sys/socket.h> //for socket ofcourse
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h> //for exit(0);
#include <errno.h> //For errno - the error number
#include <netinet/tcp.h> //Provides declarations for tcp header
@@ -43,7 +44,7 @@
#include <stdarg.h>
#include <assert.h>
#include <linux/if_packet.h>
#include <linux/if_tun.h>
#include<unordered_map>
#include<unordered_set>
@@ -66,10 +67,11 @@ typedef u64_t my_time_t;
const int max_data_len=2200;
const int buf_len=max_data_len+200;
const u32_t conv_clear_interval=200;
//const u32_t timer_interval=400;
////const u32_t conv_timeout=180000;
const u32_t conv_timeout=40000;//for test
//const u32_t conv_timeout=40000;//for test
const u32_t conv_timeout=180000;
const int max_conv_num=10000;
const int max_conn_num=200;
@@ -84,12 +86,12 @@ const u32_t client_retry_interval=1000;
const u32_t server_handshake_timeout=10000;// this should be much longer than clients. client retry initially ,server retry passtively*/
const int conv_clear_ratio=10; //conv grabage collecter check 1/10 of all conv one time
const int conn_clear_ratio=10;
const int conv_clear_min=5;
const int conv_clear_ratio=30; //conv grabage collecter check 1/30 of all conv one time
const int conn_clear_ratio=50;
const int conv_clear_min=1;
const int conn_clear_min=1;
const u32_t conv_clear_interval=1000;
const u32_t conn_clear_interval=1000;
@@ -97,7 +99,7 @@ const i32_t max_fail_time=0;//disable
const u32_t heartbeat_interval=1000;
const u32_t timer_interval=500;//this should be smaller than heartbeat_interval and retry interval;
const u32_t timer_interval=400;//this should be smaller than heartbeat_interval and retry interval;
//const uint32_t conv_timeout=120000; //120 second
//const u32_t conv_timeout=120000; //for test
@@ -114,10 +116,13 @@ extern int about_to_exit;
enum raw_mode_t{mode_faketcp=0,mode_udp,mode_icmp,mode_end};
extern raw_mode_t raw_mode;
enum program_mode_t {unset_mode=0,client_mode,server_mode};
extern program_mode_t program_mode;
extern program_mode_t client_or_server;
extern unordered_map<int, const char*> raw_mode_tostring ;
extern int delay_capacity;
enum working_mode_t {unset_working_mode=0,tunnel_mode,tun_dev_mode};
extern working_mode_t working_mode;
extern int socket_buf_size;
typedef u32_t id_t;
@@ -130,8 +135,8 @@ typedef u64_t anti_replay_seq_t;
typedef u64_t fd64_t;
enum dest_type{none=0,type_ip_port,type_fd64,type_ip_port_conv,type_fd64_conv/*,type_fd*/};
//enum dest_type{none=0,type_fd64_ip_port,type_fd64,type_fd64_ip_port_conv,type_fd64_conv/*,type_fd*/};
enum dest_type{none=0,type_fd64_ip_port,type_fd64,type_fd,type_write_fd,type_fd_ip_port/*,type_fd*/};
struct ip_port_t
{
@@ -142,11 +147,22 @@ struct ip_port_t
char * to_s();
};
struct fd64_ip_port_t
{
fd64_t fd64;
ip_port_t ip_port;
};
struct fd_ip_port_t
{
int fd;
ip_port_t ip_port;
};
union inner_t
{
ip_port_t ip_port;
//int fd;
fd64_t fd64;
int fd;
fd64_ip_port_t fd64_ip_port;
fd_ip_port_t fd_ip_port;
};
struct dest_t
{
@@ -161,6 +177,13 @@ struct fd_info_t
ip_port_t ip_port;
};
struct pseudo_header {
u_int32_t source_address;
u_int32_t dest_address;
u_int8_t placeholder;
u_int8_t protocol;
u_int16_t tcp_length;
};
u64_t get_current_time();
u64_t get_current_time_us();
@@ -194,6 +217,7 @@ void setnonblocking(int sock);
int set_buf_size(int fd,int socket_buf_size,int force_socket_buf=0);
unsigned short csum(const unsigned short *ptr,int nbytes);
unsigned short tcp_csum(const pseudo_header & ph,const unsigned short *ptr,int nbytes);
void signal_handler(int sig);
int numbers_to_char(id_t id1,id_t id2,id_t id3,char * &data,int &len);
@@ -211,8 +235,13 @@ int set_timer_ms(int epollfd,int &timer_fd,u32_t timer_interval);
int round_up_div(int a,int b);
int create_fifo(char * file);
/*
int create_new_udp(int &new_udp_fd,int remote_address_uint32,int remote_port);
*/
int new_listen_socket(int &fd,u32_t ip,int port);
int new_connected_socket(int &fd,u32_t ip,int port);
#endif /* COMMON_H_ */

View File

@@ -47,7 +47,7 @@ void conv_manager_t::clear()
{
//if(disable_conv_clear) return ;//////what was the purpose of this code?
if(program_mode==server_mode)
if(client_or_server==server_mode)
{
for(auto it=conv_to_u64.begin();it!=conv_to_u64.end();it++)
{
@@ -111,7 +111,7 @@ int conv_manager_t::erase_conv(u32_t conv)
//if(disable_conv_clear) return 0;
assert(conv_last_active_time.find(conv)!=conv_last_active_time.end());
u64_t u64=conv_to_u64[conv];
if(program_mode==server_mode)
if(client_or_server==server_mode)
{
server_clear_function(u64);
}

View File

@@ -107,7 +107,7 @@ struct conn_info_t //stores info for a raw connection.for client ,there is o
fec_encode_manager_t fec_encode_manager;
fec_decode_manager_t fec_decode_manager;
my_timer_t timer;
ip_port_t ip_port;
//ip_port_t ip_port;
u64_t last_active_time;
stat_t stat;
conn_info_t()

View File

@@ -66,7 +66,11 @@ int delay_manager_t::add(my_time_t delay,const dest_t &dest,char *data,int len)
delay_data_t tmp=delay_data;
tmp.data=(char *)malloc(delay_data.len+100);
if(!tmp.data)
{
mylog(log_warn, "malloc() returned null in delay_manager_t::add()");
return -1;
}
memcpy(tmp.data,data,delay_data.len);
my_time_t tmp_time=get_current_time_us();

268
doc/README.zh-cn.md Normal file
View File

@@ -0,0 +1,268 @@
# UDPspeeder
![image0](/images/cn/speedercn.PNG)
双边网络加速工具软件本身的功能是加速UDP不过配合vpn可以加速全流量(包括TCP/UDP/ICMP)。通过合理配置可以加速游戏降低游戏的丢包和延迟也可以加速下载和看视频这种大流量的应用。用1.5倍的流量就可以把10%的丢包率降低到万分之一以下。跟 kcptun/finalspeed/BBR 等现有方案比,主要优势是可以加速 UDP 和 ICMP现有方案几乎都只能加速 TCP。
我自己稳定用了几个月用来加速美服的Brawl Stars和亚服的Mobile Legend效果不错加速前卡得几乎没法玩加速后就没怎么卡过了。用来看视频也基本满速。
最新的版本是v2版在v1版的基础上增加了FEC功能更省流量。如果你用的是v1版路由器固件里自带的集成版很可能是v1版的请看[v1版主页](/doc/README.zh-cn.v1.md)
配合vpn加速全流量的原理图(已测试支持VPN的有OpenVPN、L2TP、$\*\*\*VPN):
![image0](/images/Capture2.PNG)
对于某些运营商UDPspeeder跟udp2raw配合可以达到更好的速度udp2raw负责把UDP伪装成TCP来绕过运营商的UDP限速。
udp2raw的repo:
https://github.com/wangyu-/udp2raw-tunnel
如果你嫌UDPspeeder+OpenVPN麻烦你可以尝试tinyFecVPN一个集成了UDPspeeder功能的VPN
tinyFecVPN的repo:
https://github.com/wangyu-/tinyFecVPN
#### 效果
![image0](/images/cn/ping_compare_cn.PNG)
![image0](/images/cn/scp_compare.PNG)
#### 原理简介
主要原理是通过冗余数据来对抗网络的丢包发送冗余数据的方式支持FEC(Forward Error Correction)和多倍发包其中FEC算法是Reed-Solomon。
FEC方式的原理图:
![image0](/images/en/fec.PNG)
#### 其他功能
对包的内容和长度做随机化可以理解为混淆从抓包看不出你发送了冗余数据不用担心vps被封。
在多个冗余包之间引入延迟时间可配来对抗突发性的丢包避开中间路由器因为瞬时buffer长度过长而连续丢掉所有副本。
模拟一定的延迟抖动时间可配这样上层应用计算出来的RTT方差会更大以等待后续冗余包的到达不至于发生在冗余包到达之前就触发重传的尴尬。
输出UDP收发情况报告可以看出丢包率。
模拟丢包模拟延迟模拟jitter。便于通过实验找出应用卡顿的原因。
client支持多个udp连接server也支持多个client
# 简明操作说明
### 环境要求
Linux主机可以是桌面版可以是android手机/平板可以是openwrt路由器也可以是树莓派。
对于windows和mac用户在虚拟机中可以稳定使用speeder跑在Linux里其他应用照常跑在window里桥接模式测试可用。可以使用[这个](https://github.com/wangyu-/udp2raw-tunnel/releases/download/20171108.0/lede-17.01.2-x86_virtual_machine_image.zip)虚拟机镜像大小只有7.5mb免去在虚拟机里装系统的麻烦虚拟机自带ssh server可以scp拷贝文件可以ssh进去可以复制粘贴root密码123456。
android版需要通过terminal运行。
##### 注意
在使用虚拟机时,建议手动指定桥接到哪个网卡,不要设置成自动。否则可能会桥接到错误的网卡。
### 安装
下载编译好的二进制文件,解压到本地和服务器的任意目录。
https://github.com/wangyu-/UDPspeeder/releases
### 运行
假设你有一个serverip为44.55.66.77有一个服务监听在udp 7777端口。 假设你需要加速本地到44.55.66.77:7777的流量。
```
在server端运行:
./speederv2 -s -l0.0.0.0:4096 -r127.0.0.1:7777 -f20:10 -k "passwd" --mode 0
在client端运行:
./speederv2 -c -l0.0.0.0:3333 -r44.55.66.77:4096 -f20:10 -k "passwd" --mode 0
```
现在client和server之间建立起了tunnel。想要连接44.55.66.77:7777只需要连接 127.0.0.1:3333。来回的所有的udp流量会被加速。
##### 备注:
`-f20:10`表示对每20个原始数据发送10个冗余包。`-f20:10``-f 20:10`都是可以的空格可以省略对于所有的单字节option都是如此。对于双字节option例如后面会提到的`--mode 0`,空格不可以省略。
`-k` 指定一个字符串,开启简单的异或加密
推荐使用`--mode 0`选项否则你可能需要考虑MTU问题。
##### 注意
这里推荐的参数是给日常/非游戏情况下使用的;玩游戏请用 [使用经验](https://github.com/wangyu-/UDPspeeder/wiki/使用经验) 里推荐的参数。
# 进阶操作说明
### 命令选项
```
UDPspeeder V2
git version:8e7a8aed92 build date:Oct 25 2017 02:00:54
repository: https://github.com/wangyu-/UDPspeeder
usage:
run as client : ./this_program -c -l local_listen_ip:local_port -r server_ip:server_port [options]
run as server : ./this_program -s -l server_listen_ip:server_port -r remote_ip:remote_port [options]
common option,must be same on both sides:
-k,--key <string> key for simple xor encryption. if not set,xor is disabled
main options:
-f,--fec x:y forward error correction,send y redundant packets for every x packets
--timeout <number> how long could a packet be held in queue before doing fec,unit: ms,default :8ms
--mode <number> fec-mode,available values: 0,1 ; 0 cost less bandwidth,1 cost less latency(default)
--report <number> turn on send/recv report,and set a period for reporting,unit:s
advanced options:
--mtu <number> mtu. for mode 0,the program will split packet to segment smaller than mtu_value.
for mode 1,no packet will be split,the program just check if the mtu is exceed.
default value:1250
-j,--jitter <number> simulated jitter.randomly delay first packet for 0~<number> ms,default value:0.
do not use if you dont know what it means.
-i,--interval <number> scatter each fec group to a interval of <number> ms,to protect burst packet loss.
default value:0.do not use if you dont know what it means.
--random-drop <number> simulate packet loss ,unit:0.01%. default value: 0
--disable-obscure <number> disable obscure,to save a bit bandwidth and cpu
developer options:
--fifo <string> use a fifo(named pipe) for sending commands to the running program,so that you
can change fec encode parameters dynamically,check readme.md in repository for
supported commands.
-j ,--jitter jmin:jmax similiar to -j above,but create jitter randomly between jmin and jmax
-i,--interval imin:imax similiar to -i above,but scatter randomly between imin and imax
-q,--queue-len <number> max fec queue len,only for mode 0
--decode-buf <number> size of buffer of fec decoder,unit:packet,default:2000
--fix-latency <number> try to stabilize latency,only for mode 0
--delay-capacity <number> max number of delayed packets
--disable-fec <number> completely disable fec,turn the program into a normal udp tunnel
--sock-buf <number> buf size for socket,>=10 and <=10240,unit:kbyte,default:1024
log and help options:
--log-level <number> 0:never 1:fatal 2:error 3:warn
4:info (default) 5:debug 6:trace
--log-position enable file name,function name,line number in log
--disable-color disable log color
-h,--help print this help message
```
### 包发送选项,两端设置可以不同。 只影响本地包发送。
##### `-f` 选项
设置fec参数影响数据的冗余度。
##### `--timeout` 选项
指定fec编码器在编码时候最多可以引入多大的延迟。越高fec越有效率调低可以降低延迟但是会牺牲效率。
##### `--mode` 选项 和 `--mtu`选项
简单来说`--mode 0`更省流量没有mtu问题`--mode 1`可以稍微降低一点延迟需要考虑mtu另外还有个`--mode 0 -q1`模式多倍发包专用没有延迟也没有mtu问题适合游戏但是最耗流量。
具体见https://github.com/wangyu-/UDPspeeder/wiki/mode和mtu选项
对于新手,建议不要纠结这些参数的具体含义,就用我在`使用经验`里推荐的设置,不要乱改参数,尤其是不要改`--mtu`
##### `--report`  选项
数据发送和接受报告。开启后可以根据此数据推测出包速和丢包率等特征。`--report 10`表示每10秒生成一次报告。
##### `-i` 选项
指定一个时间窗口长度为n毫秒。同一个fec分组的数据在发送时候会被均匀分散到这n毫秒中。可以对抗突发性的丢包。默认值是0因为这个功能需要用到时钟在某些虚拟机里时钟不稳定可能会导致个别包出现非常大的延迟所以默认关掉了。这个功能很有用默认参数效果不理想时可以尝试打开比如用`-i 10`。这个选项的跟通信原理上常说的`交错fec` `交织fec`的原理是差不多的。
##### `-j` 选项
为原始数据的发送增加一个延迟抖动值。这样上层应用计算出来的RTT方差会更大以等待后续冗余包的到达不至于发生在冗余包到达之前就触发重传的尴尬。配合-t选项使用。正常情况下跨国网络本身的延迟抖动就很大可以不用设-j。这个功能也需要时钟默认关掉了不过一般情况应该不需要这个功能。
-j选项不但可以模拟延迟抖动也可以模拟延迟。
##### `--random-drop` 选项
随机丢包。模拟高丢包的网络环境时使用。 `--random-drop``-j`选项一起用可以模拟高延迟或者高延迟抖动高丢包的网络可用于测试FEC参数在各种网络环境下的表现。
##### `-q` 选项
仅对mode 0模式有用。设置fec编码器的最大队列长度。 比如`-q5`的意思是在编码器积攒了5个数据包后就立即发送。合理使用可以改善延迟。在下文的`使用经验`里有提到用`--mode 0 -q1` 来多倍发包。
`-q``--timeout`的作用类似。`-q`决定fec编码器积攒了多少个数据包之后立即发送。`--timeout`决定编码器收到第一个数据包以后,最多延迟多少毫秒后发送。
默认值是200也就是尽可能多得积攒数据。
建议不要自己调整这个参数,除非是用我在`使用经验`里推荐给你的形式。
#### `--fifo` option
用fifo(命名管道)向运行中的程序发送command。例如`--fifo fifo.file`可用的command有
```
echo fec 19:9 > fifo.file
echo mtu 1100 > fifo.file
echo timeout 5 > fifo.file
echo queue-len 100 > fifo.file
echo mode 0 > fifo.file
```
可以动态改变fec编码器参数。可以从程序的log里看到command是否发送成功。
### 以下设置两端必须相同。
##### `-k`选项
指定一个字符串server/client间所有收发的包都会被异或改变协议特征防止UDPspeeder的协议被运营商针对。
##### `--disable-obscure`
UDPspeeder默认情况下会对每个发出的数据包随机填充和异或一些字节(4~32字节)这样通过抓包难以发现你发了冗余数据防止VPS被封。这个功能只是为了小心谨慎即使你关掉这个功能基本上也没问题关掉可以省一些带宽和CPU。`--disable-obscure`可以关掉这个功能。
# 使用经验
https://github.com/wangyu-/UDPspeeder/wiki/使用经验
# 应用
#### UDPspeeder + OpenVPN加速任何流量也适用于其他VPN
![image0](/images/Capture2.PNG)
可以和BBR/锐速叠加不过BBR/锐速部署在VPS上只对本地和VPS间的流量有效对从本地和第三方服务器间的流量无效。
需要在服务端开启ipforward和NAT。在客户端改路由表可以手动修改也可以由OpenVPN的redirect-gateway选项自动加好
Linux具体配置: [UDPspeeder + openvpn config guide](/doc/udpspeeder_openvpn.md).
Windows具体配置: [win10系统UDPspeeder+OpenVPN的完整设置](https://github.com/wangyu-/UDPspeeder/wiki/win10系统UDPspeeder-OpenVPN的完整设置)
如果UDPspeeder + OpenVPN对你来说显得太麻烦了你可以尝试一下tinyFecVPN,一个集成了UDPspeeder功能的VPN:
https://github.com/wangyu-/tinyFecVPN/
#### UDPspeeder + kcptun/finalspeed + $*** 同时加速tcp和udp流量
如果你需要用加速的tcp看视频和下载文件这样效果可能比没有BBR的UDPspeeder+vpn方案更好。另外如果你需要玩游戏但是嫌配VPN麻烦也可以用这种方案。
![image0](/images/cn/speeder_kcptun.PNG)
具体配置方法简介:
假设$\*\*\* server监听在在44.55.66.77的443端口(tcp和udp同时)。用kcptun把tcp 443映射到本地的tcp 1234用UDPspeeder把udp 443的映射到本地的udp 1234。
然后让$\*\*\* client 去连127.0.0.1:1234就可以了tcp和udp都被加速了。完整命令
```
run at server side:
./kcp_server -l ":4000" -t "127.0.0.1:443" -mode fast2
./speederv2 -s -l0.0.0.0:4001 -r127.0.0.1:443 -f20:10 -k "passwd"
run at client side:
./kcp_client -l ":1234" -r "44.55.66.77:4000" -mode fast2
./speederv2 -c -l0.0.0.0:1234 -r44.55.66.77:4001 -f20:10 -k "passwd"
```
这就是全部的命令了。issue里有很多人困惑于怎么把tcp和udp流量"分开",其实很简单就可以做到。
如果只需要加速UDP不需要加速TCP可以把kcptun换成其他的任意端口转发方式比如ncat/socat/ssh tunnel/iptables/[tinyPortMapper](https://github.com/wangyu-/tinyPortMapper/releases)。
另外如果没有kcptun只有BBR/锐速的话也可以把kcptun换成ncat/socat/ssh tunnel/iptables/[tinyPortMapper](https://github.com/wangyu-/tinyPortMapper/releases)。这样TCP流量由锐速/BBR加速UDP由UDPspeeder加速。
#### UDPspeeder + openvpn + $*** 混合方案也适用于其他VPN
也是我正在用的方案。优点是可以随时在vpn和$\*\*\*方案间快速切换。
实际部署起来比图中看起来的还要简单。不需要改路由表不需要写iptables规则和开启NAT需要做的只是用openvpn分配的ip访问$*** server。
![image0](/images/cn/speeder_vpn_s.PNG)
(也可以把图中的$*** server换成其他的socks5 server这样就不需要$*** client了)
可以和BBR/锐速叠加BBR/锐速只要部署在VPS上就有效。
也可以用[tinyFecVPN](https://github.com/wangyu-/tinyFecVPN/) + $\*\*\* ,配置起来更简单。
# 应用实例
#### win10系统UDPspeeder+OpenVPN的完整设置
https://github.com/wangyu-/UDPspeeder/wiki/win10系统UDPspeeder-OpenVPN的完整设置
#### 用树莓派做路由器,搭建透明代理,加速游戏主机的网络
https://github.com/wangyu-/UDPspeeder/wiki/用树莓派做路由器,搭建透明代理,加速游戏主机的网络
# 编译教程
暂时先参考udp2raw的这篇教程几乎一样的过程。
https://github.com/wangyu-/udp2raw-tunnel/blob/master/doc/build_guide.zh-cn.md

View File

@@ -1,18 +1,21 @@
# UDPspeeder
# UDPspeeder (v1)
![image0](/images/Capture7.PNG)
UDP双边加速工具降低丢包率配合vpn可以加速任何协议尤其适用于加速游戏和网页打开速度同时也是一个UDP连接的调试和统计工具。
这个是我自己稳定用了一个月的项目用来加速美服的Brawl Stars和亚服的Mobile Legend效果不错。加速前卡得几乎没法玩加速后就没怎么卡过了。
目前最新版是v2版这个是v1版的主页
#### 效果
![image0](/images/Capture8.PNG)
#### 原理简介
目前原理是多倍发包。以后会做各种优化比如对高频率的短包先合并再冗余FECForward Error Correction在包速低的时候多倍发包包速高时用FEC。
目前原理是多倍发包。以后会做各种优化比如对高频率的短包先合并再冗余FECForward Error Correction在包速低的时候多倍发包包速高时用FEC(这些功能在v2版里已经实现)
跟net-speeder比优势在于client和server会把收到的多余包自动去掉这个过程对上层透明没有兼容性问题。而且发出的冗余数据包会做长度和内容的随机化抓包是看不出发了冗余数据的所以不用担心vps被封的问题。
每个冗余数据包都是间隔数毫秒可配置以后延迟发出的可以避开中间路由器因为瞬时buffer长度过长而连续丢掉所有副本。
模拟一定的延迟抖动,这样上层应用计算出来的RTT方差会更大以等待后续冗余包的到达不至于发生在冗余包到达之前就触发重传的尴尬。
模拟一定的延迟抖动这样上层应用计算出来的RTT方差会更大以等待后续冗余包的到达不至于发生在冗余包到达之前就触发重传的尴尬。
#### 适用场景
绝大部分流量不高的情况。程序本身加速udp但是配合openvpn可以加速任何流量。网络状况不好时游戏卡得没法玩或者网页卡得没法打开使用起来效果最好。对于解决语音通话的断断续续效果也不错。不适合大流量的场景比如BT下载和在线看视频。 无论从自己使用效果的角度,还是从国际出口带宽占用的角度,都建议不要在大流量环境使用。
@@ -131,20 +134,20 @@ other options:
跟openvpn via kcptun方式的对比
kcptun在udp层有RS code也是一种冗余传输通过openvpn把流量转成tcp再通过kcptun加速是有一定效果的。但是tcp只支持按序到达。按序到达的意思是,如果你发了1 2 3 4 5 6 ,6个包如果第一个包丢了那么必须等第一个包重传成功以后 2 3 4 5 6 才能到达只要有一个包不到后续数据包就要一直等待。用tcp承载udp流量会破坏udp的实时性。会造成游戏卡顿更严重。
kcptun在udp层有RS code也是一种冗余传输通过openvpn把流量转成tcp再通过kcptun加速是有一定效果的。但是tcp只支持按序到达。按序到达的意思是如果你发了1 2 3 4 5 66个包如果第一个包丢了那么必须等第一个包重传成功以后 2 3 4 5 6 才能到达只要有一个包不到后续数据包就要一直等待。用tcp承载udp流量会破坏udp的实时性。会造成游戏卡顿更严重。
udp协议本身是ip协议加上了端口之后的直接封装udp继承了ip协议的实时/乱序到达特性更适合中转vpn。
#### UDPspeeder + kcptun/finalspeed + ss 同时加速tcp和udp流量
#### UDPspeeder + kcptun/finalspeed + $*** 同时加速tcp和udp流量
如果你需要用加速的tcp看视频和下载文件这样效果比vpn方案更好。不论是速度还是流量的耗费上。
![image0](/images/Capture3.PNG)
![image0](/images/cn/speeder_kcptun.PNG)
#### UDPspeeder + openvpn + ss 混合方案
也是我正在用的方案。优点是可以随时在vpn和ss方案间快速切换。
实际部署起来比图中看起来的还要简单。不需要改路由表需要做的只是用openvpn的ip访问ss server。
#### UDPspeeder + openvpn + $*** 混合方案
也是我正在用的方案。优点是可以随时在vpn和$*** 方案间快速切换。
实际部署起来比图中看起来的还要简单。不需要改路由表需要做的只是用openvpn的ip访问$*** server。
![image0](/images/Capture10.PNG)
(也可以把图中的ss server换成其他的socks5 server这样连ss client也不需要了)
![image0](/images/cn/speeder_vpn_s.PNG)
(也可以把图中的$*** server换成其他的socks5 server这样连$*** client也不需要了)
# 编译教程
暂时先参考udp2raw的这篇教程几乎一样的过程。

View File

@@ -1,12 +1,14 @@
# UDPspeeder + openvpn config guide
![image_vpn](/images/en/udpspeeder+openvpn.PNG)
![image_vpn](/images/en/udpspeeder+openvpn3.PNG)
# UDPspeeder command
#### run at server side
```
./speederv2 -s -l0.0.0.0:8855 -r 127.0.0.1:7777 -f20:10
```
#### run at client side
assume server ip is 45.66.77.88
```
@@ -37,7 +39,7 @@ mute 20
comp-lzo no
fragment 1200 ##### very important you can turn it up a bit. but,the lower the safer
fragment 1200 ##### very important you can turn it up a bit. but, the lower the safer
mssfix 1200 ##### very important
sndbuf 2000000 ##### important
@@ -77,10 +79,29 @@ mute 20
comp-lzo no
fragment 1200 ##### very important you can turn it up a bit. but,the lower the safer
fragment 1200 ##### very important you can turn it up a bit. but, the lower the safer
mssfix 1200 ##### very important
sndbuf 2000000 ##### important
rcvbuf 2000000 ##### important
txqueuelen 4000 ##### suggested
```
##### Note:
If you use the `redirect-gateway` option of OpenVPN, you may need to add a route exception for your remote server ip at client side.Otherwise OpenVPN may hijack UDPspeeder 's traffic.
For example, depend on your network environment, the command may looks like:
```
ip route add 44.55.66.77 via 44.55.66.1
```
or
```
ip route add 44.55.66.77 dev XXX
```
(run at client side)
##### Other Info
You can also use tinyFecVPN,a lightweight VPN with build-in FEC support:
https://github.com/wangyu-/tinyFecVPN

View File

@@ -11,6 +11,15 @@
#include "lib/rs.h"
#include "fd_manager.h"
int g_fec_data_num=20;
int g_fec_redundant_num=10;
int g_fec_mtu=1250;
int g_fec_queue_len=200;
int g_fec_timeout=8*1000; //8ms
int g_fec_mode=1;
int dynamic_update_fec=1;
const int encode_fast_send=1;
const int decode_fast_send=1;
@@ -118,6 +127,15 @@ int blob_decode_t::output(int &n,char ** &s_arr,int *&len_arr)
return 0;
}
fec_encode_manager_t::~fec_encode_manager_t()
{
fd_manager.fd64_close(timer_fd64);
}
u64_t fec_encode_manager_t::get_timer_fd64()
{
return timer_fd64;
}
fec_encode_manager_t::fec_encode_manager_t()
{
//int timer_fd;
@@ -128,36 +146,22 @@ fec_encode_manager_t::fec_encode_manager_t()
}
timer_fd64=fd_manager.create(timer_fd);
re_init(4,2,1200,100,10000,0);
seq=(u32_t)get_true_random_number(); //TODO temp solution for a bug.
reset_fec_parameter(g_fec_data_num,g_fec_redundant_num,g_fec_mtu,g_fec_queue_len,g_fec_timeout,g_fec_mode);
}
fec_encode_manager_t::~fec_encode_manager_t()
{
fd_manager.fd64_close(timer_fd64);
}
u64_t fec_encode_manager_t::get_timer_fd64()
{
return timer_fd64;
}
int fec_encode_manager_t::re_init(int data_num,int redundant_num,int mtu,int pending_num,int pending_time,int type)
int fec_encode_manager_t::reset_fec_parameter(int data_num,int redundant_num,int mtu,int queue_len,int timeout,int mode)
{
fec_data_num=data_num;
fec_redundant_num=redundant_num;
fec_mtu=mtu;
fec_pending_num=pending_num;
fec_pending_time=pending_time;
this->type=type;
fec_queue_len=queue_len;
fec_timeout=timeout;
fec_mode=mode;
assert(data_num+redundant_num<max_fec_packet_num);
counter=0;
blob_encode.clear();
ready_for_output=0;
//seq=0;
itimerspec zero_its;
memset(&zero_its, 0, sizeof(zero_its));
timerfd_settime(timer_fd, TFD_TIMER_ABSTIME, &zero_its, 0);
clear();
return 0;
}
@@ -168,20 +172,20 @@ int fec_encode_manager_t::append(char *s,int len/*,int &is_first_packet*/)
itimerspec its;
memset(&its.it_interval,0,sizeof(its.it_interval));
first_packet_time=get_current_time_us();
my_time_t tmp_time=fec_pending_time+first_packet_time;
my_time_t tmp_time=fec_timeout+first_packet_time;
its.it_value.tv_sec=tmp_time/1000000llu;
its.it_value.tv_nsec=(tmp_time%1000000llu)*1000llu;
timerfd_settime(timer_fd,TFD_TIMER_ABSTIME,&its,0);
}
if(type==0)//for type 0 use blob
if(fec_mode==0)//for type 0 use blob
{
assert(blob_encode.input(s,len)==0);
}
else if(type==1)//for tpe 1 use input_buf and counter
else if(fec_mode==1)//for tpe 1 use input_buf and counter
{
mylog(log_trace,"counter=%d\n",counter);
assert(len<=65535&&len>=0);
assert(len<=fec_mtu);
//assert(len<=fec_mtu);//relax this limitation
char * p=input_buf[counter]+sizeof(u32_t)+4*sizeof(char);//copy directly to final position,avoid unnecessary copy.
//remember to change this,if protocol is modified
@@ -199,20 +203,34 @@ int fec_encode_manager_t::append(char *s,int len/*,int &is_first_packet*/)
}
int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
{
if(counter==0&&dynamic_update_fec)
{
fec_data_num=g_fec_data_num;
fec_redundant_num=g_fec_redundant_num;
fec_mtu=g_fec_mtu;
fec_queue_len=g_fec_queue_len;
fec_timeout=g_fec_timeout;
fec_mode=g_fec_mode;
}
int about_to_fec=0;
int delayed_append=0;
//int counter_back=counter;
assert(type==0||type==1);
assert(fec_mode==0||fec_mode==1);
if(type==0&& s!=0 &&counter==0&&blob_encode.get_shard_len(fec_data_num,len)>=fec_mtu)
if(fec_mode==0&& s!=0 &&counter==0)
{
mylog(log_warn,"message too long len=%d,ignored\n",len);
return -1;
int out_len=blob_encode.get_shard_len(fec_data_num,len);
if(out_len>fec_mtu)
{
mylog(log_warn,"message too long ori_len=%d out_len=%d fec_mtu=%d,ignored\n",len,out_len,fec_mtu);
return -1;
}
}
if(type==1&&s!=0&&len>=fec_mtu)
if(fec_mode==1&&s!=0&&len>fec_mtu)
{
mylog(log_warn,"message too long len=%d fec_mtu=%d,ignored\n",len,fec_mtu);
return -1;
mylog(log_warn,"mode==1,message len=%d,len>fec_mtu,fec_mtu=%d,packet may not be delivered\n",len,fec_mtu);
//return -1;
}
if(s==0&&counter==0)
{
@@ -221,10 +239,10 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
}
if(s==0) about_to_fec=1;//now
if(type==0&& blob_encode.get_shard_len(fec_data_num,len)>=fec_mtu) {about_to_fec=1; delayed_append=1;}//fec then add packet
if(fec_mode==0&& blob_encode.get_shard_len(fec_data_num,len)>fec_mtu) {about_to_fec=1; delayed_append=1;}//fec then add packet
if(type==0) assert(counter<fec_pending_num);//counter will never equal fec_pending_num,if that happens fec should already been done.
if(type==1) assert(counter<fec_data_num);
if(fec_mode==0) assert(counter<fec_queue_len);//counter will never equal fec_pending_num,if that happens fec should already been done.
if(fec_mode==1) assert(counter<fec_data_num);
if(s!=0&&!delayed_append)
@@ -232,9 +250,9 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
append(s,len);
}
if(type==0&& counter==fec_pending_num) about_to_fec=1;
if(fec_mode==0&& counter==fec_queue_len) about_to_fec=1;
if(type==1&& counter==fec_data_num) about_to_fec=1;
if(fec_mode==1&& counter==fec_data_num) about_to_fec=1;
if(about_to_fec)
@@ -252,7 +270,7 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
int actual_data_num;
int actual_redundant_num;
if(type==0)
if(fec_mode==0)
{
actual_data_num=fec_data_num;
@@ -264,7 +282,10 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
int best_data_num=fec_data_num;
for(int i=1;i<actual_data_num;i++)
{
u32_t new_len=(blob_encode.get_shard_len(i,0)+header_overhead)*(i+fec_redundant_num);
u32_t shard_len=blob_encode.get_shard_len(i,0);
if(shard_len>(u32_t)fec_mtu) continue;
u32_t new_len=(shard_len+header_overhead)*(i+fec_redundant_num);
if(new_len<best_len)
{
best_len=new_len;
@@ -299,8 +320,8 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
write_u32(input_buf[i] + tmp_idx, seq);
tmp_idx += sizeof(u32_t);
input_buf[i][tmp_idx++] = (unsigned char) type;
if (type == 1 && i < actual_data_num)
input_buf[i][tmp_idx++] = (unsigned char) fec_mode;
if (fec_mode == 1 && i < actual_data_num)
{
input_buf[i][tmp_idx++] = (unsigned char) 0;
input_buf[i][tmp_idx++] = (unsigned char) 0;
@@ -313,7 +334,7 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
tmp_output_buf[i]=input_buf[i]+tmp_idx; //////caution ,trick here.
if(type==0)
if(fec_mode==0)
{
output_len[i]=tmp_idx+fec_len;
if(i<actual_data_num)
@@ -383,7 +404,7 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
memset(&its,0,sizeof(its));
timerfd_settime(timer_fd,TFD_TIMER_ABSTIME,&its,0);
if(encode_fast_send&&type==1)
if(encode_fast_send&&fec_mode==1)
{
int packet_to_send[max_fec_packet_num+5]={0};
int packet_to_send_counter=0;
@@ -407,7 +428,7 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
}
else
{
if(encode_fast_send&&s!=0&&type==1)
if(encode_fast_send&&s!=0&&fec_mode==1)
{
assert(counter>=1);
assert(counter<=255);
@@ -422,7 +443,7 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
write_u32(input_buf[input_buf_idx]+tmp_idx,seq);
tmp_idx+=sizeof(u32_t);
input_buf[input_buf_idx][tmp_idx++]=(unsigned char)type;
input_buf[input_buf_idx][tmp_idx++]=(unsigned char)fec_mode;
input_buf[input_buf_idx][tmp_idx++]=(unsigned char)0;
input_buf[input_buf_idx][tmp_idx++]=(unsigned char)0;
input_buf[input_buf_idx][tmp_idx++]=(unsigned char)((u32_t)input_buf_idx);
@@ -444,7 +465,7 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
if(s!=0&&delayed_append)
{
assert(type!=1);
assert(fec_mode!=1);
append(s,len);
}
@@ -468,15 +489,12 @@ int fec_encode_manager_t::output(int &n,char ** &s_arr,int *&len)
}
return 0;
}
/*
int fec_decode_manager_t::re_init()
{
for(int i=0;i<(int)fec_buff_num;i++)
fec_data[i].used=0;
ready_for_output=0;
index=0;
clear();
return 0;
}
}*/
int fec_decode_manager_t::input(char *s,int len)
{

View File

@@ -19,6 +19,17 @@ const int max_fec_packet_num=255;// this is the limitation of the rs lib
extern u32_t fec_buff_num;
/*begin for first time init or dynamic update*/
extern int g_fec_data_num;
extern int g_fec_redundant_num;
extern int g_fec_mtu;
extern int g_fec_queue_len;
extern int g_fec_timeout; //8ms
extern int g_fec_mode;
extern int dynamic_update_fec;
/*end for first time init or dynamic update*/
struct anti_replay_t
{
@@ -26,10 +37,16 @@ struct anti_replay_t
unordered_set<u32_t> st;
int index;
anti_replay_t()
{
clear();
}
int clear()
{
memset(replay_buffer,-1,sizeof(replay_buffer));
st.clear();
st.rehash(anti_replay_buff_size*3);
index=0;
return 0;
}
void set_invaild(u32_t seq)
{
@@ -98,11 +115,11 @@ class fec_encode_manager_t
private:
u32_t seq;
int type;
int fec_mode;
int fec_data_num,fec_redundant_num;
int fec_mtu;
int fec_pending_num;
int fec_pending_time;
int fec_queue_len;
int fec_timeout;
my_time_t first_packet_time;
my_time_t first_packet_time_for_output;
@@ -129,17 +146,38 @@ public:
fec_encode_manager_t();
~fec_encode_manager_t();
int clear()
{
counter=0;
blob_encode.clear();
ready_for_output=0;
itimerspec zero_its;
memset(&zero_its, 0, sizeof(zero_its));
timerfd_settime(timer_fd, TFD_TIMER_ABSTIME, &zero_its, 0);
seq=(u32_t)get_true_random_number(); //TODO temp solution for a bug.
return 0;
}
my_time_t get_first_packet_time()
{
return first_packet_time_for_output;
}
int get_pending_time()
{
return fec_timeout;
}
int get_type()
{
return type;
return fec_mode;
}
u64_t get_timer_fd64();
int re_init(int data_num,int redundant_num,int mtu,int pending_num,int pending_time,int type);
int reset_fec_parameter(int data_num,int redundant_num,int mtu,int pending_num,int pending_time,int type);
int input(char *s,int len/*,int &is_first_packet*/);
int output(int &n,char ** &s_arr,int *&len);
};
@@ -184,7 +222,7 @@ public:
fec_decode_manager_t()
{
fec_data=new fec_data_t[fec_buff_num+5];
re_init();
clear();
}
fec_decode_manager_t(const fec_decode_manager_t &b)
{
@@ -194,7 +232,21 @@ public:
{
delete fec_data;
}
int re_init();
int clear()
{
anti_replay.clear();
mp.clear();
mp.rehash(fec_buff_num*3);
for(int i=0;i<(int)fec_buff_num;i++)
fec_data[i].used=0;
ready_for_output=0;
index=0;
return 0;
}
//int re_init();
int input(char *s,int len);
int output(int &n,char ** &s_arr,int* &len_arr);
};

1
images/cn/11 Normal file
View File

@@ -0,0 +1 @@

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

BIN
images/cn/scp_compare.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
images/cn/scp_compare2.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
images/cn/speeder_vpn_s.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
images/cn/speedercn.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
images/en/fec.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@@ -51,6 +51,6 @@ void fec_encode(void *code, void *src[], void *dst, int index, int sz) ;
int fec_decode(void *code, void *pkt[], int index[], int sz) ;
int get_k(void *code);
int get_n(void *codev);
int get_n(void *code);
/* end of file */

View File

@@ -51,6 +51,10 @@ void* get_code(int k,int n)
if (table==0)
{
table=(void* (*)[256]) malloc(sizeof(void*)*256*256);
if(!table)
{
return table;
}
memset(table,0,sizeof(void*)*256*256);
}
if(table[k][n]==0)

1629
main.cpp

File diff suppressed because it is too large Load Diff

View File

@@ -8,12 +8,12 @@ cc_arm= /toolchains/arm-2014.05/bin/arm-none-linux-gnueabi-g++
#cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -ggdb
SOURCES=main.cpp log.cpp common.cpp lib/fec.c lib/rs.c packet.cpp delay_manager.cpp fd_manager.cpp connection.cpp fec_manager.cpp
SOURCES=main.cpp log.cpp common.cpp lib/fec.c lib/rs.c packet.cpp delay_manager.cpp fd_manager.cpp connection.cpp fec_manager.cpp misc.cpp tunnel.cpp
NAME=speederv2
TARGETS=amd64 arm mips24kc_be x86 mips24kc_le
TAR=${NAME}_binaries.tar.gz `echo ${TARGETS}|sed -r 's/([^ ]+)/speederv2_\1/g'`
TAR=${NAME}_binaries.tar.gz `echo ${TARGETS}|sed -r 's/([^ ]+)/speederv2_\1/g'` version.txt
all:git_version
rm -f ${NAME}
@@ -56,6 +56,7 @@ cross3:git_version
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -static -O3
release: ${TARGETS}
cp git_version.h version.txt
tar -zcvf ${TAR}
clean:

967
misc.cpp Normal file
View File

@@ -0,0 +1,967 @@
/*
* misc.cpp
*
* Created on: Oct 26, 2017
* Author: root
*/
#include "misc.h"
char fifo_file[1000]="";
int mtu_warn=1350;
int disable_mtu_warn=1;
int disable_fec=0;
int debug_force_flush_fec=0;
int jitter_min=0*1000;
int jitter_max=0*1000;
int output_interval_min=0*1000;
int output_interval_max=0*1000;
int fix_latency=0;
u32_t local_ip_uint32,remote_ip_uint32=0;
char local_ip[100], remote_ip[100];
int local_port = -1, remote_port = -1;
conn_manager_t conn_manager;
delay_manager_t delay_manager;
fd_manager_t fd_manager;
int time_mono_test=0;
int delay_capacity=0;
char sub_net[100]="10.22.22.0";
u32_t sub_net_uint32=0;
char tun_dev[100]="";
int keep_reconnect=0;
int tun_mtu=1500;
int mssfix=1;
int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay)
{
static my_time_t out_delay_buf[max_fec_packet_num+100]={0};
//static int out_len_buf[max_fec_packet_num+100]={0};
//static int counter=0;
out_delay=out_delay_buf;
//out_len=out_len_buf;
inner_stat_t &inner_stat=conn_info.stat.normal_to_fec;
if(disable_fec)
{
if(data==0)
{
out_n=0;
return 0;
}
//assert(data!=0);
inner_stat.input_packet_num++;
inner_stat.input_packet_size+=len;
inner_stat.output_packet_num++;
inner_stat.output_packet_size+=len;
out_n=1;
static char *data_static;
data_static=data;
static int len_static;
len_static=len;
out_arr=&data_static;
out_len=&len_static;
out_delay[0]=0;
}
else
{
if(data!=0)
{
inner_stat.input_packet_num++;
inner_stat.input_packet_size+=len;
}
//counter++;
conn_info.fec_encode_manager.input(data,len);
//if(counter%5==0)
//conn_info.fec_encode_manager.input(0,0);
//int n;
//char **s_arr;
//int s_len;
conn_info.fec_encode_manager.output(out_n,out_arr,out_len);
if(out_n>0)
{
my_time_t common_latency=0;
my_time_t first_packet_time=conn_info.fec_encode_manager.get_first_packet_time();
if(fix_latency==1&&conn_info.fec_encode_manager.get_type()==0)
{
my_time_t current_time=get_current_time_us();
my_time_t tmp;
assert(first_packet_time!=0);
//mylog(log_info,"current_time=%llu first_packlet_time=%llu fec_pending_time=%llu\n",current_time,first_packet_time,(my_time_t)fec_pending_time);
if((my_time_t)conn_info.fec_encode_manager.get_pending_time() >=(current_time - first_packet_time))
{
tmp=(my_time_t)conn_info.fec_encode_manager.get_pending_time()-(current_time - first_packet_time);
//mylog(log_info,"tmp=%llu\n",tmp);
}
else
{
tmp=0;
//mylog(log_info,"0\n");
}
common_latency+=tmp;
}
common_latency+=random_between(jitter_min,jitter_max);
out_delay_buf[0]=common_latency;
for(int i=1;i<out_n;i++)
{
out_delay_buf[i]=out_delay_buf[i-1]+ (my_time_t)( random_between(output_interval_min,output_interval_max)/(out_n-1) );
}
}
}
mylog(log_trace,"from_normal_to_fec input_len=%d,output_n=%d\n",len,out_n);
if(out_n>0)
{
log_bare(log_trace,"seq= %u ",read_u32(out_arr[0]));
}
for(int i=0;i<out_n;i++)
{
inner_stat.output_packet_num++;
inner_stat.output_packet_size+=out_len[i];
log_bare(log_trace,"%d ",out_len[i]);
}
log_bare(log_trace,"\n");
//for(int i=0;i<n;i++)
//{
//delay_send(0,dest,s_arr[i],s_len);
//}
//delay_send(0,dest,data,len);
//delay_send(1000*1000,dest,data,len);
return 0;
}
int from_fec_to_normal(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay)
{
static my_time_t out_delay_buf[max_blob_packet_num+100]={0};
out_delay=out_delay_buf;
inner_stat_t &inner_stat=conn_info.stat.fec_to_normal;
if(disable_fec)
{
assert(data!=0);
inner_stat.input_packet_num++;
inner_stat.input_packet_size+=len;
inner_stat.output_packet_num++;
inner_stat.output_packet_size+=len;
if(data==0)
{
out_n=0;
return 0;
}
out_n=1;
static char *data_static;
data_static=data;
static int len_static;
len_static=len;
out_arr=&data_static;
out_len=&len_static;
out_delay[0]=0;
}
else
{
if(data!=0)
{
inner_stat.input_packet_num++;
inner_stat.input_packet_size+=len;
}
conn_info.fec_decode_manager.input(data,len);
//int n;char ** s_arr;int* len_arr;
conn_info.fec_decode_manager.output(out_n,out_arr,out_len);
for(int i=0;i<out_n;i++)
{
out_delay_buf[i]=0;
inner_stat.output_packet_num++;
inner_stat.output_packet_size+=out_len[i];
}
}
mylog(log_trace,"from_fec_to_normal input_len=%d,output_n=%d,input_seq=%u\n",len,out_n,read_u32(data));
// printf("<n:%d>",n);
/*
for(int i=0;i<n;i++)
{
delay_send(0,dest,s_arr[i],len_arr[i]);
//s_arr[i][len_arr[i]]=0;
//printf("<%s>\n",s_arr[i]);
}*/
//my_send(dest,data,len);
return 0;
}
int delay_send(my_time_t delay,const dest_t &dest,char *data,int len)
{
//int rand=random()%100;
//mylog(log_info,"rand = %d\n",rand);
if (dest.cook&&random_drop != 0) {
if (get_true_random_number() % 10000 < (u32_t) random_drop) {
return 0;
}
}
return delay_manager.add(delay,dest,data,len);;
}
int print_parameter()
{
mylog(log_info,"jitter_min=%d jitter_max=%d output_interval_min=%d output_interval_max=%d fec_timeout=%d fec_data_num=%d fec_redundant_num=%d fec_mtu=%d fec_queue_len=%d fec_mode=%d\n",
jitter_min/1000,jitter_max/1000,output_interval_min/1000,output_interval_max/1000,g_fec_timeout/1000,
g_fec_data_num,g_fec_redundant_num,g_fec_mtu,g_fec_queue_len,g_fec_mode);
return 0;
}
int handle_command(char *s)
{
int len=strlen(s);
while(len>=1&&s[len-1]=='\n')
s[len-1]=0;
mylog(log_info,"got data from fifo,len=%d,s=[%s]\n",len,s);
int a=-1,b=-1;
if(strncmp(s,"fec",strlen("fec"))==0)
{
mylog(log_info,"got command [fec]\n");
sscanf(s,"fec %d:%d",&a,&b);
if(a<1||b<0||a+b>254)
{
mylog(log_warn,"invaild value\n");
return -1;
}
g_fec_data_num=a;
g_fec_redundant_num=b;
}
else if(strncmp(s,"mtu",strlen("mtu"))==0)
{
mylog(log_info,"got command [mtu]\n");
sscanf(s,"mtu %d",&a);
if(a<100||a>2000)
{
mylog(log_warn,"invaild value\n");
return -1;
}
g_fec_mtu=a;
}
else if(strncmp(s,"queue-len",strlen("queue-len"))==0)
{
mylog(log_info,"got command [queue-len]\n");
sscanf(s,"queue-len %d",&a);
if(a<1||a>10000)
{
mylog(log_warn,"invaild value\n");
return -1;
}
g_fec_queue_len=a;
}
else if(strncmp(s,"mode",strlen("mode"))==0)
{
mylog(log_info,"got command [mode]\n");
sscanf(s,"mode %d",&a);
if(a!=0&&a!=1)
{
mylog(log_warn,"invaild value\n");
return -1;
}
g_fec_mode=a;
}
else if(strncmp(s,"timeout",strlen("timeout"))==0)
{
mylog(log_info,"got command [timeout]\n");
sscanf(s,"timeout %d",&a);
if(a<0||a>1000)
{
mylog(log_warn,"invaild value\n");
return -1;
}
g_fec_timeout=a*1000;
}
else
{
mylog(log_info,"unknown command\n");
}
print_parameter();
return 0;
}
int unit_test()
{
int i,j,k;
void *code=fec_new(3,6);
char arr[6][100]=
{
"aaa","bbb","ccc"
,"ddd","eee","fff"
};
char *data[6];
for(i=0;i<6;i++)
{
data[i]=arr[i];
}
rs_encode2(3,6,data,3);
//printf("%d %d",(int)(unsigned char)arr[5][0],(int)('a'^'b'^'c'^'d'^'e'));
for(i=0;i<6;i++)
{
printf("<%s>",data[i]);
}
data[0]=0;
//data[1]=0;
//data[5]=0;
int ret=rs_decode2(3,6,data,3);
printf("ret:%d\n",ret);
for(i=0;i<6;i++)
{
printf("<%s>",data[i]);
}
fec_free(code);
char arr2[6][100]=
{
"aaa11111","","ccc333333333"
,"ddd444","eee5555","ff6666"
};
blob_encode_t blob_encode;
for(int i=0;i<6;i++)
blob_encode.input(arr2[i],strlen(arr2[i]));
char **output;
int shard_len;
blob_encode.output(7,output,shard_len);
printf("<shard_len:%d>",shard_len);
blob_decode_t blob_decode;
for(int i=0;i<7;i++)
{
blob_decode.input(output[i],shard_len);
}
char **decode_output;
int * len_arr;
int num;
ret=blob_decode.output(num,decode_output,len_arr);
printf("<num:%d,ret:%d>\n",num,ret);
for(int i=0;i<num;i++)
{
char buf[1000]={0};
memcpy(buf,decode_output[i],len_arr[i]);
printf("<%d:%s>",len_arr[i],buf);
}
printf("\n");
static fec_encode_manager_t fec_encode_manager;
static fec_decode_manager_t fec_decode_manager;
{
string a = "11111";
string b = "22";
string c = "33333333";
fec_encode_manager.input((char *) a.c_str(), a.length());
fec_encode_manager.input((char *) b.c_str(), b.length());
fec_encode_manager.input((char *) c.c_str(), c.length());
fec_encode_manager.input(0, 0);
int n;
char **s_arr;
int *len;
fec_encode_manager.output(n,s_arr,len);
printf("<n:%d,len:%d>",n,len[0]);
for(int i=0;i<n;i++)
{
fec_decode_manager.input(s_arr[i],len[i]);
}
{
int n;char ** s_arr;int* len_arr;
fec_decode_manager.output(n,s_arr,len_arr);
printf("<n:%d>",n);
for(int i=0;i<n;i++)
{
s_arr[i][len_arr[i]]=0;
printf("<%s>\n",s_arr[i]);
}
}
}
{
string a = "aaaaaaa";
string b = "bbbbbbbbbbbbb";
string c = "ccc";
fec_encode_manager.input((char *) a.c_str(), a.length());
fec_encode_manager.input((char *) b.c_str(), b.length());
fec_encode_manager.input((char *) c.c_str(), c.length());
fec_encode_manager.input(0, 0);
int n;
char **s_arr;
int * len;
fec_encode_manager.output(n,s_arr,len);
printf("<n:%d,len:%d>",n,len[0]);
for(int i=0;i<n;i++)
{
if(i==1||i==3||i==5||i==0)
fec_decode_manager.input(s_arr[i],len[i]);
}
{
int n;char ** s_arr;int* len_arr;
fec_decode_manager.output(n,s_arr,len_arr);
printf("<n:%d>",n);
for(int i=0;i<n;i++)
{
s_arr[i][len_arr[i]]=0;
printf("<%s>\n",s_arr[i]);
}
}
}
for(int i=0;i<10;i++)
{
string a = "aaaaaaaaaaaaaaaaaaaaaaa";
string b = "bbbbbbbbbbbbb";
string c = "cccccccccccccccccc";
printf("======\n");
int n;
char **s_arr;
int * len;
fec_decode_manager.output(n,s_arr,len);
fec_encode_manager.reset_fec_parameter(3,2,g_fec_mtu,g_fec_queue_len,g_fec_timeout,1);
fec_encode_manager.input((char *) a.c_str(), a.length());
fec_encode_manager.output(n,s_arr,len);
assert(n==1);
fec_decode_manager.input(s_arr[0],len[0]);
fec_decode_manager.output(n,s_arr,len);
assert(n==1);
printf("%s\n",s_arr[0]);
fec_encode_manager.input((char *) b.c_str(), b.length());
fec_encode_manager.output(n,s_arr,len);
assert(n==1);
//fec_decode_manager.input(s_arr[0],len[0]);
fec_encode_manager.input((char *) c.c_str(), c.length());
fec_encode_manager.output(n,s_arr,len);
assert(n==3);
fec_decode_manager.input(s_arr[0],len[0]);
//printf("n=%d\n",n);
{
int n;
char **s_arr;
int * len;
fec_decode_manager.output(n,s_arr,len);
assert(n==1);
printf("%s\n",s_arr[0]);
}
fec_decode_manager.input(s_arr[1],len[1]);
{
int n;
char **s_arr;
int * len;
fec_decode_manager.output(n,s_arr,len);
assert(n==1);
printf("n=%d\n",n);
s_arr[0][len[0]]=0;
printf("%s\n",s_arr[0]);
}
}
return 0;
}
void process_arg(int argc, char *argv[])
{
int is_client=0,is_server=0;
int i, j, k;
int opt;
static struct option long_options[] =
{
{"log-level", required_argument, 0, 1},
{"log-position", no_argument, 0, 1},
{"disable-color", no_argument, 0, 1},
{"disable-filter", no_argument, 0, 1},
{"disable-fec", no_argument, 0, 1},
{"disable-obscure", no_argument, 0, 1},
{"disable-xor", no_argument, 0, 1},
{"fix-latency", no_argument, 0, 1},
{"sock-buf", required_argument, 0, 1},
{"random-drop", required_argument, 0, 1},
{"report", required_argument, 0, 1},
{"delay-capacity", required_argument, 0, 1},
{"mtu", required_argument, 0, 1},
{"mode", required_argument, 0,1},
{"timeout", required_argument, 0,1},
{"decode-buf", required_argument, 0,1},
{"queue-len", required_argument, 0,'q'},
{"fec", required_argument, 0,'f'},
{"jitter", required_argument, 0,'j'},
{"fifo", required_argument, 0, 1},
{"sub-net", required_argument, 0, 1},
{"tun-dev", required_argument, 0, 1},
{"tun-mtu", required_argument, 0, 1},
{"disable-mssfix", no_argument, 0, 1},
{"keep-reconnect", no_argument, 0, 1},
{NULL, 0, 0, 0}
};
int option_index = 0;
for (i = 0; i < argc; i++)
{
if(strcmp(argv[i],"--unit-test")==0)
{
unit_test();
myexit(0);
}
}
for (i = 0; i < argc; i++)
{
if(strcmp(argv[i],"--log-level")==0)
{
if(i<argc -1)
{
sscanf(argv[i+1],"%d",&log_level);
if(0<=log_level&&log_level<log_end)
{
}
else
{
log_bare(log_fatal,"invalid log_level\n");
myexit(-1);
}
}
}
if(strcmp(argv[i],"--disable-color")==0)
{
enable_log_color=0;
}
}
mylog(log_info,"argc=%d ", argc);
for (i = 0; i < argc; i++) {
log_bare(log_info, "%s ", argv[i]);
}
log_bare(log_info, "\n");
int no_l = 1, no_r = 1;
while ((opt = getopt_long(argc, argv, "l:r:hcsk:j:f:p:n:i:q:",long_options,&option_index)) != -1)
{
//string opt_key;
//opt_key+=opt;
switch (opt)
{
case 'k':
sscanf(optarg,"%s\n",key_string);
mylog(log_debug,"key=%s\n",key_string);
if(strlen(key_string)==0)
{
mylog(log_fatal,"key len=0??\n");
myexit(-1);
}
break;
case 'j':
if (strchr(optarg, ':') == 0)
{
int jitter;
sscanf(optarg,"%d\n",&jitter);
if(jitter<0 ||jitter>1000*10)
{
mylog(log_fatal,"jitter must be between 0 and 10,000(10 second)\n");
myexit(-1);
}
jitter_min=0;
jitter_max=jitter;
}
else
{
sscanf(optarg,"%d:%d\n",&jitter_min,&jitter_max);
if(jitter_min<0 ||jitter_max<0||jitter_min>jitter_max)
{
mylog(log_fatal," must satisfy 0<=jmin<=jmax\n");
myexit(-1);
}
}
jitter_min*=1000;
jitter_max*=1000;
break;
case 'i':
if (strchr(optarg, ':') == 0)
{
int output_interval=-1;
sscanf(optarg,"%d\n",&output_interval);
if(output_interval<0||output_interval>1000*10)
{
mylog(log_fatal,"output_interval must be between 0 and 10,000(10 second)\n");
myexit(-1);
}
output_interval_min=output_interval_max=output_interval;
}
else
{
sscanf(optarg,"%d:%d\n",&output_interval_min,&output_interval_max);
if(output_interval_min<0 ||output_interval_max<0||output_interval_min>output_interval_max)
{
mylog(log_fatal," must satisfy 0<=output_interval_min<=output_interval_max\n");
myexit(-1);
}
}
output_interval_min*=1000;
output_interval_max*=1000;
break;
case 'f':
if (strchr(optarg, ':') == 0)
{
mylog(log_fatal,"invalid format for f");
myexit(-1);
}
else
{
sscanf(optarg,"%d:%d\n",&g_fec_data_num,&g_fec_redundant_num);
if(g_fec_data_num<1 ||g_fec_redundant_num<0||g_fec_data_num+g_fec_redundant_num>254)
{
mylog(log_fatal,"fec_data_num<1 ||fec_redundant_num<0||fec_data_num+fec_redundant_num>254\n");
myexit(-1);
}
}
break;
case 'q':
sscanf(optarg,"%d",&g_fec_queue_len);
if(g_fec_queue_len<1||g_fec_queue_len>10000)
{
mylog(log_fatal,"fec_pending_num should be between 1 and 10000\n");
myexit(-1);
}
break;
case 'c':
is_client = 1;
break;
case 's':
is_server = 1;
break;
case 'l':
no_l = 0;
if (strchr(optarg, ':') != 0)
{
sscanf(optarg, "%[^:]:%d", local_ip, &local_port);
}
else
{
mylog(log_fatal," -r ip:port\n");
myexit(1);
strcpy(local_ip, "127.0.0.1");
sscanf(optarg, "%d", &local_port);
}
break;
case 'r':
no_r = 0;
if (strchr(optarg, ':') != 0)
{
//printf("in :\n");
//printf("%s\n",optarg);
sscanf(optarg, "%[^:]:%d", remote_ip, &remote_port);
//printf("%d\n",remote_port);
}
else
{
mylog(log_fatal," -r ip:port\n");
myexit(1);
strcpy(remote_ip, "127.0.0.1");
sscanf(optarg, "%d", &remote_port);
}
break;
case 'h':
break;
case 1:
if(strcmp(long_options[option_index].name,"log-level")==0)
{
}
else if(strcmp(long_options[option_index].name,"disable-filter")==0)
{
disable_replay_filter=1;
//enable_log_color=0;
}
else if(strcmp(long_options[option_index].name,"disable-color")==0)
{
//enable_log_color=0;
}
else if(strcmp(long_options[option_index].name,"disable-fec")==0)
{
disable_fec=1;
}
else if(strcmp(long_options[option_index].name,"disable-obscure")==0)
{
mylog(log_info,"obscure disabled\n");
disable_obscure=1;
}
else if(strcmp(long_options[option_index].name,"disable-xor")==0)
{
mylog(log_info,"xor disabled\n");
disable_xor=1;
}
else if(strcmp(long_options[option_index].name,"fix-latency")==0)
{
mylog(log_info,"fix-latency enabled\n");
fix_latency=1;
}
else if(strcmp(long_options[option_index].name,"log-position")==0)
{
enable_log_position=1;
}
else if(strcmp(long_options[option_index].name,"random-drop")==0)
{
sscanf(optarg,"%d",&random_drop);
if(random_drop<0||random_drop>10000)
{
mylog(log_fatal,"random_drop must be between 0 10000 \n");
myexit(-1);
}
mylog(log_info,"random_drop=%d\n",random_drop);
}
else if(strcmp(long_options[option_index].name,"delay-capacity")==0)
{
sscanf(optarg,"%d",&delay_capacity);
if(delay_capacity<0)
{
mylog(log_fatal,"delay_capacity must be >=0 \n");
myexit(-1);
}
}
else if(strcmp(long_options[option_index].name,"report")==0)
{
sscanf(optarg,"%d",&report_interval);
if(report_interval<=0)
{
mylog(log_fatal,"report_interval must be >0 \n");
myexit(-1);
}
}
else if(strcmp(long_options[option_index].name,"sock-buf")==0)
{
int tmp=-1;
sscanf(optarg,"%d",&tmp);
if(10<=tmp&&tmp<=10*1024)
{
socket_buf_size=tmp*1024;
}
else
{
mylog(log_fatal,"sock-buf value must be between 1 and 10240 (kbyte) \n");
myexit(-1);
}
}
else if(strcmp(long_options[option_index].name,"decode-buf")==0)
{
sscanf(optarg,"%d",&fec_buff_num);
if(fec_buff_num<300 || fec_buff_num>20000)
{
mylog(log_fatal,"decode-buf value must be between 300 and 20000 (kbyte) \n");
myexit(-1);
}
mylog(log_info,"decode-buf=%d\n",fec_buff_num);
}
else if(strcmp(long_options[option_index].name,"mode")==0)
{
sscanf(optarg,"%d",&g_fec_mode);
if(g_fec_mode!=0&&g_fec_mode!=1)
{
mylog(log_fatal,"mode should be 0 or 1\n");
myexit(-1);
}
}
else if(strcmp(long_options[option_index].name,"mtu")==0)
{
sscanf(optarg,"%d",&g_fec_mtu);
if(g_fec_mtu<100||g_fec_mtu>2000)
{
mylog(log_fatal,"fec_mtu should be between 100 and 2000\n");
myexit(-1);
}
}
else if(strcmp(long_options[option_index].name,"timeout")==0)
{
sscanf(optarg,"%d",&g_fec_timeout);
if(g_fec_timeout<0||g_fec_timeout>1000)
{
mylog(log_fatal,"fec_pending_time should be between 0 and 1000(1s)\n");
myexit(-1);
}
g_fec_timeout*=1000;
}
else if(strcmp(long_options[option_index].name,"fifo")==0)
{
sscanf(optarg,"%s",fifo_file);
mylog(log_info,"fifo_file =%s \n",fifo_file);
}
else if(strcmp(long_options[option_index].name,"keep-reconnect")==0)
{
keep_reconnect=1;
mylog(log_info,"keep_reconnect enabled\n");
}
else if(strcmp(long_options[option_index].name,"sub-net")==0)
{
sscanf(optarg,"%s",sub_net);
mylog(log_info,"sub_net %s\n",sub_net);
}
else if(strcmp(long_options[option_index].name,"tun-dev")==0)
{
sscanf(optarg,"%s",tun_dev);
mylog(log_info,"tun_dev=%s\n",tun_dev);
mylog(log_info,"running at tun-dev mode\n");
working_mode=tun_dev_mode;
}
else if(strcmp(long_options[option_index].name,"tun-mtu")==0)
{
sscanf(optarg,"%d",&tun_mtu);
mylog(log_warn,"changed tun_mtu,tun_mtu=%d\n",tun_mtu);
}
else if(strcmp(long_options[option_index].name,"disable-mssfix")==0)
{
mssfix=0;
mylog(log_warn,"mssfix disabled\n");
}
else
{
mylog(log_fatal,"unknown option\n");
myexit(-1);
}
break;
default:
mylog(log_fatal,"unknown option <%x>", opt);
myexit(-1);
}
}
if (is_client == 0 && is_server == 0)
{
mylog(log_fatal,"-s -c hasnt been set\n");
myexit(-1);
}
if (is_client == 1 && is_server == 1)
{
mylog(log_fatal,"-s -c cant be both set\n");
myexit(-1);
}
if(is_client==1)
{
client_or_server=client_mode;
}
else
{
client_or_server=server_mode;
}
if(working_mode==tunnel_mode)
{
if (no_l)
mylog(log_fatal,"error: -l not found\n");
if (no_r)
mylog(log_fatal,"error: -r not found\n");
if (no_l || no_r)
myexit(-1);
}
else if(working_mode==tun_dev_mode)
{
if(client_or_server==client_mode&&no_r)
{
mylog(log_fatal,"error: -r not found\n");
myexit(-1);
}
else if(client_or_server==server_mode&&no_l)
{
mylog(log_fatal,"error: -l not found\n");
myexit(-1);
}
}
print_parameter();
}

73
misc.h Normal file
View File

@@ -0,0 +1,73 @@
/*
* misc.h
*
* Created on: Oct 26, 2017
* Author: root
*/
#ifndef MISC_H_
#define MISC_H_
#include "common.h"
#include "connection.h"
#include "fd_manager.h"
#include "delay_manager.h"
#include "fec_manager.h"
extern char fifo_file[1000];
extern int mtu_warn;
extern int disable_mtu_warn;
extern int disable_fec;
extern int debug_force_flush_fec;
extern int jitter_min;
extern int jitter_max;
extern int output_interval_min;
extern int output_interval_max;
extern int fix_latency;
extern u32_t local_ip_uint32,remote_ip_uint32;
extern char local_ip[100], remote_ip[100];
extern int local_port, remote_port;
extern conn_manager_t conn_manager;
extern delay_manager_t delay_manager;
extern fd_manager_t fd_manager;
extern int time_mono_test;
extern int delay_capacity;
extern int keep_reconnect;
extern int tun_mtu;
extern int mssfix;
int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay);
int from_fec_to_normal(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay);
int delay_send(my_time_t delay,const dest_t &dest,char *data,int len);
int print_parameter();
int handle_command(char *s);
int unit_test();
//void print_help();
void process_arg(int argc, char *argv[]);
extern char sub_net[100];
extern u32_t sub_net_uint32;
extern char tun_dev[100];
#endif /* MISC_H_ */

View File

@@ -27,7 +27,7 @@ int random_drop=0;
char key_string[1000]= "";
int local_listen_fd=-1;
//int local_listen_fd=-1;
void encrypt_0(char * input,int &len,char *key)
@@ -162,10 +162,11 @@ int sendto_fd_ip_port (int fd,u32_t ip,int port,char * buf, int len,int flags)
(struct sockaddr *) &tmp_sockaddr,
sizeof(tmp_sockaddr));
}
/*
int sendto_ip_port (u32_t ip,int port,char * buf, int len,int flags)
{
return sendto_fd_ip_port(local_listen_fd,ip,port,buf,len,flags);
}
}*/
int send_fd (int fd,char * buf, int len,int flags)
{
@@ -176,23 +177,31 @@ int my_send(const dest_t &dest,char *data,int len)
{
if(dest.cook)
{
put_crc32(data,len);
if(!disable_obscure)do_obscure(data,len);
if(!disable_xor)encrypt_0(data,len,key_string);
do_cook(data,len);
}
switch(dest.type)
{
case type_ip_port:
case type_fd_ip_port:
{
return sendto_ip_port(dest.inner.ip_port.ip,dest.inner.ip_port.port,data,len,0);
return sendto_fd_ip_port(dest.inner.fd,dest.inner.fd_ip_port.ip_port.ip,dest.inner.fd_ip_port.ip_port.port,data,len,0);
break;
}
case type_ip_port_conv:
case type_fd64_ip_port:
{
char *new_data;
int new_len;
put_conv(dest.conv,data,len,new_data,new_len);
return sendto_ip_port(dest.inner.ip_port.ip,dest.inner.ip_port.port,new_data,new_len,0);
if(!fd_manager.exist(dest.inner.fd64)) return -1;
int fd=fd_manager.to_fd(dest.inner.fd64);
return sendto_fd_ip_port(fd,dest.inner.fd64_ip_port.ip_port.ip,dest.inner.fd64_ip_port.ip_port.port,data,len,0);
break;
}
case type_fd:
{
return send_fd(dest.inner.fd,data,len,0);
break;
}
case type_write_fd:
{
return write(dest.inner.fd,data,len);
break;
}
case type_fd64:
@@ -200,9 +209,25 @@ int my_send(const dest_t &dest,char *data,int len)
if(!fd_manager.exist(dest.inner.fd64)) return -1;
int fd=fd_manager.to_fd(dest.inner.fd64);
return send_fd(fd,data,len,0);
break;
}
/*
case type_fd64_ip_port_conv:
{
if(!fd_manager.exist(dest.inner.fd64)) return -1;
int fd=fd_manager.to_fd(dest.inner.fd64);
char *new_data;
int new_len;
put_conv(dest.conv,data,len,new_data,new_len);
return sendto_fd_ip_port(fd,dest.inner.fd64_ip_port.ip_port.ip,dest.inner.fd64_ip_port.ip_port.port,new_data,new_len,0);
break;
}*/
/*
case type_fd64_conv:
{
char *new_data;
@@ -212,7 +237,7 @@ int my_send(const dest_t &dest,char *data,int len)
if(!fd_manager.exist(dest.inner.fd64)) return -1;
int fd=fd_manager.to_fd(dest.inner.fd64);
return send_fd(fd,new_data,new_len,0);
}
}*/
/*
case type_fd:
{
@@ -300,6 +325,14 @@ int put_crc32(char * s,int &len)
return 0;
}
int do_cook(char * data,int &len)
{
put_crc32(data,len);
if(!disable_obscure)do_obscure(data,len);
if(!disable_xor)encrypt_0(data,len,key_string);
return 0;
}
int de_cook(char * s,int &len)
{
if(!disable_xor)decrypt_0(s,len,key_string);
@@ -362,3 +395,6 @@ int get_conv(u32_t &conv,const char *input,int len_in,char *&output,int &len_out
}
return 0;
}

View File

@@ -21,7 +21,6 @@ extern u64_t dup_packet_recv_count;
extern char key_string[1000];
extern int disable_replay_filter;
extern int random_drop;
extern int local_listen_fd;
extern int disable_obscure;
extern int disable_xor;
@@ -43,5 +42,6 @@ int put_conv(u32_t conv,const char * input,int len_in,char *&output,int &len_out
int get_conv(u32_t &conv,const char *input,int len_in,char *&output,int &len_out );
int put_crc32(char * s,int &len);
int rm_crc32(char * s,int &len);
int do_cook(char * data,int &len);
int de_cook(char * s,int &len);
#endif /* PACKET_H_ */

705
tunnel.cpp Normal file
View File

@@ -0,0 +1,705 @@
/*
* tunnel.cpp
*
* Created on: Oct 26, 2017
* Author: root
*/
#include "tunnel.h"
int tunnel_client_event_loop()
{
//char buf[buf_len];
int i, j, k;int ret;
int yes = 1;
int epoll_fd;
int remote_fd;
fd64_t remote_fd64;
conn_info_t *conn_info_p=new conn_info_t;
conn_info_t &conn_info=*conn_info_p; //huge size of conn_info,do not allocate on stack
//conn_info.conv_manager.reserve();
//conn_info.fec_encode_manager.re_init(fec_data_num,fec_redundant_num,fec_mtu,fec_pending_num,fec_pending_time,fec_type);
int local_listen_fd;
//fd64_t local_listen_fd64;
new_listen_socket(local_listen_fd,local_ip_uint32,local_port);
//local_listen_fd64=fd_manager.create(local_listen_fd);
epoll_fd = epoll_create1(0);
assert(epoll_fd>0);
const int max_events = 4096;
struct epoll_event ev, events[max_events];
if (epoll_fd < 0) {
mylog(log_fatal,"epoll return %d\n", epoll_fd);
myexit(-1);
}
ev.events = EPOLLIN;
ev.data.u64 = local_listen_fd;
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, local_listen_fd, &ev);
if (ret!=0) {
mylog(log_fatal,"add udp_listen_fd error\n");
myexit(-1);
}
assert(new_connected_socket(remote_fd,remote_ip_uint32,remote_port)==0);
remote_fd64=fd_manager.create(remote_fd);
mylog(log_debug,"remote_fd64=%llu\n",remote_fd64);
ev.events = EPOLLIN;
ev.data.u64 = remote_fd64;
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, remote_fd, &ev);
if (ret!= 0) {
mylog(log_fatal,"add raw_fd error\n");
myexit(-1);
}
ev.events = EPOLLIN;
ev.data.u64 = delay_manager.get_timer_fd();
mylog(log_debug,"delay_manager.get_timer_fd()=%d\n",delay_manager.get_timer_fd());
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, delay_manager.get_timer_fd(), &ev);
if (ret!= 0) {
mylog(log_fatal,"add delay_manager.get_timer_fd() error\n");
myexit(-1);
}
u64_t tmp_fd64=conn_info.fec_encode_manager.get_timer_fd64();
ev.events = EPOLLIN;
ev.data.u64 = tmp_fd64;
mylog(log_debug,"conn_info.fec_encode_manager.get_timer_fd64()=%llu\n",conn_info.fec_encode_manager.get_timer_fd64());
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd_manager.to_fd(tmp_fd64), &ev);
if (ret!= 0) {
mylog(log_fatal,"add fec_encode_manager.get_timer_fd64() error\n");
myexit(-1);
}
//my_timer_t timer;
conn_info.timer.add_fd_to_epoll(epoll_fd);
conn_info.timer.set_timer_repeat_us(timer_interval*1000);
mylog(log_debug,"conn_info.timer.get_timer_fd()=%d\n",conn_info.timer.get_timer_fd());
int fifo_fd=-1;
if(fifo_file[0]!=0)
{
fifo_fd=create_fifo(fifo_file);
ev.events = EPOLLIN;
ev.data.u64 = fifo_fd;
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fifo_fd, &ev);
if (ret!= 0) {
mylog(log_fatal,"add fifo_fd to epoll error %s\n",strerror(errno));
myexit(-1);
}
mylog(log_info,"fifo_file=%s\n",fifo_file);
}
while(1)////////////////////////
{
if(about_to_exit) myexit(0);
int nfds = epoll_wait(epoll_fd, events, max_events, 180 * 1000);
if (nfds < 0) { //allow zero
if(errno==EINTR )
{
mylog(log_info,"epoll interrupted by signal\n");
myexit(0);
}
else
{
mylog(log_fatal,"epoll_wait return %d\n", nfds);
myexit(-1);
}
}
int idx;
for (idx = 0; idx < nfds; ++idx) {
if(events[idx].data.u64==(u64_t)conn_info.timer.get_timer_fd())
{
uint64_t value;
read(conn_info.timer.get_timer_fd(), &value, 8);
conn_info.conv_manager.clear_inactive();
mylog(log_trace,"events[idx].data.u64==(u64_t)conn_info.timer.get_timer_fd()\n");
conn_info.stat.report_as_client();
if(debug_force_flush_fec)
{
int out_n;char **out_arr;int *out_len;my_time_t *out_delay;
dest_t dest;
dest.type=type_fd64;
dest.inner.fd64=remote_fd64;
dest.cook=1;
from_normal_to_fec(conn_info,0,0,out_n,out_arr,out_len,out_delay);
for(int i=0;i<out_n;i++)
{
delay_send(out_delay[i],dest,out_arr[i],out_len[i]);
}
}
}
else if (events[idx].data.u64 == (u64_t)fifo_fd)
{
char buf[buf_len];
int len=read (fifo_fd, buf, sizeof (buf));
if(len<0)
{
mylog(log_warn,"fifo read failed len=%d,errno=%s\n",len,strerror(errno));
continue;
}
buf[len]=0;
handle_command(buf);
}
else if (events[idx].data.u64 == (u64_t)local_listen_fd||events[idx].data.u64 == conn_info.fec_encode_manager.get_timer_fd64())
{
char data[buf_len];
int data_len;
ip_port_t ip_port;
u32_t conv;
int out_n;char **out_arr;int *out_len;my_time_t *out_delay;
dest_t dest;
dest.type=type_fd64;
dest.inner.fd64=remote_fd64;
dest.cook=1;
if(events[idx].data.u64 == conn_info.fec_encode_manager.get_timer_fd64())
{
fd64_t fd64=events[idx].data.u64;
mylog(log_trace,"events[idx].data.u64 == conn_info.fec_encode_manager.get_timer_fd64()\n");
//mylog(log_info,"timer!!!\n");
uint64_t value;
if(!fd_manager.exist(fd64)) //fd64 has been closed
{
mylog(log_trace,"!fd_manager.exist(fd64)");
continue;
}
if((ret=read(fd_manager.to_fd(fd64), &value, 8))!=8)
{
mylog(log_trace,"(ret=read(fd_manager.to_fd(fd64), &value, 8))!=8,ret=%d\n",ret);
continue;
}
if(value==0)
{
mylog(log_debug,"value==0\n");
continue;
}
assert(value==1);
from_normal_to_fec(conn_info,0,0,out_n,out_arr,out_len,out_delay);
//from_normal_to_fec(conn_info,0,0,out_n,out_arr,out_len,out_delay);
}
else//events[idx].data.u64 == (u64_t)local_listen_fd
{
mylog(log_trace,"events[idx].data.u64 == (u64_t)local_listen_fd\n");
struct sockaddr_in udp_new_addr_in={0};
socklen_t udp_new_addr_len = sizeof(sockaddr_in);
if ((data_len = recvfrom(local_listen_fd, data, max_data_len, 0,
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) == -1) {
mylog(log_error,"recv_from error,this shouldnt happen,err=%s,but we can try to continue\n",strerror(errno));
continue;
//mylog(log_error,"recv_from error,this shouldnt happen at client\n");
//myexit(1);
};
if(!disable_mtu_warn&&data_len>=mtu_warn)
{
mylog(log_warn,"huge packet,data len=%d (>=%d).strongly suggested to set a smaller mtu at upper level,to get rid of this warn\n ",data_len,mtu_warn);
}
mylog(log_trace,"Received packet from %s:%d,len: %d\n", inet_ntoa(udp_new_addr_in.sin_addr),
ntohs(udp_new_addr_in.sin_port),data_len);
ip_port.ip=udp_new_addr_in.sin_addr.s_addr;
ip_port.port=ntohs(udp_new_addr_in.sin_port);
u64_t u64=ip_port.to_u64();
if(!conn_info.conv_manager.is_u64_used(u64))
{
if(conn_info.conv_manager.get_size() >=max_conv_num)
{
mylog(log_warn,"ignored new udp connect bc max_conv_num exceed\n");
continue;
}
conv=conn_info.conv_manager.get_new_conv();
conn_info.conv_manager.insert_conv(conv,u64);
mylog(log_info,"new packet from %s:%d,conv_id=%x\n",inet_ntoa(udp_new_addr_in.sin_addr),ntohs(udp_new_addr_in.sin_port),conv);
}
else
{
conv=conn_info.conv_manager.find_conv_by_u64(u64);
mylog(log_trace,"conv=%d\n",conv);
}
conn_info.conv_manager.update_active_time(conv);
char * new_data;
int new_len;
put_conv(conv,data,data_len,new_data,new_len);
mylog(log_trace,"data_len=%d new_len=%d\n",data_len,new_len);
//dest.conv=conv;
from_normal_to_fec(conn_info,new_data,new_len,out_n,out_arr,out_len,out_delay);
}
mylog(log_trace,"out_n=%d\n",out_n);
for(int i=0;i<out_n;i++)
{
delay_send(out_delay[i],dest,out_arr[i],out_len[i]);
}
//my_send(dest,data,data_len);
}
else if (events[idx].data.u64 == (u64_t)delay_manager.get_timer_fd()) {
uint64_t value;
read(delay_manager.get_timer_fd(), &value, 8);
mylog(log_trace,"events[idx].data.u64 == (u64_t)delay_manager.get_timer_fd()\n");
//printf("<timerfd_triggered, %d>",delay_mp.size());
//fflush(stdout);
}
else if(events[idx].data.u64>u32_t(-1) )
{
char data[buf_len];
if(!fd_manager.exist(events[idx].data.u64)) //fd64 has been closed
{
mylog(log_trace,"!fd_manager.exist(events[idx].data.u64)");
continue;
}
assert(events[idx].data.u64==remote_fd64);
int fd=fd_manager.to_fd(remote_fd64);
int data_len =recv(fd,data,max_data_len,0);
mylog(log_trace, "received data from udp fd %d, len=%d\n", remote_fd,data_len);
if(data_len<0)
{
if(errno==ECONNREFUSED)
{
//conn_manager.clear_list.push_back(udp_fd);
mylog(log_debug, "recv failed %d ,udp_fd%d,errno:%s\n", data_len,remote_fd,strerror(errno));
}
mylog(log_warn, "recv failed %d ,udp_fd%d,errno:%s\n", data_len,remote_fd,strerror(errno));
continue;
}
if(!disable_mtu_warn&&data_len>mtu_warn)
{
mylog(log_warn,"huge packet,data len=%d (>%d).strongly suggested to set a smaller mtu at upper level,to get rid of this warn\n ",data_len,mtu_warn);
}
if(de_cook(data,data_len)!=0)
{
mylog(log_debug,"de_cook error");
continue;
}
int out_n;char **out_arr;int *out_len;my_time_t *out_delay;
from_fec_to_normal(conn_info,data,data_len,out_n,out_arr,out_len,out_delay);
mylog(log_trace,"out_n=%d\n",out_n);
for(int i=0;i<out_n;i++)
{
u32_t conv;
char *new_data;
int new_len;
if(get_conv(conv,out_arr[i],out_len[i],new_data,new_len)!=0)
{
mylog(log_debug,"get_conv(conv,out_arr[i],out_len[i],new_data,new_len)!=0");
continue;
}
if(!conn_info.conv_manager.is_conv_used(conv))
{
mylog(log_trace,"!conn_info.conv_manager.is_conv_used(conv)");
continue;
}
conn_info.conv_manager.update_active_time(conv);
u64_t u64=conn_info.conv_manager.find_u64_by_conv(conv);
dest_t dest;
dest.inner.fd_ip_port.fd=local_listen_fd;
dest.inner.fd_ip_port.ip_port.from_u64(u64);
dest.type=type_fd_ip_port;
//dest.conv=conv;
delay_send(out_delay[i],dest,new_data,new_len);
}
//mylog(log_trace,"[%s] send packet\n",dest.inner.ip_port.to_s());
}
else
{
mylog(log_fatal,"unknown fd,this should never happen\n");
myexit(-1);
}
}
delay_manager.check();
}
return 0;
}
int tunnel_server_event_loop()
{
//char buf[buf_len];
int i, j, k;int ret;
int yes = 1;
int epoll_fd;
int remote_fd;
// conn_info_t conn_info;
int local_listen_fd;
// fd64_t local_listen_fd64;
new_listen_socket(local_listen_fd,local_ip_uint32,local_port);
// local_listen_fd64=fd_manager.create(local_listen_fd);
epoll_fd = epoll_create1(0);
assert(epoll_fd>0);
const int max_events = 4096;
struct epoll_event ev, events[max_events];
if (epoll_fd < 0) {
mylog(log_fatal,"epoll return %d\n", epoll_fd);
myexit(-1);
}
ev.events = EPOLLIN;
ev.data.u64 = local_listen_fd;
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, local_listen_fd, &ev);
if (ret!=0) {
mylog(log_fatal,"add udp_listen_fd error\n");
myexit(-1);
}
ev.events = EPOLLIN;
ev.data.u64 = delay_manager.get_timer_fd();
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, delay_manager.get_timer_fd(), &ev);
if (ret!= 0) {
mylog(log_fatal,"add delay_manager.get_timer_fd() error\n");
myexit(-1);
}
mylog(log_debug," delay_manager.get_timer_fd() =%d\n", delay_manager.get_timer_fd());
mylog(log_info,"now listening at %s:%d\n",my_ntoa(local_ip_uint32),local_port);
my_timer_t timer;
timer.add_fd_to_epoll(epoll_fd);
timer.set_timer_repeat_us(timer_interval*1000);
mylog(log_debug," timer.get_timer_fd() =%d\n",timer.get_timer_fd());
int fifo_fd=-1;
if(fifo_file[0]!=0)
{
fifo_fd=create_fifo(fifo_file);
ev.events = EPOLLIN;
ev.data.u64 = fifo_fd;
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fifo_fd, &ev);
if (ret!= 0) {
mylog(log_fatal,"add fifo_fd to epoll error %s\n",strerror(errno));
myexit(-1);
}
mylog(log_info,"fifo_file=%s\n",fifo_file);
}
while(1)////////////////////////
{
if(about_to_exit) myexit(0);
int nfds = epoll_wait(epoll_fd, events, max_events, 180 * 1000);
if (nfds < 0) { //allow zero
if(errno==EINTR )
{
mylog(log_info,"epoll interrupted by signal\n");
myexit(0);
}
else
{
mylog(log_fatal,"epoll_wait return %d\n", nfds);
myexit(-1);
}
}
int idx;
for (idx = 0; idx < nfds; ++idx)
{
/*
if ((events[idx].data.u64 ) == (u64_t)timer_fd)
{
conn_manager.clear_inactive();
u64_t dummy;
read(timer_fd, &dummy, 8);
//current_time_rough=get_current_time();
}
else */
if(events[idx].data.u64==(u64_t)timer.get_timer_fd())
{
uint64_t value;
read(timer.get_timer_fd(), &value, 8);
conn_manager.clear_inactive();
mylog(log_trace,"events[idx].data.u64==(u64_t)timer.get_timer_fd()\n");
//conn_info.conv_manager.clear_inactive();
}
else if (events[idx].data.u64 == (u64_t)fifo_fd)
{
char buf[buf_len];
int len=read (fifo_fd, buf, sizeof (buf));
if(len<0)
{
mylog(log_warn,"fifo read failed len=%d,errno=%s\n",len,strerror(errno));
continue;
}
buf[len]=0;
handle_command(buf);
}
else if (events[idx].data.u64 == (u64_t)local_listen_fd)
{
mylog(log_trace,"events[idx].data.u64 == (u64_t)local_listen_fd\n");
//int recv_len;
char data[buf_len];
int data_len;
struct sockaddr_in udp_new_addr_in={0};
socklen_t udp_new_addr_len = sizeof(sockaddr_in);
if ((data_len = recvfrom(local_listen_fd, data, max_data_len, 0,
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) == -1) {
mylog(log_error,"recv_from error,this shouldnt happen,err=%s,but we can try to continue\n",strerror(errno));
continue;
//myexit(1);
};
mylog(log_trace,"Received packet from %s:%d,len: %d\n", inet_ntoa(udp_new_addr_in.sin_addr),
ntohs(udp_new_addr_in.sin_port),data_len);
if(!disable_mtu_warn&&data_len>=mtu_warn)///////////////////////delete this for type 0 in furture
{
mylog(log_warn,"huge packet,data len=%d (>=%d).strongly suggested to set a smaller mtu at upper level,to get rid of this warn\n ",data_len,mtu_warn);
}
if(de_cook(data,data_len)!=0)
{
mylog(log_debug,"de_cook error");
continue;
}
ip_port_t ip_port;
ip_port.ip=udp_new_addr_in.sin_addr.s_addr;
ip_port.port=ntohs(udp_new_addr_in.sin_port);
mylog(log_trace,"ip_port= %s\n",ip_port.to_s());
if(!conn_manager.exist(ip_port))
{
if(conn_manager.mp.size() >=max_conn_num)
{
mylog(log_warn,"new connection %s ignored bc max_conn_num exceed\n",ip_port.to_s());
continue;
}
conn_manager.insert(ip_port);
conn_info_t &conn_info=conn_manager.find(ip_port);
//conn_info.fec_encode_manager.re_init(fec_data_num,fec_redundant_num,fec_mtu,fec_pending_num,fec_pending_time,fec_type);
//conn_info.conv_manager.reserve(); //already reserved in constructor
u64_t fec_fd64=conn_info.fec_encode_manager.get_timer_fd64();
mylog(log_debug,"fec_fd64=%llu\n",fec_fd64);
ev.events = EPOLLIN;
ev.data.u64 = fec_fd64;
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd_manager.to_fd(fec_fd64), &ev);
fd_manager.get_info(fec_fd64).ip_port=ip_port;
conn_info.timer.add_fd64_to_epoll(epoll_fd);
conn_info.timer.set_timer_repeat_us(timer_interval*1000);
mylog(log_debug,"conn_info.timer.get_timer_fd64()=%llu\n",conn_info.timer.get_timer_fd64());
u64_t timer_fd64=conn_info.timer.get_timer_fd64();
fd_manager.get_info(timer_fd64).ip_port=ip_port;
mylog(log_info,"new connection from %s\n",ip_port.to_s());
}
conn_info_t &conn_info=conn_manager.find(ip_port);
conn_info.update_active_time();
int out_n;char **out_arr;int *out_len;my_time_t *out_delay;
from_fec_to_normal(conn_info,data,data_len,out_n,out_arr,out_len,out_delay);
mylog(log_trace,"out_n= %d\n",out_n);
for(int i=0;i<out_n;i++)
{
u32_t conv;
char *new_data;
int new_len;
if(get_conv(conv,out_arr[i],out_len[i],new_data,new_len)!=0)
{
mylog(log_debug,"get_conv failed");
continue;
}
/*
id_t tmp_conv_id;
memcpy(&tmp_conv_id,&data_[0],sizeof(tmp_conv_id));
tmp_conv_id=ntohl(tmp_conv_id);*/
if (!conn_info.conv_manager.is_conv_used(conv))
{
if(conn_info.conv_manager.get_size() >=max_conv_num)
{
mylog(log_warn,"ignored new udp connect bc max_conv_num exceed\n");
continue;
}
int new_udp_fd;
ret=new_connected_socket(new_udp_fd,remote_ip_uint32,remote_port);
if (ret != 0) {
mylog(log_warn, "[%s]new_connected_socket failed\n",ip_port.to_s());
continue;
}
fd64_t fd64 = fd_manager.create(new_udp_fd);
ev.events = EPOLLIN;
ev.data.u64 = fd64;
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, new_udp_fd, &ev);
conn_info.conv_manager.insert_conv(conv, fd64);
fd_manager.get_info(fd64).ip_port=ip_port;
mylog(log_info,"[%s]new conv %x,fd %d created,fd64=%llu\n",ip_port.to_s(),conv,new_udp_fd,fd64);
//assert(!conn_manager.exist_fd64(fd64));
//conn_manager.insert_fd64(fd64,ip_port);
}
conn_info.conv_manager.update_active_time(conv);
fd64_t fd64= conn_info.conv_manager.find_u64_by_conv(conv);
//int fd=fd_manager.fd64_to_fd(fd64);
dest_t dest;
dest.type=type_fd64;
dest.inner.fd64=fd64;
//dest.conv=conv;
delay_send(out_delay[i],dest,new_data,new_len);
}
}
else if (events[idx].data.u64 == (u64_t)delay_manager.get_timer_fd()) {
uint64_t value;
read(delay_manager.get_timer_fd(), &value, 8);
mylog(log_trace,"events[idx].data.u64 == (u64_t)delay_manager.get_timer_fd()\n");
}
else if (events[idx].data.u64 >u32_t(-1))
{
char data[buf_len];
int data_len;
u32_t conv;
fd64_t fd64=events[idx].data.u64;
mylog(log_trace,"events[idx].data.u64 >u32_t(-1),%llu\n",(u64_t)events[idx].data.u64);
if(!fd_manager.exist(fd64)) //fd64 has been closed
{
mylog(log_trace,"!fd_manager.exist(fd64)\n");
continue;
}
assert(fd_manager.exist_info(fd64));
ip_port_t ip_port=fd_manager.get_info(fd64).ip_port;
assert(conn_manager.exist(ip_port));
conn_info_t &conn_info=conn_manager.find(ip_port);
//conn_info.update_active_time(); //cant put it here
int out_n=-2;char **out_arr;int *out_len;my_time_t *out_delay;
dest_t dest;
dest.inner.fd_ip_port.fd=local_listen_fd;
dest.inner.fd_ip_port.ip_port=ip_port;
dest.type=type_fd_ip_port;
dest.cook=1;
if(fd64==conn_info.fec_encode_manager.get_timer_fd64())
{
//mylog(log_infol,"timer!!!\n");
uint64_t value;
if((ret=read(fd_manager.to_fd(fd64), &value, 8))!=8)
{
mylog(log_trace,"fd_manager.to_fd(fd64), &value, 8)!=8 ,%d\n",ret);
continue;
}
if(value==0)
{
mylog(log_trace,"value==0\n");
continue;
}
assert(value==1);
from_normal_to_fec(conn_info,0,0,out_n,out_arr,out_len,out_delay);
}
else if(fd64==conn_info.timer.get_timer_fd64())
{
uint64_t value;
read(conn_info.timer.get_timer_fd(), &value, 8);
conn_info.conv_manager.clear_inactive();
if(debug_force_flush_fec)
{
from_normal_to_fec(conn_info,0,0,out_n,out_arr,out_len,out_delay);
}
conn_info.stat.report_as_server(ip_port);
continue;
}
else
{
assert(conn_info.conv_manager.is_u64_used(fd64));
conv=conn_info.conv_manager.find_conv_by_u64(fd64);
conn_info.conv_manager.update_active_time(conv);
conn_info.update_active_time();
int fd=fd_manager.to_fd(fd64);
data_len=recv(fd,data,max_data_len,0);
mylog(log_trace,"received a packet from udp_fd,len:%d,conv=%d\n",data_len,conv);
if(data_len<0)
{
mylog(log_debug,"udp fd,recv_len<0 continue,%s\n",strerror(errno));
continue;
}
if(!disable_mtu_warn&&data_len>=mtu_warn)
{
mylog(log_warn,"huge packet,data len=%d (>=%d).strongly suggested to set a smaller mtu at upper level,to get rid of this warn\n ",data_len,mtu_warn);
}
char * new_data;
int new_len;
put_conv(conv,data,data_len,new_data,new_len);
from_normal_to_fec(conn_info,new_data,new_len,out_n,out_arr,out_len,out_delay);
}
mylog(log_trace,"out_n=%d\n",out_n);
for(int i=0;i<out_n;i++)
{
delay_send(out_delay[i],dest,out_arr[i],out_len[i]);
}
//mylog(log_trace,"[%s] send packet\n",ip_port.to_s());
}
else
{
mylog(log_fatal,"unknown fd,this should never happen\n");
myexit(-1);
}
}
delay_manager.check();
}
return 0;
}

17
tunnel.h Normal file
View File

@@ -0,0 +1,17 @@
/*
* tunnel.h
*
* Created on: Oct 26, 2017
* Author: root
*/
#ifndef TUNNEL_H_
#define TUNNEL_H_
#include "misc.h"
int tunnel_client_event_loop();
int tunnel_server_event_loop();
#endif /* TUNNEL_H_ */