1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-09 10:19:41 +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,48 @@
description = """\
Full Smack library for Java SE."""
dependencies {
api project(':smack-bosh')
api project(':smack-debug')
api project(':smack-experimental')
api project(':smack-extensions')
api project(':smack-java7')
api project(':smack-legacy')
api project(':smack-omemo')
api project(':smack-omemo-signal')
api project(':smack-openpgp')
api project(':smack-resolver-minidns')
api project(':smack-resolver-minidns-dox')
api project(':smack-tcp')
testImplementation project(path: ":smack-core", configuration: "testRuntime")
}
task printModularXmppClientToServerConnectionStateGraph(type: JavaExec) {
classpath sourceSets.main.runtimeClasspath
main 'org.jivesoftware.smack.full.ModularXmppClientToServerConnectionTool'
}
task generateModularXmppClientToServerConnectionStateGraph(type: JavaExec) {
// TODO: Filter out all files which do not contain the String
// StateDescriptor.
inputs.files file('..').listFiles().findAll {it.name.endsWith('.java')}
outputs.files 'src/javadoc/org/jivesoftware/smack/full/doc-files/ModularXmppClientToServerConnectionStateGraph.dot'
classpath sourceSets.main.runtimeClasspath
main 'org.jivesoftware.smack.full.ModularXmppClientToServerConnectionTool'
args outputs.files
}
task convertModularXmppClientToServerConnectionStateGraphDotToPng(type: Exec) {
dependsOn generateModularXmppClientToServerConnectionStateGraph
inputs.files 'src/javadoc/org/jivesoftware/smack/full/doc-files/ModularXmppClientToServerConnectionStateGraph.dot'
outputs.files 'src/javadoc/org/jivesoftware/smack/full/doc-files/ModularXmppClientToServerConnectionStateGraph.png'
executable 'dot'
args "-Tpng", "-o", "${outputs.files.first()}", "${inputs.files.first()}"
}
task cleanGenerateFiles(type: Delete) {
delete 'src/javadoc/org/jivesoftware/smack/full/doc-files/ModularXmppClientToServerConnectionStateGraph.dot', 'src/javadoc/org/jivesoftware/smack/full/doc-files/ModularXmppClientToServerConnectionStateGraph.png'
}
clean.dependsOn cleanGenerateFiles

View file

@ -0,0 +1,2 @@
/ModularXmppClientToServerConnectionStateGraph.dot
/ModularXmppClientToServerConnectionStateGraph.png

View file

@ -0,0 +1,71 @@
/**
*
* 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.full;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration;
import org.jxmpp.stringprep.XmppStringprepException;
public class ModularXmppClientToServerConnectionTool {
@SuppressWarnings("DefaultCharset")
public static void main(String[] args) throws XmppStringprepException, FileNotFoundException {
final PrintWriter pw;
final boolean breakStateName;
switch (args.length) {
case 0:
pw = new PrintWriter(System.out);
breakStateName = false;
break;
case 1:
Path outputFilePath = Paths.get(args[0]);
File outputFile = outputFilePath.toFile();
if (outputFile.exists()) {
outputFile.delete();
}
pw = new PrintWriter(outputFile);
breakStateName = true;
break;
default:
throw new IllegalArgumentException("At most one argument allowed");
}
printStateGraph(pw, breakStateName);
pw.flush();
}
public static void printStateGraph(PrintWriter pw, boolean breakStateName) throws XmppStringprepException {
ModularXmppClientToServerConnectionConfiguration.Builder configurationBuilder = ModularXmppClientToServerConnectionConfiguration.builder()
.setUsernameAndPassword("user", "password")
.setXmppDomain("example.org");
ModularXmppClientToServerConnectionConfiguration configuration = configurationBuilder.build();
configuration.printStateGraphInDotFormat(pw, breakStateName);
pw.flush();
}
}

View file

@ -0,0 +1,28 @@
/**
*
* 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.
*/
/**
* The Smack XMPP client library.
* <h2>Modular XMPP c2s connection</h2>
* <p>
* The graph below shows the current states of the modular xmpp client connection. Only some states are final states,
* most states are intermediate states in order to reach a final state.
* </p>
* <img src="doc-files/ModularXmppClientToServerConnectionStateGraph.png" alt="The state graph of XmppNioTcpConnection">
*/
package org.jivesoftware.smack.full;

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 ]
}