本文整理汇总了Golang中v2ray/com/core/common/loader.NewTypedSettings函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTypedSettings函数的具体用法?Golang NewTypedSettings怎么用?Golang NewTypedSettings使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTypedSettings函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Build
func (this *VMessInboundConfig) Build() (*loader.TypedSettings, error) {
config := new(inbound.Config)
if this.Defaults != nil {
config.Default = this.Defaults.Build()
}
if this.DetourConfig != nil {
config.Detour = this.DetourConfig.Build()
} else if this.Features != nil && this.Features.Detour != nil {
config.Detour = this.Features.Detour.Build()
}
config.User = make([]*protocol.User, len(this.Users))
for idx, rawData := range this.Users {
user := new(protocol.User)
if err := json.Unmarshal(rawData, user); err != nil {
return nil, errors.New("VMess|Inbound: Invalid user: " + err.Error())
}
account := new(VMessAccount)
if err := json.Unmarshal(rawData, account); err != nil {
return nil, errors.New("VMess|Inbound: Invalid user: " + err.Error())
}
user.Account = loader.NewTypedSettings(account.Build())
config.User[idx] = user
}
return loader.NewTypedSettings(config), nil
}
示例2: Build
func (this *ShadowsocksServerConfig) Build() (*loader.TypedSettings, error) {
config := new(shadowsocks.ServerConfig)
config.UdpEnabled = this.UDP
if len(this.Password) == 0 {
return nil, errors.New("Shadowsocks password is not specified.")
}
account := &shadowsocks.Account{
Password: this.Password,
Ota: shadowsocks.Account_Auto,
}
cipher := strings.ToLower(this.Cipher)
switch cipher {
case "aes-256-cfb":
account.CipherType = shadowsocks.CipherType_AES_256_CFB
case "aes-128-cfb":
account.CipherType = shadowsocks.CipherType_AES_128_CFB
case "chacha20":
account.CipherType = shadowsocks.CipherType_CHACHA20
case "chacha20-ietf":
account.CipherType = shadowsocks.CipherType_CHACHA20_IEFT
default:
return nil, errors.New("Unknown cipher method: " + cipher)
}
config.User = &protocol.User{
Email: this.Email,
Level: uint32(this.Level),
Account: loader.NewTypedSettings(account),
}
return loader.NewTypedSettings(config), nil
}
示例3: TestUDPEncoding
func TestUDPEncoding(t *testing.T) {
assert := assert.On(t)
request := &protocol.RequestHeader{
Version: Version,
Command: protocol.RequestCommandUDP,
Address: v2net.LocalHostIP,
Port: 1234,
User: &protocol.User{
Email: "[email protected]",
Account: loader.NewTypedSettings(&Account{
Password: "shadowsocks-password",
CipherType: CipherType_AES_128_CFB,
Ota: Account_Disabled,
}),
},
}
data := alloc.NewLocalBuffer(256).Clear().AppendString("test string")
encodedData, err := EncodeUDPPacket(request, data)
assert.Error(err).IsNil()
decodedRequest, decodedData, err := DecodeUDPPacket(request.User, encodedData)
assert.Error(err).IsNil()
assert.Bytes(decodedData.Value).Equals(data.Value)
assert.Address(decodedRequest.Address).Equals(request.Address)
assert.Port(decodedRequest.Port).Equals(request.Port)
}
示例4: Build
func (this *SocksServerConfig) Build() (*loader.TypedSettings, error) {
config := new(socks.ServerConfig)
if this.AuthMethod == AuthMethodNoAuth {
config.AuthType = socks.AuthType_NO_AUTH
} else if this.AuthMethod == AuthMethodUserPass {
config.AuthType = socks.AuthType_PASSWORD
} else {
return nil, errors.New("Unknown socks auth method: " + this.AuthMethod)
}
if len(this.Accounts) > 0 {
config.Accounts = make(map[string]string, len(this.Accounts))
for _, account := range this.Accounts {
config.Accounts[account.Username] = account.Password
}
}
config.UdpEnabled = this.UDP
if this.Host != nil {
config.Address = this.Host.Build()
}
config.Timeout = this.Timeout
return loader.NewTypedSettings(config), nil
}
示例5: Build
func (this *HttpServerConfig) Build() (*loader.TypedSettings, error) {
config := &http.ServerConfig{
Timeout: this.Timeout,
}
return loader.NewTypedSettings(config), nil
}
示例6: Get
func (this *userByEmail) Get(email string) (*protocol.User, bool) {
var user *protocol.User
var found bool
this.RLock()
user, found = this.cache[email]
this.RUnlock()
if !found {
this.Lock()
user, found = this.cache[email]
if !found {
account := &vmess.Account{
Id: uuid.New().String(),
AlterId: uint32(this.defaultAlterIDs),
}
user = &protocol.User{
Level: this.defaultLevel,
Email: email,
Account: loader.NewTypedSettings(account),
}
this.cache[email] = user
}
this.Unlock()
}
return user, found
}
示例7: TestTCPRequest
func TestTCPRequest(t *testing.T) {
assert := assert.On(t)
request := &protocol.RequestHeader{
Version: Version,
Command: protocol.RequestCommandTCP,
Address: v2net.LocalHostIP,
Option: RequestOptionOneTimeAuth,
Port: 1234,
User: &protocol.User{
Email: "[email protected]",
Account: loader.NewTypedSettings(&Account{
Password: "tcp-password",
CipherType: CipherType_CHACHA20,
}),
},
}
data := alloc.NewLocalBuffer(256).Clear().AppendString("test string")
cache := alloc.NewBuffer().Clear()
writer, err := WriteTCPRequest(request, cache)
assert.Error(err).IsNil()
writer.Write(data)
decodedRequest, reader, err := ReadTCPSession(request.User, cache)
assert.Error(err).IsNil()
assert.Address(decodedRequest.Address).Equals(request.Address)
assert.Port(decodedRequest.Port).Equals(request.Port)
decodedData, err := reader.Read()
assert.Error(err).IsNil()
assert.Bytes(decodedData.Value).Equals([]byte("test string"))
}
示例8: Build
func (this *KCPConfig) Build() (*loader.TypedSettings, error) {
config := new(kcp.Config)
if this.Mtu != nil {
mtu := *this.Mtu
if mtu < 576 || mtu > 1460 {
return nil, fmt.Errorf("KCP|Config: Invalid MTU size: %d", mtu)
}
config.Mtu = &kcp.MTU{Value: mtu}
}
if this.Tti != nil {
tti := *this.Tti
if tti < 10 || tti > 100 {
return nil, fmt.Errorf("KCP|Config: Invalid TTI: %d", tti)
}
config.Tti = &kcp.TTI{Value: tti}
}
if this.UpCap != nil {
config.UplinkCapacity = &kcp.UplinkCapacity{Value: *this.UpCap}
}
if this.DownCap != nil {
config.DownlinkCapacity = &kcp.DownlinkCapacity{Value: *this.DownCap}
}
if this.Congestion != nil {
config.Congestion = *this.Congestion
}
if this.ReadBufferSize != nil {
size := *this.ReadBufferSize
if size > 0 {
config.ReadBuffer = &kcp.ReadBuffer{Size: size * 1024 * 1024}
} else {
config.ReadBuffer = &kcp.ReadBuffer{Size: 512 * 1024}
}
}
if this.WriteBufferSize != nil {
size := *this.WriteBufferSize
if size > 0 {
config.WriteBuffer = &kcp.WriteBuffer{Size: size * 1024 * 1024}
} else {
config.WriteBuffer = &kcp.WriteBuffer{Size: 512 * 1024}
}
}
if len(this.HeaderConfig) > 0 {
headerConfig, _, err := kcpHeaderLoader.Load(this.HeaderConfig)
if err != nil {
return nil, errors.New("KCP|Config: Failed to parse header config: " + err.Error())
}
ts, err := headerConfig.(Buildable).Build()
if err != nil {
return nil, errors.New("Failed to get KCP authenticator config: " + err.Error())
}
config.HeaderConfig = ts
}
return loader.NewTypedSettings(config), nil
}
示例9: Build
func (this *FreedomConfig) Build() (*loader.TypedSettings, error) {
config := new(freedom.Config)
config.DomainStrategy = freedom.Config_AS_IS
domainStrategy := strings.ToLower(this.DomainStrategy)
if domainStrategy == "useip" || domainStrategy == "use_ip" {
config.DomainStrategy = freedom.Config_USE_IP
}
config.Timeout = this.Timeout
return loader.NewTypedSettings(config), nil
}
示例10: Build
func (this *DokodemoConfig) Build() (*loader.TypedSettings, error) {
config := new(dokodemo.Config)
if this.Host != nil {
config.Address = this.Host.Build()
}
config.Port = uint32(this.PortValue)
config.NetworkList = this.NetworkList.Build()
config.Timeout = this.TimeoutValue
config.FollowRedirect = this.Redirect
return loader.NewTypedSettings(config), nil
}
示例11: handleSwitchAccount
func (this *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
account := &vmess.Account{
Id: cmd.ID.String(),
AlterId: uint32(cmd.AlterIds),
}
user := &protocol.User{
Email: "",
Level: cmd.Level,
Account: loader.NewTypedSettings(account),
}
dest := v2net.TCPDestination(cmd.Host, cmd.Port)
until := time.Now().Add(time.Duration(cmd.ValidMin) * time.Minute)
this.serverList.AddServer(protocol.NewServerSpec(dest, protocol.BeforeTime(until), user))
}
示例12: Build
func (this *BlackholeConfig) Build() (*loader.TypedSettings, error) {
config := new(blackhole.Config)
if this.Response != nil {
response, _, err := configLoader.Load(this.Response)
if err != nil {
return nil, errors.New("Blackhole: Failed to parse response config: " + err.Error())
}
responseSettings, err := response.(Buildable).Build()
if err != nil {
return nil, err
}
config.Response = responseSettings
}
return loader.NewTypedSettings(config), nil
}
示例13: Build
func (this *HTTPAuthenticator) Build() (*loader.TypedSettings, error) {
config := new(http.Config)
requestConfig, err := this.Request.Build()
if err != nil {
return nil, err
}
config.Request = requestConfig
responseConfig, err := this.Response.Build()
if err != nil {
return nil, err
}
config.Response = responseConfig
return loader.NewTypedSettings(config), nil
}
示例14: TestUDPReaderWriter
func TestUDPReaderWriter(t *testing.T) {
assert := assert.On(t)
user := &protocol.User{
Account: loader.NewTypedSettings(&Account{
Password: "test-password",
CipherType: CipherType_CHACHA20_IEFT,
}),
}
cache := alloc.NewBuffer().Clear()
writer := &UDPWriter{
Writer: cache,
Request: &protocol.RequestHeader{
Version: Version,
Address: v2net.DomainAddress("v2ray.com"),
Port: 123,
User: user,
Option: RequestOptionOneTimeAuth,
},
}
reader := &UDPReader{
Reader: cache,
User: user,
}
err := writer.Write(alloc.NewBuffer().Clear().AppendString("test payload"))
assert.Error(err).IsNil()
payload, err := reader.Read()
assert.Error(err).IsNil()
assert.String(payload.String()).Equals("test payload")
err = writer.Write(alloc.NewBuffer().Clear().AppendString("test payload 2"))
assert.Error(err).IsNil()
payload, err = reader.Read()
assert.Error(err).IsNil()
assert.String(payload.String()).Equals("test payload 2")
}
示例15: TestRequestSerialization
func TestRequestSerialization(t *testing.T) {
assert := assert.On(t)
user := &protocol.User{
Level: 0,
Email: "[email protected]",
}
account := &vmess.Account{
Id: uuid.New().String(),
AlterId: 0,
}
user.Account = loader.NewTypedSettings(account)
expectedRequest := &protocol.RequestHeader{
Version: 1,
User: user,
Command: protocol.RequestCommandTCP,
Option: protocol.RequestOption(0),
Address: v2net.DomainAddress("www.v2ray.com"),
Port: v2net.Port(443),
}
buffer := alloc.NewBuffer().Clear()
client := NewClientSession(protocol.DefaultIDHash)
client.EncodeRequestHeader(expectedRequest, buffer)
userValidator := vmess.NewTimedUserValidator(protocol.DefaultIDHash)
userValidator.Add(user)
server := NewServerSession(userValidator)
actualRequest, err := server.DecodeRequestHeader(buffer)
assert.Error(err).IsNil()
assert.Byte(expectedRequest.Version).Equals(actualRequest.Version)
assert.Byte(byte(expectedRequest.Command)).Equals(byte(actualRequest.Command))
assert.Byte(byte(expectedRequest.Option)).Equals(byte(actualRequest.Option))
assert.Address(expectedRequest.Address).Equals(actualRequest.Address)
assert.Port(expectedRequest.Port).Equals(actualRequest.Port)
}