1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 17:49:38 +02:00

Introduce Smack's Modular Connection Architecture

This is a complete redesign of what was previously
XmppNioTcpConnection. The new architecture allows to extend an XMPP
client to server (c2s) connection with new transport bindings and
other extensions.
This commit is contained in:
Florian Schmaus 2020-04-04 13:03:31 +02:00
parent cec312fe64
commit cc636fff21
142 changed files with 6819 additions and 4068 deletions

View file

@ -1,33 +0,0 @@
/**
*
* Copyright 2018 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack.tcp;
import org.jivesoftware.smack.fsm.StateDescriptor;
import org.jivesoftware.smack.fsm.StateDescriptorGraph.GraphVertex;
import org.jivesoftware.smack.tcp.XmppNioTcpConnection.InstantShutdownStateDescriptor;
public class XmppNioTcpConnectionTest {
public void graphComplete() {
assertContains(XmppNioTcpConnection.INITIAL_STATE_DESCRIPTOR_VERTEX, InstantShutdownStateDescriptor.class);
}
private static void assertContains(GraphVertex<StateDescriptor> graph, Class<? extends StateDescriptor> state) {
// TODO: Implement this.
throw new Error("Implement me: " + graph + " " + state);
}
}

View file

@ -0,0 +1,87 @@
/**
*
* Copyright 2018-2020 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack.tcp.rce;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.datatypes.UInt16;
import org.jivesoftware.smack.tcp.rce.RemoteXmppTcpConnectionEndpoints.DomainType;
import org.jivesoftware.smack.util.rce.RemoteConnectionEndpoint;
import org.jivesoftware.smack.util.rce.RemoteConnectionEndpointLookupFailure;
import org.jivesoftware.smack.util.rce.RemoteConnectionException;
import org.junit.jupiter.api.Test;
import org.minidns.record.A;
public class RemoteXmppTcpConnectionEndpointsTest {
@Test
public void simpleDomainTypeTest() {
DomainType client = DomainType.client;
assertEquals(RemoteXmppTcpConnectionEndpoints.XMPP_CLIENT_DNS_SRV_PREFIX, client.srvPrefix.ace);
DomainType server = DomainType.server;
assertEquals(RemoteXmppTcpConnectionEndpoints.XMPP_SERVER_DNS_SRV_PREFIX, server.srvPrefix.ace);
}
@Test
public void testConnectionException() {
List<RemoteConnectionException<? extends RemoteConnectionEndpoint>> connectionExceptions = new ArrayList<>();
{
A aRr = new A("1.2.3.4");
UInt16 port = UInt16.from(1234);
String host = "example.org";
IpTcpRemoteConnectionEndpoint<A> remoteConnectionEndpoint = new IpTcpRemoteConnectionEndpoint<>(host, port,
aRr);
Exception exception = new Exception("Failed for some reason");
RemoteConnectionException<IpTcpRemoteConnectionEndpoint<A>> remoteConnectionException = RemoteConnectionException.from(
remoteConnectionEndpoint, exception);
connectionExceptions.add(remoteConnectionException);
}
{
A aRr = new A("1.3.3.7");
UInt16 port = UInt16.from(5678);
String host = "other.example.org";
IpTcpRemoteConnectionEndpoint<A> remoteConnectionEndpoint = new IpTcpRemoteConnectionEndpoint<>(host, port,
aRr);
Exception exception = new Exception("Failed for some other reason");
RemoteConnectionException<IpTcpRemoteConnectionEndpoint<A>> remoteConnectionException = RemoteConnectionException.from(
remoteConnectionEndpoint, exception);
connectionExceptions.add(remoteConnectionException);
}
List<RemoteConnectionEndpointLookupFailure> lookupFailures = Collections.emptyList();
SmackException.EndpointConnectionException endpointConnectionException = SmackException.EndpointConnectionException.from(
lookupFailures, connectionExceptions);
String message = endpointConnectionException.getMessage();
assertEquals("The following addresses failed: "
+ "'RFC 6120 A/AAAA Endpoint + [example.org:1234] (/1.2.3.4:1234)' failed because: java.lang.Exception: Failed for some reason, "
+ "'RFC 6120 A/AAAA Endpoint + [other.example.org:5678] (/1.3.3.7:5678)' failed because: java.lang.Exception: Failed for some other reason",
message);
}
}