Have encapsulation.ReadData return an error when the buffer is short.

https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/merge_requests/154#note_2919109

Still ignoring the io.ErrShortBuffer at the callers, which retains
current behavior.
This commit is contained in:
David Fifield 2023-11-07 05:49:48 +00:00
parent 001f691b47
commit d99f31d881
4 changed files with 24 additions and 16 deletions

View file

@ -38,10 +38,10 @@ func newEncapsulationPacketConn(
// ReadFrom reads an encapsulated packet from the stream.
func (c *encapsulationPacketConn) ReadFrom(p []byte) (int, net.Addr, error) {
n, err := encapsulation.ReadData(c.ReadWriteCloser, p)
if err != nil {
return n, c.remoteAddr, err
if err == io.ErrShortBuffer {
err = nil
}
return n, c.remoteAddr, nil
return n, c.remoteAddr, err
}
// WriteTo writes an encapsulated packet to the stream.