Commit 684cc6e9 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Fixed 2 problems.

git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/branches@2795 b35dd754-fafc-0310-a699-88a17e54d16e
parent 5bcc57e4
...@@ -58,22 +58,18 @@ public class TLSStreamReader { ...@@ -58,22 +58,18 @@ public class TLSStreamReader {
* Read TLS encrpyted data from SocketChannel, and use <code>decrypt</code> method to decypt. * Read TLS encrpyted data from SocketChannel, and use <code>decrypt</code> method to decypt.
*/ */
private void doRead() throws IOException { private void doRead() throws IOException {
//inNetBB.clear(); //System.out.println("doRead inNet position: " + inNetBB.position() + " capacity: " + inNetBB.capacity() + " (before read)");
System.out.println("doRead inNet position: " + inNetBB.position());
/*if (lastStatus != TLSStatus.UNDERFLOW) {
inAppBB.clear();
}*/
final int cnt = rbc.read(inNetBB); final int cnt = rbc.read(inNetBB);
if (cnt > 0) { if (cnt > 0) {
System.out.println("doRead inNet position: " + inNetBB.position() + " capacity: " + inNetBB.capacity() + " (after read)"); //System.out.println("doRead inNet position: " + inNetBB.position() + " capacity: " + inNetBB.capacity() + " (after read)");
System.out.println("doRead inAppBB (before decrypt) position: " + inAppBB.position() + " limit: " + inAppBB.limit() + " capacity: " + inAppBB.capacity()); //System.out.println("doRead inAppBB (before decrypt) position: " + inAppBB.position() + " limit: " + inAppBB.limit() + " capacity: " + inAppBB.capacity());
inAppBB = decrypt(inNetBB, inAppBB); inAppBB = decrypt(inNetBB, inAppBB);
System.out.println("doRead inAppBB (after decrypt) position: " + inAppBB.position() + " limit: " + inAppBB.limit() + " capacity: " + inAppBB.capacity() + " lastStatus: " + lastStatus); ///System.out.println("doRead inAppBB (after decrypt) position: " + inAppBB.position() + " limit: " + inAppBB.limit() + " capacity: " + inAppBB.capacity() + " lastStatus: " + lastStatus);
if (lastStatus == TLSStatus.OK) { if (lastStatus == TLSStatus.OK) {
inAppBB.flip(); inAppBB.flip();
} }
else { else {
System.out.println("Intento de nuevo doRead"); //System.out.println("Intento de nuevo doRead");
doRead(); doRead();
} }
} else { } else {
...@@ -93,7 +89,6 @@ public class TLSStreamReader { ...@@ -93,7 +89,6 @@ public class TLSStreamReader {
private ByteBuffer decrypt(ByteBuffer input, ByteBuffer output) throws IOException { private ByteBuffer decrypt(ByteBuffer input, ByteBuffer output) throws IOException {
TLSStatus stat = null; TLSStatus stat = null;
ByteBuffer out = output; ByteBuffer out = output;
//int i = 1;
input.flip(); input.flip();
do { do {
...@@ -104,23 +99,13 @@ public class TLSStreamReader { ...@@ -104,23 +99,13 @@ public class TLSStreamReader {
}*/ }*/
stat = wrapper.getStatus(); stat = wrapper.getStatus();
//if (i > 1) {
//System.out.println(i + " - " + stat + " - " + input.hasRemaining() + " - pos: " + input.position() + " - lim: " + input.limit());
//}
//i++;
} while ((stat == TLSStatus.NEED_READ || stat == TLSStatus.OK) && input.hasRemaining()); } while ((stat == TLSStatus.NEED_READ || stat == TLSStatus.OK) && input.hasRemaining());
if (stat != TLSStatus.OK) {
System.out.println(stat);
}
if (input.hasRemaining()) { if (input.hasRemaining()) {
System.out.println("hasRemaining = true " + stat); //System.out.println("inNetBB has remaining. inNetBB compacted");
System.out.println("Hice rewind"); input.compact();
input.rewind();
} else { } else {
input.clear(); input.clear();
System.out.println("inNet position con clear: " + inNetBB.position() + " / " + input.position());
} }
lastStatus = stat; lastStatus = stat;
...@@ -147,7 +132,13 @@ public class TLSStreamReader { ...@@ -147,7 +132,13 @@ public class TLSStreamReader {
} }
public synchronized int read(byte[] bytes, int off, int len) throws IOException { public synchronized int read(byte[] bytes, int off, int len) throws IOException {
doRead(); if (inAppBB.position() == 0) {
doRead();
}
else {
//System.out.println("XX remaining: " + inAppBB.remaining() + " position: " + inAppBB.position() + " lastStatus: " + lastStatus);
inAppBB.flip();
}
int b = inAppBB.remaining(); int b = inAppBB.remaining();
int len2 = Math.min(len, b); int len2 = Math.min(len, b);
if (len2 == 0) { if (len2 == 0) {
...@@ -155,17 +146,18 @@ public class TLSStreamReader { ...@@ -155,17 +146,18 @@ public class TLSStreamReader {
return -1; return -1;
} }
inAppBB.get(bytes, off, len2); inAppBB.get(bytes, off, len2);
System.out.println("#createInputStream. available in buffer : " + b + " requested: " + len2); if (b != len2) {
//System.out.println("#createInputStream. available in buffer : " + b + " requested: " + len2);
}
if (inAppBB.hasRemaining()) { if (inAppBB.hasRemaining()) {
inAppBB.compact(); inAppBB.compact();
System.out.println("#createInputStream. inAppBB compact position: " + inAppBB.position() + " limit: " + inAppBB.limit()); //System.out.println("#createInputStream. inAppBB compact position: " + inAppBB.position() + " limit: " + inAppBB.limit());
} }
else { else {
inAppBB.clear(); inAppBB.clear();
} }
//inAppBB.compact();
if (len2 <= 0) { if (len2 <= 0) {
System.out.println("????: " + new String(inAppBB.array())); //System.out.println("????: " + new String(inAppBB.array()));
} }
return len2; return len2;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment