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

feat: add support for socket activation #3133

Merged
merged 4 commits into from
Sep 5, 2024

Conversation

ruihe774
Copy link
Contributor

@ruihe774 ruihe774 commented Aug 29, 2024

This PR adds special handing for addresses in the form of /dev/fd/*. These addresses are treated as already listened. net.FileListener is used in this scenario instead of net.Listen. In this way, systemd socket activation can be supported.

For example, with v2ray.service installed, we can write a v2ray.socket:

[Unit]
Description=V2Ray Socket

[Socket]
ListenStream=127.0.0.1:1080
ListenStream=127.0.0.1:1081

[Install]
WantedBy=sockets.target

And set the listen addresses of the inbound to the activated sockets (starting from fd 3) in config.json:

// ...
{
    "proto": "http",
    "listen": "/dev/fd/3"  // this will be 127.0.0.1:1080
},
{
    "proto": "http",
    "listen": "/dev/fd/4"  // this will be 127.0.0.1:1081
}
// ...

v2ray.service will be automatically started by systemd once connections are made to 127.0.0.1:1080 and 127.0.0.1:1081.

Benefits of using socket activation:

XXX:

  • Current implementation treats such addresses as UNIX domain socket despite of its real proto. The inbound proto must support UNIX ds to listen on such addresses.
  • UDP (ListenDatagram=) is not supported yet.

@ruihe774 ruihe774 force-pushed the socket-activation branch 2 times, most recently from ef182df to cd6983f Compare August 30, 2024 23:31
Copy link
Contributor

@xiaokangwang xiaokangwang left a comment

Choose a reason for hiding this comment

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

I think there are some minor coding style issue with your current implementation of the feature. However, I believe this change is ready to be merged once these issue are addressed.

transport/internet/socket_activation_other.go Outdated Show resolved Hide resolved
transport/internet/socket_activation_unix.go Outdated Show resolved Hide resolved
transport/internet/system_listener.go Outdated Show resolved Hide resolved
@xiaokangwang xiaokangwang merged commit 3d07f68 into v2fly:master Sep 5, 2024
37 of 39 checks passed
Copy link
Contributor

@xiaokangwang xiaokangwang left a comment

Choose a reason for hiding this comment

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

I have merged it! Thanks for your contribution.

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