Skip to content

Commit

Permalink
Add UNIX socket notifications for unknown users to VLESS
Browse files Browse the repository at this point in the history
  • Loading branch information
leninalive committed Oct 11, 2024
1 parent 8f7bfe4 commit 2c5cda7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 32 deletions.
10 changes: 6 additions & 4 deletions infra/conf/vless.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ type VLessInboundFallback struct {
}

type VLessInboundConfig struct {
Clients []json.RawMessage `json:"clients"`
Decryption string `json:"decryption"`
Fallback *VLessInboundFallback `json:"fallback"`
Fallbacks []*VLessInboundFallback `json:"fallbacks"`
Clients []json.RawMessage `json:"clients"`
Decryption string `json:"decryption"`
Fallback *VLessInboundFallback `json:"fallback"`
Fallbacks []*VLessInboundFallback `json:"fallbacks"`
Notifications string `json:"notifications"`
}

// Build implements Buildable
Expand Down Expand Up @@ -72,6 +73,7 @@ func (c *VLessInboundConfig) Build() (proto.Message, error) {
return nil, newError(`VLESS settings: please add/set "decryption":"none" to every settings`)
}
config.Decryption = c.Decryption
config.Notifications = c.Notifications

if c.Fallback != nil {
return nil, newError(`VLESS settings: please use "fallbacks":[{}] instead of "fallback":{}`)
Expand Down
43 changes: 27 additions & 16 deletions proxy/vless/inbound/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proxy/vless/inbound/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ message Config {
// for now.
string decryption = 2;
repeated Fallback fallbacks = 3;
string notifications = 4;
}
26 changes: 14 additions & 12 deletions proxy/vless/inbound/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,25 @@ func New(ctx context.Context, config *Config, dc dns.Client) (*Handler, error) {
}
}

socketPath := "/var/run/vless_notifications.sock"
socketPath := config.Notifications

if _, err := os.Stat(socketPath); err == nil {
os.Remove(socketPath)
}
if socketPath != "" {
if _, err := os.Stat(socketPath); err == nil {
os.Remove(socketPath)
}

listener, err := net.Listen("unix", socketPath)
if err != nil {
//log.Record("Error setting up UNIX domain socket listener: %v", err)
return nil, err
}
listener, err := net.Listen("unix", socketPath)
if err != nil {
newError("error setting up UNIX domain socket listener: %v").Base(err).AtError().WriteToLog()
return nil, err
}

os.Chmod(socketPath, 0600)
os.Chmod(socketPath, 0600)

handler.unixListener = listener
handler.unixListener = listener

go handler.acceptUnixSocketClients()
go handler.acceptUnixSocketClients()
}

return handler, nil
}
Expand Down

0 comments on commit 2c5cda7

Please sign in to comment.