tried to fix some race conditions. not adding duplicate candidates. needs more checks though

This commit is contained in:
Daniel Gultsch 2014-04-14 20:35:11 +02:00
parent 2014af0f7e
commit 18c3333271
4 changed files with 45 additions and 20 deletions

View file

@ -134,8 +134,7 @@ public class XmppConnectionService extends Service {
message = MessageParser.parsePgpChat(pgpBody, packet, message = MessageParser.parsePgpChat(pgpBody, packet,
account, service); account, service);
message.markUnread(); message.markUnread();
} else if (packet.hasChild("body") } else if ((packet.getBody()!=null) && (packet.getBody().startsWith("?OTR"))) {
&& (packet.getBody().startsWith("?OTR"))) {
message = MessageParser.parseOtrChat(packet, account, message = MessageParser.parseOtrChat(packet, account,
service); service);
if (message != null) { if (message != null) {

View file

@ -142,7 +142,6 @@ public class JingleConnection {
} else { } else {
Log.d("xmppService","no file offer was attached. aborting"); Log.d("xmppService","no file offer was attached. aborting");
} }
Log.d("xmppService","session Id "+getSessionId());
} }
private void sendInitRequest() { private void sendInitRequest() {
@ -168,7 +167,8 @@ public class JingleConnection {
@Override @Override
public void onPrimaryCandidateFound(boolean success, Element candidate) { public void onPrimaryCandidateFound(boolean success, Element candidate) {
if (success) { if (success) {
if (mergeCandidate(candidate)) { if (!equalCandidateExists(candidate)) {
mergeCandidate(candidate);
content.addCandidate(candidate); content.addCandidate(candidate);
} }
} }
@ -202,7 +202,7 @@ public class JingleConnection {
private void accept(JinglePacket packet) { private void accept(JinglePacket packet) {
Log.d("xmppService","session-accept: "+packet.toString()); Log.d("xmppService","session-accept: "+packet.toString());
Content content = packet.getJingleContent(); Content content = packet.getJingleContent();
this.mergeCandidates(content.getCanditates()); mergeCandidates(content.getCanditates());
this.status = STATUS_ACCEPTED; this.status = STATUS_ACCEPTED;
this.connectWithCandidates(); this.connectWithCandidates();
IqPacket response = packet.generateRespone(IqPacket.TYPE_RESULT); IqPacket response = packet.generateRespone(IqPacket.TYPE_RESULT);
@ -322,14 +322,25 @@ public class JingleConnection {
} }
} }
private void sendCandidateUsed(String cid) { private void sendCandidateUsed(final String cid) {
JinglePacket packet = bootstrapPacket(); JinglePacket packet = bootstrapPacket();
packet.setAction("transport-info"); packet.setAction("transport-info");
Content content = new Content(); Content content = new Content();
content.setUsedCandidate(this.content.getTransportId(), cid); content.setUsedCandidate(this.content.getTransportId(), cid);
packet.setContent(content); packet.setContent(content);
Log.d("xmppService","send using candidate: "+packet.toString()); Log.d("xmppService","send using candidate: "+cid);
this.account.getXmppConnection().sendIqPacket(packet, responseListener); this.account.getXmppConnection().sendIqPacket(packet, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
Log.d("xmppService","got ack for our candidate used");
if (status!=STATUS_TRANSMITTING) {
connect(connections.get(cid));
} else {
Log.d("xmppService","ignoring cuz already transmitting");
}
}
});
} }
public String getInitiator() { public String getInitiator() {
@ -344,19 +355,27 @@ public class JingleConnection {
return this.status; return this.status;
} }
private boolean mergeCandidate(Element candidate) { private boolean equalCandidateExists(Element candidate) {
for(Element c : this.candidates) { for(Element c : this.candidates) {
if (c.getAttribute("host").equals(candidate.getAttribute("host"))&&(c.getAttribute("port").equals(candidate.getAttribute("port")))) { if (c.getAttribute("host").equals(candidate.getAttribute("host"))&&(c.getAttribute("port").equals(candidate.getAttribute("port")))) {
return true;
}
}
return false; return false;
} }
private void mergeCandidate(Element candidate) {
for(Element c : this.candidates) {
if (c.getAttribute("cid").equals(candidate.getAttribute("cid"))) {
return;
}
} }
this.candidates.add(candidate); this.candidates.add(candidate);
return true;
} }
private void mergeCandidates(List<Element> canditates) { private void mergeCandidates(List<Element> candidates) {
for(Element c : canditates) { for(Element c : candidates) {
this.mergeCandidate(c); mergeCandidate(c);
} }
} }
} }

View file

@ -43,8 +43,6 @@ public class JingleConnectionManager {
.getCounterPart().equals(packet.getFrom())) { .getCounterPart().equals(packet.getFrom())) {
connection.deliverPacket(packet); connection.deliverPacket(packet);
return; return;
} else {
Log.d("xmppService","no match sid:"+connection.getSessionId()+"="+packet.getSessionId()+" counterpart:"+connection.getCounterPart()+"="+packet.getFrom()+" account:"+connection.getAccountJid()+"="+packet.getTo());
} }
} }
Log.d("xmppService","delivering packet failed "+packet.toString()); Log.d("xmppService","delivering packet failed "+packet.toString());
@ -135,6 +133,11 @@ public class JingleConnectionManager {
} }
public long getAutoAcceptFileSize() { public long getAutoAcceptFileSize() {
return this.xmppConnectionService.getPreferences().getLong("auto_accept_file_size", 0); String config = this.xmppConnectionService.getPreferences().getString("auto_accept_file_size", "0");
try {
return Long.parseLong(config);
} catch (NumberFormatException e) {
return 0;
}
} }
} }

View file

@ -160,10 +160,14 @@ public class SocksConnection {
count = (int) remainingSize; count = (int) remainingSize;
} }
count = inputStream.read(buffer, 0, count); count = inputStream.read(buffer, 0, count);
if (count==-1) {
Log.d("xmppService","end of stream");
} else {
fileOutputStream.write(buffer, 0, count); fileOutputStream.write(buffer, 0, count);
digest.update(buffer, 0, count); digest.update(buffer, 0, count);
remainingSize-=count; remainingSize-=count;
} }
}
fileOutputStream.flush(); fileOutputStream.flush();
fileOutputStream.close(); fileOutputStream.close();
file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest())); file.setSha1Sum(CryptoHelper.bytesToHex(digest.digest()));