| 
									
										
										
										
											2015-11-01 21:15:08 +01:00
										 |  |  | package mocks | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"io" | 
					
						
							|  |  |  | 	"sync" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-06 11:00:10 +01:00
										 |  |  | 	"github.com/v2ray/v2ray-core/app" | 
					
						
							| 
									
										
										
										
											2016-04-26 00:13:26 +02:00
										 |  |  | 	"github.com/v2ray/v2ray-core/common/alloc" | 
					
						
							| 
									
										
										
										
											2016-01-29 13:39:55 +00:00
										 |  |  | 	v2io "github.com/v2ray/v2ray-core/common/io" | 
					
						
							| 
									
										
										
										
											2015-11-01 21:15:08 +01:00
										 |  |  | 	v2net "github.com/v2ray/v2ray-core/common/net" | 
					
						
							| 
									
										
										
										
											2016-01-02 23:32:18 +01:00
										 |  |  | 	"github.com/v2ray/v2ray-core/proxy" | 
					
						
							| 
									
										
										
										
											2015-11-01 21:15:08 +01:00
										 |  |  | 	"github.com/v2ray/v2ray-core/transport/ray" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type OutboundConnectionHandler struct { | 
					
						
							|  |  |  | 	Destination v2net.Destination | 
					
						
							|  |  |  | 	ConnInput   io.Reader | 
					
						
							|  |  |  | 	ConnOutput  io.Writer | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 00:13:26 +02:00
										 |  |  | func (this *OutboundConnectionHandler) Dispatch(destination v2net.Destination, payload *alloc.Buffer, ray ray.OutboundRay) error { | 
					
						
							| 
									
										
										
										
											2015-11-01 21:15:08 +01:00
										 |  |  | 	input := ray.OutboundInput() | 
					
						
							|  |  |  | 	output := ray.OutboundOutput() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 00:13:26 +02:00
										 |  |  | 	this.Destination = destination | 
					
						
							|  |  |  | 	this.ConnOutput.Write(payload.Value) | 
					
						
							|  |  |  | 	payload.Release() | 
					
						
							| 
									
										
										
										
											2015-11-01 21:15:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 00:13:26 +02:00
										 |  |  | 	writeFinish := &sync.Mutex{} | 
					
						
							| 
									
										
										
										
											2015-11-01 21:15:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 00:13:26 +02:00
										 |  |  | 	writeFinish.Lock() | 
					
						
							| 
									
										
										
										
											2015-11-01 21:15:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 00:13:26 +02:00
										 |  |  | 	go func() { | 
					
						
							|  |  |  | 		v2writer := v2io.NewAdaptiveWriter(this.ConnOutput) | 
					
						
							|  |  |  | 		defer v2writer.Release() | 
					
						
							| 
									
										
										
										
											2016-04-18 19:01:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 00:13:26 +02:00
										 |  |  | 		v2io.Pipe(input, v2writer) | 
					
						
							|  |  |  | 		writeFinish.Unlock() | 
					
						
							|  |  |  | 		input.Release() | 
					
						
							|  |  |  | 	}() | 
					
						
							| 
									
										
										
										
											2015-11-01 21:15:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 00:13:26 +02:00
										 |  |  | 	writeFinish.Lock() | 
					
						
							| 
									
										
										
										
											2015-11-01 21:15:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-18 19:01:24 +02:00
										 |  |  | 	v2reader := v2io.NewAdaptiveReader(this.ConnInput) | 
					
						
							|  |  |  | 	defer v2reader.Release() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	v2io.Pipe(v2reader, output) | 
					
						
							| 
									
										
										
										
											2016-04-18 18:44:10 +02:00
										 |  |  | 	output.Close() | 
					
						
							| 
									
										
										
										
											2015-11-01 21:15:08 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-25 17:18:24 +01:00
										 |  |  | func (this *OutboundConnectionHandler) Create(space app.Space, config interface{}) (proxy.OutboundHandler, error) { | 
					
						
							| 
									
										
										
										
											2015-11-01 21:15:08 +01:00
										 |  |  | 	return this, nil | 
					
						
							|  |  |  | } |