config.go 978 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package socks
  2. import (
  3. v2net "v2ray.com/core/common/net"
  4. "v2ray.com/core/common/protocol"
  5. "github.com/golang/protobuf/ptypes"
  6. google_protobuf "github.com/golang/protobuf/ptypes/any"
  7. )
  8. func (this *Account) Equals(another protocol.Account) bool {
  9. if account, ok := another.(*Account); ok {
  10. return this.Username == account.Username
  11. }
  12. return false
  13. }
  14. func (this *Account) AsAccount() (protocol.Account, error) {
  15. return this, nil
  16. }
  17. func NewAccount() protocol.AsAccount {
  18. return &Account{}
  19. }
  20. func (this *Account) AsAny() (*google_protobuf.Any, error) {
  21. return ptypes.MarshalAny(this)
  22. }
  23. func (this *ServerConfig) HasAccount(username, password string) bool {
  24. if this.Accounts == nil {
  25. return false
  26. }
  27. storedPassed, found := this.Accounts[username]
  28. if !found {
  29. return false
  30. }
  31. return storedPassed == password
  32. }
  33. func (this *ServerConfig) GetNetAddress() v2net.Address {
  34. if this.Address == nil {
  35. return v2net.LocalHostIP
  36. }
  37. return this.Address.AsAddress()
  38. }