mirror of
https://github.com/go-i2p/go-gitlooseleaf.git
synced 2025-06-16 22:10:45 -04:00
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
// copy this file to modules/graceful/net_anon.go before building gitea
|
|
package graceful
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/go-i2p/go-meta-listener/mirror"
|
|
)
|
|
|
|
var mirrorListener, err = mirror.NewMirror()
|
|
|
|
// This implements the GetListener function for TLS, I2P, and Onion. Note the exemption for Unix sockets.
|
|
func MultiGetListener(network, address string) (net.Listener, error) {
|
|
EMAIL := os.Getenv("EMAIL")
|
|
if EMAIL == "" {
|
|
log.Printf("Warning: %s", fmt.Errorf("EMAIL environment variable not set, TLS not possible"))
|
|
} else {
|
|
log.Printf("Using %s as email for TLS", EMAIL)
|
|
}
|
|
// Add a deferral to say that we've tried to grab a listener
|
|
defer GetManager().InformCleanup()
|
|
switch network {
|
|
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 := ResolveUnixAddr(network, address)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return GetListenerUnixWrapper(network, unixAddr)
|
|
default:
|
|
return mirrorListener.Listen(address, EMAIL, "./certs", true)
|
|
}
|
|
}
|
|
|
|
// We use `init() to ensure that the appropriate Listeners and Dialers are correctly placed at runtime
|
|
func init() {
|
|
GetListener = MultiGetListener
|
|
httpClient := &http.Client{
|
|
Transport: &http.Transport{
|
|
Dial: Dial,
|
|
},
|
|
}
|
|
|
|
http.DefaultClient = httpClient
|
|
http.DefaultTransport = httpClient.Transport
|
|
}
|