From 965008e8462e42b55c2554d8e8993fa9d90cbd81 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 14 Oct 2024 19:47:22 +0300 Subject: [PATCH] bridgev2: add optional stop method for network connectors --- bridgev2/bridge.go | 3 +++ bridgev2/networkinterface.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/bridgev2/bridge.go b/bridgev2/bridge.go index 2b520e23..16ebdb77 100644 --- a/bridgev2/bridge.go +++ b/bridgev2/bridge.go @@ -216,6 +216,9 @@ func (br *Bridge) Stop() { } wg.Wait() br.cacheLock.Unlock() + if stopNet, ok := br.Network.(StoppableNetwork); ok { + stopNet.Stop() + } err := br.DB.Close() if err != nil { br.Log.Warn().Err(err).Msg("Failed to close database") diff --git a/bridgev2/networkinterface.go b/bridgev2/networkinterface.go index 3b406a9d..ae7d6520 100644 --- a/bridgev2/networkinterface.go +++ b/bridgev2/networkinterface.go @@ -229,6 +229,11 @@ type NetworkConnector interface { CreateLogin(ctx context.Context, user *User, flowID string) (LoginProcess, error) } +type StoppableNetwork interface { + // Stop is called when the bridge is stopping, after all network clients have been disconnected. + Stop() +} + // DirectMediableNetwork is an optional interface that network connectors can implement to support direct media access. // // If the Matrix connector has direct media enabled, SetUseDirectMedia will be called