Parcourir la source

Handle StreamReplaced errors

Tulir Asokan il y a 2 ans
Parent
commit
60506593e5
6 fichiers modifiés avec 18 ajouts et 4 suppressions
  1. 2 1
      config/bridge.go
  2. 1 0
      config/upgrade.go
  3. 3 0
      example-config.yaml
  4. 1 1
      go.mod
  5. 2 2
      go.sum
  6. 9 0
      user.go

+ 2 - 1
config/bridge.go

@@ -121,7 +121,8 @@ type BridgeConfig struct {
 	DisableStatusBroadcastSend   bool `yaml:"disable_status_broadcast_send"`
 	DisappearingMessagesInGroups bool `yaml:"disappearing_messages_in_groups"`
 
-	DisableBridgeAlerts bool `yaml:"disable_bridge_alerts"`
+	DisableBridgeAlerts   bool `yaml:"disable_bridge_alerts"`
+	CrashOnStreamReplaced bool `yaml:"crash_on_stream_replaced"`
 
 	CommandPrefix string `yaml:"command_prefix"`
 

+ 1 - 0
config/upgrade.go

@@ -89,6 +89,7 @@ func DoUpgrade(helper *up.Helper) {
 	helper.Copy(up.Bool, "bridge", "federate_rooms")
 	helper.Copy(up.Bool, "bridge", "disappearing_messages_in_groups")
 	helper.Copy(up.Bool, "bridge", "disable_bridge_alerts")
+	helper.Copy(up.Bool, "bridge", "crash_on_stream_replaced")
 	helper.Copy(up.Bool, "bridge", "url_previews")
 	helper.Copy(up.Bool, "bridge", "caption_in_message")
 	helper.Copy(up.Str|up.Null, "bridge", "message_handling_timeout", "error_after")

+ 3 - 0
example-config.yaml

@@ -274,6 +274,9 @@ bridge:
     # Should the bridge never send alerts to the bridge management room?
     # These are mostly things like the user being logged out.
     disable_bridge_alerts: false
+    # Should the bridge stop if the WhatsApp server says another user connected with the same session?
+    # This is only safe on single-user bridges.
+    crash_on_stream_replaced: false
     # Should the bridge detect URLs in outgoing messages, ask the homeserver to generate a preview,
     # and send it to WhatsApp? URL previews can always be sent using the `com.beeper.linkpreviews`
     # key in the event content even if this is disabled.

+ 1 - 1
go.mod

@@ -16,7 +16,7 @@ require (
 	golang.org/x/net v0.0.0-20220812174116-3211cb980234
 	google.golang.org/protobuf v1.28.1
 	maunium.net/go/maulogger/v2 v2.3.2
-	maunium.net/go/mautrix v0.12.1-0.20220825085831-88c1e0dc4593
+	maunium.net/go/mautrix v0.12.1-0.20220906193443-f700a94f80b7
 )
 
 require (

+ 2 - 2
go.sum

@@ -100,5 +100,5 @@ maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
 maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
 maunium.net/go/maulogger/v2 v2.3.2 h1:1XmIYmMd3PoQfp9J+PaHhpt80zpfmMqaShzUTC7FwY0=
 maunium.net/go/maulogger/v2 v2.3.2/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
-maunium.net/go/mautrix v0.12.1-0.20220825085831-88c1e0dc4593 h1:HsTKCkpyDnJg0rOjzynChCAgK9NrICXEqMRaRiz43fI=
-maunium.net/go/mautrix v0.12.1-0.20220825085831-88c1e0dc4593/go.mod h1:/jxQFIipObSsjZPH6o3xyUi8uoULz3Hfr/8p9loqpYE=
+maunium.net/go/mautrix v0.12.1-0.20220906193443-f700a94f80b7 h1:7HXfRjWHoZ9ISo9K19yR1j8WSrbn1q2Sd0eqdAQXxVg=
+maunium.net/go/mautrix v0.12.1-0.20220906193443-f700a94f80b7/go.mod h1:/jxQFIipObSsjZPH6o3xyUi8uoULz3Hfr/8p9loqpYE=

+ 9 - 0
user.go

@@ -815,6 +815,15 @@ func (user *User) HandleEvent(event interface{}) {
 		}
 		go user.BridgeState.Send(status.BridgeState{StateEvent: status.StateUnknownError, Message: message})
 		user.bridge.Metrics.TrackConnectionState(user.JID, false)
+	case *events.StreamReplaced:
+		if user.bridge.Config.Bridge.CrashOnStreamReplaced {
+			user.log.Infofln("Stopping bridge due to StreamReplaced event")
+			user.bridge.ManualStop(60)
+		} else {
+			go user.BridgeState.Send(status.BridgeState{StateEvent: status.StateUnknownError, Message: "Stream replaced"})
+			user.bridge.Metrics.TrackConnectionState(user.JID, false)
+			user.sendMarkdownBridgeAlert("The bridge was started in another location. Use `reconnect` to reconnect this one.")
+		}
 	case *events.ConnectFailure:
 		go user.BridgeState.Send(status.BridgeState{StateEvent: status.StateUnknownError, Message: fmt.Sprintf("Unknown connection failure: %s", v.Reason)})
 		user.bridge.Metrics.TrackConnectionState(user.JID, false)