File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed
Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -373,6 +373,34 @@ func (br *Bridge) StartLogins(ctx context.Context) error {
373373 return nil
374374}
375375
376+ func (br * Bridge ) ResetNetworkConnections () {
377+ nrn , ok := br .Network .(NetworkResettingNetwork )
378+ if ok {
379+ br .Log .Info ().Msg ("Resetting network connections with NetworkConnector.ResetNetworkConnections" )
380+ nrn .ResetNetworkConnections ()
381+ return
382+ }
383+
384+ br .Log .Info ().Msg ("Network connector doesn't support ResetNetworkConnections, recreating clients manually" )
385+ for _ , login := range br .GetAllCachedUserLogins () {
386+ login .Log .Debug ().Msg ("Disconnecting and recreating client for network reset" )
387+ ctx := login .Log .WithContext (br .BackgroundCtx )
388+ login .Client .Disconnect ()
389+ err := login .recreateClient (ctx )
390+ if err != nil {
391+ login .Log .Err (err ).Msg ("Failed to recreate client during network reset" )
392+ login .BridgeState .Send (status.BridgeState {
393+ StateEvent : status .StateUnknownError ,
394+ Error : "bridgev2-network-reset-fail" ,
395+ Info : map [string ]any {"go_error" : err .Error ()},
396+ })
397+ } else {
398+ login .Client .Connect (ctx )
399+ }
400+ }
401+ br .Log .Info ().Msg ("Finished resetting all user logins" )
402+ }
403+
376404func (br * Bridge ) IsStopping () bool {
377405 return br .stopping .Load ()
378406}
Original file line number Diff line number Diff line change @@ -318,6 +318,16 @@ type MaxFileSizeingNetwork interface {
318318 SetMaxFileSize (maxSize int64 )
319319}
320320
321+ type NetworkResettingNetwork interface {
322+ NetworkConnector
323+ // ResetHTTPTransport should recreate the HTTP client used by the bridge.
324+ // It should refetch settings from the Matrix connector using GetHTTPClientSettings if applicable.
325+ ResetHTTPTransport ()
326+ // ResetNetworkConnections should forcefully disconnect and restart any persistent network connections.
327+ // ResetHTTPTransport will usually be called before this, so resetting the transport is not necessary here.
328+ ResetNetworkConnections ()
329+ }
330+
321331type RemoteEchoHandler func (RemoteMessage , * database.Message ) (bool , error )
322332
323333type MatrixMessageResponse struct {
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
1010 "cmp"
1111 "context"
1212 "fmt"
13+ "maps"
1314 "slices"
1415 "sync"
1516 "time"
@@ -140,6 +141,12 @@ func (br *Bridge) GetCachedUserLoginByID(id networkid.UserLoginID) *UserLogin {
140141 return br .userLoginsByID [id ]
141142}
142143
144+ func (br * Bridge ) GetAllCachedUserLogins () (logins []* UserLogin ) {
145+ br .cacheLock .Lock ()
146+ defer br .cacheLock .Unlock ()
147+ return slices .Collect (maps .Values (br .userLoginsByID ))
148+ }
149+
143150func (br * Bridge ) GetCurrentBridgeStates () (states []status.BridgeState ) {
144151 br .cacheLock .Lock ()
145152 defer br .cacheLock .Unlock ()
You can’t perform that action at this time.
0 commit comments