1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 09:39:39 +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

@ -0,0 +1,83 @@
/**
*
* Copyright 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.full;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import org.jivesoftware.smack.util.EqualsUtil;
import org.jivesoftware.smack.util.HashCode;
import com.google.common.io.Resources;
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.graph.DirectedPseudograph;
import org.jgrapht.io.DOTImporter;
import org.jgrapht.io.ImportException;
import org.junit.jupiter.api.Test;
public class ModularXmppClientToServerConnectionStateGraphTest {
@Test
public void testStateGraphDotOutput() throws IOException, ImportException {
URL stateGraphDotFileUrl = Resources.getResource("state-graph.dot");
String expectedStateGraphDot = Resources.toString(stateGraphDotFileUrl, StandardCharsets.UTF_8);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ModularXmppClientToServerConnectionTool.printStateGraph(pw, false);
String currentStateGraphDot = sw.toString();
@SuppressWarnings("serial")
DOTImporter<String, DefaultEdge> dotImporter = new DOTImporter<>(
(id, attributes) -> id,
(from, to, label, attributes) -> {
return new DefaultEdge() {
@Override
public int hashCode() {
return HashCode.builder()
.append(getSource())
.append(getTarget())
.build();
}
@Override
public boolean equals(Object other) {
return EqualsUtil.equals(this, other, (b, o) ->
b.append(getSource(), o.getSource())
.append(getTarget(), o.getTarget())
);
}
};
}
);
DirectedPseudograph<String, DefaultEdge> currentStateGraph = new DirectedPseudograph<>(DefaultEdge.class);
DirectedPseudograph<String, DefaultEdge> expectedStateGraph = new DirectedPseudograph<>(DefaultEdge.class);
dotImporter.importGraph(expectedStateGraph, new StringReader(expectedStateGraphDot));
dotImporter.importGraph(currentStateGraph, new StringReader(currentStateGraphDot));
assertEquals(expectedStateGraph, currentStateGraph);
}
}

View file

@ -0,0 +1,36 @@
digraph {
"Disconnected" -> "LookupRemoteConnectionEndpoints";
"LookupRemoteConnectionEndpoints" -> "EstablishingTcpConnection";
"EstablishingTcpConnection" -> "EstablishTls (RFC 6120 § 5)" [xlabel="1"];
"EstablishTls (RFC 6120 § 5)" -> "ConnectedButUnauthenticated";
"ConnectedButUnauthenticated" -> "Bind2 (XEP-0386)" [xlabel="1"];
"Bind2 (XEP-0386)" -> "AuthenticatedAndResourceBound";
"AuthenticatedAndResourceBound" -> "Shutdown" [xlabel="1"];
"Shutdown" -> "CloseConnection";
"CloseConnection" -> "Disconnected";
"AuthenticatedAndResourceBound" -> "InstantShutdown" [xlabel="2"];
"InstantShutdown" -> "CloseConnection";
"AuthenticatedAndResourceBound" [ style=filled ]
"Bind2 (XEP-0386)" [ style=dashed ]
"ConnectedButUnauthenticated" -> "InstantStreamResumption (XEP-0397)" [xlabel="2"];
"InstantStreamResumption (XEP-0397)" -> "AuthenticatedAndResourceBound";
"InstantStreamResumption (XEP-0397)" [ style=dashed ]
"ConnectedButUnauthenticated" -> "SaslAuthentication (RFC 6120 § 6)" [xlabel="3"];
"SaslAuthentication (RFC 6120 § 6)" -> "AuthenticatedButUnbound";
"AuthenticatedButUnbound" -> "Compression (XEP-0138)" [xlabel="1"];
"Compression (XEP-0138)" -> "AuthenticatedButUnbound";
"AuthenticatedButUnbound" -> "ResumeStream (XEP-0198)" [xlabel="2"];
"ResumeStream (XEP-0198)" -> "AuthenticatedAndResourceBound";
"ResumeStream (XEP-0198)" [ style=dashed ]
"AuthenticatedButUnbound" -> "ResourceBinding (RFC 6120 § 7)" [xlabel="3"];
"ResourceBinding (RFC 6120 § 7)" -> "EnableStreamManagement (XEP-0198)" [xlabel="1"];
"EnableStreamManagement (XEP-0198)" -> "AuthenticatedAndResourceBound";
"EnableStreamManagement (XEP-0198)" [ style=dashed ]
"ResourceBinding (RFC 6120 § 7)" -> "AuthenticatedAndResourceBound" [xlabel="2"];
"AuthenticatedButUnbound" [ style=bold ]
"ConnectedButUnauthenticated" -> "Shutdown" [xlabel="4"];
"ConnectedButUnauthenticated" -> "InstantShutdown" [xlabel="5"];
"ConnectedButUnauthenticated" [ style=filled ]
"EstablishingTcpConnection" -> "ConnectedButUnauthenticated" [xlabel="2"];
"Disconnected" [ style=filled ]
}