Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

非SIP003插件的正确使用方式? #1969

Closed
ghost opened this issue Aug 18, 2018 · 31 comments

Comments

@ghost
Copy link

commented Aug 18, 2018

Shadowsocks version / 影梭版本

4.1.1

Environment(Operating system, .NET Framework, etc) / 使用环境(操作系统,.NET Framework等)

WIN7 64bit .NET Framework4.72

Steps you have tried / 操作步骤

设置插件参数

What did you expect to see? / 期望的结果

可启用非SIP003插件

What did you see instead? / 实际结果

非SIP003插件(原版Kcptun)无效

Config and error log in detail (with all sensitive info masked) / 配置文件和日志文件(请隐去敏感信息)

服务器地址:服务器IP
服务器端口:服务器kcptun端口
插件程序:路径\kcptun.exe
插件选项:空
插件参数:-c 路径\config.json
config.json:
{
"key": "密钥",
"crypt": "salsa20",
"mode": "manual",
"conn": 1,
"autoexpire": 300,
"mtu": 1300,
"sndwnd": 512,
"rcvwnd": 1024,
"datashard": 30,
"parityshard": 15,
"dscp": 46,
"nocomp": true,
"acknodelay": false,
"nodelay": 0,
"interval": 20,
"resend": 2,
"nc": 1,
"sockbuf": 4194304,
"keepalive": 10,
"quiet": true
}

使用以上方式,kcptun已启用,实际无效。

改为:
插件程序:路径\kcptun.exe
插件选项:空
插件参数:-key 密钥 -crypt salsa20 -mode manual -conn 1 -autoexpire 300 -mtu 1300 -sndwnd 512 -rcvwnd 1024 -datashard 30 -parityshard 15 -dscp 46 -nocomp true -acknodelay false -nodelay 0 -interval 20 -resend 2 -nc 1 -sockbuf 4194304 -keepalive 10

kcptun已启用,实际仍无效。
请教非SIP003插件的正确使用方式?

@chenshaoju

This comment has been minimized.

Copy link
Collaborator

commented Aug 18, 2018

kcptun有符合SIP003规范的版本。
具体请阅读: #1813 (comment)

@ghost

This comment has been minimized.

Copy link
Author

commented Aug 18, 2018

@chenshaoju 就是说新增加的“插件参数”不适用于非SIP003规范的kcptun吗?哪非SIP003规范的obfs呢?
如不支持,这个功能添加的意义是什么?

@ghost

This comment has been minimized.

Copy link
Author

commented Aug 18, 2018

@celeron533 希望能完善调用CLI插件的功能,配合使用kcpraw实现加速同时突破UDP Qos是有必要的。

@chenshaoju

This comment has been minimized.

Copy link
Collaborator

commented Aug 18, 2018

Edit:
经过研究后,发现一个问题,Shadowsocks for Windows无法直接将变量值传递给插件,而是需要插件自己去读变量值,但是并不是所有非SIP003规范的插件都能读取系统变量。

通过 cmd.exe 可以传递变量值给插件,因此,你需要这样填写:
插件程序:
C:\Windows\system32\cmd.exe

插件参数:
/c D:\Software\Shadowsocks\client_windows_amd64.exe -l %SS_LOCAL_HOST%:%SS_LOCAL_PORT% -r %SS_REMOTE_HOST%:%SS_REMOTE_PORT% --key 123456 --crypt salsa20 --mode fast2

@ghost

This comment has been minimized.

Copy link
Author

commented Aug 18, 2018

代码中可否添加“插件参数”的非空判断。如果“插件参数”非空,则不要生成%SS_LOCAL_HOST%、%SS_LOCAL_PORT% 、 %SS_REMOTE_HOST%、%SS_REMOTE_PORT%,并对插件程序附值。

这样编缉服务器信息如下:
服务器地址:127.0.0.1 <==kcptun本地监听地址
服务器端口:1099 <==kcptun本地监听端口
插件程序:路径\kcptun.exe
插件选项:空
插件参数:-l 127.0.0.1:1099 -r SS服务器地址:SS服务器端口 -key 密钥 -crypt salsa20 -mode manual -conn 1 -autoexpire 300 -mtu 1300 -sndwnd 512 -rcvwnd 1024 -datashard 30 -parityshard 15 -dscp 46 -nocomp true -acknodelay false -nodelay 0 -interval 20 -resend 2 -nc 1 -sockbuf 4194304 -keepalive 10

是否可以这样较简单的实现非SIP003插件的使用呢?

@chenshaoju

This comment has been minimized.

Copy link
Collaborator

commented Aug 18, 2018

根据SIP003的规范: https://github.com/shadowsocks/shadowsocks-org/wiki/Plugin

这几个变量是必定要提供的。

当然,你也可以不理会这些配置,手动设置你的情况。

@ghost

This comment has been minimized.

Copy link
Author

commented Aug 18, 2018

@chenshaoju 谢谢,你的方法是有效的!

@studentmain

This comment has been minimized.

Copy link
Contributor

commented Aug 18, 2018

@colalan 我尝试实现了一下你说的做法。这是生成的exe文件,希望你能试试。
在插件参数中可以直接使用%SS_REMOTE_HOST% %SS_REMOTE_PORT%等,当插件选项为空时会将其自动替换为相应值,但同时仍然生成相应环境变量。
SHA1: 1EFB89BA21E0D84B5AA2DA9EED2200B552EDC4BF

@chenshaoju

This comment has been minimized.

Copy link
Collaborator

commented Aug 18, 2018

@studentmain 测试了一下,能兼容符合SIP003规范的插件,因为kcptun的环境没有了,无法测试非SIP003规范的插件。

如果可能,欢迎提交PR。😘

@celeron533

This comment has been minimized.

Copy link
Collaborator

commented Aug 18, 2018

改为:
插件程序:路径\kcptun.exe
插件选项:空
插件参数:-key 密钥 -crypt salsa20 -mode manual -conn 1 -autoexpire 300 -mtu 1300 -sndwnd 512 -rcvwnd 1024 -datashard 30 -parityshard 15 -dscp 46 -nocomp true -acknodelay false -nodelay 0 -interval 20 -resend 2 -nc 1 -sockbuf 4194304 -keepalive 10

你至少需要填写要让kcptun监听哪一个本地端口,然后远程的kcptun服务器的IP和端口

插件工作原理实际上只是一个额外的代理链:
直连: ss-win (connect to 202.12.34.56:1234) --> (listening on 0.0.0.0:1234) ss-server
插件: ss-win (connect to 127.0.0.1:9999) --> (listening on 127.0.0.1:9999) kcptun client (connect to 202.12.34.56:4321) --> (listening on 0.0.0.0:4321) kcptun server (connect to 127.0.0.1:1234) --> (listening on 0.0.0.0:1234) ss-server

@ghost

This comment has been minimized.

Copy link
Author

commented Aug 18, 2018

@studentmain 你提供的执行文件有效,确实能在非sip003规范的原版KCPTUN上实现。
原版KCPTUN不支持%SS_LOCAL_HOST% %SS_LOCAL_PORT% %SS_REMOTE_HOST% %SS_REMOTE_PORT%这样的环境变量作为参数,经由你说的自动替换为“127.0.0.1:1099”这样的参数后,确实有效实现原版KCPTUN带参数运行。
但由于是对参数进行变量转换,所以无法支持-c config.json这样的由配置文件运行了。

@ghost

This comment has been minimized.

Copy link
Author

commented Aug 18, 2018

@celeron533 如果插件参数填写为:-l 127.0.0.1:1099 -r 44.55.66.78:1234 -key 8888 -crypt salsa20 -mode manual -conn 1 -autoexpire 300 -mtu 1300 -sndwnd 512 -rcvwnd 1024 -datashard 30 -parityshard 15 -dscp 46 -nocomp true -acknodelay false -nodelay 0 -interval 20 -resend 2 -nc 1 -sockbuf 4194304 -keepalive 10
如你说的,给出确定的kcptun监听端口。
这样也是无法实现的,因为当ss-win设置中“插件程序”为非空时,ss-win自行生成了个%SS_LOCAL_PORT%变量作为它的服务器端口,也就是说ss-win的服务器端口并非KCPTUN参数中定义的监听端口:1099,所以无法完成连接。

补充:
在ss-win中设置为:
服务器地址:SS服务器IP <==上例为44.55.66.78
服务器端口:服务器kcptun端口 <==上例为1234
或:
服务器地址:KCPTUN本地监听IP <==上例为127.0.0.1
服务器端口:kcptun本地监听端口 <==上例为1099
都是无效的,原因如上所说,ss-win自行生成了个不同于设置%SS_LOCAL_PORT%,造成无法连接。

@studentmain

This comment has been minimized.

Copy link
Contributor

commented Aug 18, 2018

@colalan 给个示例配置文件看看?

@ghost

This comment has been minimized.

Copy link
Author

commented Aug 18, 2018

@studentmain
config.json
{
"localaddr": "127.0.0.1:1099",
"remoteaddr": "44.55.66.78:1234",
"key": "8888",
"crypt": "salsa20",
"mode": "manual",
"conn": 1,
"autoexpire": 300,
"mtu": 1300,
"sndwnd": 512,
"rcvwnd": 1024,
"datashard": 30,
"parityshard": 15,
"dscp": 46,
"nocomp": true,
"acknodelay": false,
"nodelay": 0,
"interval": 20,
"resend": 2,
"nc": 1,
"sockbuf": 4194304,
"keepalive": 10,
"quiet": true
}
这是完整的kcptun配置文件,如果ss-win可以读取并转换成参数格式,那就可以不用:
"localaddr": "127.0.0.1:1099",
"remoteaddr": "44.55.66.78:1234",
这两行,而经由你所做的,由%SS_REMOTE_HOST% %SS_REMOTE_PORT%等转换成就可以了,那么配置文件就如下了:
config.json
{
"key": "8888",
"crypt": "salsa20",
"mode": "manual",
"conn": 1,
"autoexpire": 300,
"mtu": 1300,
"sndwnd": 512,
"rcvwnd": 1024,
"datashard": 30,
"parityshard": 15,
"dscp": 46,
"nocomp": true,
"acknodelay": false,
"nodelay": 0,
"interval": 20,
"resend": 2,
"nc": 1,
"sockbuf": 4194304,
"keepalive": 10,
"quiet": true
}
实现结果是:ss-win判断插件参数为-c config.json时,读取配置文件并还原为参数格式,同时添加由%SS_LOCAL_HOST%、%SS_LOCAL_PORT% 替换而成的 "localaddr"(-l)参数。

@studentmain

This comment has been minimized.

Copy link
Contributor

commented Aug 18, 2018

等等……插件标准是要求由SS本身指定端口

如果要求使用固定端口,还要改前端,划不来。如果要求自动改配置文件,那要打开配置文件现场编,更划不来。

@studentmain

This comment has been minimized.

Copy link
Contributor

commented Aug 18, 2018

判断插件参数是不是-c config.json那就过了,说不定某个奇葩插件要求用-d cfg.ini读配置文件呢。
依我看改一下插件的配置部分的代码来得更直接。

@ghost

This comment has been minimized.

Copy link
Author

commented Aug 18, 2018

@studentmain 你的实现方法已经很好了,无必要非得支持配置文件方式。如可能,望并入主分支中。

@studentmain studentmain referenced this issue Aug 18, 2018
3 of 5 tasks complete
@studentmain

This comment has been minimized.

Copy link
Contributor

commented Aug 18, 2018

@chenshaoju @colalan PR已发

celeron533 added a commit that referenced this issue Aug 19, 2018
Cause: process's additional environment variables are not expanded
by correctly.
@celeron533 celeron533 added the bug label Aug 19, 2018
@chenshaoju

This comment has been minimized.

Copy link
Collaborator

commented Aug 20, 2018

@colalan 请尝试该版本的SS,是否可以配合非SIP003规范的插件并具备变量的情况下工作:
https://ci.appveyor.com/project/celeron533/shadowsocks-windows/build/4.1.1.11/job/ltbdckeq5lhrsmwf/artifacts

@ghost

This comment has been minimized.

Copy link
Author

commented Aug 20, 2018

@chenshaoju 你的这个版本可以配合非SIP003规范的插件运行!

ss-win设置如下:
服务器地址:44.55.66.78 <==示例:SS服务器IP
服务器端口:1234 <==示例:服务器kcptun监听端口

插件程序:D:\KCPTun\KCPTun.exe <==示例:插件路径
插件选项:空
插件参数:-l %SS_LOCAL_HOST%:%SS_LOCAL_PORT% -r %SS_REMOTE_HOST%:%SS_REMOTE_PORT% -key password -crypt salsa20 -mode manual -conn 1 -autoexpire 300 -mtu 1300 -sndwnd 512 -rcvwnd 1024 -datashard 30 -parityshard 15 -dscp 46 -nocomp true -acknodelay false -nodelay 0 -interval 20 -resend 2 -nc 1 -sockbuf 4194304 -keepalive 10

测试了原版kcptun和它的再开发版kcpraw,均可以正确加载运行插件.
good job!

@chenshaoju

This comment has been minimized.

Copy link
Collaborator

commented Aug 20, 2018

@colalan 感谢你的回报,谢谢! 😘

@ghost

This comment has been minimized.

Copy link
Author

commented Aug 20, 2018

SIP003规范的“插件选项”中的可以不填"-l %SS_LOCAL_HOST%:%SS_LOCAL_PORT% -r %SS_REMOTE_HOST%:%SS_REMOTE_PORT%"这部份。
非SIP003规范插件不知可否做到不在填写参数时必填,就像SIP003规范的插件在填写插件选项时一样,交由代码完成补充。
亦或可以合并SIP003规范和非SIP003规范插件的选项填列,统一它们的参数或选项填列方式,这样就不必区分插件是否符合SIP003规范。

@chenshaoju

This comment has been minimized.

Copy link
Collaborator

commented Aug 20, 2018

主要是无法控制插件的参数, kcptun 用的是 -r 和 -l ,但是别的插件不一定,比如simple-obfs是 -s -p -l ,这个是开发者决定的,控制不了。

@ghost

This comment has been minimized.

Copy link
Author

commented Aug 20, 2018

@chenshaoju 你说的对,毕竟SIP003规范的插件目前只有两个,还是专门针对ss-win再楄写的。无需关心它们的参数形式。

celeron533 added a commit that referenced this issue Aug 20, 2018
Fix #1969 #1818
@celeron533 celeron533 reopened this Aug 20, 2018
@ghost

This comment has been minimized.

Copy link
Author

commented Aug 20, 2018

小小建议,可否将"插件选项"和"插件参数"的填列合并为一个,加个复选框来对是否SIP003规范进行区分.
0
这对代码处理两种插件的方式也有帮助吧.
因为"插件选项"和"插件参数"对于新手来说理解点难度.

@studentmain

This comment has been minimized.

Copy link
Contributor

commented Aug 20, 2018

提议把"插件参数"改为"命令行参数",毕竟很多其他地方说的选项,指的其实是命令行参数。有些人(包括我)咋看来插件选项就是插件参数。

@celeron533

This comment has been minimized.

Copy link
Collaborator

commented Sep 13, 2018

提议把"插件参数"改为"命令行参数"

就怕有人理解成ss主程序的命令行参数。。。
结合 #1907 ,这个窗口的UI需要改动

@celeron533

This comment has been minimized.

Copy link
Collaborator

commented Sep 18, 2018

提议把"插件参数"改为"命令行参数"

@studentmain PR is welcome :)

@tatorhan

This comment has been minimized.

Copy link

commented Sep 28, 2018

如果用KCPTUN作为加速,SS 4.1.2插件程序、参数都怎么配置

@celeron533 celeron533 closed this Nov 11, 2018
@vinsec

This comment has been minimized.

Copy link

commented Feb 24, 2019

@chenshaoju 你的这个版本可以配合非SIP003规范的插件运行!

ss-win设置如下:
服务器地址:44.55.66.78 <==示例:SS服务器IP
服务器端口:1234 <==示例:服务器kcptun监听端口

插件程序:D:\KCPTun\KCPTun.exe <==示例:插件路径
插件选项:空
插件参数:-l %SS_LOCAL_HOST%:%SS_LOCAL_PORT% -r %SS_REMOTE_HOST%:%SS_REMOTE_PORT% -key password -crypt salsa20 -mode manual -conn 1 -autoexpire 300 -mtu 1300 -sndwnd 512 -rcvwnd 1024 -datashard 30 -parityshard 15 -dscp 46 -nocomp true -acknodelay false -nodelay 0 -interval 20 -resend 2 -nc 1 -sockbuf 4194304 -keepalive 10

测试了原版kcptun和它的再开发版kcpraw,均可以正确加载运行插件.
good job!

it works and thanks for contributing your solution:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.