mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-27 00:32:07 +01:00
Throttle for IBB
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3416 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
d323d6db9c
commit
d1ed521726
1 changed files with 24 additions and 9 deletions
|
@ -27,6 +27,7 @@ import org.jivesoftware.smack.filter.*;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
import org.jivesoftware.smackx.packet.IBBExtensions;
|
import org.jivesoftware.smackx.packet.IBBExtensions;
|
||||||
import org.jivesoftware.smackx.packet.IBBExtensions.Open;
|
import org.jivesoftware.smackx.packet.IBBExtensions.Open;
|
||||||
import org.jivesoftware.smackx.packet.StreamInitiation;
|
import org.jivesoftware.smackx.packet.StreamInitiation;
|
||||||
|
@ -206,7 +207,7 @@ public class IBBTransferNegotiator extends StreamNegotiator {
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeToXML(byte[] buffer, int offset, int len) {
|
private synchronized void writeToXML(byte[] buffer, int offset, int len) {
|
||||||
Message template = createTemplate(messageID + "_" + seq);
|
Message template = createTemplate(messageID + "_" + seq);
|
||||||
IBBExtensions.Data ext = new IBBExtensions.Data(sid);
|
IBBExtensions.Data ext = new IBBExtensions.Data(sid);
|
||||||
template.addExtension(ext);
|
template.addExtension(ext);
|
||||||
|
@ -215,6 +216,13 @@ public class IBBTransferNegotiator extends StreamNegotiator {
|
||||||
|
|
||||||
ext.setData(enc);
|
ext.setData(enc);
|
||||||
ext.setSeq(seq);
|
ext.setSeq(seq);
|
||||||
|
synchronized(this) {
|
||||||
|
try {
|
||||||
|
this.wait(100);
|
||||||
|
}
|
||||||
|
catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
connection.sendPacket(template);
|
connection.sendPacket(template);
|
||||||
|
|
||||||
|
@ -260,6 +268,8 @@ public class IBBTransferNegotiator extends StreamNegotiator {
|
||||||
|
|
||||||
private IQ closeConfirmation;
|
private IQ closeConfirmation;
|
||||||
|
|
||||||
|
private Message lastMess;
|
||||||
|
|
||||||
private IBBInputStream(String streamID, PacketFilter dataFilter,
|
private IBBInputStream(String streamID, PacketFilter dataFilter,
|
||||||
PacketFilter closeFilter) {
|
PacketFilter closeFilter) {
|
||||||
this.streamID = streamID;
|
this.streamID = streamID;
|
||||||
|
@ -319,22 +329,23 @@ public class IBBTransferNegotiator extends StreamNegotiator {
|
||||||
mess = (Message) dataCollector.nextResult(1000);
|
mess = (Message) dataCollector.nextResult(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lastMess = mess;
|
||||||
data = (IBBExtensions.Data) mess.getExtension(
|
data = (IBBExtensions.Data) mess.getExtension(
|
||||||
IBBExtensions.Data.ELEMENT_NAME,
|
IBBExtensions.Data.ELEMENT_NAME,
|
||||||
IBBExtensions.NAMESPACE);
|
IBBExtensions.NAMESPACE);
|
||||||
|
|
||||||
checkSequence((int) data.getSeq());
|
checkSequence(mess, (int) data.getSeq());
|
||||||
buffer = Base64.decode(data.getData());
|
buffer = Base64.decode(data.getData());
|
||||||
bufferPointer = 0;
|
bufferPointer = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkSequence(int seq) throws IOException {
|
private void checkSequence(Message mess, int seq) throws IOException {
|
||||||
if (this.seq == 65535) {
|
if (this.seq == 65535) {
|
||||||
this.seq = -1;
|
this.seq = -1;
|
||||||
}
|
}
|
||||||
if (seq - 1 != this.seq) {
|
if (seq - 1 != this.seq) {
|
||||||
cancelTransfer();
|
cancelTransfer(mess);
|
||||||
throw new IOException("Packets out of sequence");
|
throw new IOException("Packets out of sequence");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -342,10 +353,10 @@ public class IBBTransferNegotiator extends StreamNegotiator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cancelTransfer() {
|
private void cancelTransfer(Message mess) {
|
||||||
cleanup();
|
cleanup();
|
||||||
|
|
||||||
sendCancelMessage();
|
sendCancelMessage(mess);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanup() {
|
private void cleanup() {
|
||||||
|
@ -353,7 +364,11 @@ public class IBBTransferNegotiator extends StreamNegotiator {
|
||||||
connection.removePacketListener(this);
|
connection.removePacketListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendCancelMessage() {
|
private void sendCancelMessage(Message message) {
|
||||||
|
IQ error = FileTransferNegotiator.createIQ(message.getPacketID(), message.getFrom(), message.getTo(),
|
||||||
|
IQ.Type.ERROR);
|
||||||
|
error.setError(new XMPPError(504));
|
||||||
|
connection.sendPacket(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean markSupported() {
|
public boolean markSupported() {
|
||||||
|
@ -379,8 +394,8 @@ public class IBBTransferNegotiator extends StreamNegotiator {
|
||||||
if (isEOF) {
|
if (isEOF) {
|
||||||
sendCloseConfirmation();
|
sendCloseConfirmation();
|
||||||
}
|
}
|
||||||
else {
|
else if(lastMess != null) {
|
||||||
sendCancelMessage();
|
sendCancelMessage(lastMess);
|
||||||
}
|
}
|
||||||
isClosed = true;
|
isClosed = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue