progress for ibb transfers

This commit is contained in:
iNPUTmice 2014-11-14 14:04:34 +01:00
parent e7a70a46e0
commit af2922adea
5 changed files with 27 additions and 13 deletions

View file

@ -21,6 +21,8 @@ public final class Config {
public static final boolean PARSE_EMOTICONS = false;
public static final int PROGRESS_UI_UPDATE_INTERVAL = 750;
public static final boolean NO_PROXY_LOOKUP = false; //useful to debug ibb
private Config() {
}

View file

@ -98,7 +98,7 @@ public class JingleConnection implements Downloadable {
Message.STATUS_RECEIVED);
} else {
message.setDownloadable(null);
if (message.getEncryption() != Message.ENCRYPTION_PGP) {
if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
file.delete();
}
}
@ -664,8 +664,7 @@ public class JingleConnection implements Downloadable {
}
}
this.transportId = packet.getJingleContent().getTransportId();
this.transport = new JingleInbandTransport(this.account,
this.responder, this.transportId, this.ibbBlockSize);
this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize);
this.transport.receive(file, onFileTransmissionSatusChanged);
JinglePacket answer = bootstrapPacket("transport-accept");
Content content = new Content("initiator", "a-file-offer");
@ -687,8 +686,7 @@ public class JingleConnection implements Downloadable {
this.ibbBlockSize = bs;
}
}
this.transport = new JingleInbandTransport(this.account,
this.responder, this.transportId, this.ibbBlockSize);
this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize);
this.transport.connect(new OnTransportConnected() {
@Override

View file

@ -75,6 +75,10 @@ public class JingleConnectionManager extends AbstractConnectionManager {
public void getPrimaryCandidate(Account account,
final OnPrimaryCandidateFound listener) {
if (Config.NO_PROXY_LOOKUP) {
listener.onPrimaryCandidateFound(false, null);
return;
}
if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) {
String xmlns = "http://jabber.org/protocol/bytestreams";
final String proxy = account.getXmppConnection()

View file

@ -8,6 +8,7 @@ import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import android.util.Base64;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.utils.CryptoHelper;
@ -28,10 +29,12 @@ public class JingleInbandTransport extends JingleTransport {
private boolean established = false;
private DownloadableFile file;
private JingleConnection connection;
private InputStream fileInputStream = null;
private OutputStream fileOutputStream;
private long remainingSize;
private long remainingSize = 0;
private long fileSize = 0;
private MessageDigest digest;
private OnFileTransmissionStatusChanged onFileTransmissionStatusChanged;
@ -45,10 +48,10 @@ public class JingleInbandTransport extends JingleTransport {
}
};
public JingleInbandTransport(final Account account, final Jid counterpart,
final String sid, final int blocksize) {
this.account = account;
this.counterpart = counterpart;
public JingleInbandTransport(final JingleConnection connection, final String sid, final int blocksize) {
this.connection = connection;
this.account = connection.getAccount();
this.counterpart = connection.getCounterPart();
this.blockSize = blocksize;
this.bufferSize = blocksize / 4;
this.sessionId = sid;
@ -92,7 +95,7 @@ public class JingleInbandTransport extends JingleTransport {
callback.onFileTransferAborted();
return;
}
this.remainingSize = file.getExpectedSize();
this.remainingSize = this.fileSize = file.getExpectedSize();
} catch (final NoSuchAlgorithmException | IOException e) {
callback.onFileTransferAborted();
}
@ -104,6 +107,8 @@ public class JingleInbandTransport extends JingleTransport {
this.onFileTransmissionStatusChanged = callback;
this.file = file;
try {
this.remainingSize = this.file.getSize();
this.fileSize = this.remainingSize;
this.digest = MessageDigest.getInstance("SHA-1");
this.digest.reset();
fileInputStream = this.file.createInputStream();
@ -126,6 +131,7 @@ public class JingleInbandTransport extends JingleTransport {
fileInputStream.close();
this.onFileTransmissionStatusChanged.onFileTransmitted(file);
} else {
this.remainingSize -= count;
this.digest.update(buffer);
String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP);
IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
@ -140,6 +146,7 @@ public class JingleInbandTransport extends JingleTransport {
this.account.getXmppConnection().sendIqPacket(iq,
this.onAckReceived);
this.seq++;
connection.updateProgress((int) ((((double) (this.fileSize - this.remainingSize)) / this.fileSize) * 100));
}
} catch (IOException e) {
this.onFileTransmissionStatusChanged.onFileTransferAborted();
@ -155,6 +162,7 @@ public class JingleInbandTransport extends JingleTransport {
}
this.remainingSize -= buffer.length;
this.fileOutputStream.write(buffer);
this.digest.update(buffer);
@ -163,6 +171,8 @@ public class JingleInbandTransport extends JingleTransport {
fileOutputStream.flush();
fileOutputStream.close();
this.onFileTransmissionStatusChanged.onFileTransmitted(file);
} else {
connection.updateProgress((int) ((((double) (this.fileSize - this.remainingSize)) / this.fileSize) * 100));
}
} catch (IOException e) {
this.onFileTransmissionStatusChanged.onFileTransferAborted();

View file

@ -105,14 +105,14 @@ public class JingleSocks5Transport extends JingleTransport {
return;
}
long size = file.getSize();
double transmitted = 0;
long transmitted = 0;
int count;
byte[] buffer = new byte[8192];
while ((count = fileInputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, count);
digest.update(buffer, 0, count);
transmitted += count;
connection.updateProgress((int) (((transmitted) / size) * 100));
connection.updateProgress((int) ((((double) transmitted) / size) * 100));
}
outputStream.flush();
file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest()));