dialdualstack

This commit is contained in:
Laptop
2025-12-12 21:32:41 +02:00
parent de5fa31d02
commit 0bebc5cef9
5 changed files with 25 additions and 33 deletions

View File

@@ -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) |

View File

@@ -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)

View File

@@ -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,
}

View File

@@ -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 {

View File

@@ -55,12 +55,12 @@ var script = []byte(`<script crossorigin src="https://a-v2.sndcdn.com/assets/`)
var httpc = &fasthttp.HostClient{
Addr: api + ":443",
IsTLS: true,
Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
MaxIdleConnDuration: cfg.MaxIdleConnDuration,
DialDualStack: cfg.DialDualStack,
}
var genericClient = &fasthttp.Client{
Dial: (&fasthttp.TCPDialer{DNSCacheDuration: cfg.DNSCacheTTL}).Dial,
DialDualStack: cfg.DialDualStack,
}
// var verRegex = regexp2.MustCompile(`^<script>window\.__sc_version="([0-9]{10})"</script>$`, 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)