2015-09-12 20:11:54 +00:00
|
|
|
package core
|
|
|
|
|
2015-10-08 12:46:18 +00:00
|
|
|
import (
|
|
|
|
"github.com/v2ray/v2ray-core/common/alloc"
|
|
|
|
)
|
|
|
|
|
2015-09-14 11:51:30 +00:00
|
|
|
const (
|
2015-09-14 16:19:17 +00:00
|
|
|
bufferSize = 16
|
2015-09-14 11:51:30 +00:00
|
|
|
)
|
|
|
|
|
2015-09-22 12:45:03 +00:00
|
|
|
// Ray is an internal tranport channel bewteen inbound and outbound connection.
|
2015-09-12 20:11:54 +00:00
|
|
|
type Ray struct {
|
2015-10-08 12:46:18 +00:00
|
|
|
Input chan *alloc.Buffer
|
|
|
|
Output chan *alloc.Buffer
|
2015-09-12 20:11:54 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 12:45:03 +00:00
|
|
|
func NewRay() *Ray {
|
|
|
|
return &Ray{
|
2015-10-08 12:46:18 +00:00
|
|
|
Input: make(chan *alloc.Buffer, bufferSize),
|
|
|
|
Output: make(chan *alloc.Buffer, bufferSize),
|
2015-09-16 15:07:05 +00:00
|
|
|
}
|
2015-09-12 20:11:54 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 10:46:44 +00:00
|
|
|
// OutboundRay is a transport interface for outbound connections.
|
2015-09-12 20:11:54 +00:00
|
|
|
type OutboundRay interface {
|
2015-10-10 10:46:44 +00:00
|
|
|
// OutboundInput provides a stream for the input of the outbound connection.
|
|
|
|
// The outbound connection shall write all the input until it is closed.
|
2015-10-08 12:46:18 +00:00
|
|
|
OutboundInput() <-chan *alloc.Buffer
|
2015-10-10 10:46:44 +00:00
|
|
|
|
|
|
|
// OutboundOutput provides a stream to retrieve the response from the
|
|
|
|
// outbound connection. The outbound connection shall close the channel
|
|
|
|
// after all responses are receivced and put into the channel.
|
2015-10-08 12:46:18 +00:00
|
|
|
OutboundOutput() chan<- *alloc.Buffer
|
2015-09-12 20:11:54 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 10:46:44 +00:00
|
|
|
// InboundRay is a transport interface for inbound connections.
|
2015-09-12 20:11:54 +00:00
|
|
|
type InboundRay interface {
|
2015-10-10 10:46:44 +00:00
|
|
|
// InboundInput provides a stream to retrieve the request from client.
|
|
|
|
// The inbound connection shall close the channel after the entire request
|
|
|
|
// is received and put into the channel.
|
2015-10-08 12:46:18 +00:00
|
|
|
InboundInput() chan<- *alloc.Buffer
|
2015-10-10 10:46:44 +00:00
|
|
|
|
|
|
|
// InboudBound provides a stream of data for the inbound connection to write
|
|
|
|
// as response. The inbound connection shall write all the data from the
|
|
|
|
// channel until it is closed.
|
2015-10-08 12:46:18 +00:00
|
|
|
InboundOutput() <-chan *alloc.Buffer
|
2015-09-12 20:11:54 +00:00
|
|
|
}
|
|
|
|
|
2015-10-08 12:46:18 +00:00
|
|
|
func (ray *Ray) OutboundInput() <-chan *alloc.Buffer {
|
2015-09-12 20:11:54 +00:00
|
|
|
return ray.Input
|
|
|
|
}
|
|
|
|
|
2015-10-08 12:46:18 +00:00
|
|
|
func (ray *Ray) OutboundOutput() chan<- *alloc.Buffer {
|
2015-09-12 20:11:54 +00:00
|
|
|
return ray.Output
|
|
|
|
}
|
|
|
|
|
2015-10-08 12:46:18 +00:00
|
|
|
func (ray *Ray) InboundInput() chan<- *alloc.Buffer {
|
2015-09-12 20:11:54 +00:00
|
|
|
return ray.Input
|
|
|
|
}
|
|
|
|
|
2015-10-08 12:46:18 +00:00
|
|
|
func (ray *Ray) InboundOutput() <-chan *alloc.Buffer {
|
2015-09-12 20:11:54 +00:00
|
|
|
return ray.Output
|
|
|
|
}
|