mirror of https://github.com/v2ray/v2ray-core
understand OTA bit
parent
008c285324
commit
7f5184e943
|
@ -25,13 +25,7 @@ func (subject *AddressSubject) DisplayString() string {
|
|||
}
|
||||
|
||||
func (subject *AddressSubject) Equals(another v2net.Address) {
|
||||
if subject.value.IsIPv4() && another.IsIPv4() {
|
||||
IP(subject.value.IP()).Equals(another.IP())
|
||||
} else if subject.value.IsIPv6() && another.IsIPv6() {
|
||||
IP(subject.value.IP()).Equals(another.IP())
|
||||
} else if subject.value.IsDomain() && another.IsDomain() {
|
||||
assert.StringLiteral(subject.value.Domain()).Equals(another.Domain())
|
||||
} else {
|
||||
if !subject.value.Equals(another) {
|
||||
subject.Fail(subject.DisplayString(), "equals to", another)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ const (
|
|||
type Request struct {
|
||||
Address v2net.Address
|
||||
Port v2net.Port
|
||||
OTA bool
|
||||
}
|
||||
|
||||
func ReadRequest(reader io.Reader) (*Request, error) {
|
||||
|
@ -32,7 +33,10 @@ func ReadRequest(reader io.Reader) (*Request, error) {
|
|||
|
||||
request := new(Request)
|
||||
|
||||
addrType := buffer.Value[0]
|
||||
addrType := (buffer.Value[0] & 0x0F)
|
||||
if (buffer.Value[0] & 0x10) == 0x10 {
|
||||
request.OTA = true
|
||||
}
|
||||
switch addrType {
|
||||
case AddrTypeIPv4:
|
||||
_, err := io.ReadFull(reader, buffer.Value[:4])
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package shadowsocks_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
|
||||
. "github.com/v2ray/v2ray-core/proxy/shadowsocks"
|
||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/assert"
|
||||
)
|
||||
|
||||
func TestNormalRequestParsing(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
|
||||
buffer := alloc.NewSmallBuffer().Clear()
|
||||
buffer.AppendBytes(1, 127, 0, 0, 1, 0, 80)
|
||||
|
||||
request, err := ReadRequest(buffer)
|
||||
assert.Error(err).IsNil()
|
||||
netassert.Address(request.Address).Equals(v2net.IPAddress([]byte{127, 0, 0, 1}))
|
||||
netassert.Port(request.Port).Equals(v2net.Port(80))
|
||||
assert.Bool(request.OTA).IsFalse()
|
||||
}
|
||||
|
||||
func TestOTARequest(t *testing.T) {
|
||||
v2testing.Current(t)
|
||||
|
||||
buffer := alloc.NewSmallBuffer().Clear()
|
||||
buffer.AppendBytes(0x13, 13, 119, 119, 119, 46, 118, 50, 114, 97, 121, 46, 99, 111, 109, 0, 0)
|
||||
|
||||
request, err := ReadRequest(buffer)
|
||||
assert.Error(err).IsNil()
|
||||
netassert.Address(request.Address).Equals(v2net.DomainAddress("www.v2ray.com"))
|
||||
assert.Bool(request.OTA).IsTrue()
|
||||
}
|
Loading…
Reference in New Issue