From 63aa921252668393096c0616a9b29b8a84052a0d Mon Sep 17 00:00:00 2001 From: Geno Date: Wed, 15 Sep 2021 17:04:06 +0200 Subject: [PATCH] distributor: check server for msgoffline support XEP-0160 with discovery XEP-0030 ;) wip #8 --- distributor/go.mod | 2 ++ distributor/xmpp.go | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/distributor/go.mod b/distributor/go.mod index 53d737a..b2441bd 100644 --- a/distributor/go.mod +++ b/distributor/go.mod @@ -35,3 +35,5 @@ require ( ) replace dev.sum7.eu/genofire/unified-push-xmpp/messages => ../messages + +replace mellium.im/xmpp => ../../../../mellium.im/xmpp diff --git a/distributor/xmpp.go b/distributor/xmpp.go index 065238c..526cd27 100644 --- a/distributor/xmpp.go +++ b/distributor/xmpp.go @@ -12,6 +12,7 @@ import ( "mellium.im/sasl" "mellium.im/xmlstream" "mellium.im/xmpp" + "mellium.im/xmpp/disco" "mellium.im/xmpp/jid" "mellium.im/xmpp/mux" "mellium.im/xmpp/stanza" @@ -62,7 +63,9 @@ func (s *XMPPService) Run(dbus *distributor.DBus, store *storage.Storage) error if err != nil { return err } + go s.checkServer() s.session.Serve(mux.New( + // disco.Handle(), mux.MessageFunc("", xml.Name{Local: "subject"}, s.message), )) return nil @@ -116,6 +119,28 @@ func (s *XMPPService) message(msgHead stanza.Message, t xmlstream.TokenReadEncod return nil } +// checkServer - background job +func (s *XMPPService) checkServer() error { + domain := s.session.LocalAddr().Domain() + log.Infof("your instant is %s - check running", domain) + info, err := disco.GetInfo(context.TODO(), "", domain, s.session) + if err != nil { + return err + } + // check if server support msgoffline + supportMSGOffline := false + for _, f := range info.Features { + if f.Var == "msgoffline" { + supportMSGOffline = true + break + } + } + if !supportMSGOffline { + log.Warn("your server does not support offline messages (XEP-0160) - it is need to deliever messages later, if this distributer has current no connection") + } + return nil +} + // Register handler of DBUS Distribution func (s *XMPPService) Register(appID, appToken string) (string, string, error) { publicToken := uuid.New().String()