mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
fix(irc): improve IRC handler management (#1269)
* fix some races in IRC handler management * remove go 1.21 and slices package * chore: update deps * fix: use exp/slices pkg and client callbacks * fix(irc): remove deadlock mutex from authenticate * restore locking in authenticate() * fix(irc): data races * fix(irc): do not allow restart of disabled network * fix(irc): disable restart btn if net disabled --------- Co-authored-by: ze0s <43699394+zze0s@users.noreply.github.com>
This commit is contained in:
parent
17e97201fd
commit
b2c32a421e
5 changed files with 230 additions and 194 deletions
6
go.mod
6
go.mod
|
@ -39,6 +39,7 @@ require (
|
||||||
github.com/stretchr/testify v1.8.4
|
github.com/stretchr/testify v1.8.4
|
||||||
go.uber.org/automaxprocs v1.5.3
|
go.uber.org/automaxprocs v1.5.3
|
||||||
golang.org/x/crypto v0.16.0
|
golang.org/x/crypto v0.16.0
|
||||||
|
golang.org/x/exp v0.0.0-20231127185646-65229373498e
|
||||||
golang.org/x/net v0.19.0
|
golang.org/x/net v0.19.0
|
||||||
golang.org/x/sync v0.5.0
|
golang.org/x/sync v0.5.0
|
||||||
golang.org/x/term v0.15.0
|
golang.org/x/term v0.15.0
|
||||||
|
@ -94,11 +95,10 @@ require (
|
||||||
github.com/subosito/gotenv v1.6.0 // indirect
|
github.com/subosito/gotenv v1.6.0 // indirect
|
||||||
go.uber.org/atomic v1.9.0 // indirect
|
go.uber.org/atomic v1.9.0 // indirect
|
||||||
go.uber.org/multierr v1.9.0 // indirect
|
go.uber.org/multierr v1.9.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
golang.org/x/mod v0.14.0 // indirect
|
||||||
golang.org/x/mod v0.12.0 // indirect
|
|
||||||
golang.org/x/sys v0.15.0 // indirect
|
golang.org/x/sys v0.15.0 // indirect
|
||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
golang.org/x/tools v0.13.0 // indirect
|
golang.org/x/tools v0.16.0 // indirect
|
||||||
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
|
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
lukechampine.com/uint128 v1.3.0 // indirect
|
lukechampine.com/uint128 v1.3.0 // indirect
|
||||||
|
|
6
go.sum
6
go.sum
|
@ -475,6 +475,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH
|
||||||
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
|
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
|
||||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
|
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
|
||||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
|
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
|
||||||
|
golang.org/x/exp v0.0.0-20231127185646-65229373498e h1:Gvh4YaCaXNs6dKTlfgismwWZKyjVZXwOPfIyUaqU3No=
|
||||||
|
golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
|
||||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
|
@ -502,6 +504,8 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91
|
||||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
|
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
|
||||||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
|
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
|
||||||
|
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
@ -698,6 +702,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
|
||||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||||
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
|
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
|
||||||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
||||||
|
golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM=
|
||||||
|
golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
|
|
@ -23,9 +23,14 @@ import (
|
||||||
"github.com/r3labs/sse/v2"
|
"github.com/r3labs/sse/v2"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/sasha-s/go-deadlock"
|
"github.com/sasha-s/go-deadlock"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
connectionInProgress = errors.New("A connection attempt is already in progress")
|
||||||
|
|
||||||
|
clientDisconnected = errors.New("Message cannot be sent because client is disconnected")
|
||||||
|
|
||||||
clientManuallyDisconnected = retry.Unrecoverable(errors.New("IRC client was manually disconnected"))
|
clientManuallyDisconnected = retry.Unrecoverable(errors.New("IRC client was manually disconnected"))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -62,6 +67,14 @@ func (ch *channelHealth) resetMonitoring() {
|
||||||
ch.m.Unlock()
|
ch.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ircState uint
|
||||||
|
|
||||||
|
const (
|
||||||
|
ircStopped ircState = iota // (Handler).client is nil
|
||||||
|
ircConnecting // still nil
|
||||||
|
ircLive // (Handler.client) is non-nil and valid
|
||||||
|
)
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
log zerolog.Logger
|
log zerolog.Logger
|
||||||
sse *sse.Server
|
sse *sse.Server
|
||||||
|
@ -72,11 +85,11 @@ type Handler struct {
|
||||||
definitions map[string]*domain.IndexerDefinition
|
definitions map[string]*domain.IndexerDefinition
|
||||||
|
|
||||||
client *ircevent.Connection
|
client *ircevent.Connection
|
||||||
|
clientState ircState
|
||||||
m deadlock.RWMutex
|
m deadlock.RWMutex
|
||||||
|
|
||||||
connectedSince time.Time
|
connectedSince time.Time
|
||||||
haveDisconnected bool
|
haveDisconnected bool
|
||||||
manuallyDisconnected bool
|
|
||||||
|
|
||||||
validAnnouncers map[string]struct{}
|
validAnnouncers map[string]struct{}
|
||||||
validChannels map[string]struct{}
|
validChannels map[string]struct{}
|
||||||
|
@ -155,7 +168,7 @@ func (h *Handler) removeIndexer() {
|
||||||
// TODO remove announceProcessor
|
// TODO remove announceProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) Run() error {
|
func (h *Handler) Run() (err error) {
|
||||||
// TODO validate
|
// TODO validate
|
||||||
// check if network requires nickserv
|
// check if network requires nickserv
|
||||||
// check if network or channels requires invite command
|
// check if network or channels requires invite command
|
||||||
|
@ -168,9 +181,31 @@ func (h *Handler) Run() error {
|
||||||
|
|
||||||
// this used to be TraceLevel but was changed to DebugLevel during connect to see the info without needing to change loglevel
|
// this used to be TraceLevel but was changed to DebugLevel during connect to see the info without needing to change loglevel
|
||||||
// we change back to TraceLevel in the handleJoined method.
|
// we change back to TraceLevel in the handleJoined method.
|
||||||
subLogger := zstdlog.NewStdLoggerWithLevel(h.log.With().Logger(), zerolog.DebugLevel)
|
subLogger := zstdlog.NewStdLoggerWithLevel(h.log.With().Logger(), zerolog.TraceLevel)
|
||||||
|
|
||||||
h.client = &ircevent.Connection{
|
shouldConnect := false
|
||||||
|
h.m.Lock()
|
||||||
|
if h.clientState == ircStopped {
|
||||||
|
shouldConnect = true
|
||||||
|
h.clientState = ircConnecting
|
||||||
|
}
|
||||||
|
h.m.Unlock()
|
||||||
|
|
||||||
|
if !shouldConnect {
|
||||||
|
return connectionInProgress
|
||||||
|
}
|
||||||
|
|
||||||
|
// either we will successfully transition to `ircLive`, or else
|
||||||
|
// we need to reset the state to `ircStopped`
|
||||||
|
defer func() {
|
||||||
|
h.m.Lock()
|
||||||
|
if h.clientState == ircConnecting {
|
||||||
|
h.clientState = ircStopped
|
||||||
|
}
|
||||||
|
h.m.Unlock()
|
||||||
|
}()
|
||||||
|
|
||||||
|
client := &ircevent.Connection{
|
||||||
Nick: h.network.Nick,
|
Nick: h.network.Nick,
|
||||||
User: h.network.Auth.Account,
|
User: h.network.Auth.Account,
|
||||||
RealName: h.network.Auth.Account,
|
RealName: h.network.Auth.Account,
|
||||||
|
@ -187,36 +222,38 @@ func (h *Handler) Run() error {
|
||||||
|
|
||||||
if h.network.Auth.Mechanism == domain.IRCAuthMechanismSASLPlain {
|
if h.network.Auth.Mechanism == domain.IRCAuthMechanismSASLPlain {
|
||||||
if h.network.Auth.Account != "" && h.network.Auth.Password != "" {
|
if h.network.Auth.Account != "" && h.network.Auth.Password != "" {
|
||||||
h.client.SASLLogin = h.network.Auth.Account
|
client.SASLLogin = h.network.Auth.Account
|
||||||
h.client.SASLPassword = h.network.Auth.Password
|
client.SASLPassword = h.network.Auth.Password
|
||||||
h.client.SASLOptional = true
|
client.SASLOptional = true
|
||||||
h.client.UseSASL = true
|
client.UseSASL = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.network.TLS {
|
if h.network.TLS {
|
||||||
h.client.UseTLS = true
|
client.UseTLS = true
|
||||||
h.client.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
client.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
h.client.AddConnectCallback(h.onConnect)
|
client.AddConnectCallback(h.onConnect)
|
||||||
h.client.AddDisconnectCallback(h.onDisconnect)
|
client.AddDisconnectCallback(h.onDisconnect)
|
||||||
|
|
||||||
h.client.AddCallback("MODE", h.handleMode)
|
client.AddCallback("MODE", h.handleMode)
|
||||||
if h.network.BotMode {
|
if h.network.BotMode {
|
||||||
h.client.AddCallback("501", h.handleModeUnknownFlag)
|
client.AddCallback("501", h.handleModeUnknownFlag)
|
||||||
}
|
}
|
||||||
h.client.AddCallback("INVITE", h.handleInvite)
|
client.AddCallback("INVITE", h.handleInvite)
|
||||||
h.client.AddCallback("366", h.handleJoined)
|
client.AddCallback("366", h.handleJoined)
|
||||||
h.client.AddCallback("PART", h.handlePart)
|
client.AddCallback("PART", h.handlePart)
|
||||||
h.client.AddCallback("PRIVMSG", h.onMessage)
|
client.AddCallback("PRIVMSG", h.onMessage)
|
||||||
h.client.AddCallback("NOTICE", h.onNotice)
|
client.AddCallback("NOTICE", h.onNotice)
|
||||||
h.client.AddCallback("NICK", h.onNick)
|
client.AddCallback("NICK", h.onNick)
|
||||||
h.client.AddCallback("903", h.handleSASLSuccess)
|
client.AddCallback("903", h.handleSASLSuccess)
|
||||||
|
|
||||||
//h.setConnectionStatus()
|
//h.setConnectionStatus()
|
||||||
h.saslauthed = false
|
h.saslauthed = false
|
||||||
|
|
||||||
|
h.client = client
|
||||||
|
|
||||||
if err := func() error {
|
if err := func() error {
|
||||||
// count connect attempts
|
// count connect attempts
|
||||||
connectAttempts := 0
|
connectAttempts := 0
|
||||||
|
@ -230,14 +267,14 @@ func (h *Handler) Run() error {
|
||||||
|
|
||||||
// #1239: don't retry if the user manually disconnected with Stop()
|
// #1239: don't retry if the user manually disconnected with Stop()
|
||||||
h.m.RLock()
|
h.m.RLock()
|
||||||
manuallyDisconnected := h.manuallyDisconnected
|
manuallyDisconnected := h.clientState == ircStopped
|
||||||
h.m.RUnlock()
|
h.m.RUnlock()
|
||||||
|
|
||||||
if manuallyDisconnected {
|
if manuallyDisconnected {
|
||||||
return clientManuallyDisconnected
|
return clientManuallyDisconnected
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.client.Connect(); err != nil {
|
if err := client.Connect(); err != nil {
|
||||||
h.log.Error().Err(err).Msg("client encountered connection error")
|
h.log.Error().Err(err).Msg("client encountered connection error")
|
||||||
connectAttempts++
|
connectAttempts++
|
||||||
return err
|
return err
|
||||||
|
@ -265,7 +302,29 @@ func (h *Handler) Run() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
h.client.Loop()
|
shouldDisconnect := false
|
||||||
|
h.m.Lock()
|
||||||
|
switch h.clientState {
|
||||||
|
case ircStopped:
|
||||||
|
// concurrent Stop(), bail
|
||||||
|
shouldDisconnect = true
|
||||||
|
case ircConnecting:
|
||||||
|
// success!
|
||||||
|
//h.client = client
|
||||||
|
h.clientState = ircLive
|
||||||
|
case ircLive:
|
||||||
|
// impossible
|
||||||
|
h.log.Error().Stack().Msgf("two concurrent connection attempts detected")
|
||||||
|
shouldDisconnect = true
|
||||||
|
}
|
||||||
|
h.m.Unlock()
|
||||||
|
|
||||||
|
if shouldDisconnect {
|
||||||
|
client.Quit()
|
||||||
|
return clientManuallyDisconnected
|
||||||
|
}
|
||||||
|
|
||||||
|
go client.Loop()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -277,29 +336,15 @@ func (h *Handler) isOurNick(nick string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) isOurCurrentNick(nick string) bool {
|
func (h *Handler) isOurCurrentNick(nick string) bool {
|
||||||
h.m.RLock()
|
return h.CurrentNick() == nick
|
||||||
defer h.m.RUnlock()
|
|
||||||
return h.client.CurrentNick() == nick
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) setConnectionStatus() {
|
func (h *Handler) setConnectionStatus() {
|
||||||
h.m.Lock()
|
h.m.Lock()
|
||||||
if h.client.Connected() {
|
if h.client != nil && h.client.Connected() {
|
||||||
h.connectedSince = time.Now()
|
h.connectedSince = time.Now()
|
||||||
}
|
}
|
||||||
h.m.Unlock()
|
h.m.Unlock()
|
||||||
//else {
|
|
||||||
// h.connectedSince = time.Time{}
|
|
||||||
// //h.channelHealth = map[string]*channelHealth{}
|
|
||||||
// h.resetChannelHealth()
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Handler) resetConnectionStatus() {
|
|
||||||
h.m.Lock()
|
|
||||||
h.connectedSince = time.Time{}
|
|
||||||
h.resetChannelHealth()
|
|
||||||
h.m.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) GetNetwork() *domain.IrcNetwork {
|
func (h *Handler) GetNetwork() *domain.IrcNetwork {
|
||||||
|
@ -331,32 +376,38 @@ func (h *Handler) AddChannelHealth(channel string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) resetChannelHealth() {
|
func (h *Handler) resetChannelHealth() {
|
||||||
|
h.m.RLock()
|
||||||
for _, ch := range h.channelHealth {
|
for _, ch := range h.channelHealth {
|
||||||
ch.resetMonitoring()
|
ch.resetMonitoring()
|
||||||
}
|
}
|
||||||
|
h.m.RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop the network and quit
|
// Stop the network and quit
|
||||||
func (h *Handler) Stop() {
|
func (h *Handler) Stop() {
|
||||||
h.m.Lock()
|
h.m.Lock()
|
||||||
h.connectedSince = time.Time{}
|
h.connectedSince = time.Time{}
|
||||||
h.manuallyDisconnected = true
|
client := h.client
|
||||||
|
h.clientState = ircStopped
|
||||||
if h.client.Connected() {
|
h.client = nil
|
||||||
h.log.Debug().Msg("Disconnecting...")
|
|
||||||
}
|
|
||||||
h.m.Unlock()
|
h.m.Unlock()
|
||||||
|
|
||||||
|
if client != nil {
|
||||||
|
h.log.Debug().Msg("Disconnecting...")
|
||||||
h.resetChannelHealth()
|
h.resetChannelHealth()
|
||||||
|
client.Quit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
h.client.Quit()
|
func (h *Handler) Stopped() bool {
|
||||||
|
h.m.RLock()
|
||||||
|
defer h.m.RUnlock()
|
||||||
|
return h.clientState == ircStopped
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restart stops the network and then runs it
|
// Restart stops the network and then runs it
|
||||||
func (h *Handler) Restart() error {
|
func (h *Handler) Restart() error {
|
||||||
h.log.Debug().Msg("Restarting network...")
|
|
||||||
h.Stop()
|
h.Stop()
|
||||||
|
|
||||||
return h.Run()
|
return h.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,7 +423,9 @@ func (h *Handler) onConnect(m ircmsg.Message) {
|
||||||
|
|
||||||
func() {
|
func() {
|
||||||
h.m.Lock()
|
h.m.Lock()
|
||||||
if h.haveDisconnected {
|
if h.haveDisconnected && h.clientState == ircLive {
|
||||||
|
h.log.Info().Msgf("network re-connected after unexpected disconnect: %s", h.network.Name)
|
||||||
|
|
||||||
h.notificationService.Send(domain.NotificationEventIRCReconnected, domain.NotificationPayload{
|
h.notificationService.Send(domain.NotificationEventIRCReconnected, domain.NotificationPayload{
|
||||||
Subject: "IRC Reconnected",
|
Subject: "IRC Reconnected",
|
||||||
Message: fmt.Sprintf("Network: %s", h.network.Name),
|
Message: fmt.Sprintf("Network: %s", h.network.Name),
|
||||||
|
@ -383,7 +436,7 @@ func (h *Handler) onConnect(m ircmsg.Message) {
|
||||||
}
|
}
|
||||||
h.m.Unlock()
|
h.m.Unlock()
|
||||||
|
|
||||||
h.log.Debug().Msgf("connected to: %s", h.network.Name)
|
h.log.Info().Msgf("network connected to: %s", h.network.Name)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
@ -416,17 +469,17 @@ func (h *Handler) onDisconnect(m ircmsg.Message) {
|
||||||
|
|
||||||
h.haveDisconnected = true
|
h.haveDisconnected = true
|
||||||
|
|
||||||
|
manuallyDisconnected := h.clientState == ircStopped
|
||||||
|
|
||||||
// check if we are responsible for disconnect
|
// check if we are responsible for disconnect
|
||||||
if !h.manuallyDisconnected {
|
if !manuallyDisconnected {
|
||||||
// only send notification if we did not initiate disconnect/restart/stop
|
// only send notification if we did not initiate disconnect/restart/stop
|
||||||
h.notificationService.Send(domain.NotificationEventIRCDisconnected, domain.NotificationPayload{
|
h.notificationService.Send(domain.NotificationEventIRCDisconnected, domain.NotificationPayload{
|
||||||
Subject: "IRC Disconnected unexpectedly",
|
Subject: "IRC Disconnected unexpectedly",
|
||||||
Message: fmt.Sprintf("Network: %s", h.network.Name),
|
Message: fmt.Sprintf("Network: %s", h.network.Name),
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
// reset
|
|
||||||
h.manuallyDisconnected = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h.m.Unlock()
|
h.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,9 +549,22 @@ func (h *Handler) handleNickServ(msg ircmsg.Message) {
|
||||||
if contains(msg.Params[1], "invalid parameters", "help identify") {
|
if contains(msg.Params[1], "invalid parameters", "help identify") {
|
||||||
h.log.Debug().Msgf("NOTICE nickserv invalid: %v", msg.Params)
|
h.log.Debug().Msgf("NOTICE nickserv invalid: %v", msg.Params)
|
||||||
|
|
||||||
if err := h.client.Send("PRIVMSG", "NickServ", fmt.Sprintf("IDENTIFY %s %s", h.network.Auth.Account, h.network.Auth.Password)); err != nil {
|
h.Send("PRIVMSG", "NickServ", fmt.Sprintf("IDENTIFY %s %s", h.network.Auth.Account, h.network.Auth.Password))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) getClient() *ircevent.Connection {
|
||||||
|
h.m.RLock()
|
||||||
|
client := h.client
|
||||||
|
h.m.RUnlock()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) Send(command string, params ...string) error {
|
||||||
|
if client := h.getClient(); client != nil {
|
||||||
|
return client.Send(command, params...)
|
||||||
|
} else {
|
||||||
|
return clientDisconnected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,28 +583,17 @@ func (h *Handler) setBotMode() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// authenticate sends NickServIdentify if not authenticated
|
// authenticate sends NickServIdentify if not authenticated
|
||||||
func (h *Handler) authenticate() bool {
|
func (h *Handler) authenticate() {
|
||||||
h.m.RLock()
|
h.m.RLock()
|
||||||
defer h.m.RUnlock()
|
shouldSendNickserv := !h.authenticated && !h.saslauthed && h.network.Auth.Password != ""
|
||||||
|
h.m.RUnlock()
|
||||||
|
|
||||||
if h.authenticated {
|
if shouldSendNickserv {
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if !h.saslauthed && h.network.Auth.Password != "" {
|
|
||||||
h.log.Trace().Msg("on connect not authenticated and password not empty: send nickserv identify")
|
h.log.Trace().Msg("on connect not authenticated and password not empty: send nickserv identify")
|
||||||
if err := h.NickServIdentify(h.network.Auth.Password); err != nil {
|
h.NickServIdentify(h.network.Auth.Password)
|
||||||
h.log.Error().Stack().Err(err).Msg("error nickserv")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
} else {
|
} else {
|
||||||
h.setAuthenticated()
|
h.setAuthenticated()
|
||||||
}
|
}
|
||||||
|
|
||||||
// return and wait for NOTICE of nickserv auth
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleSASLSuccess we get here early so set saslauthed before we hit onConnect
|
// handleSASLSuccess we get here early so set saslauthed before we hit onConnect
|
||||||
|
@ -551,9 +606,18 @@ func (h *Handler) handleSASLSuccess(msg ircmsg.Message) {
|
||||||
// setAuthenticated sets the states for authenticated, connectionErrors, failedNickServAttempts
|
// setAuthenticated sets the states for authenticated, connectionErrors, failedNickServAttempts
|
||||||
// and then sends inviteCommand and after that JoinChannels
|
// and then sends inviteCommand and after that JoinChannels
|
||||||
func (h *Handler) setAuthenticated() {
|
func (h *Handler) setAuthenticated() {
|
||||||
|
h.m.Lock()
|
||||||
|
alreadyAuthenticated := h.authenticated
|
||||||
|
if !alreadyAuthenticated {
|
||||||
h.authenticated = true
|
h.authenticated = true
|
||||||
h.connectionErrors = []string{}
|
h.connectionErrors = []string{}
|
||||||
h.failedNickServAttempts = 0
|
h.failedNickServAttempts = 0
|
||||||
|
}
|
||||||
|
h.m.Unlock()
|
||||||
|
|
||||||
|
if alreadyAuthenticated {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
h.inviteCommand()
|
h.inviteCommand()
|
||||||
h.JoinChannels()
|
h.JoinChannels()
|
||||||
|
@ -594,9 +658,7 @@ func (h *Handler) onNick(msg ircmsg.Message) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !h.authenticated {
|
|
||||||
h.authenticate()
|
h.authenticate()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) publishSSEMsg(msg domain.IrcMessage) {
|
func (h *Handler) publishSSEMsg(msg domain.IrcMessage) {
|
||||||
|
@ -679,24 +741,15 @@ func (h *Handler) JoinChannels() {
|
||||||
|
|
||||||
// JoinChannel sends join command
|
// JoinChannel sends join command
|
||||||
func (h *Handler) JoinChannel(channel string, password string) error {
|
func (h *Handler) JoinChannel(channel string, password string) error {
|
||||||
m := ircmsg.Message{
|
params := []string{channel}
|
||||||
Command: "JOIN",
|
|
||||||
Params: []string{channel},
|
|
||||||
}
|
|
||||||
|
|
||||||
// support channel password
|
// support channel password
|
||||||
if password != "" {
|
if password != "" {
|
||||||
m.Params = []string{channel, password}
|
params = append(params, password)
|
||||||
}
|
}
|
||||||
|
|
||||||
h.log.Debug().Msgf("sending JOIN command %s", strings.Join(m.Params, " "))
|
h.log.Debug().Msgf("sending JOIN command %s", strings.Join(params, " "))
|
||||||
|
|
||||||
if err := h.client.SendIRCMessage(m); err != nil {
|
return h.Send("JOIN", params...)
|
||||||
h.log.Error().Stack().Err(err).Msgf("error handling join: %s", channel)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// handlePart listens for PART events
|
// handlePart listens for PART events
|
||||||
|
@ -723,14 +776,9 @@ func (h *Handler) handlePart(msg ircmsg.Message) {
|
||||||
func (h *Handler) PartChannel(channel string) error {
|
func (h *Handler) PartChannel(channel string) error {
|
||||||
h.log.Debug().Msgf("Leaving channel %s", channel)
|
h.log.Debug().Msgf("Leaving channel %s", channel)
|
||||||
|
|
||||||
if err := h.client.Part(channel); err != nil {
|
return h.Send("PART", channel)
|
||||||
h.log.Error().Err(err).Msgf("error handling part: %s", channel)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO remove announceProcessor
|
// TODO remove announceProcessor
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleJoined listens for 366 JOIN events
|
// handleJoined listens for 366 JOIN events
|
||||||
|
@ -782,9 +830,6 @@ func (h *Handler) handleJoined(msg ircmsg.Message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
h.log.Info().Msgf("Monitoring channel %s", channel)
|
h.log.Info().Msgf("Monitoring channel %s", channel)
|
||||||
|
|
||||||
// reset log level to Trace now that we are monitoring a channel
|
|
||||||
h.client.Log = zstdlog.NewStdLoggerWithLevel(h.log.With().Logger(), zerolog.TraceLevel)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendConnectCommands sends invite commands
|
// sendConnectCommands sends invite commands
|
||||||
|
@ -800,15 +845,12 @@ func (h *Handler) sendConnectCommands(msg string) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
m := ircmsg.Message{
|
|
||||||
Command: "PRIVMSG",
|
|
||||||
Params: strings.Split(cmd, " "),
|
|
||||||
}
|
|
||||||
|
|
||||||
h.log.Debug().Msgf("sending connect command: %s", cmd)
|
h.log.Debug().Msgf("sending connect command: %s", cmd)
|
||||||
|
|
||||||
if err := h.client.SendIRCMessage(m); err != nil {
|
params := strings.SplitN(cmd, " ", 2)
|
||||||
h.log.Error().Err(err).Msgf("error handling connect command: %v", m)
|
|
||||||
|
if err := h.Send("PRIVMSG", params...); err != nil {
|
||||||
|
h.log.Error().Err(err).Msgf("error handling connect command: %s", cmd)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -836,7 +878,7 @@ func (h *Handler) handleInvite(msg ircmsg.Message) {
|
||||||
|
|
||||||
h.log.Debug().Msgf("INVITE from %s, joining %s", msg.Nick(), channel)
|
h.log.Debug().Msgf("INVITE from %s, joining %s", msg.Nick(), channel)
|
||||||
|
|
||||||
if err := h.client.Join(msg.Params[1]); err != nil {
|
if err := h.Send("JOIN", msg.Params[1]); err != nil {
|
||||||
h.log.Error().Stack().Err(err).Msgf("error handling join: %s", msg.Params[1])
|
h.log.Error().Stack().Err(err).Msgf("error handling join: %s", msg.Params[1])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -846,15 +888,8 @@ func (h *Handler) handleInvite(msg ircmsg.Message) {
|
||||||
|
|
||||||
// NickServIdentify sends NickServ Identify commands
|
// NickServIdentify sends NickServ Identify commands
|
||||||
func (h *Handler) NickServIdentify(password string) error {
|
func (h *Handler) NickServIdentify(password string) error {
|
||||||
m := ircmsg.Message{
|
if err := h.Send("PRIVMSG", "NickServ", fmt.Sprintf("IDENTIFY %s", password)); err != nil {
|
||||||
Command: "PRIVMSG",
|
h.log.Error().Stack().Err(err).Msgf("error identifying with nickserv")
|
||||||
Params: []string{"NickServ", "IDENTIFY", password},
|
|
||||||
}
|
|
||||||
|
|
||||||
h.log.Debug().Msgf("NickServ: %v", m)
|
|
||||||
|
|
||||||
if err := h.client.SendIRCMessage(m); err != nil {
|
|
||||||
h.log.Error().Stack().Err(err).Msgf("error identifying with nickserv: %v", m)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -865,19 +900,29 @@ func (h *Handler) NickServIdentify(password string) error {
|
||||||
func (h *Handler) NickChange(nick string) error {
|
func (h *Handler) NickChange(nick string) error {
|
||||||
h.log.Debug().Msgf("NICK change: %s", nick)
|
h.log.Debug().Msgf("NICK change: %s", nick)
|
||||||
|
|
||||||
h.client.SetNick(nick)
|
if client := h.getClient(); client != nil {
|
||||||
|
client.SetNick(nick)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentNick returns our current nick set by the server
|
// CurrentNick returns our current nick set by the server
|
||||||
func (h *Handler) CurrentNick() string {
|
func (h *Handler) CurrentNick() string {
|
||||||
return h.client.CurrentNick()
|
if client := h.getClient(); client != nil {
|
||||||
|
return client.CurrentNick()
|
||||||
|
} else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreferredNick returns our preferred nick from settings
|
// PreferredNick returns our preferred nick from settings
|
||||||
func (h *Handler) PreferredNick() string {
|
func (h *Handler) PreferredNick() string {
|
||||||
return h.client.PreferredNick()
|
if client := h.getClient(); client != nil {
|
||||||
|
return client.PreferredNick()
|
||||||
|
} else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// listens for MODE events
|
// listens for MODE events
|
||||||
|
@ -886,9 +931,7 @@ func (h *Handler) handleMode(msg ircmsg.Message) {
|
||||||
|
|
||||||
// if our nick and user mode +r (Identifies the nick as being Registered (settable by services only)) then return
|
// if our nick and user mode +r (Identifies the nick as being Registered (settable by services only)) then return
|
||||||
if h.isOurCurrentNick(msg.Params[0]) && strings.Contains(msg.Params[1], "+r") {
|
if h.isOurCurrentNick(msg.Params[0]) && strings.Contains(msg.Params[1], "+r") {
|
||||||
if !h.authenticated {
|
|
||||||
h.setAuthenticated()
|
h.setAuthenticated()
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -907,7 +950,7 @@ func (h *Handler) handleModeUnknownFlag(msg ircmsg.Message) {
|
||||||
func (h *Handler) SendMsg(channel, msg string) error {
|
func (h *Handler) SendMsg(channel, msg string) error {
|
||||||
h.log.Debug().Msgf("sending msg command: %s", msg)
|
h.log.Debug().Msgf("sending msg command: %s", msg)
|
||||||
|
|
||||||
if err := h.client.Privmsg(channel, msg); err != nil {
|
if err := h.Send("PRIVMSG", channel, msg); err != nil {
|
||||||
h.log.Error().Stack().Err(err).Msgf("error sending msg: %s", msg)
|
h.log.Error().Stack().Err(err).Msgf("error sending msg: %s", msg)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -965,46 +1008,43 @@ func (h *Handler) addConnectError(message string) {
|
||||||
h.connectionErrors = append(h.connectionErrors, message)
|
h.connectionErrors = append(h.connectionErrors, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Healthy if enabled but not monitoring return false,
|
func (h *Handler) ReportStatus(netw *domain.IrcNetworkWithHealth) {
|
||||||
//
|
h.m.RLock()
|
||||||
// if any channel is enabled but not monitoring return false,
|
defer h.m.RUnlock()
|
||||||
// else return true
|
|
||||||
func (h *Handler) Healthy() bool {
|
// only set connected and connected since if we have an active handler and connection
|
||||||
isHealthy := h.networkHealth()
|
if !h.network.Enabled {
|
||||||
if !isHealthy {
|
return
|
||||||
h.log.Warn().Msg("network unhealthy")
|
}
|
||||||
return isHealthy
|
if h.client == nil {
|
||||||
}
|
return
|
||||||
|
}
|
||||||
h.log.Trace().Msg("network healthy")
|
netw.Connected = h.connectedSince != time.Time{}
|
||||||
|
netw.ConnectedSince = h.connectedSince
|
||||||
return true
|
netw.CurrentNick = h.client.CurrentNick()
|
||||||
}
|
netw.PreferredNick = h.client.PreferredNick()
|
||||||
|
|
||||||
func (h *Handler) networkHealth() bool {
|
if !netw.Connected {
|
||||||
if h.network.Enabled {
|
return
|
||||||
if !h.client.Connected() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if (h.connectedSince == time.Time{}) {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
channelsHealthy := true
|
||||||
for _, channel := range h.network.Channels {
|
for _, channel := range h.network.Channels {
|
||||||
name := strings.ToLower(channel.Name)
|
name := strings.ToLower(channel.Name)
|
||||||
|
|
||||||
if chanHealth, ok := h.channelHealth[name]; ok {
|
if chanHealth, ok := h.channelHealth[name]; ok {
|
||||||
chanHealth.m.RLock()
|
chanHealth.m.RLock()
|
||||||
|
channelsHealthy = channelsHealthy && chanHealth.monitoring
|
||||||
if !chanHealth.monitoring {
|
|
||||||
chanHealth.m.RUnlock()
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
chanHealth.m.RUnlock()
|
chanHealth.m.RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !channelsHealthy {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
netw.Healthy = channelsHealthy
|
||||||
|
|
||||||
|
// TODO with Go 1.21 this can moved from golang.org/x/exp/slices to built in slices:
|
||||||
|
netw.ConnectionErrors = slices.Clone(h.connectionErrors)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/autobrr/autobrr/internal/domain"
|
"github.com/autobrr/autobrr/internal/domain"
|
||||||
"github.com/autobrr/autobrr/internal/indexer"
|
"github.com/autobrr/autobrr/internal/indexer"
|
||||||
|
@ -127,7 +126,7 @@ func (s *service) startNetwork(network domain.IrcNetwork) error {
|
||||||
if existingHandler, found := s.handlers[network.ID]; found {
|
if existingHandler, found := s.handlers[network.ID]; found {
|
||||||
s.log.Debug().Msgf("starting network: %s", network.Name)
|
s.log.Debug().Msgf("starting network: %s", network.Name)
|
||||||
|
|
||||||
if !existingHandler.client.Connected() {
|
if existingHandler.Stopped() {
|
||||||
go func(handler *Handler) {
|
go func(handler *Handler) {
|
||||||
if err := handler.Run(); err != nil {
|
if err := handler.Run(); err != nil {
|
||||||
s.log.Error().Err(err).Msgf("failed to start existing handler for network: %s", handler.network.Name)
|
s.log.Error().Err(err).Msgf("failed to start existing handler for network: %s", handler.network.Name)
|
||||||
|
@ -178,7 +177,7 @@ func (s *service) checkIfNetworkRestartNeeded(network *domain.IrcNetwork) error
|
||||||
// if server, tls, invite command, port : changed - restart
|
// if server, tls, invite command, port : changed - restart
|
||||||
// if nickserv account, nickserv password : changed - stay connected, and change those
|
// if nickserv account, nickserv password : changed - stay connected, and change those
|
||||||
// if channels len : changes - join or leave
|
// if channels len : changes - join or leave
|
||||||
if existingHandler.client.Connected() {
|
if !existingHandler.Stopped() {
|
||||||
handler := existingHandler.GetNetwork()
|
handler := existingHandler.GetNetwork()
|
||||||
restartNeeded := false
|
restartNeeded := false
|
||||||
var fieldsChanged []string
|
var fieldsChanged []string
|
||||||
|
@ -341,6 +340,10 @@ func (s *service) RestartNetwork(ctx context.Context, id int64) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !network.Enabled {
|
||||||
|
return errors.New("network disabled, could not restart")
|
||||||
|
}
|
||||||
|
|
||||||
return s.restartNetwork(*network)
|
return s.restartNetwork(*network)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,26 +462,7 @@ func (s *service) GetNetworksWithHealth(ctx context.Context) ([]domain.IrcNetwor
|
||||||
|
|
||||||
handler, ok := s.handlers[n.ID]
|
handler, ok := s.handlers[n.ID]
|
||||||
if ok {
|
if ok {
|
||||||
handler.m.RLock()
|
handler.ReportStatus(&netw)
|
||||||
|
|
||||||
// only set connected and connected since if we have an active handler and connection
|
|
||||||
if handler.client.Connected() {
|
|
||||||
|
|
||||||
netw.Connected = handler.connectedSince != time.Time{}
|
|
||||||
netw.ConnectedSince = handler.connectedSince
|
|
||||||
|
|
||||||
// current and preferred nick is only available if the network is connected
|
|
||||||
netw.CurrentNick = handler.CurrentNick()
|
|
||||||
netw.PreferredNick = handler.PreferredNick()
|
|
||||||
}
|
|
||||||
netw.Healthy = handler.Healthy()
|
|
||||||
|
|
||||||
// if we have any connection errors like bad nickserv auth add them here
|
|
||||||
if len(handler.connectionErrors) > 0 {
|
|
||||||
netw.ConnectionErrors = handler.connectionErrors
|
|
||||||
}
|
|
||||||
|
|
||||||
handler.m.RUnlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
channels, err := s.repo.ListChannels(n.ID)
|
channels, err := s.repo.ListChannels(n.ID)
|
||||||
|
|
|
@ -536,14 +536,20 @@ const ListItemDropdown = ({
|
||||||
{({ active }) => (
|
{({ active }) => (
|
||||||
<button
|
<button
|
||||||
className={classNames(
|
className={classNames(
|
||||||
active ? "bg-blue-600 text-white" : "text-gray-900 dark:text-gray-300",
|
"font-medium group flex rounded-md items-center w-full px-2 py-2 text-sm",
|
||||||
"font-medium group flex rounded-md items-center w-full px-2 py-2 text-sm"
|
network.enabled
|
||||||
|
? active ? "bg-blue-600 text-white" : "text-gray-900 dark:text-gray-300"
|
||||||
|
: "text-gray-600 dark:text-gray-500"
|
||||||
)}
|
)}
|
||||||
onClick={() => restart(network.id)}
|
onClick={() => restart(network.id)}
|
||||||
|
disabled={!network.enabled}
|
||||||
|
title={network.enabled ? "Restart" : "Network disabled"}
|
||||||
>
|
>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className={classNames(
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className={classNames(
|
||||||
active ? "text-white" : "text-blue-500",
|
"w-5 h-5 mr-2",
|
||||||
"w-5 h-5 mr-2"
|
network.enabled
|
||||||
|
? active ? "text-white" : "text-blue-500 dark:text-blue-500"
|
||||||
|
: "text-gray-600 dark:text-gray-500"
|
||||||
)}>
|
)}>
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" d="M5.636 5.636a9 9 0 1012.728 0M12 3v9" />
|
<path strokeLinecap="round" strokeLinejoin="round" d="M5.636 5.636a9 9 0 1012.728 0M12 3v9" />
|
||||||
</svg>
|
</svg>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue