From 5e0ec90bf4bf9c4dd93f8595b66d1e009a6aa419 Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Thu, 16 Sep 2021 20:21:43 -0500 Subject: [PATCH 1/2] also use xmpp JID as part of settings persistence --- distributor/xmpp.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/distributor/xmpp.go b/distributor/xmpp.go index 9a87ce3..4683e99 100644 --- a/distributor/xmpp.go +++ b/distributor/xmpp.go @@ -178,7 +178,7 @@ func (s *XMPPService) selectGateway() { if s.KeepGateway { return } - conns := s.store.GetUnequalSettings(s.gateway.String()) + conns := s.store.GetUnequalSettings(s.gateway.String() + s.session.LocalAddr().Bare().String()) if len(conns) <= 0 { return } @@ -242,7 +242,7 @@ func (s *XMPPService) Register(appID, appToken string) (string, string, error) { "appID": appID, "appToken": appToken, }) - conn := s.store.NewConnection(appID, appToken, s.gateway.String()) + conn := s.store.NewConnection(appID, appToken, s.gateway.String()+s.session.LocalAddr().Bare().String()) if conn == nil { errStr := "error to store public token" err := errors.New(errStr) -- 2.44.0 From 656c3237ddddbcdb4eb4b39d0aa25a20986d40b6 Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Fri, 17 Sep 2021 09:58:20 -0500 Subject: [PATCH 2/2] add other part of conn.Settings check --- distributor/xmpp.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/distributor/xmpp.go b/distributor/xmpp.go index 4683e99..cba241a 100644 --- a/distributor/xmpp.go +++ b/distributor/xmpp.go @@ -6,6 +6,7 @@ import ( "encoding/xml" "errors" "io" + "strings" "time" "github.com/bdlm/log" @@ -112,7 +113,7 @@ func (s *XMPPService) message(msgHead stanza.Message, t xmlstream.TokenReadEncod return nil } from := msgHead.From.String() - if from != conn.Settings { + if settings := strings.Split(conn.Settings, ":"); len(settings) > 1 && settings[0] == from { log.WithField("from", from).Info("message not from gateway, that is no notification") return nil } @@ -178,7 +179,7 @@ func (s *XMPPService) selectGateway() { if s.KeepGateway { return } - conns := s.store.GetUnequalSettings(s.gateway.String() + s.session.LocalAddr().Bare().String()) + conns := s.store.GetUnequalSettings(s.gateway.String() + ":" + s.session.LocalAddr().Bare().String()) if len(conns) <= 0 { return } @@ -242,7 +243,7 @@ func (s *XMPPService) Register(appID, appToken string) (string, string, error) { "appID": appID, "appToken": appToken, }) - conn := s.store.NewConnection(appID, appToken, s.gateway.String()+s.session.LocalAddr().Bare().String()) + conn := s.store.NewConnection(appID, appToken, s.gateway.String()+":"+s.session.LocalAddr().Bare().String()) if conn == nil { errStr := "error to store public token" err := errors.New(errStr) -- 2.44.0