feat: Make moxxmpp_socket Flutter independent
This commit is contained in:
parent
4855a289d9
commit
565089e1c8
@ -10,8 +10,8 @@ This package contains the actual XMPP code that is platform-independent.
|
|||||||
### moxxmpp_socket
|
### moxxmpp_socket
|
||||||
|
|
||||||
`moxxmpp_socket` contains the implementation of the `BaseSocketWrapper` class that
|
`moxxmpp_socket` contains the implementation of the `BaseSocketWrapper` class that
|
||||||
allows the user to resolve SRV records and thus support XEP-0368. Due to how DNS
|
implements the RFC6120 connection algorithm and XEP-0368 direct TLS connections,
|
||||||
resolution is implemented, Flutter is required.
|
if a DNS implementation is given, and supports StartTLS.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
# This is a generated file; do not edit or check into version control.
|
|
||||||
moxdns=/home/alexander/.pub-cache/hosted/git.polynom.me%47api%47packages%47Moxxy%47pub%47/moxdns-0.1.4/
|
|
||||||
moxdns_android=/home/alexander/.pub-cache/hosted/git.polynom.me%47api%47packages%47Moxxy%47pub%47/moxdns_android-0.1.4/
|
|
||||||
moxdns_linux=/home/alexander/.pub-cache/hosted/git.polynom.me%47api%47packages%47Moxxy%47pub%47/moxdns_linux-0.1.4/
|
|
@ -1 +0,0 @@
|
|||||||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[],"android":[{"name":"moxdns_android","path":"/home/alexander/.pub-cache/hosted/git.polynom.me%47api%47packages%47Moxxy%47pub%47/moxdns_android-0.1.4/","native_build":true,"dependencies":[]}],"macos":[],"linux":[{"name":"moxdns_linux","path":"/home/alexander/.pub-cache/hosted/git.polynom.me%47api%47packages%47Moxxy%47pub%47/moxdns_linux-0.1.4/","native_build":true,"dependencies":[]}],"windows":[],"web":[]},"dependencyGraph":[{"name":"moxdns","dependencies":["moxdns_android","moxdns_linux"]},{"name":"moxdns_android","dependencies":["moxdns"]},{"name":"moxdns_linux","dependencies":["moxdns"]}],"date_created":"2022-11-08 14:21:52.966343","version":"3.3.3"}
|
|
@ -1,6 +1,15 @@
|
|||||||
# moxxmpp_socket
|
# moxxmpp_socket
|
||||||
|
|
||||||
A socket for moxxmpp that does SRV resolution.
|
A socket for moxxmpp that implements the connection algorithm as specified by
|
||||||
|
[RFC6210](https://xmpp.org/rfcs/rfc6120.html) and [XEP-0368](https://xmpp.org/extensions/xep-0368.html),
|
||||||
|
while also supporting StartTLS and direct TLS.
|
||||||
|
|
||||||
|
In order to make this package independent of Flutter, I removed DNS SRV resolution from
|
||||||
|
the package. The `TCPSocketWrapper` contains a method called `srvQuery` that can be
|
||||||
|
overridden by the user. It takes the domain to query and a DNSSEC flag and is expected
|
||||||
|
to return the list of SRV records, encoded by `MoxSrvRecord` objects. To perform the
|
||||||
|
resolution, one can use any DNS library. A Flutter plugin implementing SRV resolution
|
||||||
|
is, for example, [moxdns](https://codeberg.org/moxxy/moxdns).
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
8
moxxmpp_socket/lib/src/record.dart
Normal file
8
moxxmpp_socket/lib/src/record.dart
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/// A data class to represent a DNS SRV record.
|
||||||
|
class MoxSrvRecord {
|
||||||
|
MoxSrvRecord(this.priority, this.weight, this.target, this.port);
|
||||||
|
final int priority;
|
||||||
|
final int weight;
|
||||||
|
final int port;
|
||||||
|
final String target;
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:moxdns/moxdns.dart';
|
import 'package:moxxmpp_socket/src/record.dart';
|
||||||
|
|
||||||
/// Sorts the SRV records according to priority and weight.
|
/// Sorts the SRV records according to priority and weight.
|
||||||
int srvRecordSortComparator(SrvRecord a, SrvRecord b) {
|
int srvRecordSortComparator(MoxSrvRecord a, MoxSrvRecord b) {
|
||||||
if (a.priority < b.priority) {
|
if (a.priority < b.priority) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2,8 +2,9 @@ import 'dart:async';
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:moxdns/moxdns.dart';
|
import 'package:meta/meta.dart';
|
||||||
import 'package:moxxmpp/moxxmpp.dart';
|
import 'package:moxxmpp/moxxmpp.dart';
|
||||||
|
import 'package:moxxmpp_socket/src/record.dart';
|
||||||
import 'package:moxxmpp_socket/src/rfc_2782.dart';
|
import 'package:moxxmpp_socket/src/rfc_2782.dart';
|
||||||
|
|
||||||
/// TCP socket implementation for XmppConnection
|
/// TCP socket implementation for XmppConnection
|
||||||
@ -38,6 +39,16 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
|||||||
void destroy() {
|
void destroy() {
|
||||||
_socketSubscription?.cancel();
|
_socketSubscription?.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Called on connect to perform a SRV query against [domain]. If [dnssec] is true,
|
||||||
|
/// then DNSSEC validation should be performed.
|
||||||
|
///
|
||||||
|
/// Returns a list of SRV records. If none are available or an error occured, an empty
|
||||||
|
/// list is returned.
|
||||||
|
@visibleForOverriding
|
||||||
|
Future<List<MoxSrvRecord>> srvQuery(String domain, bool dnssec) async {
|
||||||
|
return <MoxSrvRecord>[];
|
||||||
|
}
|
||||||
|
|
||||||
bool _onBadCertificate(dynamic certificate, String domain) {
|
bool _onBadCertificate(dynamic certificate, String domain) {
|
||||||
_log.fine('Bad certificate: ${certificate.toString()}');
|
_log.fine('Bad certificate: ${certificate.toString()}');
|
||||||
@ -49,7 +60,7 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
|||||||
|
|
||||||
Future<bool> _xep368Connect(String domain) async {
|
Future<bool> _xep368Connect(String domain) async {
|
||||||
// TODO(Unknown): Maybe do DNSSEC one day
|
// TODO(Unknown): Maybe do DNSSEC one day
|
||||||
final results = await MoxdnsPlugin.srvQuery('_xmpps-client._tcp.$domain', false);
|
final results = await srvQuery('_xmpps-client._tcp.$domain', false);
|
||||||
if (results.isEmpty) {
|
if (results.isEmpty) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -90,7 +101,7 @@ class TCPSocketWrapper extends BaseSocketWrapper {
|
|||||||
|
|
||||||
Future<bool> _rfc6120Connect(String domain) async {
|
Future<bool> _rfc6120Connect(String domain) async {
|
||||||
// TODO(Unknown): Maybe do DNSSEC one day
|
// TODO(Unknown): Maybe do DNSSEC one day
|
||||||
final results = await MoxdnsPlugin.srvQuery('_xmpp-client._tcp.$domain', false);
|
final results = await srvQuery('_xmpp-client._tcp.$domain', false);
|
||||||
results.sort(srvRecordSortComparator);
|
results.sort(srvRecordSortComparator);
|
||||||
|
|
||||||
for (final srv in results) {
|
for (final srv in results) {
|
||||||
|
@ -1,18 +1,15 @@
|
|||||||
name: moxxmpp_socket
|
name: moxxmpp_socket
|
||||||
description: A socket for moxxmpp that resolves SRV records
|
description: A socket for moxxmpp that implements the RFC6120 connection algorithm
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
homepage: https://codeberg.org/moxxy/moxxmpp
|
homepage: https://codeberg.org/moxxy/moxxmpp
|
||||||
publish_to: https://git.polynom.me/api/packages/Moxxy/pub
|
publish_to: https://git.polynom.me/api/packages/Moxxy/pub
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.18.0 <3.0.0'
|
sdk: '>=2.18.0 <3.0.0'
|
||||||
flutter: '>=2.13.0-0.1'
|
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
logging: 1.0.2
|
logging: 1.0.2
|
||||||
moxdns:
|
meta: ^1.6.0
|
||||||
hosted: https://git.polynom.me/api/packages/Moxxy/pub
|
|
||||||
version: 0.1.4
|
|
||||||
moxxmpp:
|
moxxmpp:
|
||||||
hosted: https://git.polynom.me/api/packages/Moxxy/pub
|
hosted: https://git.polynom.me/api/packages/Moxxy/pub
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
|
Loading…
Reference in New Issue
Block a user