Browse Source

comments

pull/692/head^2
Darien Raymond 7 years ago
parent
commit
c3fc27f7a1
  1. 7
      app/proxyman/mux/reader.go
  2. 2
      app/proxyman/mux/session.go

7
app/proxyman/mux/reader.go

@ -7,6 +7,7 @@ import (
"v2ray.com/core/common/serial"
)
// ReadMetadata reads FrameMetadata from the given reader.
func ReadMetadata(reader io.Reader) (*FrameMetadata, error) {
metaLen, err := serial.ReadUint16(reader)
if err != nil {
@ -25,11 +26,13 @@ func ReadMetadata(reader io.Reader) (*FrameMetadata, error) {
return ReadFrameFrom(b.Bytes())
}
// PacketReader is an io.Reader that reads whole chunk of Mux frames every time.
type PacketReader struct {
reader io.Reader
eof bool
}
// NewPacketReader creates a new PacketReader.
func NewPacketReader(reader io.Reader) *PacketReader {
return &PacketReader{
reader: reader,
@ -37,6 +40,7 @@ func NewPacketReader(reader io.Reader) *PacketReader {
}
}
// Read implements buf.Reader.
func (r *PacketReader) Read() (buf.MultiBuffer, error) {
if r.eof {
return nil, io.EOF
@ -61,11 +65,13 @@ func (r *PacketReader) Read() (buf.MultiBuffer, error) {
return buf.NewMultiBufferValue(b), nil
}
// StreamReader reads Mux frame as a stream.
type StreamReader struct {
reader io.Reader
leftOver int
}
// NewStreamReader creates a new StreamReader.
func NewStreamReader(reader io.Reader) *StreamReader {
return &StreamReader{
reader: reader,
@ -73,6 +79,7 @@ func NewStreamReader(reader io.Reader) *StreamReader {
}
}
// Read implmenets buf.Reader.
func (r *StreamReader) Read() (buf.MultiBuffer, error) {
if r.leftOver == 0 {
r.leftOver = -1

2
app/proxyman/mux/session.go

@ -122,6 +122,7 @@ func (m *SessionManager) Close() {
m.sessions = nil
}
// Session represents a client connection in a Mux connection.
type Session struct {
input ray.InputStream
output ray.OutputStream
@ -137,6 +138,7 @@ func (s *Session) Close() {
s.parent.Remove(s.ID)
}
// NewReader creates a buf.Reader based on the transfer type of this Session.
func (s *Session) NewReader(reader io.Reader) buf.Reader {
if s.transferType == protocol.TransferTypeStream {
return NewStreamReader(reader)

Loading…
Cancel
Save