diff --git a/app/proxyman/outbound/handler.go b/app/proxyman/outbound/handler.go index 804788fee..76208e66f 100644 --- a/app/proxyman/outbound/handler.go +++ b/app/proxyman/outbound/handler.go @@ -122,6 +122,11 @@ func (h *Handler) Dial(ctx context.Context, dest v2net.Destination) (internet.Co return internet.Dial(ctx, dest) } +var ( + _ buf.MultiBufferReader = (*Connection)(nil) + _ buf.MultiBufferWriter = (*Connection)(nil) +) + type Connection struct { stream ray.Ray closed bool @@ -170,11 +175,11 @@ func (v *Connection) Write(b []byte) (int, error) { return buf.ToBytesWriter(v.writer).Write(b) } -func (v *Connection) WriteMultiBuffer(mb buf.MultiBuffer) (int, error) { +func (v *Connection) WriteMultiBuffer(mb buf.MultiBuffer) error { if v.closed { - return 0, io.ErrClosedPipe + return io.ErrClosedPipe } - return mb.Len(), v.writer.Write(mb) + return v.writer.Write(mb) } // Close implements net.Conn.Close(). diff --git a/common/buf/multi_buffer.go b/common/buf/multi_buffer.go index e6d54de3d..5c11c8305 100644 --- a/common/buf/multi_buffer.go +++ b/common/buf/multi_buffer.go @@ -3,7 +3,7 @@ package buf import "net" type MultiBufferWriter interface { - WriteMultiBuffer(MultiBuffer) (int, error) + WriteMultiBuffer(MultiBuffer) error } type MultiBufferReader interface { diff --git a/common/buf/writer.go b/common/buf/writer.go index 262879fd8..988580d1c 100644 --- a/common/buf/writer.go +++ b/common/buf/writer.go @@ -22,8 +22,7 @@ type writerAdapter struct { // Write implements buf.MultiBufferWriter. func (w *writerAdapter) Write(mb MultiBuffer) error { - _, err := w.writer.WriteMultiBuffer(mb) - return err + return w.writer.WriteMultiBuffer(mb) } type mergingWriter struct { @@ -62,6 +61,10 @@ func (w *seqWriter) Write(mb MultiBuffer) error { return nil } +var ( + _ MultiBufferWriter = (*bytesToBufferWriter)(nil) +) + type bytesToBufferWriter struct { writer Writer } @@ -81,8 +84,8 @@ func (w *bytesToBufferWriter) Write(payload []byte) (int, error) { return len(payload), nil } -func (w *bytesToBufferWriter) WriteMultiBuffer(mb MultiBuffer) (int, error) { - return mb.Len(), w.writer.Write(mb) +func (w *bytesToBufferWriter) WriteMultiBuffer(mb MultiBuffer) error { + return w.writer.Write(mb) } func (w *bytesToBufferWriter) ReadFrom(reader io.Reader) (int64, error) { diff --git a/common/crypto/io.go b/common/crypto/io.go index 133094f7b..60e593e52 100644 --- a/common/crypto/io.go +++ b/common/crypto/io.go @@ -27,6 +27,10 @@ func (r *CryptionReader) Read(data []byte) (int, error) { return nBytes, err } +var ( + _ buf.MultiBufferWriter = (*CryptionWriter)(nil) +) + type CryptionWriter struct { stream cipher.Stream writer io.Writer @@ -46,11 +50,11 @@ func (w *CryptionWriter) Write(data []byte) (int, error) { return w.writer.Write(data) } -func (w *CryptionWriter) WriteMultiBuffer(mb buf.MultiBuffer) (int, error) { +func (w *CryptionWriter) WriteMultiBuffer(mb buf.MultiBuffer) error { bs := mb.ToNetBuffers() for _, b := range bs { w.stream.XORKeyStream(b, b) } - nBytes, err := bs.WriteTo(w.writer) - return int(nBytes), err + _, err := bs.WriteTo(w.writer) + return err } diff --git a/transport/internet/kcp/connection.go b/transport/internet/kcp/connection.go index a395a162a..5dd15705d 100644 --- a/transport/internet/kcp/connection.go +++ b/transport/internet/kcp/connection.go @@ -375,11 +375,11 @@ func (v *Connection) Write(b []byte) (int, error) { } } -func (c *Connection) WriteMultiBuffer(mb buf.MultiBuffer) (int, error) { +func (c *Connection) WriteMultiBuffer(mb buf.MultiBuffer) error { if c.mergingWriter == nil { c.mergingWriter = buf.NewMergingWriterSize(c, c.mss) } - return mb.Len(), c.mergingWriter.Write(mb) + return c.mergingWriter.Write(mb) } func (v *Connection) SetState(state State) { diff --git a/transport/internet/tls/tls.go b/transport/internet/tls/tls.go index 4b4f3f689..12f5a155a 100644 --- a/transport/internet/tls/tls.go +++ b/transport/internet/tls/tls.go @@ -9,6 +9,11 @@ import ( //go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg tls -path Transport,Internet,TLS +var ( + _ buf.MultiBufferReader = (*conn)(nil) + _ buf.MultiBufferWriter = (*conn)(nil) +) + type conn struct { net.Conn @@ -23,11 +28,11 @@ func (c *conn) ReadMultiBuffer() (buf.MultiBuffer, error) { return c.mergingReader.Read() } -func (c *conn) WriteMultiBuffer(mb buf.MultiBuffer) (int, error) { +func (c *conn) WriteMultiBuffer(mb buf.MultiBuffer) error { if c.mergingWriter == nil { c.mergingWriter = buf.NewMergingWriter(c.Conn) } - return mb.Len(), c.mergingWriter.Write(mb) + return c.mergingWriter.Write(mb) } func Client(c net.Conn, config *tls.Config) net.Conn { diff --git a/transport/internet/websocket/connection.go b/transport/internet/websocket/connection.go index 01bfccef2..5b7db36d3 100644 --- a/transport/internet/websocket/connection.go +++ b/transport/internet/websocket/connection.go @@ -69,11 +69,11 @@ func (c *connection) Write(b []byte) (int, error) { return len(b), nil } -func (c *connection) WriteMultiBuffer(mb buf.MultiBuffer) (int, error) { +func (c *connection) WriteMultiBuffer(mb buf.MultiBuffer) error { if c.mergingWriter == nil { c.mergingWriter = buf.NewMergingWriter(c) } - return mb.Len(), c.mergingWriter.Write(mb) + return c.mergingWriter.Write(mb) } func (c *connection) Close() error {