dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit e9b9c7946ec0f68795e10cd4b80242f8a5032787
parent 5525002ed2e3d35e6fdc6b1932ed86673100fa5d
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon,  9 Jan 2023 17:33:22 -0800

start web servers for i2p/tor

Diffstat:
Mpkg/web/web.go | 34++++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/pkg/web/web.go b/pkg/web/web.go @@ -278,27 +278,53 @@ func getMainServer() echo.HandlerFunc { } } -// Start ... -func Start(host string, port int) { +func getBaseServer() *echo.Echo { e := echo.New() e.HideBanner = true e.HidePort = true e.Debug = true - e.GET("/file-drop/:uuid", handlers.FileDropHandler) e.POST("/file-drop/:uuid", handlers.FileDropHandler) e.Any("*", getMainServer()) + return e +} +func startI2pServer(host string, port int) { + if config.Development.IsTrue() { + return + } + address := host + ":" + strconv.Itoa(port) + e := getBaseServer() + logrus.Info("start i2p server on " + address) + if err := e.Start(address); err != nil { + if err != http.ErrServerClosed { + logrus.Error(err) + } + } +} + +func startTorServer(host string, port int) { + address := host + ":" + strconv.Itoa(port) + e := getBaseServer() if config.Development.IsFalse() { prodServer(e) } - if err := e.Start(host + ":" + strconv.Itoa(port)); err != nil { + logrus.Info("start tor server on " + address) + if err := e.Start(address); err != nil { if err != http.ErrServerClosed { logrus.Error(err) } } } +// Start ... +func Start(host string, port int) { + // Start server for I2P + go startI2pServer(host, port+1) + // Server for Tor/dev + startTorServer(host, port) +} + func extractGlobalCircuitIdentifier(m string) int64 { // You can compute the global circuit identifier using the following formula given the IPv6 address "fc00:dead:beef:4dad::AABB:CCDD": // global_circuit_id = (0xAA << 24) + (0xBB << 16) + (0xCC << 8) + 0xDD;