commit e9a829f

delthas  ·  2022-12-23 17:46:42 +0000 UTC
parent 58464d5
Backoff from 0 seconds to 1 minute on reconnect

Resets on successful connection.
1 files changed,  +23, -21
M app.go
M app.go
+23, -21
 1@@ -298,11 +298,20 @@ func (app *App) ircLoop(netID string) {
 2 		NetID:    netID,
 3 		Auth:     auth,
 4 	}
 5+	const throttleInterval = 6 * time.Second
 6+	const throttleMax = 1 * time.Minute
 7+	var delay time.Duration = 0
 8 	for app.wantsNetwork(netID) {
 9+		time.Sleep(delay)
10+		if delay < throttleMax {
11+			delay += throttleInterval
12+		}
13 		conn := app.connect(netID)
14 		if conn == nil {
15-			break
16+			continue
17 		}
18+		delay = throttleInterval
19+
20 		in, out := irc.ChanInOut(conn)
21 		if app.cfg.Debug {
22 			out = app.debugOutputMessages(netID, out)
23@@ -342,30 +351,23 @@ func (app *App) ircLoop(netID string) {
24 			HeadColor: tcell.ColorRed,
25 			Body:      ui.PlainString("Connection lost"),
26 		})
27-		if !app.wantsNetwork(netID) {
28-			break
29-		}
30-		time.Sleep(10 * time.Second)
31 	}
32 }
33 
34 func (app *App) connect(netID string) net.Conn {
35-	for app.wantsNetwork(netID) {
36-		app.queueStatusLine(netID, ui.Line{
37-			Head: "--",
38-			Body: ui.PlainSprintf("Connecting to %s...", app.cfg.Addr),
39-		})
40-		conn, err := app.tryConnect()
41-		if err == nil {
42-			return conn
43-		}
44-		app.queueStatusLine(netID, ui.Line{
45-			Head:      "!!",
46-			HeadColor: tcell.ColorRed,
47-			Body:      ui.PlainSprintf("Connection failed: %v", err),
48-		})
49-		time.Sleep(1 * time.Minute)
50-	}
51+	app.queueStatusLine(netID, ui.Line{
52+		Head: "--",
53+		Body: ui.PlainSprintf("Connecting to %s...", app.cfg.Addr),
54+	})
55+	conn, err := app.tryConnect()
56+	if err == nil {
57+		return conn
58+	}
59+	app.queueStatusLine(netID, ui.Line{
60+		Head:      "!!",
61+		HeadColor: tcell.ColorRed,
62+		Body:      ui.PlainSprintf("Connection failed: %v", err),
63+	})
64 	return nil
65 }
66