From 172a63aaea8576f7294b0771c22d618f26e55cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Snorre=20Magnus=20Dav=C3=B8en?= Date: Tue, 19 Nov 2024 15:30:47 +0100 Subject: [PATCH] fix: Add user agent and fix backoff socket dialer logic The websocket backoff logic was not properly configured and so would relentlessly spam the web socket endpoint with connect requests. Woops. Also provide a user agent in the header when requesting to be polite with server. --- firehose/firehose.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/firehose/firehose.go b/firehose/firehose.go index a275d4d..1b82beb 100644 --- a/firehose/firehose.go +++ b/firehose/firehose.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "net/http" "norsky/models" "strings" "time" @@ -25,12 +26,21 @@ import ( // Subscribe to the firehose using the Firehose struct as a receiver func Subscribe(ctx context.Context, postChan chan interface{}, ticker *time.Ticker, seq int64) { address := "wss://bsky.network/xrpc/com.atproto.sync.subscribeRepos" + headers := http.Header{} + headers.Set("User-Agent", "NorSky: https://github.com/snorremd/norsky") + if seq >= 0 { log.Info("Starting from sequence: ", seq) address = fmt.Sprintf("%s?cursor=%d", address, seq) } + // Identify dialer with User-Agent header + dialer := websocket.DefaultDialer backoff := backoff.NewExponentialBackOff() + backoff.InitialInterval = 3 * time.Second + backoff.MaxInterval = 30 * time.Second + backoff.Multiplier = 1.5 + backoff.MaxElapsedTime = 120 * time.Second // Check if context is cancelled, if so exit the connection loop for {