Skip to content

TorOutputStream improvments #8

Open

Description

@n0rbyt3

Hey guys,

finally, I could use OrchIdSocketImplFactory as tunnel for any socket connections. I went into the problem that nothing was written to the OutputStream, but after disabling the OrchIdSocketImplFactory the program ran fine. I spent hours for debugging the streams and found two possible fixes.

The problem:

A ServerSocket, that accepts a client Socket instantiates a java.net.SocketOutputStream. This class extends FileOutputStream aand immediately writes the data received by the 2 "write" methods out. The "flush" method is empty and is also never called by the application. So if I write 3 bytes, 3 bytes are really written. This causes traffic by sending many small packets, but the stream doesn't wait until its fulfilled (512 bytes).

The fix:

@Override
public synchronized void write(int b) throws IOException {
    checkOpen();
    if(currentOutputCell == null)
        flushCurrentOutputCell();
    currentOutputCell.putByte(b);
    flushCurrentOutputCell();
}

public synchronized void write(byte[] data, int offset, int length) throws IOException {
    checkOpen();
    if(currentOutputCell == null)
        flushCurrentOutputCell();

    while(length > 0) {
        final int writeCount = Math.min(length, currentOutputCell.cellBytesRemaining());
        currentOutputCell.putByteArray(data, offset, writeCount);
        flushCurrentOutputCell();
        offset += writeCount;
        length -= writeCount;
    }
}

I didn't test the socks listener, may this cause any additional problems?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions