mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-04-09 15:25:29 -04:00
move transport methods from net to io
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/proxy/internal"
|
||||
@@ -25,7 +26,7 @@ func (this *BlackHole) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) e
|
||||
|
||||
close(ray.OutboundOutput())
|
||||
if firstPacket.MoreChunks() {
|
||||
v2net.ChanToWriter(ioutil.Discard, ray.OutboundInput())
|
||||
v2io.ChanToWriter(ioutil.Discard, ray.OutboundInput())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
@@ -140,12 +141,12 @@ func (this *DokodemoDoor) HandleTCPConnection(conn *hub.TCPConn) {
|
||||
}
|
||||
|
||||
func dumpInput(reader io.Reader, input chan<- *alloc.Buffer, finish *sync.Mutex) {
|
||||
v2net.ReaderToChan(input, reader)
|
||||
v2io.RawReaderToChan(input, reader)
|
||||
finish.Unlock()
|
||||
close(input)
|
||||
}
|
||||
|
||||
func dumpOutput(writer io.Writer, output <-chan *alloc.Buffer, finish *sync.Mutex) {
|
||||
v2net.ChanToWriter(writer, output)
|
||||
v2io.ChanToWriter(writer, output)
|
||||
finish.Unlock()
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/common/retry"
|
||||
@@ -50,7 +51,7 @@ func (this *FreedomConnection) Dispatch(firstPacket v2net.Packet, ray ray.Outbou
|
||||
writeMutex.Unlock()
|
||||
} else {
|
||||
go func() {
|
||||
v2net.ChanToWriter(conn, input)
|
||||
v2io.ChanToWriter(conn, input)
|
||||
writeMutex.Unlock()
|
||||
}()
|
||||
}
|
||||
@@ -59,7 +60,7 @@ func (this *FreedomConnection) Dispatch(firstPacket v2net.Packet, ray ray.Outbou
|
||||
defer readMutex.Unlock()
|
||||
defer close(output)
|
||||
|
||||
response, err := v2net.ReadFrom(conn, nil)
|
||||
response, err := v2io.ReadFrom(conn, nil)
|
||||
log.Info("Freedom receives ", response.Len(), " bytes from ", conn.RemoteAddr())
|
||||
if response.Len() > 0 {
|
||||
output <- response
|
||||
@@ -73,7 +74,7 @@ func (this *FreedomConnection) Dispatch(firstPacket v2net.Packet, ray ray.Outbou
|
||||
return
|
||||
}
|
||||
|
||||
v2net.ReaderToChan(output, conn)
|
||||
v2io.RawReaderToChan(output, conn)
|
||||
}()
|
||||
|
||||
if this.space.HasDnsCache() {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
||||
v2proxy "github.com/v2ray/v2ray-core/proxy"
|
||||
@@ -128,7 +129,7 @@ func TestSocksTcpConnect(t *testing.T) {
|
||||
tcpConn.CloseWrite()
|
||||
}
|
||||
|
||||
dataReturned, err := v2net.ReadFrom(conn, nil)
|
||||
dataReturned, err := v2io.ReadFrom(conn, nil)
|
||||
assert.Error(err).IsNil()
|
||||
conn.Close()
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/common/serial"
|
||||
@@ -153,13 +154,13 @@ func (this *HttpProxyServer) transport(input io.Reader, output io.Writer, ray ra
|
||||
defer wg.Wait()
|
||||
|
||||
go func() {
|
||||
v2net.ReaderToChan(ray.InboundInput(), input)
|
||||
v2io.RawReaderToChan(ray.InboundInput(), input)
|
||||
close(ray.InboundInput())
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
v2net.ChanToWriter(output, ray.InboundOutput())
|
||||
v2io.ChanToWriter(output, ray.InboundOutput())
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
@@ -84,7 +85,7 @@ func (this *Shadowsocks) handlerUDPPayload(payload *alloc.Buffer, dest v2net.Des
|
||||
return
|
||||
}
|
||||
|
||||
buffer, _ := v2net.ReadFrom(reader, nil)
|
||||
buffer, _ := v2io.ReadFrom(reader, nil)
|
||||
|
||||
packet := v2net.NewPacket(v2net.TCPDestination(request.Address, request.Port), buffer, false)
|
||||
ray := this.space.PacketDispatcher().DispatchToOutbound(packet)
|
||||
@@ -168,12 +169,12 @@ func (this *Shadowsocks) handleConnection(conn *hub.TCPConn) {
|
||||
payload.Release()
|
||||
|
||||
writer.Write(firstChunk.Value)
|
||||
v2net.ChanToWriter(writer, ray.InboundOutput())
|
||||
v2io.ChanToWriter(writer, ray.InboundOutput())
|
||||
}
|
||||
writeFinish.Unlock()
|
||||
}()
|
||||
|
||||
v2net.ReaderToChan(ray.InboundInput(), reader)
|
||||
v2io.RawReaderToChan(ray.InboundInput(), reader)
|
||||
close(ray.InboundInput())
|
||||
|
||||
writeFinish.Lock()
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
@@ -227,8 +228,8 @@ func (this *SocksServer) handleUDP(reader *v2net.TimeOutReader, writer io.Writer
|
||||
return err
|
||||
}
|
||||
|
||||
reader.SetTimeOut(300) /* 5 minutes */
|
||||
v2net.ReadFrom(reader, nil) // Just in case of anything left in the socket
|
||||
reader.SetTimeOut(300) /* 5 minutes */
|
||||
v2io.ReadFrom(reader, nil) // Just in case of anything left in the socket
|
||||
// The TCP connection closes after this method returns. We need to wait until
|
||||
// the client closes it.
|
||||
// TODO: get notified from UDP part
|
||||
@@ -270,13 +271,13 @@ func (this *SocksServer) transport(reader io.Reader, writer io.Writer, firstPack
|
||||
outputFinish.Lock()
|
||||
|
||||
go func() {
|
||||
v2net.ReaderToChan(input, reader)
|
||||
v2io.RawReaderToChan(input, reader)
|
||||
inputFinish.Unlock()
|
||||
close(input)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
v2net.ChanToWriter(writer, output)
|
||||
v2io.ChanToWriter(writer, output)
|
||||
outputFinish.Unlock()
|
||||
}()
|
||||
outputFinish.Lock()
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
@@ -41,13 +42,13 @@ func (this *InboundConnectionHandler) Communicate(packet v2net.Packet) error {
|
||||
writeFinish.Lock()
|
||||
|
||||
go func() {
|
||||
v2net.ReaderToChan(input, this.ConnInput)
|
||||
v2io.RawReaderToChan(input, this.ConnInput)
|
||||
close(input)
|
||||
readFinish.Unlock()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
v2net.ChanToWriter(this.ConnOutput, output)
|
||||
v2io.ChanToWriter(this.ConnOutput, output)
|
||||
writeFinish.Unlock()
|
||||
}()
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
"github.com/v2ray/v2ray-core/transport/ray"
|
||||
@@ -32,14 +33,14 @@ func (this *OutboundConnectionHandler) Dispatch(packet v2net.Packet, ray ray.Out
|
||||
writeFinish.Lock()
|
||||
|
||||
go func() {
|
||||
v2net.ChanToWriter(this.ConnOutput, input)
|
||||
v2io.ChanToWriter(this.ConnOutput, input)
|
||||
writeFinish.Unlock()
|
||||
}()
|
||||
|
||||
writeFinish.Lock()
|
||||
}
|
||||
|
||||
v2net.ReaderToChan(output, this.ConnInput)
|
||||
v2io.RawReaderToChan(output, this.ConnInput)
|
||||
close(output)
|
||||
|
||||
return nil
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2crypto "github.com/v2ray/v2ray-core/common/crypto"
|
||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/common/serial"
|
||||
@@ -136,11 +137,11 @@ func handleInput(request *protocol.VMessRequest, reader io.Reader, input chan<-
|
||||
return
|
||||
}
|
||||
requestReader := v2crypto.NewCryptionReader(aesStream, reader)
|
||||
v2net.ReaderToChan(input, requestReader)
|
||||
v2io.RawReaderToChan(input, requestReader)
|
||||
}
|
||||
|
||||
func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-chan *alloc.Buffer, finish *sync.Mutex) {
|
||||
v2net.ChanToWriter(writer, output)
|
||||
v2io.ChanToWriter(writer, output)
|
||||
finish.Unlock()
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/v2ray/v2ray-core/app"
|
||||
"github.com/v2ray/v2ray-core/common/alloc"
|
||||
v2crypto "github.com/v2ray/v2ray-core/common/crypto"
|
||||
v2io "github.com/v2ray/v2ray-core/common/io"
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/proxy"
|
||||
@@ -132,7 +133,7 @@ func (this *VMessOutboundHandler) handleRequest(conn net.Conn, request *protocol
|
||||
}
|
||||
|
||||
if moreChunks {
|
||||
v2net.ChanToWriter(encryptRequestWriter, input)
|
||||
v2io.ChanToWriter(encryptRequestWriter, input)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -154,7 +155,7 @@ func (this *VMessOutboundHandler) handleResponse(conn net.Conn, request *protoco
|
||||
}
|
||||
decryptResponseReader := v2crypto.NewCryptionReader(aesStream, conn)
|
||||
|
||||
buffer, err := v2net.ReadFrom(decryptResponseReader, nil)
|
||||
buffer, err := v2io.ReadFrom(decryptResponseReader, nil)
|
||||
if err != nil {
|
||||
log.Error("VMessOut: Failed to read VMess response (", buffer.Len(), " bytes): ", err)
|
||||
buffer.Release()
|
||||
@@ -184,7 +185,7 @@ func (this *VMessOutboundHandler) handleResponse(conn net.Conn, request *protoco
|
||||
output <- buffer
|
||||
|
||||
if !isUDP {
|
||||
v2net.ReaderToChan(output, decryptResponseReader)
|
||||
v2io.RawReaderToChan(output, decryptResponseReader)
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestReadSingleByte(t *testing.T) {
|
||||
|
||||
reader := NewVMessRequestReader(nil)
|
||||
_, err := reader.Read(bytes.NewReader(make([]byte, 1)))
|
||||
assert.Error(err).Equals(io.EOF)
|
||||
assert.Error(err).Equals(io.ErrUnexpectedEOF)
|
||||
}
|
||||
|
||||
func BenchmarkVMessRequestWriting(b *testing.B) {
|
||||
|
||||
Reference in New Issue
Block a user