From fc95519dbfdf702e0ec748ab8b5b5c2f855f9f4a Mon Sep 17 00:00:00 2001 From: Oneric Date: Sun, 25 Feb 2024 23:27:10 +0100 Subject: [PATCH] Allow fetching over IPv6 Mint/Finch disable IPv6 by default preventing us from fetching anything from IPv6-only hosts without this. --- CHANGELOG.md | 9 +++++++++ lib/pleroma/application.ex | 1 + lib/pleroma/http/adapter_helper.ex | 23 ++++++++++++++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9033050a1..bc5a4cc21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## Unreleased + +## Added + +## Changed + +## Fixed +- Issue preventing fetching anything from IPv6-only instances + ## 2024.02 ## Added diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 3200175d1..28a86d0aa 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -288,6 +288,7 @@ defp http_children do |> Config.get([]) |> Pleroma.HTTP.AdapterHelper.add_pool_size(pool_size) |> Pleroma.HTTP.AdapterHelper.maybe_add_proxy_pool(proxy) + |> Pleroma.HTTP.AdapterHelper.ensure_ipv6() |> Keyword.put(:name, MyFinch) [{Finch, config}] diff --git a/lib/pleroma/http/adapter_helper.ex b/lib/pleroma/http/adapter_helper.ex index 303ccdf2a..c1d95b3a4 100644 --- a/lib/pleroma/http/adapter_helper.ex +++ b/lib/pleroma/http/adapter_helper.ex @@ -65,6 +65,15 @@ def add_pool_size(opts, pool_size) do |> put_in([:pools, :default, :size], pool_size) end + def ensure_ipv6(opts) do + # Default transport opts already enable IPv6, so just ensure they're loaded + opts + |> maybe_add_pools() + |> maybe_add_default_pool() + |> maybe_add_conn_opts() + |> maybe_add_transport_opts() + end + defp maybe_add_pools(opts) do if Keyword.has_key?(opts, :pools) do opts @@ -96,11 +105,15 @@ defp maybe_add_conn_opts(opts) do defp maybe_add_transport_opts(opts) do transport_opts = get_in(opts, [:pools, :default, :conn_opts, :transport_opts]) - unless is_nil(transport_opts) do - opts - else - put_in(opts, [:pools, :default, :conn_opts, :transport_opts], []) - end + opts = + unless is_nil(transport_opts) do + opts + else + put_in(opts, [:pools, :default, :conn_opts, :transport_opts], []) + end + + # IPv6 is disabled and IPv4 enabled by default; ensure we can use both + put_in(opts, [:pools, :default, :conn_opts, :transport_opts, :inet6], true) end @doc """