1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-12 08:01:08 +01:00

More Refactoring in Negotiation Speed

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7364 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Thiago Camargo 2007-03-03 07:31:53 +00:00 committed by thiago
parent 3c455c8367
commit a616e34bd7
4 changed files with 42 additions and 26 deletions

View file

@ -277,29 +277,43 @@ public abstract class TransportNegotiator extends JingleNegotiator {
public void run() {
// Sleep for some time, waiting for the candidates checks
try {
Thread.sleep(CANDIDATES_ACCEPT_PERIOD
+ TransportResolver.CHECK_TIMEOUT);
int totalTime= (CANDIDATES_ACCEPT_PERIOD + (TransportResolver.CHECK_TIMEOUT * (resolver.getCandidatesList().size()+1)));
int tries = (int)Math.ceil(totalTime/1000);
for (int i = 0; i < tries; i++) {
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
// Once we are in pending state, look for any valid remote
// candidate, and send an "accept" if we have one...
TransportCandidate bestRemote = getBestRemoteCandidate();
State state = getState();
if (bestRemote != null && (state == pending || state == active)) {
// Accepting the remote candidate
Jingle jout = new Jingle(Jingle.Action.TRANSPORTACCEPT);
jout.addTransport(getJingleTransport(bestRemote));
// Send the packet
js.sendFormattedJingle(jin, jout);
if (isEstablished()) {
setState(active);
break;
}
}
}
catch (InterruptedException e) {
e.printStackTrace();
}
// Once we are in pending state, look for any valid remote
// candidate, and send an "accept" if we have one...
TransportCandidate bestRemote = getBestRemoteCandidate();
State state = getState();
if (bestRemote != null && (state == pending || state == active)) {
// Accepting the remote candidate
Jingle jout = new Jingle(Jingle.Action.TRANSPORTACCEPT);
jout.addTransport(getJingleTransport(bestRemote));
// Send the packet
js.sendFormattedJingle(jin, jout);
if (isEstablished()) {
setState(active);
if (getState() == null || !getState().equals(active)) {
try {
session.terminate();
}
catch (XMPPException e) {
e.printStackTrace();
}
}
}