1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-23 06:42:05 +01:00

Fixes in Negotiations

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7720 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Thiago Camargo 2007-03-27 04:24:18 +00:00 committed by thiago
parent 99aae28885
commit 6059fb7b82
6 changed files with 145 additions and 99 deletions

View file

@ -136,18 +136,6 @@ public class IncomingJingleSession extends JingleSession {
updatePacketListener(); updatePacketListener();
Jingle packet = initialJingleSessionRequest.getJingle();
if (packet != null) {
// Initialize the session information
setSid(packet.getSid());
respond(packet);
}
else {
throw new XMPPException(
"Session request with null Jingle packet.");
}
} }
@ -173,6 +161,20 @@ public class IncomingJingleSession extends JingleSession {
* @throws XMPPException * @throws XMPPException
*/ */
public void start(JingleSessionRequest initialJingleSessionRequest) throws XMPPException { public void start(JingleSessionRequest initialJingleSessionRequest) throws XMPPException {
Jingle packet = initialJingleSessionRequest.getJingle();
if (packet != null) {
// Initialize the session information
setSid(packet.getSid());
sendAck(packet);
}
else {
throw new XMPPException(
"Session request with null Jingle packet.");
}
// Set the new session state
setState(pending);
} }
/** /**
@ -181,15 +183,16 @@ public class IncomingJingleSession extends JingleSession {
* @throws XMPPException * @throws XMPPException
*/ */
public void start() throws XMPPException { public void start() throws XMPPException {
start(this.getInitialSessionRequest());
} }
/** /**
* Force a call acceptance. Used to accept a hooked call. * Force a call acceptance. Used to accept a hooked call.
*
* @deprecated Avoid to use this method. Not compliance. * @deprecated Avoid to use this method. Not compliance.
*/ */
public void accept(){ public void accept() {
setState(active); setState(active);
} }
/** /**
@ -230,8 +233,6 @@ public class IncomingJingleSession extends JingleSession {
* @throws XMPPException * @throws XMPPException
*/ */
public Jingle eventInitiate(Jingle inJingle) throws XMPPException { public Jingle eventInitiate(Jingle inJingle) throws XMPPException {
// Set the new session state
setState(pending);
return super.eventInitiate(inJingle); return super.eventInitiate(inJingle);
} }

View file

@ -202,6 +202,7 @@ public abstract class JingleSession extends JingleNegotiator {
/** /**
* Get the JingleMediaSession of this Jingle Session * Get the JingleMediaSession of this Jingle Session
*
* @return the JingleMediaSession * @return the JingleMediaSession
*/ */
public JingleMediaSession getJingleMediaSession() { public JingleMediaSession getJingleMediaSession() {
@ -428,8 +429,7 @@ public abstract class JingleSession extends JingleNegotiator {
jout = getState().eventInfo(jin); jout = getState().eventInfo(jin);
} }
else if (action.equals(Jingle.Action.SESSIONINITIATE)) { else if (action.equals(Jingle.Action.SESSIONINITIATE)) {
if (getState() != null) jout = getState().eventInitiate(jin);
jout = getState().eventInitiate(jin);
} }
else if (action.equals(Jingle.Action.SESSIONREDIRECT)) { else if (action.equals(Jingle.Action.SESSIONREDIRECT)) {
jout = getState().eventRedirect(jin); jout = getState().eventRedirect(jin);
@ -493,7 +493,8 @@ public abstract class JingleSession extends JingleNegotiator {
} }
// Acknowledge the IQ reception // Acknowledge the IQ reception
sendAck(iq); if (!(getState() instanceof IncomingJingleSession.Accepting))
sendAck(iq);
// ... and send all these parts in a Jingle response. // ... and send all these parts in a Jingle response.
response = sendJingleParts(iq, (Jingle) sessionResponse, response = sendJingleParts(iq, (Jingle) sessionResponse,
@ -502,6 +503,7 @@ public abstract class JingleSession extends JingleNegotiator {
} }
catch (JingleException e) { catch (JingleException e) {
// Send an error message, if present // Send an error message, if present
System.out.println("E:" + iq);
JingleError error = e.getError(); JingleError error = e.getError();
if (error != null) { if (error != null) {
sendFormattedError(iq, error); sendFormattedError(iq, error);
@ -511,6 +513,9 @@ public abstract class JingleSession extends JingleNegotiator {
triggerSessionClosedOnError(e); triggerSessionClosedOnError(e);
} }
} }
else {
System.out.println("K:" + iq);
}
return response; return response;
} }

View file

@ -244,6 +244,8 @@ public class STUN extends IQ {
return true; return true;
} }
System.out.println(item.getName()+"-"+info.getType());
} }
} }
catch (XMPPException e) { catch (XMPPException e) {

View file

@ -83,7 +83,7 @@ public class JingleMediaTest extends SmackTestCase {
session.addStateListener(new JingleSessionStateListener() { session.addStateListener(new JingleSessionStateListener() {
public void beforeChange(JingleNegotiator.State old, JingleNegotiator.State newOne) throws JingleNegotiator.JingleException { public void beforeChange(JingleNegotiator.State old, JingleNegotiator.State newOne) throws JingleNegotiator.JingleException {
if (newOne instanceof IncomingJingleSession.Active) { if (newOne instanceof IncomingJingleSession.Active) {
throw new JingleNegotiator.JingleException(); throw new JingleNegotiator.JingleException();
} }
} }
@ -134,7 +134,6 @@ public class JingleMediaTest extends SmackTestCase {
XMPPConnection x0 = getConnection(0); XMPPConnection x0 = getConnection(0);
XMPPConnection x1 = getConnection(1); XMPPConnection x1 = getConnection(1);
ICETransportManager icetm0 = new ICETransportManager(x0, "jivesoftware.com", 3478); ICETransportManager icetm0 = new ICETransportManager(x0, "jivesoftware.com", 3478);
ICETransportManager icetm1 = new ICETransportManager(x1, "jivesoftware.com", 3478); ICETransportManager icetm1 = new ICETransportManager(x1, "jivesoftware.com", 3478);
@ -170,7 +169,7 @@ public class JingleMediaTest extends SmackTestCase {
try { try {
IncomingJingleSession session = request.accept(jm1.getMediaManager().getPayloads()); IncomingJingleSession session = request.accept(jm1.getMediaManager().getPayloads());
session.start(request); //session.start(request);
} }
catch (XMPPException e) { catch (XMPPException e) {
e.printStackTrace(); e.printStackTrace();
@ -179,17 +178,31 @@ public class JingleMediaTest extends SmackTestCase {
} }
}); });
OutgoingJingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser()); for (int i = 0; i < 10; i++) {
js0.start(); OutgoingJingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser());
Thread.sleep(60000); js0.addStateListener(new JingleSessionStateListener() {
js0.terminate();
Thread.sleep(6000); public void beforeChange(JingleNegotiator.State old, JingleNegotiator.State newOne) throws JingleNegotiator.JingleException {
}
x0.disconnect(); public void afterChanged(JingleNegotiator.State old, JingleNegotiator.State newOne) {
x1.disconnect(); if (newOne != null) {
System.out.println(newOne.getClass().getCanonicalName());
assertFalse(newOne instanceof OutgoingJingleSession.Active);
}
}
});
js0.start();
Thread.sleep(5000);
js0.terminate();
Thread.sleep(1500);
}
} }
catch (Exception e) { catch (Exception e) {

View file

@ -134,28 +134,28 @@ public class PacketReaderTest extends SmackTestCase {
*/ */
public void testRemoveListener() { public void testRemoveListener() {
PacketListener listener = new PacketListener() { PacketListener listener = new PacketListener() {
public void processPacket(Packet packet) { public void processPacket(Packet packet) {
// Do nothing // Do nothing
} }
}; };
// Keep number of current listeners // Keep number of current listeners
int listenersSize = getConnection(0).packetReader.listeners.size(); int listenersSize = getConnection(0).packetReader.listeners.size();
// Add a new listener // Add a new listener
getConnection(0).addPacketListener(listener, new MockPacketFilter(true)); getConnection(0).addPacketListener(listener, new MockPacketFilter(true));
// Check that the listener was added // Check that the listener was added
assertEquals("Listener was not added", listenersSize + 1, assertEquals("Listener was not added", listenersSize + 1,
getConnection(0).packetReader.listeners.size()); getConnection(0).packetReader.listeners.size());
Message msg = new Message(getConnection(0).getUser(), Message.Type.normal); Message msg = new Message(getConnection(0).getUser(), Message.Type.normal);
getConnection(1).sendPacket(msg); getConnection(1).sendPacket(msg);
// Remove the listener // Remove the listener
getConnection(0).removePacketListener(listener); getConnection(0).removePacketListener(listener);
// Check that the number of listeners is correct (i.e. the listener was removed) // Check that the number of listeners is correct (i.e. the listener was removed)
assertEquals("Listener was not removed", listenersSize, assertEquals("Listener was not removed", listenersSize,
getConnection(0).packetReader.listeners.size()); getConnection(0).packetReader.listeners.size());
} }
/** /**
@ -200,67 +200,91 @@ public class PacketReaderTest extends SmackTestCase {
} }
/** /**
* Tests that PacketReader adds new listeners and also removes them correctly. * Tests that PacketReader adds new listeners and also removes them correctly.
*/ */
public void testFiltersRemotion() { public void testFiltersRemotion() {
resetCounter(); resetCounter();
int repeat=10; int repeat = 10;
for (int j = 0; j < repeat; j++) { for (int j = 0; j < repeat; j++) {
PacketListener listener = new PacketListener() { PacketListener listener0 = new PacketListener() {
public void processPacket(Packet packet) { public void processPacket(Packet packet) {
System.out.println("Packet Captured"); System.out.println("Packet Captured");
incCounter(); incCounter();
} }
}; };
PacketFilter pf = new PacketFilter() { PacketFilter pf0 = new PacketFilter() {
public boolean accept(Packet packet) { public boolean accept(Packet packet) {
System.out.println("Packet Filtered"); System.out.println("Packet Filtered");
incCounter(); incCounter();
return true; return true;
} }
}; };
getConnection(0).addPacketListener(listener,pf); PacketListener listener1 = new PacketListener() {
// Check that the listener was added public void processPacket(Packet packet) {
System.out.println("Packet Captured");
incCounter();
}
};
PacketFilter pf1 = new PacketFilter() {
public boolean accept(Packet packet) {
System.out.println("Packet Filtered");
incCounter();
return true;
}
};
Message msg = new Message(getConnection(0).getUser(), Message.Type.normal); getConnection(0).addPacketListener(listener0, pf0);
getConnection(1).addPacketListener(listener1, pf1);
getConnection(1).sendPacket(msg); // Check that the listener was added
try { Message msg0 = new Message(getConnection(0).getUser(), Message.Type.normal);
Thread.sleep(100); Message msg1 = new Message(getConnection(1).getUser(), Message.Type.normal);
}
catch (InterruptedException e) {
e.printStackTrace();
}
// Remove the listener
getConnection(0).removePacketListener(listener);
try { for (int i = 0; i < 5; i++) {
Thread.sleep(200); getConnection(1).sendPacket(msg0);
} getConnection(0).sendPacket(msg1);
catch (InterruptedException e) { }
e.printStackTrace();
}
for (int i = 0; i < 10; i++) try {
getConnection(1).sendPacket(msg); Thread.sleep(100);
}
catch (InterruptedException e) {
e.printStackTrace();
}
try { // Remove the listener
Thread.sleep(100); getConnection(0).removePacketListener(listener0);
} getConnection(1).removePacketListener(listener1);
catch (InterruptedException e) {
e.printStackTrace(); try {
} Thread.sleep(300);
} }
System.out.println(valCounter()); catch (InterruptedException e) {
assertEquals(valCounter(),repeat*2); e.printStackTrace();
} }
for (int i = 0; i < 10; i++) {
getConnection(0).sendPacket(msg1);
getConnection(1).sendPacket(msg0);
}
try {
Thread.sleep(100);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println(valCounter());
assertEquals(valCounter(), repeat * 2 * 10);
}
protected int getMaxConnections() { protected int getMaxConnections() {
return 2; return 2;

View file

@ -65,6 +65,7 @@ public abstract class SmackTestCase extends TestCase {
*/ */
public SmackTestCase(String arg0) { public SmackTestCase(String arg0) {
super(arg0); super(arg0);
XMPPConnection.DEBUG_ENABLED=true;
} }
/** /**