You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
forgejo/modules
idk cdd3d4b8d8
Allow the use of alternative net.Listener implementations by downstreams (#25855)
This is a simple PR which moves the `GetListener` function to a
`DefaultGetListener` function, and changes `GetListener` to be a
variable which by default points to the `DefaultGetListener` function.
This allows people who may exist quasi-downstream of Gitea to create
alternate "GetListener" functions, with identical signatures, which
return different implementations of the `net.Listener` interface. This
approach is expressly intended to be non-invasive and have the least
possible impact on the gitea codebase. A previous version of this idea
was rejected before: https://github.com/go-gitea/gitea/issues/15544 but
because of issues like: https://github.com/go-gitea/gitea/issues/22335 I
**really** think that recommending people configure proxies by hand is
exactly the wrong way to do things(This is why there is a Tor Browser.).
This tiny change lets me put proper hidden service configuration into
single `i2p.go` file which lives in `modules/graceful/` and which never
has to be checked in to your codebase or affect your dependencies or
bloat your project in any way, it can live on a branch in my fork and
I'll fast-forward every release and never the twain shall meet.

The main use-case for this is to listen on Peer-to-Peer networks and
Hidden Services directly without error-prone and cumbersome
port-forwarding configuration. For instance, I might implement an
"I2PGetListener" as follows:

```Go
// adapted from i2p.go which is unchecked-in in my modules/graceful/ directory
import "github.com/eyedeekay/onramp"

var garlic = &onramp.Garlic{}

func I2PGetListener(network, address string) (net.Listener, error) {
	// Add a deferral to say that we've tried to grab a listener
	defer GetManager().InformCleanup()
	switch network {
	case "tcp", "tcp4", "tcp6", "i2p", "i2pt":
		return garlic.Listen()
	case "unix", "unixpacket":
// I2P isn't really a replacement for the stuff you use Unix sockets for and it's also not an anonymity risk, so treat them normally
		unixAddr, err := net.ResolveUnixAddr(network, address)
		if err != nil {
			return nil, err
		}
		return GetListenerUnix(network, unixAddr)
	default:
		return nil, net.UnknownNetworkError(network)
	}
}
```

I could then substitute that GetListener function and be 50% of the way
to having a fully-functioning gitea-over-hidden-services instance
without any additional configuration(The other 50% doesn't require any
code-changes on gitea's part).

There are 2 advantages here, one being convenience, first this turns
hidden services into a zero-configuration option for self-hosting gitea,
and second safety, these Go libraries are passing around
hidden-service-only versions of the net.Addr struct, they're using
hidden-service-only versions of the sockets, which are both expressly
designed to never require access to any information outside the hidden
service network, manipulating the application so it reveals information
about the host becomes much more difficult, and some attacks become
nearly impossible. It also opens up TLS-over-Hidden Services support
which is niche right now, of course, but in a future where gitea
instances federate if hidden services want to be part of the federation
they're probably going to need TLS certificates. They don't need to be
painful to set up.

This doesn't fix an open issue, but it might affect:
- https://github.com/go-gitea/gitea/issues/22335 - my `i2p.go` file
actually has a mod that fixes this but it requires adding a handful of
new dependencies to gitea and isn't compatible with the normal way you
guys recommend using a proxy so I don't think it's ready to send to you
as a PR, but if I can find a non-invasive way to fix it I will.
 - https://github.com/go-gitea/gitea/issues/18240

I hereby agree to the Code of Conduct published here:
8b89563bf1/CODE_OF_CONDUCT.md
I have read and understood the recommendations published here:
8b89563bf1/CONTRIBUTING.md

Thank you for your consideration.

---------

Co-authored-by: eyedeekay <idk@mulder>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
12 months ago
..
actions Fix `ref` for workflows triggered by `pull_request_target` (#25743) 1 year ago
activitypub Update tool dependencies, lock govulncheck and actionlint (#25655) 1 year ago
analyze Implement FSFE REUSE for golang files (#21840) 2 years ago
assetfs Skip unuseful error message in dev mode when watching local filesystem (#25919) 12 months ago
auth Use a general approach to access custom/static/builtin assets (#24022) 1 year ago
avatar Remove nfnt/resize and oliamb/cutter (#25999) 12 months ago
base Replace `interface{}` with `any` (#25686) 1 year ago
cache Upgrade go dependencies (#25819) 12 months ago
charset Replace `interface{}` with `any` (#25686) 1 year ago
container Implement FSFE REUSE for golang files (#21840) 2 years ago
context Add context parameter to some database functions (#26055) 12 months ago
csv Refactor locale number (#24134) 1 year ago
doctor Upgrade go dependencies (#25819) 12 months ago
emoji Update emoji set to Unicode 15 (#25595) 1 year ago
eventsource Less naked returns (#25713) 1 year ago
generate Bump github.com/golang-jwt/jwt to v5 (#25975) 12 months ago
git Remove `git.FileBlame` (#25841) 12 months ago
gitgraph Add context cache as a request level cache (#22294) 1 year ago
graceful Allow the use of alternative net.Listener implementations by downstreams (#25855) 12 months ago
hcaptcha Consume hcaptcha and pwn deps (#22610) 1 year ago
highlight Upgrade go dependencies (#25819) 12 months ago
hostmatcher Implement FSFE REUSE for golang files (#21840) 2 years ago
html Replace `interface{}` with `any` (#25686) 1 year ago
httpcache Less naked returns (#25713) 1 year ago
httplib Less naked returns (#25713) 1 year ago
indexer Add open/closed field support for issue index (#25708) 1 year ago
issue/template Replace `interface{}` with `any` (#25686) 1 year ago
json Replace `interface{}` with `any` (#25686) 1 year ago
label Make label templates have consistent behavior and priority (#23749) 1 year ago
lfs Rewrite logger system (#24726) 1 year ago
log Use stderr as fallback if the log file can't be opened (#26074) 12 months ago
markup Disallow dangerous url schemes (#25960) 12 months ago
mcaptcha Implement FSFE REUSE for golang files (#21840) 2 years ago
metrics Use a separate admin page to show global stats, remove `actions` stat (#25062) 1 year ago
migration Replace `interface{}` with `any` (#25686) 1 year ago
mirror Improve queue and logger context (#24924) 1 year ago
nosql Update tool dependencies, lock govulncheck and actionlint (#25655) 1 year ago
notification Add Adopt repository event and handler (#25497) 1 year ago
options Use a general approach to access custom/static/builtin assets (#24022) 1 year ago
packages Add support for different Maven POM encoding (#25873) 12 months ago
paginator Use more specific test methods (#24265) 1 year ago
pprof Implement FSFE REUSE for golang files (#21840) 2 years ago
private Replace `interface{}` with `any` (#25686) 1 year ago
process Less naked returns (#25713) 1 year ago
proxy Use proxy for pull mirror (#22771) 1 year ago
proxyprotocol Implement FSFE REUSE for golang files (#21840) 2 years ago
public Serve pre-defined files in "public", add "security.txt", add CORS header for ".well-known" (#25974) 12 months ago
queue Update tool dependencies, lock govulncheck and actionlint (#25655) 1 year ago
recaptcha Implement FSFE REUSE for golang files (#21840) 2 years ago
references Use correct captured group range when parsing cross-reference (#22672) 1 year ago
regexplru Upgrade go dependencies (#25819) 12 months ago
repository Support copy protected branch from template repository (#25889) 12 months ago
secret Improve decryption failure message (#24573) 1 year ago
session Replace `interface{}` with `any` (#25686) 1 year ago
setting Serve pre-defined files in "public", add "security.txt", add CORS header for ".well-known" (#25974) 12 months ago
sitemap Fix sitemap (#22272) 2 years ago
ssh Refactor path & config system (#25330) 1 year ago
storage Replace `interface{}` with `any` (#25686) 1 year ago
structs Remove commit status running and warning to align GitHub (#25839) 12 months ago
svg Move public asset files to the proper directory (#25907) 12 months ago
sync Implement FSFE REUSE for golang files (#21840) 2 years ago
system Implement FSFE REUSE for golang files (#21840) 2 years ago
templates Replace `interface{}` with `any` (#25686) 1 year ago
test Replace `interface{}` with `any` (#25686) 1 year ago
testlogger Replace `interface{}` with `any` (#25686) 1 year ago
timeutil Fix incorrect webhook time and use relative-time to display it (#24477) 1 year ago
translation Replace `interface{}` with `any` (#25686) 1 year ago
turnstile Add new captcha: cloudflare turnstile (#22369) 1 year ago
typesniffer Do not recognize text files as audio (#23355) 1 year ago
updatechecker Implement FSFE REUSE for golang files (#21840) 2 years ago
upload Implement FSFE REUSE for golang files (#21840) 2 years ago
uri Implement FSFE REUSE for golang files (#21840) 2 years ago
user Implement FSFE REUSE for golang files (#21840) 2 years ago
util Less naked returns (#25713) 1 year ago
validation Replace `interface{}` with `any` (#25686) 1 year ago
web Remove redundant "RouteMethods" method (#26024) 12 months ago
webhook New webhook trigger for receiving Pull Request review requests (#24481) 1 year ago