github.com/xmplusdev/xmcore@v1.8.11-0.20240412132628-5518b55526af/proxy/vmess/account.go (about) 1 package vmess 2 3 import ( 4 "strings" 5 6 "github.com/xmplusdev/xmcore/common/protocol" 7 "github.com/xmplusdev/xmcore/common/uuid" 8 ) 9 10 // MemoryAccount is an in-memory form of VMess account. 11 type MemoryAccount struct { 12 // ID is the main ID of the account. 13 ID *protocol.ID 14 // Security type of the account. Used for client connections. 15 Security protocol.SecurityType 16 17 AuthenticatedLengthExperiment bool 18 NoTerminationSignal bool 19 } 20 21 // Equals implements protocol.Account. 22 func (a *MemoryAccount) Equals(account protocol.Account) bool { 23 vmessAccount, ok := account.(*MemoryAccount) 24 if !ok { 25 return false 26 } 27 return a.ID.Equals(vmessAccount.ID) 28 } 29 30 // AsAccount implements protocol.Account. 31 func (a *Account) AsAccount() (protocol.Account, error) { 32 id, err := uuid.ParseString(a.Id) 33 if err != nil { 34 return nil, newError("failed to parse ID").Base(err).AtError() 35 } 36 protoID := protocol.NewID(id) 37 var AuthenticatedLength, NoTerminationSignal bool 38 if strings.Contains(a.TestsEnabled, "AuthenticatedLength") { 39 AuthenticatedLength = true 40 } 41 if strings.Contains(a.TestsEnabled, "NoTerminationSignal") { 42 NoTerminationSignal = true 43 } 44 return &MemoryAccount{ 45 ID: protoID, 46 Security: a.SecuritySettings.GetSecurityType(), 47 AuthenticatedLengthExperiment: AuthenticatedLength, 48 NoTerminationSignal: NoTerminationSignal, 49 }, nil 50 }