last_buttonpress = 0
}
// Try to XMPP Ping the server and if that fails, quit XMPPBot
- if bot.PingServer(2000) == false { return }
+ if bot.PingServer(3500) == false { return }
case r3events.DoorProblemEvent:
xmpp_presence_events_chan <- r3xmppbot.XMPPMsgEvent{Msg: fmt.Sprintf("Door Problem: %s. SeverityLevel: %d (%s)",event.Problem, event.Severity, time.Unix(event.Ts,0).String()), DistributeLevel: r3xmppbot.R3OnlineOnlyInfo, RememberAsStatus: false}
}
} else {
Syslog_.Printf("Error starting XMPP Bot: %s", xmpperr.Error())
}
- time.Sleep(5 * time.Second)
+ time.Sleep(10 * time.Second)
}
}
go RunXMPPBot(ps, zmqctx)
// --- receive and distribute events ---
- ticker := time.NewTicker(time.Duration(5) * time.Minute)
+ ticker := time.NewTicker(time.Duration(6) * time.Minute)
for {
select {
case e := <-zmqsub.In():
if inmsg.Body == nil || inmsg.GetHeader() == nil {
return
}
- if inmsg.Type == "error" || inmsg.Error != nil {
- Syslog_.Printf("XMPP Message Error: %s", inmsg.Error.Error())
- }
bodytext :=inmsg.Body.Chardata
if botdata.isAuthenticated(inmsg.GetHeader().From) {
switch bodytext {
close(jabber_events)
}()
+ var error_count int = 0
var incoming_stanza interface{}
+
+ handleStanzaError := func() bool {
+ error_count++
+ if error_count > 15 {
+ Syslog_.Println("handleIncomingXMPPStanzas: too many errors in series.. bailing out")
+ botdata.StopBot()
+ return true
+ }
+ return false
+ }
+
for incoming_stanza = range xmppin {
switch stanza := incoming_stanza.(type) {
case *xmpp.Message:
+ if stanza.GetHeader() == nil { continue }
botdata.handleIncomingMessageDialog(*stanza, xmppout, jabber_events)
+ if stanza.Type == "error" || stanza.Error != nil {
+ Syslog_.Printf("XMPP %T Error: %s", stanza, stanza)
+ if handleStanzaError() { return }
+ continue
+ } else { error_count = 0 }
case *xmpp.Presence:
if stanza.GetHeader() == nil { continue }
if stanza.Type == "error" || stanza.Error != nil {
- Syslog_.Printf("XMPP Presence Error: %s", stanza.Error.Error())
- }
+ Syslog_.Printf("XMPP %T Error: %s", stanza, stanza)
+ if handleStanzaError() { return }
+ continue
+ } else { error_count = 0 }
switch stanza.GetHeader().Type {
case "subscribe":
xmppout <- botdata.makeXMPPPresence(stanza.GetHeader().From, "subscribed", "", "")
default:
jabber_events <- JabberEvent{stanza.GetHeader().From, true, R3NoChange, false}
}
+
case *xmpp.Iq:
if stanza.GetHeader() == nil { continue }
if stanza.Type == "error" || stanza.Error != nil {
- Syslog_.Printf("XMPP Iq Error: %s", stanza.Error.Error())
- }
+ Syslog_.Printf("XMPP %T Error: %s", stanza, stanza)
+ if handleStanzaError() { return }
+ continue
+ } else { error_count = 0 }
+
if HandleServerToClientPing(stanza, xmppout) {continue} //if true then routine handled it and we can continue
Debug_.Printf("Unhandled Iq: %s", stanza)
}