1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-17 23:06:30 -05:00

Unix listeners(sync commit)

This commit is contained in:
Shelikhoo 2018-03-11 13:44:21 +08:00
parent 91f32cc8c4
commit 43abfc9463
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
3 changed files with 72 additions and 4 deletions

View File

@ -143,8 +143,7 @@ func NewHandler(ctx context.Context, config *core.InboundHandlerConfig) (core.In
return nil, newError("unknown allocation strategy: ", receiverSettings.AllocationStrategy.Type).AtError()
}
func (m *Manager) asUnixReceiverConfig(ctx context.Context, config *core.InboundHandlerConfig) {
func (m *Manager) asUnixReceiverConfig(ctx context.Context, config *core.InboundHandlerConfig, unixrx proxyman.UnixReceiverConfig) {
return
}

View File

@ -0,0 +1,65 @@
package inbound
import (
"context"
"v2ray.com/core/app/proxyman"
"v2ray.com/core/app/proxyman/mux"
"v2ray.com/core/common"
"v2ray.com/core/common/net"
"v2ray.com/core/proxy"
"v2ray.com/core/transport/internet/domainsocket"
)
type UnixInboundHandler struct {
tag string
listenerHolder *domainsocket.Listener
ctx context.Context
path string
proxy proxy.Inbound
mux *mux.Server
}
func (uih *UnixInboundHandler) Start() {
var err error
uih.listenerHolder, err = domainsocket.ListenDS(uih.ctx, uih.path)
newError(err).AtError().WriteToLog()
}
func (uih *UnixInboundHandler) Close() {
if uih.listenerHolder != nil {
uih.listenerHolder.Down()
} else {
newError("Called UnixInboundHandler.Close while listenerHolder is nil").AtDebug().WriteToLog()
}
}
func (uih *UnixInboundHandler) Tag() string {
return uih.tag
}
func (uih *UnixInboundHandler) GetRandomInboundProxy() (interface{}, net.Port, int) {
//It makes bo sense to support it
return nil, 0, 0
}
func NewUnixInboundHandler(ctx context.Context, tag string, receiverConfig *proxyman.UnixReceiverConfig, proxyConfig interface{}) (*UnixInboundHandler, error) {
rawProxy, err := common.CreateObject(ctx, proxyConfig)
if err != nil {
return nil, err
}
p, ok := rawProxy.(proxy.Inbound)
if !ok {
return nil, newError("not an inbound proxy.")
}
h := &UnixInboundHandler{
proxy: p,
mux: mux.NewServer(ctx),
tag: tag,
ctx: ctx,
path: receiverConfig.DomainSockSettings.GetPath(),
}
return h, nil
}

View File

@ -12,11 +12,15 @@ type Listener struct {
func ListenDS(ctx context.Context, path string) (*Listener, error) {
addr := new(net.UnixAddr)
addr.Name = path
addr.Net = "unixpacket"
li, err := net.ListenUnix("unixpacket", addr)
addr.Net = "unix"
li, err := net.ListenUnix("unix", addr)
if err != nil {
return nil, err
}
vln := &Listener{ln: li}
return vln, nil
}
func (ls *Listener) Down() {
ls.ln.Close()
}