v2fly/transport/internet/domainsocket/config.go

41 lines
785 B
Go
Raw Normal View History

2019-02-01 19:08:21 +00:00
// +build !confonly
2018-04-09 15:09:24 +00:00
package domainsocket
2018-04-09 18:45:23 +00:00
import (
2021-02-16 20:31:50 +00:00
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/common/net"
"github.com/v2fly/v2ray-core/v4/transport/internet"
2018-04-09 18:45:23 +00:00
)
2018-04-09 15:09:24 +00:00
2021-05-19 21:28:52 +00:00
const (
protocolName = "domainsocket"
sizeofSunPath = 108
)
2018-08-06 11:48:35 +00:00
2018-04-09 15:09:24 +00:00
func (c *Config) GetUnixAddr() (*net.UnixAddr, error) {
path := c.Path
if path == "" {
2018-04-09 15:09:24 +00:00
return nil, newError("empty domain socket path")
}
if c.Abstract && path[0] != '@' {
path = "@" + path
}
if c.Abstract && c.Padding {
raw := []byte(path)
addr := make([]byte, sizeofSunPath)
copy(addr, raw)
path = string(addr)
2018-04-09 15:09:24 +00:00
}
return &net.UnixAddr{
Name: path,
Net: "unix",
}, nil
}
2018-04-09 18:45:23 +00:00
func init() {
2019-01-06 19:33:58 +00:00
common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
2018-04-09 18:45:23 +00:00
return new(Config)
}))
}