mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
unify NewPacketReader
This commit is contained in:
parent
4f08b7c795
commit
b234cfb4c4
@ -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 {
|
func isPacketWriter(writer io.Writer) bool {
|
||||||
if _, ok := writer.(net.PacketConn); ok {
|
if _, ok := writer.(net.PacketConn); ok {
|
||||||
return true
|
return true
|
||||||
|
@ -131,7 +131,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
connReader = &dns_proto.UDPReader{
|
connReader = &dns_proto.UDPReader{
|
||||||
Reader: &buf.PacketReader{Reader: conn},
|
Reader: buf.NewPacketReader(conn),
|
||||||
}
|
}
|
||||||
connWriter = &dns_proto.UDPWriter{
|
connWriter = &dns_proto.UDPWriter{
|
||||||
Writer: buf.NewWriter(conn),
|
Writer: buf.NewWriter(conn),
|
||||||
|
@ -119,7 +119,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
|||||||
|
|
||||||
var reader buf.Reader
|
var reader buf.Reader
|
||||||
if dest.Network == net.Network_UDP {
|
if dest.Network == net.Network_UDP {
|
||||||
reader = &buf.PacketReader{Reader: conn}
|
reader = buf.NewPacketReader(conn)
|
||||||
} else {
|
} else {
|
||||||
reader = buf.NewReader(conn)
|
reader = buf.NewReader(conn)
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
|||||||
defer tConn.Close()
|
defer tConn.Close()
|
||||||
|
|
||||||
writer = &buf.SequentialWriter{Writer: tConn}
|
writer = &buf.SequentialWriter{Writer: tConn}
|
||||||
tReader := &buf.PacketReader{Reader: tConn}
|
tReader := buf.NewPacketReader(tConn)
|
||||||
requestCount++
|
requestCount++
|
||||||
tproxyRequest = func() error {
|
tproxyRequest = func() error {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -166,7 +166,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||||||
if destination.Network == net.Network_TCP {
|
if destination.Network == net.Network_TCP {
|
||||||
reader = buf.NewReader(conn)
|
reader = buf.NewReader(conn)
|
||||||
} else {
|
} else {
|
||||||
reader = &buf.PacketReader{Reader: conn}
|
reader = buf.NewPacketReader(conn)
|
||||||
}
|
}
|
||||||
if err := buf.Copy(reader, output, buf.UpdateActivity(timer)); err != nil {
|
if err := buf.Copy(reader, output, buf.UpdateActivity(timer)); err != nil {
|
||||||
return newError("failed to process response").Base(err)
|
return newError("failed to process response").Base(err)
|
||||||
|
@ -97,7 +97,7 @@ func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
|
|||||||
}
|
}
|
||||||
inbound.User = s.user
|
inbound.User = s.user
|
||||||
|
|
||||||
reader := &buf.PacketReader{Reader: conn}
|
reader := buf.NewPacketReader(conn)
|
||||||
for {
|
for {
|
||||||
mpayload, err := reader.ReadMultiBuffer()
|
mpayload, err := reader.ReadMultiBuffer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -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))
|
newError("client UDP connection from ", inbound.Source).WriteToLog(session.ExportIDToError(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
reader := &buf.PacketReader{Reader: conn}
|
reader := buf.NewPacketReader(conn)
|
||||||
for {
|
for {
|
||||||
mpayload, err := reader.ReadMultiBuffer()
|
mpayload, err := reader.ReadMultiBuffer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user