diff --git a/app/router/rules/condition.go b/app/router/rules/condition.go index 5dc72b35a..262d85c37 100644 --- a/app/router/rules/condition.go +++ b/app/router/rules/condition.go @@ -63,12 +63,12 @@ func (this *AnyCondition) Len() int { } type PlainDomainMatcher struct { - pattern serial.StringLiteral + pattern serial.StringT } func NewPlainDomainMatcher(pattern string) *PlainDomainMatcher { return &PlainDomainMatcher{ - pattern: serial.StringLiteral(pattern), + pattern: serial.StringT(pattern), } } @@ -76,7 +76,7 @@ func (this *PlainDomainMatcher) Apply(dest v2net.Destination) bool { if !dest.Address().IsDomain() { return false } - domain := serial.StringLiteral(dest.Address().Domain()) + domain := serial.StringT(dest.Address().Domain()) return domain.Contains(this.pattern) } @@ -98,7 +98,7 @@ func (this *RegexpDomainMatcher) Apply(dest v2net.Destination) bool { if !dest.Address().IsDomain() { return false } - domain := serial.StringLiteral(dest.Address().Domain()) + domain := serial.StringT(dest.Address().Domain()) return this.pattern.MatchString(domain.ToLower().String()) } diff --git a/common/log/internal/log_entry_test.go b/common/log/internal/log_entry_test.go index f406320d0..61ce83c88 100644 --- a/common/log/internal/log_entry_test.go +++ b/common/log/internal/log_entry_test.go @@ -13,15 +13,15 @@ func TestAccessLog(t *testing.T) { v2testing.Current(t) entry := &AccessLog{ - From: serial.StringLiteral("test_from"), - To: serial.StringLiteral("test_to"), + From: serial.StringT("test_from"), + To: serial.StringT("test_to"), Status: "Accepted", - Reason: serial.StringLiteral("test_reason"), + Reason: serial.StringT("test_reason"), } entryStr := entry.String() - assert.StringLiteral(entryStr).Contains(serial.StringLiteral("test_from")) - assert.StringLiteral(entryStr).Contains(serial.StringLiteral("test_to")) - assert.StringLiteral(entryStr).Contains(serial.StringLiteral("test_reason")) - assert.StringLiteral(entryStr).Contains(serial.StringLiteral("Accepted")) + assert.StringLiteral(entryStr).Contains(serial.StringT("test_from")) + assert.StringLiteral(entryStr).Contains(serial.StringT("test_to")) + assert.StringLiteral(entryStr).Contains(serial.StringT("test_reason")) + assert.StringLiteral(entryStr).Contains(serial.StringT("Accepted")) } diff --git a/common/net/network.go b/common/net/network.go index 7dbc9316f..860466949 100644 --- a/common/net/network.go +++ b/common/net/network.go @@ -13,7 +13,7 @@ const ( ) // Network represents a communication network on internet. -type Network serial.StringLiteral +type Network serial.StringT func (this Network) AsList() *NetworkList { list := NetworkList([]Network{this}) @@ -24,7 +24,7 @@ func (this Network) AsList() *NetworkList { type NetworkList []Network // NewNetworkList construsts a NetWorklist from the given StringListeralList. -func NewNetworkList(networks serial.StringLiteralList) NetworkList { +func NewNetworkList(networks serial.StringTList) NetworkList { list := NetworkList(make([]Network, networks.Len())) for idx, network := range networks { list[idx] = Network(network.TrimSpace().ToLower()) diff --git a/common/net/testing/assert/address.go b/common/net/testing/assert/address.go index 57c5efbe5..17730d11e 100644 --- a/common/net/testing/assert/address.go +++ b/common/net/testing/assert/address.go @@ -32,36 +32,36 @@ func (subject *AddressSubject) Equals(another v2net.Address) { func (subject *AddressSubject) IsIPv4() { if !subject.value.IsIPv4() { - subject.Fail(subject.DisplayString(), "is", serial.StringLiteral("an IPv4 address")) + subject.Fail(subject.DisplayString(), "is", serial.StringT("an IPv4 address")) } } func (subject *AddressSubject) IsNotIPv4() { if subject.value.IsIPv4() { - subject.Fail(subject.DisplayString(), "is not", serial.StringLiteral("an IPv4 address")) + subject.Fail(subject.DisplayString(), "is not", serial.StringT("an IPv4 address")) } } func (subject *AddressSubject) IsIPv6() { if !subject.value.IsIPv6() { - subject.Fail(subject.DisplayString(), "is", serial.StringLiteral("an IPv6 address")) + subject.Fail(subject.DisplayString(), "is", serial.StringT("an IPv6 address")) } } func (subject *AddressSubject) IsNotIPv6() { if subject.value.IsIPv6() { - subject.Fail(subject.DisplayString(), "is not", serial.StringLiteral("an IPv6 address")) + subject.Fail(subject.DisplayString(), "is not", serial.StringT("an IPv6 address")) } } func (subject *AddressSubject) IsDomain() { if !subject.value.IsDomain() { - subject.Fail(subject.DisplayString(), "is", serial.StringLiteral("a domain address")) + subject.Fail(subject.DisplayString(), "is", serial.StringT("a domain address")) } } func (subject *AddressSubject) IsNotDomain() { if subject.value.IsDomain() { - subject.Fail(subject.DisplayString(), "is not", serial.StringLiteral("a domain address")) + subject.Fail(subject.DisplayString(), "is not", serial.StringT("a domain address")) } } diff --git a/common/net/testing/assert/destination.go b/common/net/testing/assert/destination.go index 5e0184555..aa75aa014 100644 --- a/common/net/testing/assert/destination.go +++ b/common/net/testing/assert/destination.go @@ -26,24 +26,24 @@ func (this *DestinationSubject) DisplayString() string { func (this *DestinationSubject) IsTCP() { if !this.value.IsTCP() { - this.Fail(this.DisplayString(), "is", serial.StringLiteral("a TCP destination")) + this.Fail(this.DisplayString(), "is", serial.StringT("a TCP destination")) } } func (this *DestinationSubject) IsNotTCP() { if this.value.IsTCP() { - this.Fail(this.DisplayString(), "is not", serial.StringLiteral("a TCP destination")) + this.Fail(this.DisplayString(), "is not", serial.StringT("a TCP destination")) } } func (this *DestinationSubject) IsUDP() { if !this.value.IsUDP() { - this.Fail(this.DisplayString(), "is", serial.StringLiteral("a UDP destination")) + this.Fail(this.DisplayString(), "is", serial.StringT("a UDP destination")) } } func (this *DestinationSubject) IsNotUDP() { if this.value.IsUDP() { - this.Fail(this.DisplayString(), "is not", serial.StringLiteral("a UDP destination")) + this.Fail(this.DisplayString(), "is not", serial.StringT("a UDP destination")) } } diff --git a/common/net/testing/assert/ip.go b/common/net/testing/assert/ip.go index 526c54405..ea56090e8 100644 --- a/common/net/testing/assert/ip.go +++ b/common/net/testing/assert/ip.go @@ -28,7 +28,7 @@ func (subject *IPSubject) DisplayString() string { func (subject *IPSubject) IsNil() { if subject.value != nil { - subject.Fail(subject.DisplayString(), "is", serial.StringLiteral("nil")) + subject.Fail(subject.DisplayString(), "is", serial.StringT("nil")) } } diff --git a/common/net/testing/assert/port.go b/common/net/testing/assert/port.go index bb19011a7..19378bce9 100644 --- a/common/net/testing/assert/port.go +++ b/common/net/testing/assert/port.go @@ -44,6 +44,6 @@ func (subject *PortSubject) LessThan(expectation v2net.Port) { func (subject *PortSubject) IsValid() { if subject.value == 0 { - subject.Fail(subject.DisplayString(), "is", serial.StringLiteral("a valid port")) + subject.Fail(subject.DisplayString(), "is", serial.StringT("a valid port")) } } diff --git a/common/serial/string.go b/common/serial/string.go index 68ddd54ac..c6138b588 100644 --- a/common/serial/string.go +++ b/common/serial/string.go @@ -9,28 +9,28 @@ type String interface { String() string } -type StringLiteral string +type StringT string -func NewStringLiteral(str String) StringLiteral { - return StringLiteral(str.String()) +func NewStringT(str String) StringT { + return StringT(str.String()) } -func (this StringLiteral) Contains(str String) bool { +func (this StringT) Contains(str String) bool { return strings.Contains(this.String(), str.String()) } -func (this StringLiteral) String() string { +func (this StringT) String() string { return string(this) } -func (this StringLiteral) ToLower() StringLiteral { - return StringLiteral(strings.ToLower(string(this))) +func (this StringT) ToLower() StringT { + return StringT(strings.ToLower(string(this))) } -func (this StringLiteral) ToUpper() StringLiteral { - return StringLiteral(strings.ToUpper(string(this))) +func (this StringT) ToUpper() StringT { + return StringT(strings.ToUpper(string(this))) } -func (this StringLiteral) TrimSpace() StringLiteral { - return StringLiteral(strings.TrimSpace(string(this))) +func (this StringT) TrimSpace() StringT { + return StringT(strings.TrimSpace(string(this))) } diff --git a/common/serial/string_json.go b/common/serial/string_json.go index 5f0f20fe0..b7372bfed 100644 --- a/common/serial/string_json.go +++ b/common/serial/string_json.go @@ -6,11 +6,11 @@ import ( "encoding/json" ) -func (this *StringLiteral) UnmarshalJSON(data []byte) error { +func (this *StringT) UnmarshalJSON(data []byte) error { var str string if err := json.Unmarshal(data, &str); err != nil { return err } - *this = StringLiteral(str) + *this = StringT(str) return nil } diff --git a/common/serial/string_list.go b/common/serial/string_list.go index ddccd94b0..dba42711f 100644 --- a/common/serial/string_list.go +++ b/common/serial/string_list.go @@ -1,15 +1,15 @@ package serial -type StringLiteralList []StringLiteral +type StringTList []StringT -func NewStringLiteralList(raw []string) *StringLiteralList { - list := StringLiteralList(make([]StringLiteral, len(raw))) +func NewStringTList(raw []string) *StringTList { + list := StringTList(make([]StringT, len(raw))) for idx, str := range raw { - list[idx] = StringLiteral(str) + list[idx] = StringT(str) } return &list } -func (this *StringLiteralList) Len() int { +func (this *StringTList) Len() int { return len(*this) } diff --git a/common/serial/string_list_json.go b/common/serial/string_list_json.go index 8da561bfc..7bb76efc1 100644 --- a/common/serial/string_list_json.go +++ b/common/serial/string_list_json.go @@ -8,17 +8,17 @@ import ( "strings" ) -func (this *StringLiteralList) UnmarshalJSON(data []byte) error { +func (this *StringTList) UnmarshalJSON(data []byte) error { var strarray []string if err := json.Unmarshal(data, &strarray); err == nil { - *this = *NewStringLiteralList(strarray) + *this = *NewStringTList(strarray) return nil } var rawstr string if err := json.Unmarshal(data, &rawstr); err == nil { strlist := strings.Split(rawstr, ",") - *this = *NewStringLiteralList(strlist) + *this = *NewStringTList(strlist) return nil } return errors.New("Unknown format of a string list: " + string(data)) diff --git a/common/serial/string_test.go b/common/serial/string_test.go index b8beb3cd9..e197203f7 100644 --- a/common/serial/string_test.go +++ b/common/serial/string_test.go @@ -20,5 +20,5 @@ func TestNewStringSerial(t *testing.T) { v2testing.Current(t) testString := &TestString{value: "abcd"} - assert.String(NewStringLiteral(testString)).Equals("abcd") + assert.String(NewStringT(testString)).Equals("abcd") } diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index 4b4e0370e..09c10abec 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -106,14 +106,14 @@ func (this *Server) handlerUDPPayload(payload *alloc.Buffer, source v2net.Destin request, err := ReadRequest(reader, NewAuthenticator(HeaderKeyGenerator(key, iv)), true) if err != nil { - log.Access(source, serial.StringLiteral(""), log.AccessRejected, serial.StringLiteral(err.Error())) + log.Access(source, serial.StringT(""), log.AccessRejected, serial.StringT(err.Error())) log.Warning("Shadowsocks: Invalid request from ", source, ": ", err) return } //defer request.Release() dest := v2net.UDPDestination(request.Address, request.Port) - log.Access(source, dest, log.AccessAccepted, serial.StringLiteral("")) + log.Access(source, dest, log.AccessAccepted, serial.StringT("")) log.Info("Shadowsocks: Tunnelling request to ", dest) this.udpServer.Dispatch(source, dest, request.DetachUDPPayload(), func(destination v2net.Destination, payload *alloc.Buffer) { @@ -172,7 +172,7 @@ func (this *Server) handleConnection(conn *hub.Connection) { ivLen := this.config.Cipher.IVSize() _, err := io.ReadFull(bufferedReader, buffer.Value[:ivLen]) if err != nil { - log.Access(conn.RemoteAddr(), serial.StringLiteral(""), log.AccessRejected, serial.StringLiteral(err.Error())) + log.Access(conn.RemoteAddr(), serial.StringT(""), log.AccessRejected, serial.StringT(err.Error())) log.Error("Shadowsocks: Failed to read IV: ", err) return } @@ -190,7 +190,7 @@ func (this *Server) handleConnection(conn *hub.Connection) { request, err := ReadRequest(reader, NewAuthenticator(HeaderKeyGenerator(key, iv)), false) if err != nil { - log.Access(conn.RemoteAddr(), serial.StringLiteral(""), log.AccessRejected, serial.StringLiteral(err.Error())) + log.Access(conn.RemoteAddr(), serial.StringT(""), log.AccessRejected, serial.StringT(err.Error())) log.Warning("Shadowsocks: Invalid request from ", conn.RemoteAddr(), ": ", err) return } @@ -201,7 +201,7 @@ func (this *Server) handleConnection(conn *hub.Connection) { timedReader.SetTimeOut(userSettings.PayloadReadTimeout) dest := v2net.TCPDestination(request.Address, request.Port) - log.Access(conn.RemoteAddr(), dest, log.AccessAccepted, serial.StringLiteral("")) + log.Access(conn.RemoteAddr(), dest, log.AccessAccepted, serial.StringT("")) log.Info("Shadowsocks: Tunnelling request to ", dest) ray := this.packetDispatcher.DispatchToOutbound(dest) diff --git a/proxy/vmess/inbound/inbound.go b/proxy/vmess/inbound/inbound.go index 1bc36e758..4f4f96823 100644 --- a/proxy/vmess/inbound/inbound.go +++ b/proxy/vmess/inbound/inbound.go @@ -130,11 +130,11 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) { request, err := session.DecodeRequestHeader(reader) if err != nil { - log.Access(connection.RemoteAddr(), serial.StringLiteral(""), log.AccessRejected, serial.StringLiteral(err.Error())) + log.Access(connection.RemoteAddr(), serial.StringT(""), log.AccessRejected, serial.StringT(err.Error())) log.Warning("VMessIn: Invalid request from ", connection.RemoteAddr(), ": ", err) return } - log.Access(connection.RemoteAddr(), request.Destination(), log.AccessAccepted, serial.StringLiteral("")) + log.Access(connection.RemoteAddr(), request.Destination(), log.AccessAccepted, serial.StringT("")) log.Debug("VMessIn: Received request for ", request.Destination()) ray := this.packetDispatcher.DispatchToOutbound(request.Destination()) diff --git a/testing/assert/stringsubject.go b/testing/assert/stringsubject.go index 8be4cec21..64e3b37d2 100644 --- a/testing/assert/stringsubject.go +++ b/testing/assert/stringsubject.go @@ -7,7 +7,7 @@ import ( ) func StringLiteral(value string) *StringSubject { - return String(serial.StringLiteral((value))) + return String(serial.StringT((value))) } func String(value serial.String) *StringSubject { @@ -30,13 +30,13 @@ func (subject *StringSubject) DisplayString() string { func (subject *StringSubject) Equals(expectation string) { if subject.value.String() != expectation { - subject.Fail(subject.DisplayString(), "is equal to", serial.StringLiteral(expectation)) + subject.Fail(subject.DisplayString(), "is equal to", serial.StringT(expectation)) } } func (subject *StringSubject) NotEquals(expectation string) { if subject.value.String() == expectation { - subject.Fail(subject.DisplayString(), "is not equal to ", serial.StringLiteral(expectation)) + subject.Fail(subject.DisplayString(), "is not equal to ", serial.StringT(expectation)) } }