commit df6aeeca8cc8e953284ce1cb8a0910500579dfaf
Author: Ox Cart <ox.to.a.c...@gmail.com>
Date:   Wed Oct 19 20:18:07 2016 -0500

    Reusing read buffer for readPackets
---
 transports/obfs4/obfs4.go  | 5 +++--
 transports/obfs4/packet.go | 5 ++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/transports/obfs4/obfs4.go b/transports/obfs4/obfs4.go
index 40b1406..304097e 100644
--- a/transports/obfs4/obfs4.go
+++ b/transports/obfs4/obfs4.go
@@ -265,7 +265,7 @@ func (sf *obfs4ServerFactory) WrapConn(conn net.Conn) 
(net.Conn, error) {
                iatDist = probdist.New(sf.iatSeed, 0, maxIATDelay, biasedDist)
        }
 
-       c := &obfs4Conn{conn, true, lenDist, iatDist, sf.iatMode, 
bytes.NewBuffer(nil), bytes.NewBuffer(nil), nil, nil}
+       c := &obfs4Conn{conn, true, lenDist, iatDist, sf.iatMode, 
bytes.NewBuffer(nil), bytes.NewBuffer(nil), make([]byte, consumeReadSize), nil, 
nil}
 
        startTime := time.Now()
 
@@ -288,6 +288,7 @@ type obfs4Conn struct {
 
        receiveBuffer        *bytes.Buffer
        receiveDecodedBuffer *bytes.Buffer
+       readBuffer           []byte
 
        encoder *framing.Encoder
        decoder *framing.Decoder
@@ -311,7 +312,7 @@ func newObfs4ClientConn(conn net.Conn, args 
*obfs4ClientArgs) (c *obfs4Conn, err
        }
 
        // Allocate the client structure.
-       c = &obfs4Conn{conn, false, lenDist, iatDist, args.iatMode, 
bytes.NewBuffer(nil), bytes.NewBuffer(nil), nil, nil}
+       c = &obfs4Conn{conn, false, lenDist, iatDist, args.iatMode, 
bytes.NewBuffer(nil), bytes.NewBuffer(nil), make([]byte, consumeReadSize), nil, 
nil}
 
        // Start the handshake timeout.
        deadline := time.Now().Add(clientHandshakeTimeout)
diff --git a/transports/obfs4/packet.go b/transports/obfs4/packet.go
index 461ad54..5125be6 100644
--- a/transports/obfs4/packet.go
+++ b/transports/obfs4/packet.go
@@ -110,9 +110,8 @@ func (conn *obfs4Conn) makePacket(w io.Writer, pktType 
uint8, data []byte, padLe
 
 func (conn *obfs4Conn) readPackets() (err error) {
        // Attempt to read off the network.
-       var buf [consumeReadSize]byte
-       rdLen, rdErr := conn.Conn.Read(buf[:])
-       conn.receiveBuffer.Write(buf[:rdLen])
+       rdLen, rdErr := conn.Conn.Read(conn.readBuffer)
+       conn.receiveBuffer.Write(conn.readBuffer[:rdLen])
 
        var decoded [framing.MaximumFramePayloadLength]byte
        for conn.receiveBuffer.Len() > 0 {



_______________________________________________
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to