1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-27 00:32:07 +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

@ -360,7 +360,7 @@ public abstract class JingleNegotiator {
} }
public Jingle eventTerminate(Jingle jin) throws XMPPException { public Jingle eventTerminate(Jingle jin) throws XMPPException {
if (neg != null) { if (neg != null && !neg.invalidState()) {
neg.close(); neg.close();
} }
return null; return null;

View file

@ -547,7 +547,7 @@ public abstract class JingleSession extends JingleNegotiator {
* @param iq The Jingle packet we are responing to * @param iq The Jingle packet we are responing to
* @param error the IQ packet we want to complete and send * @param error the IQ packet we want to complete and send
*/ */
protected IQ sendFormattedError(IQ iq, JingleError error) { public IQ sendFormattedError(IQ iq, JingleError error) {
IQ perror = null; IQ perror = null;
if (error != null) { if (error != null) {
perror = createIQ(getSid(), iq.getFrom(), iq.getTo(), IQ.Type.ERROR); perror = createIQ(getSid(), iq.getFrom(), iq.getTo(), IQ.Type.ERROR);
@ -1121,6 +1121,7 @@ public abstract class JingleSession extends JingleNegotiator {
* @throws XMPPException * @throws XMPPException
*/ */
public void terminate() throws XMPPException { public void terminate() throws XMPPException {
if (isClosed()) return;
System.out.println("State: " + this.getState()); System.out.println("State: " + this.getState());
Jingle result = null; Jingle result = null;
Jingle jout = new Jingle(Jingle.Action.SESSIONTERMINATE); Jingle jout = new Jingle(Jingle.Action.SESSIONTERMINATE);
@ -1133,6 +1134,7 @@ public abstract class JingleSession extends JingleNegotiator {
* Terminate negotiations. * Terminate negotiations.
*/ */
public void close() { public void close() {
if (isClosed()) return;
destroyMediaNeg(); destroyMediaNeg();
destroyTransportNeg(); destroyTransportNeg();
removePacketListener(); removePacketListener();

View file

@ -277,29 +277,43 @@ public abstract class TransportNegotiator extends JingleNegotiator {
public void run() { public void run() {
// Sleep for some time, waiting for the candidates checks // Sleep for some time, waiting for the candidates checks
try {
Thread.sleep(CANDIDATES_ACCEPT_PERIOD int totalTime= (CANDIDATES_ACCEPT_PERIOD + (TransportResolver.CHECK_TIMEOUT * (resolver.getCandidatesList().size()+1)));
+ TransportResolver.CHECK_TIMEOUT); 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) { if (getState() == null || !getState().equals(active)) {
e.printStackTrace(); try {
} session.terminate();
}
// Once we are in pending state, look for any valid remote catch (XMPPException e) {
// candidate, and send an "accept" if we have one... e.printStackTrace();
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);
} }
} }
} }

View file

@ -129,10 +129,10 @@ public class JingleMediaTest extends SmackTestCase {
x1, new BasicTransportManager()); x1, new BasicTransportManager());
MultiMediaManager jingleMediaManager0 = new MultiMediaManager(); MultiMediaManager jingleMediaManager0 = new MultiMediaManager();
// jingleMediaManager0.addMediaManager(new SpeexMediaManager()); jingleMediaManager0.addMediaManager(new SpeexMediaManager());
jingleMediaManager0.addMediaManager(new JmfMediaManager()); jingleMediaManager0.addMediaManager(new JmfMediaManager());
MultiMediaManager jingleMediaManager1 = new MultiMediaManager(); MultiMediaManager jingleMediaManager1 = new MultiMediaManager();
// jingleMediaManager1.addMediaManager(new JmfMediaManager()); jingleMediaManager1.addMediaManager(new JmfMediaManager());
jingleMediaManager1.addMediaManager(new SpeexMediaManager()); jingleMediaManager1.addMediaManager(new SpeexMediaManager());
jm0.setMediaManager(jingleMediaManager0); jm0.setMediaManager(jingleMediaManager0);