progress for ibb transfers
This commit is contained in:
parent
e7a70a46e0
commit
af2922adea
|
@ -21,6 +21,8 @@ public final class Config {
|
||||||
public static final boolean PARSE_EMOTICONS = false;
|
public static final boolean PARSE_EMOTICONS = false;
|
||||||
public static final int PROGRESS_UI_UPDATE_INTERVAL = 750;
|
public static final int PROGRESS_UI_UPDATE_INTERVAL = 750;
|
||||||
|
|
||||||
|
public static final boolean NO_PROXY_LOOKUP = false; //useful to debug ibb
|
||||||
|
|
||||||
private Config() {
|
private Config() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class JingleConnection implements Downloadable {
|
||||||
Message.STATUS_RECEIVED);
|
Message.STATUS_RECEIVED);
|
||||||
} else {
|
} else {
|
||||||
message.setDownloadable(null);
|
message.setDownloadable(null);
|
||||||
if (message.getEncryption() != Message.ENCRYPTION_PGP) {
|
if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -664,8 +664,7 @@ public class JingleConnection implements Downloadable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.transportId = packet.getJingleContent().getTransportId();
|
this.transportId = packet.getJingleContent().getTransportId();
|
||||||
this.transport = new JingleInbandTransport(this.account,
|
this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize);
|
||||||
this.responder, this.transportId, this.ibbBlockSize);
|
|
||||||
this.transport.receive(file, onFileTransmissionSatusChanged);
|
this.transport.receive(file, onFileTransmissionSatusChanged);
|
||||||
JinglePacket answer = bootstrapPacket("transport-accept");
|
JinglePacket answer = bootstrapPacket("transport-accept");
|
||||||
Content content = new Content("initiator", "a-file-offer");
|
Content content = new Content("initiator", "a-file-offer");
|
||||||
|
@ -687,8 +686,7 @@ public class JingleConnection implements Downloadable {
|
||||||
this.ibbBlockSize = bs;
|
this.ibbBlockSize = bs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.transport = new JingleInbandTransport(this.account,
|
this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize);
|
||||||
this.responder, this.transportId, this.ibbBlockSize);
|
|
||||||
this.transport.connect(new OnTransportConnected() {
|
this.transport.connect(new OnTransportConnected() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -75,6 +75,10 @@ public class JingleConnectionManager extends AbstractConnectionManager {
|
||||||
|
|
||||||
public void getPrimaryCandidate(Account account,
|
public void getPrimaryCandidate(Account account,
|
||||||
final OnPrimaryCandidateFound listener) {
|
final OnPrimaryCandidateFound listener) {
|
||||||
|
if (Config.NO_PROXY_LOOKUP) {
|
||||||
|
listener.onPrimaryCandidateFound(false, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) {
|
if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) {
|
||||||
String xmlns = "http://jabber.org/protocol/bytestreams";
|
String xmlns = "http://jabber.org/protocol/bytestreams";
|
||||||
final String proxy = account.getXmppConnection()
|
final String proxy = account.getXmppConnection()
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.DownloadableFile;
|
import eu.siacs.conversations.entities.DownloadableFile;
|
||||||
import eu.siacs.conversations.utils.CryptoHelper;
|
import eu.siacs.conversations.utils.CryptoHelper;
|
||||||
|
@ -28,10 +29,12 @@ public class JingleInbandTransport extends JingleTransport {
|
||||||
private boolean established = false;
|
private boolean established = false;
|
||||||
|
|
||||||
private DownloadableFile file;
|
private DownloadableFile file;
|
||||||
|
private JingleConnection connection;
|
||||||
|
|
||||||
private InputStream fileInputStream = null;
|
private InputStream fileInputStream = null;
|
||||||
private OutputStream fileOutputStream;
|
private OutputStream fileOutputStream;
|
||||||
private long remainingSize;
|
private long remainingSize = 0;
|
||||||
|
private long fileSize = 0;
|
||||||
private MessageDigest digest;
|
private MessageDigest digest;
|
||||||
|
|
||||||
private OnFileTransmissionStatusChanged onFileTransmissionStatusChanged;
|
private OnFileTransmissionStatusChanged onFileTransmissionStatusChanged;
|
||||||
|
@ -45,10 +48,10 @@ public class JingleInbandTransport extends JingleTransport {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public JingleInbandTransport(final Account account, final Jid counterpart,
|
public JingleInbandTransport(final JingleConnection connection, final String sid, final int blocksize) {
|
||||||
final String sid, final int blocksize) {
|
this.connection = connection;
|
||||||
this.account = account;
|
this.account = connection.getAccount();
|
||||||
this.counterpart = counterpart;
|
this.counterpart = connection.getCounterPart();
|
||||||
this.blockSize = blocksize;
|
this.blockSize = blocksize;
|
||||||
this.bufferSize = blocksize / 4;
|
this.bufferSize = blocksize / 4;
|
||||||
this.sessionId = sid;
|
this.sessionId = sid;
|
||||||
|
@ -92,7 +95,7 @@ public class JingleInbandTransport extends JingleTransport {
|
||||||
callback.onFileTransferAborted();
|
callback.onFileTransferAborted();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.remainingSize = file.getExpectedSize();
|
this.remainingSize = this.fileSize = file.getExpectedSize();
|
||||||
} catch (final NoSuchAlgorithmException | IOException e) {
|
} catch (final NoSuchAlgorithmException | IOException e) {
|
||||||
callback.onFileTransferAborted();
|
callback.onFileTransferAborted();
|
||||||
}
|
}
|
||||||
|
@ -104,6 +107,8 @@ public class JingleInbandTransport extends JingleTransport {
|
||||||
this.onFileTransmissionStatusChanged = callback;
|
this.onFileTransmissionStatusChanged = callback;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
try {
|
try {
|
||||||
|
this.remainingSize = this.file.getSize();
|
||||||
|
this.fileSize = this.remainingSize;
|
||||||
this.digest = MessageDigest.getInstance("SHA-1");
|
this.digest = MessageDigest.getInstance("SHA-1");
|
||||||
this.digest.reset();
|
this.digest.reset();
|
||||||
fileInputStream = this.file.createInputStream();
|
fileInputStream = this.file.createInputStream();
|
||||||
|
@ -126,6 +131,7 @@ public class JingleInbandTransport extends JingleTransport {
|
||||||
fileInputStream.close();
|
fileInputStream.close();
|
||||||
this.onFileTransmissionStatusChanged.onFileTransmitted(file);
|
this.onFileTransmissionStatusChanged.onFileTransmitted(file);
|
||||||
} else {
|
} else {
|
||||||
|
this.remainingSize -= count;
|
||||||
this.digest.update(buffer);
|
this.digest.update(buffer);
|
||||||
String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP);
|
String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP);
|
||||||
IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
|
IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
|
||||||
|
@ -140,6 +146,7 @@ public class JingleInbandTransport extends JingleTransport {
|
||||||
this.account.getXmppConnection().sendIqPacket(iq,
|
this.account.getXmppConnection().sendIqPacket(iq,
|
||||||
this.onAckReceived);
|
this.onAckReceived);
|
||||||
this.seq++;
|
this.seq++;
|
||||||
|
connection.updateProgress((int) ((((double) (this.fileSize - this.remainingSize)) / this.fileSize) * 100));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
this.onFileTransmissionStatusChanged.onFileTransferAborted();
|
this.onFileTransmissionStatusChanged.onFileTransferAborted();
|
||||||
|
@ -155,6 +162,7 @@ public class JingleInbandTransport extends JingleTransport {
|
||||||
}
|
}
|
||||||
this.remainingSize -= buffer.length;
|
this.remainingSize -= buffer.length;
|
||||||
|
|
||||||
|
|
||||||
this.fileOutputStream.write(buffer);
|
this.fileOutputStream.write(buffer);
|
||||||
|
|
||||||
this.digest.update(buffer);
|
this.digest.update(buffer);
|
||||||
|
@ -163,6 +171,8 @@ public class JingleInbandTransport extends JingleTransport {
|
||||||
fileOutputStream.flush();
|
fileOutputStream.flush();
|
||||||
fileOutputStream.close();
|
fileOutputStream.close();
|
||||||
this.onFileTransmissionStatusChanged.onFileTransmitted(file);
|
this.onFileTransmissionStatusChanged.onFileTransmitted(file);
|
||||||
|
} else {
|
||||||
|
connection.updateProgress((int) ((((double) (this.fileSize - this.remainingSize)) / this.fileSize) * 100));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
this.onFileTransmissionStatusChanged.onFileTransferAborted();
|
this.onFileTransmissionStatusChanged.onFileTransferAborted();
|
||||||
|
|
|
@ -105,14 +105,14 @@ public class JingleSocks5Transport extends JingleTransport {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long size = file.getSize();
|
long size = file.getSize();
|
||||||
double transmitted = 0;
|
long transmitted = 0;
|
||||||
int count;
|
int count;
|
||||||
byte[] buffer = new byte[8192];
|
byte[] buffer = new byte[8192];
|
||||||
while ((count = fileInputStream.read(buffer)) > 0) {
|
while ((count = fileInputStream.read(buffer)) > 0) {
|
||||||
outputStream.write(buffer, 0, count);
|
outputStream.write(buffer, 0, count);
|
||||||
digest.update(buffer, 0, count);
|
digest.update(buffer, 0, count);
|
||||||
transmitted += count;
|
transmitted += count;
|
||||||
connection.updateProgress((int) (((transmitted) / size) * 100));
|
connection.updateProgress((int) ((((double) transmitted) / size) * 100));
|
||||||
}
|
}
|
||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest()));
|
file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest()));
|
||||||
|
|
Loading…
Reference in New Issue