I tried to send a file from Smack to SleekXMPP.
SleekXMPP currently supports only IBB (In-band Bytestream), the negotiation works fine.
But when Smack sends its first data packet, SleekXMPP shows the following message:
Bad file transfer packet received! Terminating session with SENDER_JID
seq 0: expected seq: 0
packet size: 5400 Max Block size: 4096
I checked org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java class
It turns out to be Smack that use a wrong buffer size.
XEP-0047 said "The base64-encoded data to be sent, prior to any wrapping in the <data/> element and IQ or message stanza, MUST NOT be larger' than the 'block-size' determined in the bytestream negotiation."
I think that block-size should be the length of 'base64-encoded data', which is longer than the actual data itself.
So, if we let the block-size=4096, the buffer size should be (4096 / 4)*3 = 3072 bytes.
(3 bytes of data will be encoded as 4 characters in base64 encoding)
I'd like to submit a patch to org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java (Smack 3.2.1)
with following buffer size calculation:
/* Old */
public IBBOutputStream() {
this.buffer = new byte[byteStreamRequest.getBlockSize()];
}
/* New */
public IBBOutputStream() {
int maximumBytesPerPacket = (byteStreamRequest.getBlockSize() / 4) *3;
this.buffer = new byte[maximumBytesPerPacket];
}