1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 01:27:03 -05:00

unify NewPacketReader

This commit is contained in:
Darien Raymond 2019-02-07 19:14:37 +01:00
parent 4f08b7c795
commit b234cfb4c4
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
6 changed files with 17 additions and 6 deletions

View File

@ -73,6 +73,17 @@ func NewReader(reader io.Reader) Reader {
}
}
// NewPacketReader creates a new PacketReader based on the given reader.
func NewPacketReader(reader io.Reader) Reader {
if mr, ok := reader.(Reader); ok {
return mr
}
return &PacketReader{
Reader: reader,
}
}
func isPacketWriter(writer io.Writer) bool {
if _, ok := writer.(net.PacketConn); ok {
return true

View File

@ -131,7 +131,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
}
} else {
connReader = &dns_proto.UDPReader{
Reader: &buf.PacketReader{Reader: conn},
Reader: buf.NewPacketReader(conn),
}
connWriter = &dns_proto.UDPWriter{
Writer: buf.NewWriter(conn),

View File

@ -119,7 +119,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
var reader buf.Reader
if dest.Network == net.Network_UDP {
reader = &buf.PacketReader{Reader: conn}
reader = buf.NewPacketReader(conn)
} else {
reader = buf.NewReader(conn)
}
@ -156,7 +156,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
defer tConn.Close()
writer = &buf.SequentialWriter{Writer: tConn}
tReader := &buf.PacketReader{Reader: tConn}
tReader := buf.NewPacketReader(tConn)
requestCount++
tproxyRequest = func() error {
defer func() {

View File

@ -166,7 +166,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
if destination.Network == net.Network_TCP {
reader = buf.NewReader(conn)
} else {
reader = &buf.PacketReader{Reader: conn}
reader = buf.NewPacketReader(conn)
}
if err := buf.Copy(reader, output, buf.UpdateActivity(timer)); err != nil {
return newError("failed to process response").Base(err)

View File

@ -97,7 +97,7 @@ func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
}
inbound.User = s.user
reader := &buf.PacketReader{Reader: conn}
reader := buf.NewPacketReader(conn)
for {
mpayload, err := reader.ReadMultiBuffer()
if err != nil {

View File

@ -200,7 +200,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
newError("client UDP connection from ", inbound.Source).WriteToLog(session.ExportIDToError(ctx))
}
reader := &buf.PacketReader{Reader: conn}
reader := buf.NewPacketReader(conn)
for {
mpayload, err := reader.ReadMultiBuffer()
if err != nil {