1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-11 01:59:38 +02:00

Some refactoring

This commit is contained in:
vanitasvitae 2017-07-27 15:18:18 +02:00
parent 3915a71824
commit 980c324f27
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
50 changed files with 401 additions and 161 deletions

View file

@ -16,7 +16,7 @@
*/
package org.jivesoftware.smackx.jingle;
import org.jivesoftware.smackx.jingle.internal.JingleContent;
import org.jivesoftware.smackx.jingle.components.JingleContent;
/**
* User callback that the user can use to control a jingle content.

View file

@ -0,0 +1,17 @@
package org.jivesoftware.smackx.jingle;
/**
* Created by vanitas on 27.07.17.
*/
public interface JingleDescriptionController {
enum State {
pending, //Not yet accepted by us/peer
negotiating, //Accepted, but still negotiating transports etc.
active, //Bytestream initialized and active
cancelled, //We/Peer cancelled the transmission
ended //Successfully ended
}
State getState();
}

View file

@ -16,9 +16,7 @@
*/
package org.jivesoftware.smackx.jingle;
import org.jivesoftware.smackx.jingle.callbacks.ContentAddCallback;
import org.jivesoftware.smackx.jingle.element.JingleElement;
import org.jivesoftware.smackx.jingle.internal.JingleContent;
import org.jivesoftware.smackx.jingle.components.JingleSession;
/**
* Manager for JingleDescription components.
@ -27,5 +25,5 @@ public interface JingleDescriptionManager {
String getNamespace();
JingleElement notifyContentListeners(JingleContent content, ContentAddCallback callback);
void notifySessionInitiate(JingleSession session);
}

View file

@ -39,11 +39,12 @@ import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
import org.jivesoftware.smackx.jingle.exception.UnsupportedDescriptionException;
import org.jivesoftware.smackx.jingle.exception.UnsupportedSecurityException;
import org.jivesoftware.smackx.jingle.exception.UnsupportedTransportException;
import org.jivesoftware.smackx.jingle.internal.JingleSession;
import org.jivesoftware.smackx.jingle.components.JingleSession;
import org.jivesoftware.smackx.jingle.provider.JingleContentDescriptionProvider;
import org.jivesoftware.smackx.jingle.provider.JingleContentSecurityProvider;
import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider;
import org.jivesoftware.smackx.jingle.transport.JingleTransportManager;
import org.jivesoftware.smackx.jingle.util.FullJidAndSessionId;
import org.jivesoftware.smackx.jingle.util.Role;
import org.jxmpp.jid.FullJid;

View file

@ -14,10 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.transport;
package org.jivesoftware.smackx.jingle;
import org.jivesoftware.smackx.jingle.internal.JingleContent;
import org.jivesoftware.smackx.jingle.internal.JingleTransport;
import org.jivesoftware.smackx.jingle.components.JingleContent;
import org.jivesoftware.smackx.jingle.components.JingleTransport;
/**
* Manager for JingleTransport components.

View file

@ -17,7 +17,7 @@
package org.jivesoftware.smackx.jingle.adapter;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
import org.jivesoftware.smackx.jingle.internal.JingleDescription;
import org.jivesoftware.smackx.jingle.components.JingleDescription;
/**
* Adapter that creates a Description object from an element.

View file

@ -17,7 +17,7 @@
package org.jivesoftware.smackx.jingle.adapter;
import org.jivesoftware.smackx.jingle.element.JingleContentSecurityElement;
import org.jivesoftware.smackx.jingle.internal.JingleSecurity;
import org.jivesoftware.smackx.jingle.components.JingleSecurity;
/**
* Adapter that creates a Security object from an element.

View file

@ -17,7 +17,7 @@
package org.jivesoftware.smackx.jingle.adapter;
import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement;
import org.jivesoftware.smackx.jingle.internal.JingleTransport;
import org.jivesoftware.smackx.jingle.components.JingleTransport;
/**
* Adapter that creates a Transport element from an element.

View file

@ -14,14 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.internal;
package org.jivesoftware.smackx.jingle.components;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
import org.jivesoftware.smackx.jingle.JingleManager;
@ -33,12 +38,17 @@ import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement;
import org.jivesoftware.smackx.jingle.Callback;
import org.jivesoftware.smackx.jingle.adapter.JingleSecurityAdapter;
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
import org.jivesoftware.smackx.jingle.JingleTransportManager;
/**
* Internal class that holds the state of a content in a modifiable form.
*/
public class JingleContent {
private static final Logger LOGGER = Logger.getLogger(JingleContent.class.getName());
private JingleSession parent;
private JingleContentElement.Creator creator;
private String name;
@ -51,8 +61,18 @@ public class JingleContent {
private final List<Callback> callbacks = Collections.synchronizedList(new ArrayList<Callback>());
private final Set<String> transportBlacklist = Collections.synchronizedSet(new HashSet<String>());
public enum STATE {
pending_accept,
pending_transmission_start,
pending_transport_replace,
transmission_in_progress,
transmission_successful,
transmission_failed,
transmission_cancelled
}
public JingleContent(JingleContentElement.Creator creator, JingleContentElement.Senders senders) {
this(null, null, null, StringUtils.randomString(24), null, creator, senders);
this(null, null, null, randomName(), null, creator, senders);
}
public JingleContent(JingleDescription description, JingleTransport transport, JingleSecurity security, String name, String disposition, JingleContentElement.Creator creator, JingleContentElement.Senders senders) {
@ -181,6 +201,18 @@ public class JingleContent {
}
}
private boolean isSending() {
return (getSenders() == JingleContentElement.Senders.initiator && getParent().isInitiator()) ||
(getSenders() == JingleContentElement.Senders.responder && getParent().isResponder()) ||
getSenders() == JingleContentElement.Senders.both;
}
private boolean isReceiving() {
return (getSenders() == JingleContentElement.Senders.initiator && getParent().isResponder()) ||
(getSenders() == JingleContentElement.Senders.responder && getParent().isInitiator()) ||
getSenders() == JingleContentElement.Senders.both;
}
public void onTransportReady() {
BytestreamSession bytestreamSession = transport.getBytestreamSession();
@ -192,7 +224,50 @@ public class JingleContent {
}
public void onTransportFailed(Exception e) {
//Add current transport to blacklist.
getTransportBlacklist().add(transport.getNamespace());
//Replace transport.
if (getParent().isInitiator()) {
try {
replaceTransport(getTransportBlacklist(), getParent().getJingleManager().getConnection());
} catch (SmackException.NotConnectedException | InterruptedException | SmackException.NoResponseException | XMPPException.XMPPErrorException e1) {
LOGGER.log(Level.SEVERE, "Could not send transport-replace: " + e, e);
}
}
}
private void replaceTransport(Set<String> blacklist, XMPPConnection connection)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
JingleSession session = getParent();
JingleManager jingleManager = session.getJingleManager();
JingleTransportManager rManager = jingleManager.getBestAvailableTransportManager(blacklist);
if (rManager == null) {
JingleElement failedTransport = JingleElement.createSessionTerminate(session.getPeer(),
session.getSessionId(), JingleReasonElement.Reason.failed_transport);
connection.createStanzaCollectorAndSend(failedTransport).nextResultOrThrow();
return;
}
JingleTransport<?> rTransport = rManager.createTransport(this);
JingleElement transportReplace = JingleElement.createTransportReplace(session.getInitiator(), session.getPeer(),
session.getSessionId(), getCreator(), getName(), rTransport.getElement());
connection.createStanzaCollectorAndSend(transportReplace).nextResultOrThrow();
}
public void onContentAccept(XMPPConnection connection, )
throws SmackException.NotConnectedException, InterruptedException {
//Establish transport
if (isReceiving()) {
getTransport().establishIncomingBytestreamSession(connection);
} else if (isSending()) {
getTransport().establishOutgoingBytestreamSession(connection);
}
}
public static String randomName() {

View file

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.internal;
package org.jivesoftware.smackx.jingle.components;
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;

View file

@ -14,11 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.internal;
package org.jivesoftware.smackx.jingle.components;
import org.jivesoftware.smackx.jingle.element.JingleContentSecurityElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
import org.jivesoftware.smackx.jingle.element.JingleContentSecurityInfoElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
/**
* Class that represents a contents security component.

View file

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.internal;
package org.jivesoftware.smackx.jingle.components;
import java.util.ArrayList;
import java.util.Collections;
@ -30,7 +30,7 @@ import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.Role;
import org.jivesoftware.smackx.jingle.util.Role;
import org.jivesoftware.smackx.jingle.adapter.JingleTransportAdapter;
import org.jivesoftware.smackx.jingle.callbacks.ContentAddCallback;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
@ -161,7 +161,6 @@ public class JingleSession {
responses.add(JingleElement.createTransportReject(getInitiator(), getPeer(), getSessionId(),
content.getCreator(), content.getName(), newTransport));
continue;
}
JingleTransportAdapter<?> transportAdapter = JingleManager.getJingleTransportAdapter(
@ -353,7 +352,7 @@ public class JingleSession {
// TODO: Send content-reject
}
};
descriptionManager.notifyContentListeners(content, callback);
descriptionManager.notifySessionInitiate();
}
}

View file

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.internal;
package org.jivesoftware.smackx.jingle.components;
import java.util.ArrayList;
import java.util.List;

View file

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.internal;
package org.jivesoftware.smackx.jingle.components;
import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidateElement;

View file

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.internal;
package org.jivesoftware.smackx.jingle.components;
import org.jivesoftware.smackx.jingle.element.JingleAction;

View file

@ -0,0 +1,8 @@
package org.jivesoftware.smackx.jingle.controller;
/**
* Created by vanitas on 27.07.17.
*/
public interface JingleDescriptionController {
}

View file

@ -27,9 +27,9 @@ import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamRequest;
import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
import org.jivesoftware.smackx.jingle.internal.JingleSession;
import org.jivesoftware.smackx.jingle.internal.JingleTransport;
import org.jivesoftware.smackx.jingle.internal.JingleTransportCandidate;
import org.jivesoftware.smackx.jingle.components.JingleSession;
import org.jivesoftware.smackx.jingle.components.JingleTransport;
import org.jivesoftware.smackx.jingle.components.JingleTransportCandidate;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.element.JingleIBBTransportElement;
/**

View file

@ -6,9 +6,9 @@ import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.transport.JingleTransportManager;
import org.jivesoftware.smackx.jingle.internal.JingleContent;
import org.jivesoftware.smackx.jingle.internal.JingleTransport;
import org.jivesoftware.smackx.jingle.JingleTransportManager;
import org.jivesoftware.smackx.jingle.components.JingleContent;
import org.jivesoftware.smackx.jingle.components.JingleTransport;
import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager;
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.provider.JingleIBBTransportProvider;

View file

@ -37,10 +37,10 @@ import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
import org.jivesoftware.smackx.jingle.exception.FailedTransportException;
import org.jivesoftware.smackx.jingle.internal.JingleContent;
import org.jivesoftware.smackx.jingle.internal.JingleSession;
import org.jivesoftware.smackx.jingle.internal.JingleTransport;
import org.jivesoftware.smackx.jingle.internal.JingleTransportCandidate;
import org.jivesoftware.smackx.jingle.components.JingleContent;
import org.jivesoftware.smackx.jingle.components.JingleSession;
import org.jivesoftware.smackx.jingle.components.JingleTransport;
import org.jivesoftware.smackx.jingle.components.JingleTransportCandidate;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportCandidateElement;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportElement;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportInfoElement;

View file

@ -21,7 +21,7 @@ import java.util.ArrayList;
import org.jivesoftware.smackx.jingle.adapter.JingleTransportAdapter;
import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidateElement;
import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement;
import org.jivesoftware.smackx.jingle.internal.JingleTransportCandidate;
import org.jivesoftware.smackx.jingle.components.JingleTransportCandidate;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportCandidateElement;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportElement;

View file

@ -26,8 +26,8 @@ import org.jivesoftware.smackx.bytestreams.socks5.Socks5Client;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5ClientForInitiator;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportCandidateElement;
import org.jivesoftware.smackx.jingle.internal.JingleSession;
import org.jivesoftware.smackx.jingle.internal.JingleTransportCandidate;
import org.jivesoftware.smackx.jingle.components.JingleSession;
import org.jivesoftware.smackx.jingle.components.JingleTransportCandidate;
/**
* Jingle SOCKS5Bytestream transport candidate.

View file

@ -37,16 +37,16 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.element.JingleElement;
import org.jivesoftware.smackx.jingle.internal.JingleContent;
import org.jivesoftware.smackx.jingle.internal.JingleSession;
import org.jivesoftware.smackx.jingle.internal.JingleTransport;
import org.jivesoftware.smackx.jingle.internal.JingleTransportCandidate;
import org.jivesoftware.smackx.jingle.components.JingleContent;
import org.jivesoftware.smackx.jingle.components.JingleSession;
import org.jivesoftware.smackx.jingle.components.JingleTransport;
import org.jivesoftware.smackx.jingle.components.JingleTransportCandidate;
import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportCandidateElement;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportElement;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.element.JingleS5BTransportInfoElement;
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.provider.JingleS5BTransportProvider;
import org.jivesoftware.smackx.jingle.transport.JingleTransportManager;
import org.jivesoftware.smackx.jingle.JingleTransportManager;
import org.jivesoftware.smackx.jingle.element.JingleAction;
import org.jivesoftware.smackx.jingle.element.JingleContentElement;

View file

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle;
package org.jivesoftware.smackx.jingle.util;
import org.jxmpp.jid.FullJid;

View file

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle;
package org.jivesoftware.smackx.jingle.util;
public enum Role {
initiator,

View file

@ -21,6 +21,7 @@ import static junit.framework.TestCase.assertNotSame;
import static junit.framework.TestCase.assertTrue;
import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smackx.jingle.util.FullJidAndSessionId;
import org.junit.Test;
import org.jxmpp.jid.FullJid;