summaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-07-20 23:16:43 +0200
committerWim <wim@42.be>2017-07-20 23:16:43 +0200
commit0f791d7a9a47ec956e247f70a31d8cc230aaa5e4 (patch)
treecc341a387d80d628079e97dccc5ae958aee845a8 /bridge
parent58779e0d65fbda528a33b4e1757c624da9cbeda9 (diff)
downloadmatterbridge-msglm-0f791d7a9a47ec956e247f70a31d8cc230aaa5e4.tar.gz
matterbridge-msglm-0f791d7a9a47ec956e247f70a31d8cc230aaa5e4.tar.bz2
matterbridge-msglm-0f791d7a9a47ec956e247f70a31d8cc230aaa5e4.zip
Handle reconnections better (xmpp). Closes #222
Diffstat (limited to 'bridge')
-rw-r--r--bridge/xmpp/xmpp.go31
1 files changed, 29 insertions, 2 deletions
diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go
index 0bd664d9..504b9747 100644
--- a/bridge/xmpp/xmpp.go
+++ b/bridge/xmpp/xmpp.go
@@ -4,6 +4,7 @@ import (
"crypto/tls"
"github.com/42wim/matterbridge/bridge/config"
log "github.com/Sirupsen/logrus"
+ "github.com/jpillora/backoff"
"github.com/mattn/go-xmpp"
"strings"
@@ -43,7 +44,29 @@ func (b *Bxmpp) Connect() error {
return err
}
flog.Info("Connection succeeded")
- go b.handleXmpp()
+ go func() {
+ initial := true
+ bf := &backoff.Backoff{
+ Min: time.Second,
+ Max: 5 * time.Minute,
+ Jitter: true,
+ }
+ for {
+ if initial {
+ b.handleXmpp()
+ initial = false
+ }
+ d := bf.Duration()
+ flog.Infof("Disconnected. Reconnecting in %s", d)
+ time.Sleep(d)
+ b.xc, err = b.createXMPP()
+ if err == nil {
+ b.Remote <- config.Message{Username: "system", Text: "rejoin", Channel: "", Account: b.Account, Event: config.EVENT_REJOIN_CHANNELS}
+ b.handleXmpp()
+ bf.Reset()
+ }
+ }
+ }()
return nil
}
@@ -96,7 +119,11 @@ func (b *Bxmpp) xmppKeepAlive() chan bool {
for {
select {
case <-ticker.C:
- b.xc.PingC2S("", "")
+ flog.Debugf("PING")
+ err := b.xc.PingC2S("", "")
+ if err != nil {
+ flog.Debugf("PING failed %#v", err)
+ }
case <-done:
return
}