summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordelthas <delthas@dille.cc>2022-12-23 18:46:42 +0100
committerdelthas <delthas@dille.cc>2022-12-23 18:48:26 +0100
commite9a829f552b9983951e4d94bd4efca75b0b91f1f (patch)
treede33a017dce0dbd234367ecfebd800954f0d4da6
parentHide on-register RPL_UMODEIS (diff)
Backoff from 0 seconds to 1 minute on reconnect
Resets on successful connection.
-rw-r--r--app.go44
1 files changed, 23 insertions, 21 deletions
diff --git a/app.go b/app.go
index 99bcda6..e193f14 100644
--- a/app.go
+++ b/app.go
@@ -298,11 +298,20 @@ func (app *App) ircLoop(netID string) {
NetID: netID,
Auth: auth,
}
+ const throttleInterval = 6 * time.Second
+ const throttleMax = 1 * time.Minute
+ var delay time.Duration = 0
for app.wantsNetwork(netID) {
+ time.Sleep(delay)
+ if delay < throttleMax {
+ delay += throttleInterval
+ }
conn := app.connect(netID)
if conn == nil {
- break
+ continue
}
+ delay = throttleInterval
+
in, out := irc.ChanInOut(conn)
if app.cfg.Debug {
out = app.debugOutputMessages(netID, out)
@@ -342,30 +351,23 @@ func (app *App) ircLoop(netID string) {
HeadColor: tcell.ColorRed,
Body: ui.PlainString("Connection lost"),
})
- if !app.wantsNetwork(netID) {
- break
- }
- time.Sleep(10 * time.Second)
}
}
func (app *App) connect(netID string) net.Conn {
- for app.wantsNetwork(netID) {
- app.queueStatusLine(netID, ui.Line{
- Head: "--",
- Body: ui.PlainSprintf("Connecting to %s...", app.cfg.Addr),
- })
- conn, err := app.tryConnect()
- if err == nil {
- return conn
- }
- app.queueStatusLine(netID, ui.Line{
- Head: "!!",
- HeadColor: tcell.ColorRed,
- Body: ui.PlainSprintf("Connection failed: %v", err),
- })
- time.Sleep(1 * time.Minute)
- }
+ app.queueStatusLine(netID, ui.Line{
+ Head: "--",
+ Body: ui.PlainSprintf("Connecting to %s...", app.cfg.Addr),
+ })
+ conn, err := app.tryConnect()
+ if err == nil {
+ return conn
+ }
+ app.queueStatusLine(netID, ui.Line{
+ Head: "!!",
+ HeadColor: tcell.ColorRed,
+ Body: ui.PlainSprintf("Connection failed: %v", err),
+ })
return nil
}