aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClombrong <cromblong@egregore.fun>2025-06-29 19:44:53 +0200
committerClombrong <cromblong@egregore.fun>2025-06-29 19:44:53 +0200
commit305c0b127a15e4abd729cd923507330ddb5fd085 (patch)
tree53cb52ef04b55c8d97f21a2a066e9bf571124709
parent9f2b84dfad021c2e520fb25170fce709c728745e (diff)
refactor(stream): move start_stream outside of negotiate
-rw-r--r--lib/stream.ml15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/stream.ml b/lib/stream.ml
index e790980..6b46ed6 100644
--- a/lib/stream.ml
+++ b/lib/stream.ml
@@ -50,6 +50,12 @@ let parse_features (stanza : Xml.element) : features =
| [], [STARTTLS] -> [STARTTLS], []
| _ -> features
+(** [start domain portal] is a promise to features that starts a stream negotiation with
+ the XMPP server [portal]. *)
+let start (domain : string) (portal : Portal.t) : features Lwt.t =
+ let* _id = Portal.header domain portal
+ in Wire.get portal.stream >|= parse_features
+
let negotiate_feature (mandatory : bool) (feat : feature) (portal : Portal.t)
({starttls; sasl; _} : config) : unit Lwt.t =
(* authenticate using SASL with the XMPP server. *)
@@ -94,19 +100,14 @@ let negotiate
| Mechanisms _ | STARTTLS -> true
| _ -> false
in
- (* Restart a stream: Send the usual business, ask for features. *)
- let start_stream () : features Lwt.t =
- let* _id = Portal.header domain portal
- in Wire.get portal.stream >|= parse_features
- in
let rec handle_features (f : features) : features Lwt.t =
match f with
| m :: mandatory, optional -> let* () = negotiate_feature true m portal config
in if needs_restart m
- then start_stream () >>= handle_features
+ then start domain portal >>= handle_features
else handle_features (mandatory, optional)
| [], _ -> Lwt.return f
- in start_stream () >>= handle_features
+ in start domain portal >>= handle_features
(** [initiate domain] initiates a stream with the XMPP server [domain]. *)
let initiate (domain : string) (config : config) : (Portal.t * features) Lwt.t =