ray.go 910 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package core
  2. import (
  3. "github.com/v2ray/v2ray-core/common/alloc"
  4. )
  5. const (
  6. bufferSize = 16
  7. )
  8. // Ray is an internal tranport channel bewteen inbound and outbound connection.
  9. type Ray struct {
  10. Input chan *alloc.Buffer
  11. Output chan *alloc.Buffer
  12. }
  13. func NewRay() *Ray {
  14. return &Ray{
  15. Input: make(chan *alloc.Buffer, bufferSize),
  16. Output: make(chan *alloc.Buffer, bufferSize),
  17. }
  18. }
  19. type OutboundRay interface {
  20. OutboundInput() <-chan *alloc.Buffer
  21. OutboundOutput() chan<- *alloc.Buffer
  22. }
  23. type InboundRay interface {
  24. InboundInput() chan<- *alloc.Buffer
  25. InboundOutput() <-chan *alloc.Buffer
  26. }
  27. func (ray *Ray) OutboundInput() <-chan *alloc.Buffer {
  28. return ray.Input
  29. }
  30. func (ray *Ray) OutboundOutput() chan<- *alloc.Buffer {
  31. return ray.Output
  32. }
  33. func (ray *Ray) InboundInput() chan<- *alloc.Buffer {
  34. return ray.Input
  35. }
  36. func (ray *Ray) InboundOutput() <-chan *alloc.Buffer {
  37. return ray.Output
  38. }