1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-27 14:47:59 +01:00

SMACK-524 Use correct block-size definition for IBB transfers

Revert IBB related changes introduced by SMACK-349 to use the correct
block size for IBB transfers.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_4_0@13863 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Florian Schmaus 2014-01-17 11:24:07 +00:00 committed by flow
parent c143f0de25
commit 962bd277f1
3 changed files with 46 additions and 48 deletions

View file

@ -594,7 +594,7 @@ public class InBandBytestreamSession implements BytestreamSession {
* Constructor.
*/
public IBBOutputStream() {
this.buffer = new byte[(byteStreamRequest.getBlockSize()/4)*3];
this.buffer = new byte[byteStreamRequest.getBlockSize()];
}
/**

View file

@ -57,7 +57,6 @@ public class InBandBytestreamSessionMessageTest {
String sessionID = "session_id";
int blockSize = 10;
int dataSize = blockSize/4 * 3;
// protocol verifier
Protocol protocol;
@ -120,7 +119,7 @@ public class InBandBytestreamSessionMessageTest {
protocol.addResponse(null, incrementingSequence);
protocol.addResponse(null, incrementingSequence);
byte[] controlData = new byte[dataSize * 3];
byte[] controlData = new byte[blockSize * 3];
OutputStream outputStream = session.getOutputStream();
outputStream.write(controlData);
@ -145,7 +144,7 @@ public class InBandBytestreamSessionMessageTest {
protocol.addResponse(null, incrementingSequence);
protocol.addResponse(null, incrementingSequence);
byte[] controlData = new byte[dataSize * 3];
byte[] controlData = new byte[blockSize * 3];
OutputStream outputStream = session.getOutputStream();
for (byte b : controlData) {
@ -172,11 +171,11 @@ public class InBandBytestreamSessionMessageTest {
protocol.addResponse(null, incrementingSequence);
protocol.addResponse(null, incrementingSequence);
byte[] controlData = new byte[(dataSize * 3) - 2];
byte[] controlData = new byte[(blockSize * 3) - 2];
OutputStream outputStream = session.getOutputStream();
int off = 0;
for (int i = 1; off+i <= controlData.length; i++) {
for (int i = 1; i <= 7; i++) {
outputStream.write(controlData, off, i);
off += i;
}
@ -193,7 +192,7 @@ public class InBandBytestreamSessionMessageTest {
*/
@Test
public void shouldSendThirtyDataPackets() throws Exception {
byte[] controlData = new byte[dataSize * 3];
byte[] controlData = new byte[blockSize * 3];
InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
initiatorJID);
@ -220,7 +219,7 @@ public class InBandBytestreamSessionMessageTest {
*/
@Test
public void shouldSendNothingOnSuccessiveCallsToFlush() throws Exception {
byte[] controlData = new byte[dataSize * 3];
byte[] controlData = new byte[blockSize * 3];
InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
initiatorJID);
@ -291,7 +290,7 @@ public class InBandBytestreamSessionMessageTest {
public void shouldReadAllReceivedData1() throws Exception {
// create random data
Random rand = new Random();
byte[] controlData = new byte[3 * dataSize];
byte[] controlData = new byte[3 * blockSize];
rand.nextBytes(controlData);
// get IBB sessions data packet listener
@ -301,8 +300,8 @@ public class InBandBytestreamSessionMessageTest {
PacketListener listener = Whitebox.getInternalState(inputStream, PacketListener.class);
// verify data packet and notify listener
for (int i = 0; i < controlData.length / dataSize; i++) {
String base64Data = StringUtils.encodeBase64(controlData, i * dataSize, dataSize,
for (int i = 0; i < controlData.length / blockSize; i++) {
String base64Data = StringUtils.encodeBase64(controlData, i * blockSize, blockSize,
false);
DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data);
Message dataMessage = new Message();
@ -310,14 +309,14 @@ public class InBandBytestreamSessionMessageTest {
listener.processPacket(dataMessage);
}
byte[] bytes = new byte[3 * dataSize];
byte[] bytes = new byte[3 * blockSize];
int read = 0;
read = inputStream.read(bytes, 0, dataSize);
assertEquals(dataSize, read);
read = inputStream.read(bytes, dataSize, dataSize);
assertEquals(dataSize, read);
read = inputStream.read(bytes, dataSize*2, dataSize);
assertEquals(dataSize, read);
read = inputStream.read(bytes, 0, blockSize);
assertEquals(blockSize, read);
read = inputStream.read(bytes, 10, blockSize);
assertEquals(blockSize, read);
read = inputStream.read(bytes, 20, blockSize);
assertEquals(blockSize, read);
// verify data
for (int i = 0; i < bytes.length; i++) {
@ -337,7 +336,7 @@ public class InBandBytestreamSessionMessageTest {
public void shouldReadAllReceivedData2() throws Exception {
// create random data
Random rand = new Random();
byte[] controlData = new byte[3 * dataSize];
byte[] controlData = new byte[3 * blockSize];
rand.nextBytes(controlData);
// get IBB sessions data packet listener
@ -347,8 +346,8 @@ public class InBandBytestreamSessionMessageTest {
PacketListener listener = Whitebox.getInternalState(inputStream, PacketListener.class);
// verify data packet and notify listener
for (int i = 0; i < controlData.length / dataSize; i++) {
String base64Data = StringUtils.encodeBase64(controlData, i * dataSize, dataSize,
for (int i = 0; i < controlData.length / blockSize; i++) {
String base64Data = StringUtils.encodeBase64(controlData, i * blockSize, blockSize,
false);
DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data);
Message dataMessage = new Message();
@ -357,7 +356,7 @@ public class InBandBytestreamSessionMessageTest {
}
// read data
byte[] bytes = new byte[3 * dataSize];
byte[] bytes = new byte[3 * blockSize];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) inputStream.read();
}

View file

@ -57,8 +57,7 @@ public class InBandBytestreamSessionTest {
String xmppServer = "xmpp-server";
String sessionID = "session_id";
int blockSize = 20;
int dataSize = blockSize/4 * 3;
int blockSize = 10;
// protocol verifier
Protocol protocol;
@ -120,7 +119,7 @@ public class InBandBytestreamSessionTest {
protocol.addResponse(resultIQ, incrementingSequence);
protocol.addResponse(resultIQ, incrementingSequence);
byte[] controlData = new byte[dataSize * 3];
byte[] controlData = new byte[blockSize * 3];
OutputStream outputStream = session.getOutputStream();
outputStream.write(controlData);
@ -146,7 +145,7 @@ public class InBandBytestreamSessionTest {
protocol.addResponse(resultIQ, incrementingSequence);
protocol.addResponse(resultIQ, incrementingSequence);
byte[] controlData = new byte[dataSize * 3];
byte[] controlData = new byte[blockSize * 3];
OutputStream outputStream = session.getOutputStream();
for (byte b : controlData) {
@ -174,11 +173,11 @@ public class InBandBytestreamSessionTest {
protocol.addResponse(resultIQ, incrementingSequence);
protocol.addResponse(resultIQ, incrementingSequence);
byte[] controlData = new byte[(dataSize * 3) - 2];
byte[] controlData = new byte[(blockSize * 3) - 2];
OutputStream outputStream = session.getOutputStream();
int off = 0;
for (int i = 1; i+off <= controlData.length; i++) {
for (int i = 1; i <= 7; i++) {
outputStream.write(controlData, off, i);
off += i;
}
@ -195,7 +194,7 @@ public class InBandBytestreamSessionTest {
*/
@Test
public void shouldSendThirtyDataPackets() throws Exception {
byte[] controlData = new byte[dataSize * 3];
byte[] controlData = new byte[blockSize * 3];
InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
initiatorJID);
@ -223,7 +222,7 @@ public class InBandBytestreamSessionTest {
*/
@Test
public void shouldSendNothingOnSuccessiveCallsToFlush() throws Exception {
byte[] controlData = new byte[dataSize * 3];
byte[] controlData = new byte[blockSize * 3];
InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream,
initiatorJID);
@ -254,7 +253,7 @@ public class InBandBytestreamSessionTest {
public void shouldSendDataCorrectly() throws Exception {
// create random data
Random rand = new Random();
final byte[] controlData = new byte[256 * dataSize];
final byte[] controlData = new byte[256 * blockSize];
rand.nextBytes(controlData);
// compares the data of each packet with the control data
@ -264,7 +263,7 @@ public class InBandBytestreamSessionTest {
byte[] decodedData = request.getDataPacketExtension().getDecodedData();
int seq = (int) request.getDataPacketExtension().getSeq();
for (int i = 0; i < decodedData.length; i++) {
assertEquals(controlData[(seq * dataSize) + i], decodedData[i]);
assertEquals(controlData[(seq * blockSize) + i], decodedData[i]);
}
}
@ -272,7 +271,7 @@ public class InBandBytestreamSessionTest {
// set acknowledgments for the data packets
IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID);
for (int i = 0; i < controlData.length / dataSize; i++) {
for (int i = 0; i < controlData.length / blockSize; i++) {
protocol.addResponse(resultIQ, incrementingSequence, dataVerification);
}
@ -480,7 +479,7 @@ public class InBandBytestreamSessionTest {
public void shouldReadAllReceivedData1() throws Exception {
// create random data
Random rand = new Random();
byte[] controlData = new byte[3 * dataSize];
byte[] controlData = new byte[3 * blockSize];
rand.nextBytes(controlData);
IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID);
@ -491,24 +490,24 @@ public class InBandBytestreamSessionTest {
InputStream inputStream = session.getInputStream();
PacketListener listener = Whitebox.getInternalState(inputStream, PacketListener.class);
// set data packet acknowledgement and notify listener
for (int i = 0; i < controlData.length / dataSize; i++) {
// set data packet acknowledgment and notify listener
for (int i = 0; i < controlData.length / blockSize; i++) {
protocol.addResponse(resultIQ);
String base64Data = StringUtils.encodeBase64(controlData, i * dataSize, dataSize,
String base64Data = StringUtils.encodeBase64(controlData, i * blockSize, blockSize,
false);
DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data);
Data data = new Data(dpe);
listener.processPacket(data);
}
byte[] bytes = new byte[3 * dataSize];
byte[] bytes = new byte[3 * blockSize];
int read = 0;
read = inputStream.read(bytes, 0, dataSize);
assertEquals(dataSize, read);
read = inputStream.read(bytes, dataSize, dataSize);
assertEquals(dataSize, read);
read = inputStream.read(bytes, dataSize*2, dataSize);
assertEquals(dataSize, read);
read = inputStream.read(bytes, 0, blockSize);
assertEquals(blockSize, read);
read = inputStream.read(bytes, 10, blockSize);
assertEquals(blockSize, read);
read = inputStream.read(bytes, 20, blockSize);
assertEquals(blockSize, read);
// verify data
for (int i = 0; i < bytes.length; i++) {
@ -528,7 +527,7 @@ public class InBandBytestreamSessionTest {
public void shouldReadAllReceivedData2() throws Exception {
// create random data
Random rand = new Random();
byte[] controlData = new byte[3 * dataSize];
byte[] controlData = new byte[3 * blockSize];
rand.nextBytes(controlData);
IQ resultIQ = IBBPacketUtils.createResultIQ(initiatorJID, targetJID);
@ -540,9 +539,9 @@ public class InBandBytestreamSessionTest {
PacketListener listener = Whitebox.getInternalState(inputStream, PacketListener.class);
// set data packet acknowledgment and notify listener
for (int i = 0; i < controlData.length / dataSize; i++) {
for (int i = 0; i < controlData.length / blockSize; i++) {
protocol.addResponse(resultIQ);
String base64Data = StringUtils.encodeBase64(controlData, i * dataSize, dataSize,
String base64Data = StringUtils.encodeBase64(controlData, i * blockSize, blockSize,
false);
DataPacketExtension dpe = new DataPacketExtension(sessionID, i, base64Data);
Data data = new Data(dpe);
@ -550,7 +549,7 @@ public class InBandBytestreamSessionTest {
}
// read data
byte[] bytes = new byte[3 * dataSize];
byte[] bytes = new byte[3 * blockSize];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) inputStream.read();
}