| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package mocks
- import (
- "io"
- "sync"
- "github.com/v2ray/v2ray-core/app/dispatcher"
- v2io "github.com/v2ray/v2ray-core/common/io"
- v2net "github.com/v2ray/v2ray-core/common/net"
- "github.com/v2ray/v2ray-core/proxy"
- )
- type InboundConnectionHandler struct {
- ListeningPort v2net.Port
- ListeningAddress v2net.Address
- PacketDispatcher dispatcher.PacketDispatcher
- ConnInput io.Reader
- ConnOutput io.Writer
- }
- func (this *InboundConnectionHandler) Start() error {
- return nil
- }
- func (this *InboundConnectionHandler) Port() v2net.Port {
- return this.ListeningPort
- }
- func (this *InboundConnectionHandler) Close() {
- }
- func (this *InboundConnectionHandler) Communicate(destination v2net.Destination) error {
- ray := this.PacketDispatcher.DispatchToOutbound(&proxy.InboundHandlerMeta{
- AllowPassiveConnection: false,
- }, &proxy.SessionInfo{
- Source: v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(0)),
- Destination: destination,
- })
- input := ray.InboundInput()
- output := ray.InboundOutput()
- readFinish := &sync.Mutex{}
- writeFinish := &sync.Mutex{}
- readFinish.Lock()
- writeFinish.Lock()
- go func() {
- v2reader := v2io.NewAdaptiveReader(this.ConnInput)
- defer v2reader.Release()
- v2io.Pipe(v2reader, input)
- input.Close()
- readFinish.Unlock()
- }()
- go func() {
- v2writer := v2io.NewAdaptiveWriter(this.ConnOutput)
- defer v2writer.Release()
- v2io.Pipe(output, v2writer)
- output.Release()
- writeFinish.Unlock()
- }()
- readFinish.Lock()
- writeFinish.Lock()
- return nil
- }
|