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

Add custom Sockopt support #3517

Merged
merged 4 commits into from
Jul 9, 2024
Merged

Add custom Sockopt support #3517

merged 4 commits into from
Jul 9, 2024

Conversation

Fangliding
Copy link
Member

@Fangliding Fangliding commented Jul 8, 2024

#3516
虽然支持一个sockopt没有意义 但是支持自定义或许有_(吗)_
举栗

{
    "streamSettings": {
        "sockopt": {
            "customSockopt": [
                {
                "value": 114,
                "opt": 514
                },
                {
                "value": 1919,
                "opt": 810
                }
            ]
        }
    }
}

@@ -121,4 +121,6 @@ message SocketConfig {
bool tcp_no_delay = 18;

bool tcp_mptcp = 19;

map<int32, int32> customSockopt = 20;
Copy link
Member

@yuhan6665 yuhan6665 Jul 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a good idea, please make it more generic that user should be able to define level (2nd param in .Setsockopt()) as well. Also it should support different value types.. Maybe something like

message Custom {
  int64 level;
  int64 opt;
  int32 type;
  string value;
}

@Fangliding
Copy link
Member Author

level是可以的 type是什么()

@Fangliding
Copy link
Member Author

Fangliding commented Jul 9, 2024

如果是说syscall包里的string和byte 可以这么写

{
"opt": 114,
"int": 514,
"str": "xxxx"
}

反正如果输的不正确直接在后面抛错误就行了
之前写tcp brutal的时候 因为需要直接塞二进制数据 只能golinkname把内部原始setsockopt函数导出来再用()

@Fangliding
Copy link
Member Author

改成了这样

{
"level": "6"
"opt": "114",
"int": "514",
"str": "abc"
}

支持了 value 和 int str选项 值全部改成了string 因为如果是int的话默认值是0 但是有时候一些值就是要设置为0 不知道到底是用户设置为0还是没填 所以改成字符串 检测空就是没填
level可以缺省 默认0x6即tcp

@yuhan6665
Copy link
Member

Please keep value in one field, otherwise it is confusing what is being set. eg.

{
"level": "6"
"opt": "114",
"type": "string"/"int", // or we can do "type": 0/1, this will decide if we call SetsockoptString or SetsockoptInt. In the future we can add even more types
"value": "abc"/"1"
}

@Fangliding
Copy link
Member Author

OK, it's doneee

@yuhan6665 yuhan6665 changed the title 增加自定义Sockopt支持 Add custom Sockopt support Jul 9, 2024
@yuhan6665 yuhan6665 merged commit 308f0c6 into XTLS:main Jul 9, 2024
34 checks passed
@yuhan6665
Copy link
Member

strconv.Atoi 的错误可能需要返回。。不过先这样吧 感谢佬!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants