From 8f844b1cde0d6eb1dd076ac6569d3eea94fe1493 Mon Sep 17 00:00:00 2001 From: Martin Dosch Date: Sun, 4 Jun 2023 11:47:56 +0200 Subject: [PATCH] Fall back to direct TLS on port 5223 Fall back to direct TLS on port 5223 if direct tls is set and no SRV records are provided. --- CHANGELOG.md | 1 + connect.go | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b45f6f..87f35fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Allow JIDs without localpart. - Use single quotes for attributes in stanzas created by github.com/beevik/etree (vial etree v1.1.4). - Fix SRV lookup when the domain has a CNAME (via xmppsrv v0.2.5). +- Fall back to directTLS on port 5223 (instead of StartTLS on port 5222) if no SRV records are provided and `-t` is set. ## [v0.5.6] 2022-11-11 ### Added diff --git a/connect.go b/connect.go index b5869a3..70f43eb 100644 --- a/connect.go +++ b/connect.go @@ -46,13 +46,23 @@ func connect(options xmpp.Options, directTLS bool) (*xmpp.Client, error) { } } } - // Try port 5222 if no xmpp-client SRV records are provided. - options.NoTLS = true - options.StartTLS = true - options.Host = net.JoinHostPort(server, "5222") - // Connect to server - client, err := options.NewClient() - return client, err + // Try port 5223 if directTLS is set and no xmpp-client SRV records are provided. + if directTLS { + options.NoTLS = false + options.StartTLS = false + options.Host = net.JoinHostPort(server, "5223") + // Connect to server + client, err := options.NewClient() + return client, err + } else { + // Try port 5222 if no xmpp-client SRV records are provided and directTLS is not set. + options.NoTLS = true + options.StartTLS = true + options.Host = net.JoinHostPort(server, "5222") + // Connect to server + client, err := options.NewClient() + return client, err + } } // Connect to server client, err := options.NewClient()