Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TorOutputStream improvments #8

Open
n0rbyt3 opened this issue Jan 7, 2014 · 0 comments
Open

TorOutputStream improvments #8

n0rbyt3 opened this issue Jan 7, 2014 · 0 comments

Comments

@n0rbyt3
Copy link

n0rbyt3 commented Jan 7, 2014

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant