From 0bebc5cef99df0d3149212bc4de4ea79ee13d737 Mon Sep 17 00:00:00 2001 From: Laptop Date: Fri, 12 Dec 2025 21:32:41 +0200 Subject: [PATCH] dialdualstack --- docs/INSTANCE_GUIDE.md | 2 +- lib/cfg/init.go | 45 ++++++++++++++++++---------------------- lib/misc/init.go | 3 --- lib/proxy_images/init.go | 2 +- lib/sc/init.go | 6 +++--- 5 files changed, 25 insertions(+), 33 deletions(-) diff --git a/docs/INSTANCE_GUIDE.md b/docs/INSTANCE_GUIDE.md index 4742e29..50c9c2f 100644 --- a/docs/INSTANCE_GUIDE.md +++ b/docs/INSTANCE_GUIDE.md @@ -118,9 +118,9 @@ Some notes: | PlaylistCacheCleanDelay | PLAYLIST_CACHE_CLEAN_DELAY | 5 minutes | Time between each cleanup of the cache (to remove expired playlists) | | UserAgent | USER_AGENT | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 | User-Agent header used for requests to SoundCloud | | ClientID | CLIENT_ID | (empty) | Authorization token for requests to SoundCloud. It's automatically extracted from the current version of the website, but you can override it if there are issues | -| DNSCacheTTL | DNS_CACHE_TTL | 60 minutes | Time until DNS cache expires | | EnableAPI | ENABLE_API | false | Should [API](API.md) be enabled? | | SoundcloudApiProxy | SOUNDCLOUD_API_PROXY | "" | SOCKS5 or HTTP proxy to use when dialing soundcloud api's | +| DialDualStack | DIAL_DUAL_STACK | false | Should try to also dial on ipv6? | | Network | NETWORK | tcp4 | Network to listen on. Can be tcp4, tcp6 or unix | | Addr | ADDR | :4664 | Address and port (or socket path) for soundcloak to listen on | | UnixSocketPerms | UNIX_SOCKET_PERMS | 0775 | Permissions for unix socket (Network must be set to unix) | diff --git a/lib/cfg/init.go b/lib/cfg/init.go index 778741e..c176510 100644 --- a/lib/cfg/init.go +++ b/lib/cfg/init.go @@ -69,9 +69,6 @@ var UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (K // override the extractor var ClientID = "" -// time-to-live for dns cache -var DNSCacheTTL = 60 * time.Minute - // enab;e api var EnableAPI = false @@ -112,6 +109,8 @@ var EnableAPI = false // cirno day everyday var SoundcloudApiProxy = "" +var DialDualStack = false + // // // some webserver configuration, put here to make it easier to configure what you need // // // // more info can be found here: https://docs.gofiber.io/api/fiber#config @@ -425,21 +424,21 @@ func fromEnv() error { ClientID = env } - env = os.Getenv("DNS_CACHE_TTL") - if env != "" { - num, err := strconv.ParseInt(env, 10, 64) - if err != nil { - return err - } - - DNSCacheTTL = time.Duration(num) * time.Second - } - env = os.Getenv("ENABLE_API") if env != "" { EnableAPI = boolean(env) } + env = os.Getenv("SOUNDCLOUD_API_PROXY") + if env != "" { + SoundcloudApiProxy = env + } + + env = os.Getenv("DIAL_DUAL_STACK") + if env != "" { + DialDualStack = boolean(env) + } + env = os.Getenv("NETWORK") if env != "" { Network = env @@ -491,11 +490,6 @@ func fromEnv() error { EmbedFiles = boolean(env) } - env = os.Getenv("SOUNDCLOUD_API_PROXY") - if env != "" { - SoundcloudApiProxy = env - } - return nil } @@ -540,6 +534,8 @@ func init() { ClientID *string DNSCacheTTL *time.Duration EnableAPI *bool + SoundcloudApiProxy *string + DialDualStack *bool Network *string Addr *string UnixSocketPerms *string @@ -548,7 +544,6 @@ func init() { TrustedProxies *[]string CodegenConfig *bool EmbedFiles *bool - SoundcloudApiProxy *string } err = json.Unmarshal(data, &config) @@ -608,12 +603,15 @@ func init() { if config.ClientID != nil { ClientID = *config.ClientID } - if config.DNSCacheTTL != nil { - DNSCacheTTL = *config.DNSCacheTTL * time.Second - } if config.EnableAPI != nil { EnableAPI = *config.EnableAPI } + if config.SoundcloudApiProxy != nil { + SoundcloudApiProxy = *config.SoundcloudApiProxy + } + if config.DialDualStack != nil { + DialDualStack = *config.DialDualStack + } if config.Network != nil { Network = *config.Network } @@ -643,9 +641,6 @@ func init() { if config.EmbedFiles != nil { EmbedFiles = *config.EmbedFiles } - if config.SoundcloudApiProxy != nil { - SoundcloudApiProxy = *config.SoundcloudApiProxy - } if config.DefaultPreferences != nil { loadDefaultPreferences(*config.DefaultPreferences) diff --git a/lib/misc/init.go b/lib/misc/init.go index 1ace6ae..7163680 100644 --- a/lib/misc/init.go +++ b/lib/misc/init.go @@ -54,7 +54,6 @@ func init() { ImageClient = &fasthttp.HostClient{ Addr: cfg.ImageCDN + ":443", IsTLS: true, - Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial, MaxIdleConnDuration: cfg.MaxIdleConnDuration, StreamResponseBody: true, } @@ -64,7 +63,6 @@ func init() { HlsClient = &fasthttp.HostClient{ Addr: cfg.HLSCDN + ":443", IsTLS: true, - Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial, MaxIdleConnDuration: cfg.MaxIdleConnDuration, StreamResponseBody: true, } @@ -72,7 +70,6 @@ func init() { HlsAacClient = &fasthttp.HostClient{ Addr: cfg.HLSAACCDN + ":443", IsTLS: true, - Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial, MaxIdleConnDuration: cfg.MaxIdleConnDuration, StreamResponseBody: true, } diff --git a/lib/proxy_images/init.go b/lib/proxy_images/init.go index dd50cbd..1dd6dac 100644 --- a/lib/proxy_images/init.go +++ b/lib/proxy_images/init.go @@ -18,9 +18,9 @@ func Load(r *fiber.App) { al_httpc = &fasthttp.HostClient{ Addr: "al.sndcdn.com:443", IsTLS: true, - Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial, MaxIdleConnDuration: cfg.MaxIdleConnDuration, StreamResponseBody: true, + DialDualStack: cfg.DialDualStack, } r.Get("/_/proxy/images", func(c fiber.Ctx) error { diff --git a/lib/sc/init.go b/lib/sc/init.go index eafed06..409e266 100644 --- a/lib/sc/init.go +++ b/lib/sc/init.go @@ -55,12 +55,12 @@ var script = []byte(`$`, 2) @@ -478,7 +478,7 @@ func GetSearchSuggestions(cid string, query string) ([]string, error) { // could probably make a generic function, whatever func init() { if cfg.SoundcloudApiProxy != "" { - d := fasthttpproxy.Dialer{Config: httpproxy.Config{HTTPProxy: cfg.SoundcloudApiProxy, HTTPSProxy: cfg.SoundcloudApiProxy}, TCPDialer: fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}, DialDualStack: true} + d := fasthttpproxy.Dialer{Config: httpproxy.Config{HTTPProxy: cfg.SoundcloudApiProxy, HTTPSProxy: cfg.SoundcloudApiProxy}, DialDualStack: cfg.DialDualStack} dialer, err := d.GetDialFunc(false) if err != nil { log.Println("[warning] failed to get dialer for proxy", err)