1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-13 23:48:45 -04:00
v2fly/proxy/socks/config.go

47 lines
942 B
Go
Raw Normal View History

package socks
import (
2016-08-20 14:55:45 -04:00
v2net "v2ray.com/core/common/net"
2016-09-25 16:54:18 -04:00
"v2ray.com/core/common/protocol"
"github.com/golang/protobuf/ptypes"
google_protobuf "github.com/golang/protobuf/ptypes/any"
)
2016-11-27 15:39:09 -05:00
func (v *Account) Equals(another protocol.Account) bool {
2016-09-25 16:54:18 -04:00
if account, ok := another.(*Account); ok {
2016-11-27 15:39:09 -05:00
return v.Username == account.Username
2016-09-25 16:54:18 -04:00
}
return false
}
2016-11-27 15:39:09 -05:00
func (v *Account) AsAccount() (protocol.Account, error) {
return v, nil
2016-09-25 16:54:18 -04:00
}
func NewAccount() protocol.AsAccount {
return &Account{}
}
2016-11-27 15:39:09 -05:00
func (v *Account) AsAny() (*google_protobuf.Any, error) {
return ptypes.MarshalAny(v)
2016-09-25 16:54:18 -04:00
}
2016-11-27 15:39:09 -05:00
func (v *ServerConfig) HasAccount(username, password string) bool {
if v.Accounts == nil {
2016-09-25 16:54:18 -04:00
return false
}
2016-11-27 15:39:09 -05:00
storedPassed, found := v.Accounts[username]
2016-09-25 16:54:18 -04:00
if !found {
return false
}
return storedPassed == password
}
2016-11-27 15:39:09 -05:00
func (v *ServerConfig) GetNetAddress() v2net.Address {
if v.Address == nil {
2016-09-25 16:54:18 -04:00
return v2net.LocalHostIP
}
2016-11-27 15:39:09 -05:00
return v.Address.AsAddress()
2016-09-25 16:54:18 -04:00
}