mirror of https://github.com/v2ray/v2ray-core
ipv6 test
parent
6bcce77afb
commit
2a486c6b9e
|
@ -16,6 +16,9 @@ var (
|
||||||
|
|
||||||
// LocalHostDomain is a constant value for localhost domain.
|
// LocalHostDomain is a constant value for localhost domain.
|
||||||
LocalHostDomain = DomainAddress("localhost")
|
LocalHostDomain = DomainAddress("localhost")
|
||||||
|
|
||||||
|
// LocalHostIPv6 is a constant value for localhost IP in IPv6.
|
||||||
|
LocalHostIPv6 = IPAddress([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1})
|
||||||
)
|
)
|
||||||
|
|
||||||
type AddressFamily int
|
type AddressFamily int
|
||||||
|
|
|
@ -658,3 +658,119 @@ func TestVMessKCP(t *testing.T) {
|
||||||
|
|
||||||
CloseAllServers()
|
CloseAllServers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVMessIPv6(t *testing.T) {
|
||||||
|
assert := assert.On(t)
|
||||||
|
|
||||||
|
tcpServer := tcp.Server{
|
||||||
|
MsgProcessor: xor,
|
||||||
|
Listen: v2net.LocalHostIPv6,
|
||||||
|
}
|
||||||
|
dest, err := tcpServer.Start()
|
||||||
|
assert.Error(err).IsNil()
|
||||||
|
defer tcpServer.Close()
|
||||||
|
|
||||||
|
userID := protocol.NewID(uuid.New())
|
||||||
|
serverPort := pickPort()
|
||||||
|
serverConfig := &core.Config{
|
||||||
|
Inbound: []*proxyman.InboundHandlerConfig{
|
||||||
|
{
|
||||||
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||||
|
PortRange: v2net.SinglePortRange(serverPort),
|
||||||
|
Listen: v2net.NewIPOrDomain(v2net.LocalHostIPv6),
|
||||||
|
}),
|
||||||
|
ProxySettings: serial.ToTypedMessage(&inbound.Config{
|
||||||
|
User: []*protocol.User{
|
||||||
|
{
|
||||||
|
Account: serial.ToTypedMessage(&vmess.Account{
|
||||||
|
Id: userID.String(),
|
||||||
|
AlterId: 64,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Outbound: []*proxyman.OutboundHandlerConfig{
|
||||||
|
{
|
||||||
|
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
App: []*serial.TypedMessage{
|
||||||
|
serial.ToTypedMessage(&log.Config{
|
||||||
|
ErrorLogLevel: log.LogLevel_Debug,
|
||||||
|
ErrorLogType: log.LogType_Console,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
clientPort := pickPort()
|
||||||
|
clientConfig := &core.Config{
|
||||||
|
Inbound: []*proxyman.InboundHandlerConfig{
|
||||||
|
{
|
||||||
|
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||||
|
PortRange: v2net.SinglePortRange(clientPort),
|
||||||
|
Listen: v2net.NewIPOrDomain(v2net.LocalHostIPv6),
|
||||||
|
}),
|
||||||
|
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||||
|
Address: v2net.NewIPOrDomain(dest.Address),
|
||||||
|
Port: uint32(dest.Port),
|
||||||
|
NetworkList: &v2net.NetworkList{
|
||||||
|
Network: []v2net.Network{v2net.Network_TCP},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Outbound: []*proxyman.OutboundHandlerConfig{
|
||||||
|
{
|
||||||
|
ProxySettings: serial.ToTypedMessage(&outbound.Config{
|
||||||
|
Receiver: []*protocol.ServerEndpoint{
|
||||||
|
{
|
||||||
|
Address: v2net.NewIPOrDomain(v2net.LocalHostIPv6),
|
||||||
|
Port: uint32(serverPort),
|
||||||
|
User: []*protocol.User{
|
||||||
|
{
|
||||||
|
Account: serial.ToTypedMessage(&vmess.Account{
|
||||||
|
Id: userID.String(),
|
||||||
|
AlterId: 64,
|
||||||
|
SecuritySettings: &protocol.SecurityConfig{
|
||||||
|
Type: protocol.SecurityType_AES128_GCM,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
App: []*serial.TypedMessage{
|
||||||
|
serial.ToTypedMessage(&log.Config{
|
||||||
|
ErrorLogLevel: log.LogLevel_Debug,
|
||||||
|
ErrorLogType: log.LogType_Console,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Error(InitializeServerConfig(serverConfig)).IsNil()
|
||||||
|
assert.Error(InitializeServerConfig(clientConfig)).IsNil()
|
||||||
|
|
||||||
|
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
||||||
|
IP: v2net.LocalHostIPv6.IP(),
|
||||||
|
Port: int(clientPort),
|
||||||
|
})
|
||||||
|
assert.Error(err).IsNil()
|
||||||
|
|
||||||
|
payload := make([]byte, 1024)
|
||||||
|
rand.Read(payload)
|
||||||
|
|
||||||
|
nBytes, err := conn.Write([]byte(payload))
|
||||||
|
assert.Error(err).IsNil()
|
||||||
|
assert.Int(nBytes).Equals(len(payload))
|
||||||
|
|
||||||
|
response := readFrom(conn, time.Second, 1024)
|
||||||
|
assert.Bytes(response).Equals(xor([]byte(payload)))
|
||||||
|
assert.Error(conn.Close()).IsNil()
|
||||||
|
|
||||||
|
CloseAllServers()
|
||||||
|
}
|
||||||
|
|
|
@ -11,13 +11,18 @@ type Server struct {
|
||||||
Port v2net.Port
|
Port v2net.Port
|
||||||
MsgProcessor func(msg []byte) []byte
|
MsgProcessor func(msg []byte) []byte
|
||||||
SendFirst []byte
|
SendFirst []byte
|
||||||
|
Listen v2net.Address
|
||||||
accepting bool
|
accepting bool
|
||||||
listener *net.TCPListener
|
listener *net.TCPListener
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) Start() (v2net.Destination, error) {
|
func (server *Server) Start() (v2net.Destination, error) {
|
||||||
|
listenerAddr := server.Listen
|
||||||
|
if listenerAddr == nil {
|
||||||
|
listenerAddr = v2net.LocalHostIP
|
||||||
|
}
|
||||||
listener, err := net.ListenTCP("tcp", &net.TCPAddr{
|
listener, err := net.ListenTCP("tcp", &net.TCPAddr{
|
||||||
IP: []byte{127, 0, 0, 1},
|
IP: listenerAddr.IP(),
|
||||||
Port: int(server.Port),
|
Port: int(server.Port),
|
||||||
Zone: "",
|
Zone: "",
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue