Compare commits

...

7 Commits

Author SHA1 Message Date
eyedeekay
b83bfb42ca move a bunch of stuff around in nomine organization 2025-08-19 17:39:31 -04:00
eyedeekay
0ea18eb24f Reorganize everything 2025-08-19 17:35:20 -04:00
eyedeekay
3c8c6c80b8 refactor more long functions 2025-08-19 17:08:49 -04:00
eyedeekay
a6dc823f2e Refactor username discovery 2025-08-19 16:56:23 -04:00
eyedeekay
ab60eb6d2c refactor pathfinding 2025-08-19 16:41:54 -04:00
eyedeekay
7a3f89fafa add stubs for utility functions that differ on BSDs 2025-08-19 16:10:01 -04:00
eyedeekay
b291d85268 add stubs for utility functions that differ on BSDs 2025-08-19 15:57:40 -04:00
17 changed files with 342 additions and 572 deletions

View File

@@ -20,8 +20,6 @@ Directories
parse the errors to know what is going on.
- **./i2cpcheck** - A terminal application which probes for an I2P router by looking in a default location. It also checks the
$PATH, or by probing I2CP.
- **./i2pdbundle** - A set of tools and libraries for embedding an I2Pd router in a Go application.
It then installs the router to a location under the application's control.
- **./proxycheck** - A tool for determining the presence of an I2P router. It does this by making a request to "proxy.i2p" by
default) over an I2P HTTP Proxy.
- **./samcheck** - A tool for determining the presence of an I2P router. It does this by performing a brief interaction with the SAM

View File

@@ -1,3 +1,4 @@
// checker.go
package checki2p
import (
@@ -8,12 +9,9 @@ import (
go_i2cp "github.com/go-i2p/go-i2cp"
)
func i2pdArgs() ([]string, error) {
return []string{""}, nil
}
// CheckI2PIsRunning is frequently the only thing I need a reliable, non-SAM
// way to test at runtime.
// Moved from: checki2cp.go (non-platform-specific)
func CheckI2PIsRunning() (bool, error) {
log.Println("Trying to discover a running I2P router")
if checksam.CheckSAMAvailable("127.0.0.1:7656") {
@@ -31,6 +29,7 @@ func CheckI2PIsRunning() (bool, error) {
// CheckI2CPConnection is determines if I2CP is available on the TCP port
// usually used by I2P routers(7654).
// Moved from: checki2cp.go (non-platform-specific)
func CheckI2CPConnection() (bool, error) {
log.Println("Trying to discover a running I2P router")
client := go_i2cp.NewClient(nil)

View File

@@ -1,8 +1,6 @@
package checki2pcontrol
import (
"log"
"github.com/go-i2p/go-i2pcontrol"
)
@@ -10,38 +8,52 @@ import (
// it returns true if the command is successful and false, with an error,
// if not.
func CheckI2PControlEcho(host, port, password, path string) (bool, error) {
host = normalizeHost(host)
port = normalizePort(port)
// Try primary connection configuration
if err := attemptI2PControlConnection(host, port, password, path); err == nil {
return true, nil
}
// Try fallback configuration
if err := attemptI2PControlConnection(host, "7657", password, "jsonrpc"); err == nil {
return true, nil
}
// Both attempts failed
return false, attemptI2PControlConnection(host, "7657", password, "jsonrpc")
}
// normalizeHost returns the default host if the provided host is empty.
func normalizeHost(host string) string {
if host == "" {
host = "127.0.0.1"
return "127.0.0.1"
}
return host
}
// normalizePort returns the default port if the provided port is empty.
func normalizePort(port string) string {
if port == "" {
port = "7650"
return "7650"
}
return port
}
// attemptI2PControlConnection tries to establish an I2PControl connection and perform an echo test.
func attemptI2PControlConnection(host, port, password, path string) error {
i2pcontrol.Initialize(host, port, path)
var finalError error
if _, err := i2pcontrol.Authenticate(password); err != nil {
finalError = err
return err
}
if _, err := i2pcontrol.Echo("Hello I2PControl"); err != nil {
finalError = err
return err
}
if finalError == nil {
return true, nil
}
log.Printf("Error: %v", finalError)
finalError = nil
port = "7657"
path = "jsonrpc"
i2pcontrol.Initialize(host, port, path)
if _, err := i2pcontrol.Authenticate(password); err != nil {
finalError = err
}
if _, err := i2pcontrol.Echo("Hello I2PControl"); err != nil {
finalError = err
}
if finalError == nil {
return true, nil
}
return false, finalError
return nil
}
// GetDefaultI2PControlPath probes default locations for the I2PControl API, returning
@@ -49,35 +61,24 @@ func CheckI2PControlEcho(host, port, password, path string) (bool, error) {
// and an error
func GetDefaultI2PControlPath(password ...string) (string, string, string, error) {
host := "127.0.0.1"
port := "7650"
pass := ""
if len(password) > 0 {
pass = password[0]
} else {
pass = "itoopie"
}
// use the provided password parameter
path := ""
i2pcontrol.Initialize(host, port, path)
var finalError error
if _, err := i2pcontrol.Authenticate(pass); err != nil {
finalError = err
}
if _, err := i2pcontrol.Echo("Hello I2PControl"); err != nil {
finalError = err
}
if finalError == nil {
pass := extractPassword(password)
// Try primary configuration
port, path := "7650", ""
if err := attemptI2PControlConnection(host, port, pass, path); err == nil {
return host, port, path, nil
}
finalError = nil
port = "7657"
path = "jsonrpc"
i2pcontrol.Initialize(host, port, path)
if _, err := i2pcontrol.Authenticate(pass); err != nil {
finalError = err
}
if _, err := i2pcontrol.Echo("Hello I2PControl"); err != nil {
finalError = err
}
return host, port, path, finalError
// Try fallback configuration
port, path = "7657", "jsonrpc"
err := attemptI2PControlConnection(host, port, pass, path)
return host, port, path, err
}
// extractPassword returns the first password from the variadic parameter or default password.
func extractPassword(password []string) string {
if len(password) > 0 {
return password[0]
}
return "itoopie"
}

8
helpers.go Normal file
View File

@@ -0,0 +1,8 @@
// helpers.go
package checki2p
// i2pdArgs returns default arguments for i2pd router initialization
// Moved from: checki2cp.go (non-platform-specific)
func i2pdArgs() ([]string, error) {
return []string{""}, nil
}

View File

@@ -1,390 +0,0 @@
<html>
<head>
<title>
checki2cp
</title>
<meta name="author" content="go-i2p" />
<meta name="description" content="checki2cp" />
<meta name="keywords" content="master" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="navbar">
<a href="#shownav">
Show navigation
</a>
<div id="shownav">
<div id="hidenav">
<ul>
<li>
<a href="index.html">
index
</a>
</li>
</ul>
<br>
<a href="#hidenav">
Hide Navigation
</a>
</div>
</div>
</div>
<h1>
<a href="/">
checki2cp
</a>
</h1>
<p>
<a href="https://goreportcard.com/report/github.com/go-i2p/checki2cp" rel="nofollow">
<img src="https://goreportcard.com/badge/github.com/go-i2p/checki2cp" alt="Go Report Card"/>
</a>
<a href="http://godoc.org/github.com/go-i2p/checki2cp" rel="nofollow">
<img src="https://godoc.org/github.com/go-i2p/checki2cp?status.svg" alt="Documentation"/>
</a>
</p>
<p>
Library and terminal application which checks for the presence of a usable i2p
router by attempting various I2P client-related probes and tests. Includes
everything you need to completely embed I2Pd in a Go application on Linux,
OSX, and Windows, or use them as modular tools for checking the status of your
I2P router.
</p>
<h2>
Directories
</h2>
<ul>
<li>
<strong>
./
</strong>
<strong>
-
</strong>
Files in the base directory contain functions that check for the presence of an I2P router in a default
location, or for the presence of an I2CP port. Makefile is also here.
</li>
<li>
<strong>
./controlcheck
</strong>
<strong>
-
</strong>
Detects whether an I2PControl API endpoint is available, and provides a tool for finding
one if it is available. It is not recommended to use I2PControl checking for presence detection, you will need to
parse the errors to know what is going on.
</li>
<li>
<strong>
./go-i2pd
</strong>
<strong>
-
</strong>
An example of running an embedded I2Pd router from a Go application
</li>
<li>
<strong>
./i2cpcheck
</strong>
<strong>
-
</strong>
A terminal application which probes for an I2P router by looking in a default location, the
$PATH, or by probing I2CP.
</li>
<li>
<strong>
./i2pdbundle
</strong>
<strong>
-
</strong>
A set of tools and libraries for embedding an I2Pd router in a Go application, then
installing it to a location under the applications control.
</li>
<li>
<strong>
./proxycheck
</strong>
<strong>
-
</strong>
A tool for determining the presence of an I2P router by making a request(to “proxy.i2p” by
default) over an I2P HTTP Proxy.
</li>
<li>
<strong>
./samcheck
</strong>
<strong>
-
</strong>
A tool for determining the presence of an I2P router by doing a brief interaction with the SAM
API.
</li>
<li>
<strong>
./zerobundle
</strong>
<strong>
-
</strong>
Moved to
<a href="https://github.com/go-i2p/zerobundle" rel="nofollow">
go-i2p/zerobundle
</a>
</li>
</ul>
<h2>
I2P Router Presence Detection tools
</h2>
<p>
Currently the command-line tool only does presence detection by checking for I2CP and or an I2P router installed in a
default location.
</p>
<h3>
Examples:
</h3>
<h4>
./ Base Directory
</h4>
<h5>
Checking for an I2P Router by default install location
</h5>
<pre><code> ok, err := CheckI2PIsInstalledDefaultLocation()
if err != nil {
t.Fatal(err)
}
if ok {
t.Log(&#34;I2P is installed, successfully confirmed&#34;)
} else {
t.Log(&#34;I2P is in a default location, user feedback is needed&#34;)
}
</code></pre>
<h5>
Checking for an I2P Router by I2CP Port
</h5>
<pre><code> ok, err := CheckI2PIsRunning()
if err != nil {
t.Fatal(err)
}
if ok {
t.Log(&#34;I2P is running, successfully confirmed I2CP&#34;)
} else {
t.Log(&#34;I2P is not running, further testing is needed&#34;)
}
</code></pre>
<h5>
Launching an installed I2P router from the Library
</h5>
<p>
TODO: Make this function work better with i2pd, find a way to integrate it into into the tests, then write the example.
</p>
<h4>
./proxycheck
</h4>
<h5>
Make a request through the default I2P HTTP Proxy to test presence
</h5>
<pre><code> if ProxyDotI2P() {
t.Log(&#34;Proxy success&#34;)
} else {
t.Fatal(&#34;Proxy not found&#34;)
}
</code></pre>
<h5>
Use a non-default proxy instead
</h5>
<p>
It honors the
<code>
http_proxy
</code>
environment variable, so just set it(I like to set both of these in case some system is
weird, I suppose its a meager measure.):
</p>
<pre><code> if err := os.Setenv(&#34;HTTP_PROXY&#34;, &#34;http://127.0.0.1:4444&#34;); err != nil {
return false
}
if err := os.Setenv(&#34;http_proxy&#34;, &#34;http://127.0.0.1:4444&#34;); err != nil {
return false
}
if ProxyDotI2P() {
t.Log(&#34;Proxy success&#34;)
} else {
t.Fatal(&#34;Proxy not found&#34;)
}
</code></pre>
<h4>
./samcheck
</h4>
<h5>
Check if SAM is available on a default port
</h5>
<pre><code> if CheckSAMAvailable(&#34;&#34;) {
t.Log(&#34;SAM success&#34;)
} else {
t.Fatal(&#34;SAM not found&#34;)
}
</code></pre>
<h5>
Check if SAM is available on a non-default host or port
</h5>
<pre><code> if CheckSAMAvailable(&#34;127.0.1.1:1234&#34;) {
t.Log(&#34;SAM success&#34;)
} else {
t.Fatal(&#34;SAM not found&#34;)
}
</code></pre>
<h2>
I2PD Embedding Tools:
</h2>
<p>
In the very far future, it would be cool to have a 100% pure-Go I2P router, but for right now, what I want to work on is
a way of working with I2P and with Go applications,
<strong>
without
</strong>
requiring undue knowledge on the part of the user. The
theory is that they want to install one application at a time, and dont want to run more than one I2P router unless
they need to. So the embedding tools assume that if they find an I2P router, that they should use that I2P router. At
this time, almost any useful I2P configuration will be detected and the embedded router will not start. In the future,
this behavior will be configurable.
</p>
<h4>
./controlcheck
</h4>
<h5>
See if an I2PControl API is present on any default port
</h5>
<pre><code> if itworks, err := CheckI2PControlEcho(&#34;&#34;, &#34;&#34;, &#34;&#34;, &#34;&#34;); works {
t.Log(&#34;Proxy success&#34;)
} else if err != nil {
t.Fatal(err)
} else {
t.Fatal(&#34;Proxy not found&#34;)
}
</code></pre>
<h5>
Check what host:port/path corresponds to an available default I2PControl API
</h5>
<p>
TODO: Explain why you need this if your goal is to tolerate Java, I2Pd, and Embedded I2Pd all at once
</p>
<pre><code> if host, port, path, err := GetDefaultI2PControlPath(); err != nil {
t.Fatal(&#34;I2PControl Not found&#34;)
} else {
t.Log(&#34;I2Pcontrol found at&#34;, host, port, path)
}
</code></pre>
<h4>
./i2pdbundle
</h4>
<p>
This will
<em>
completely
</em>
install, configure, wrap, and run a minimal i2pd router from within a Go application. From here
you attach applications via SAM and I2PControl.
</p>
<pre><code> package main
import (
&#34;log&#34;
&#34;github.com/go-i2p/checki2cp/i2pdbundle&#34;
)
func main() {
if err := i2pd.UnpackI2Pd(); err != nil {
log.Println(err)
}
if path, err := i2pd.FindI2Pd(); err != nil {
log.Println(err)
} else {
log.Println(path)
}
// if cmd, err := i2pd.LaunchI2Pd(); err != nil {
if _, err := i2pd.LaunchI2Pd(); err != nil {
log.Println(err)
}
}
</code></pre>
<h3>
Roadmap
</h3>
<p>
libboost-date-time1.67.0,libboost-filesystem1.67.0,libboost-program-options1.67.0,libboost-system1.67.0,libc6,libgcc1,libminiupnpc17,libssl1.1,libstdc++6,zlib1g,lsb-base
</p>
<ol>
<li>
Minimum requirement for Golang UI: Use i2pd and a custom LD_LIBRARY_PATH to create an i2pd bundle for use as a
fallback in the non-presence of a usable router.
</li>
<li>
Set up router with SWIG instead of with static embedded executable.
</li>
<li>
Minimize number of components we build(nothing but I2PControl, SAM, and
I2CP).
</li>
<li>
Provide easy router/client setup functions to import i2p routers into
applications with minimal boilerplate.
</li>
<li>
Pure-Go I2PControl implementation.
</li>
<li>
Pure-Go SAM implementation.
</li>
<li>
Pure-Go I2CP implementation.
</li>
</ol>
<div>
<a href="#show">
Show license
</a>
<div id="show">
<div id="hide">
<pre><code>MIT License
Copyright (c) 2019 idk
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
</code></pre>
<a href="#hide">
Hide license
</a>
</div>
</div>
</div>
<div>
<iframe src="https://snowflake.torproject.org/embed.html" width="320" height="240" frameborder="0" scrolling="no"></iframe>
</div>
<div>
<a href="https://geti2p.net/">
I2P
</a>
</div>
</body>
</html>

View File

@@ -1,3 +1,4 @@
// launcher.go
package checki2p
import (
@@ -12,6 +13,7 @@ import (
// ConditionallyLaunchI2P If an already-installed I2P router is present, then
// make sure that it is started, i.e. launch the router *only* if it is not
// already running.
// Moved from: launch.go (non-platform-specific)
func ConditionallyLaunchI2P() (bool, error) {
log.Println("Checking if I2P is installed at the default location.")
ok, err := util.FindI2PIsInstalledDefaultLocation()
@@ -38,6 +40,7 @@ func ConditionallyLaunchI2P() (bool, error) {
// This function is used by ConditionallyLaunchI2P to start the router if it is not already running.
// it returns a boolean value indicating whether the router was started successfully or not.
// it also returns an error if the router could not be started.
// Moved from: launch.go (non-platform-specific)
func LaunchI2P(path string) (bool, error) {
log.Println("Looking for an I2P router to start")
if strings.HasSuffix(path, "i2prouter") || strings.HasSuffix(path, "i2prouter.exe") || strings.HasSuffix(path, "i2psvc") || strings.HasSuffix(path, "i2psvc.exe") {

9
types.go Normal file
View File

@@ -0,0 +1,9 @@
// types.go
package checki2p
// This file contains all interfaces extracted from non-platform-specific code
// to provide clear API contracts and facilitate testing and mocking.
// Currently, no interfaces are defined in the non-platform-specific codebase.
// This file is prepared for future interface definitions that may be extracted
// during the reorganization process.

View File

@@ -1,24 +1,47 @@
// constants.go
package util
// File paths and locations for various I2P router installations
// All constants consolidated from non-platform-specific code
var (
// I2CP_HOST is the i2cp host
// Moved from: constant.go (non-platform-specific)
I2CP_HOST string
// I2CP_PORT is the i2cp port
// Moved from: constant.go (non-platform-specific)
I2CP_PORT string
// WINDOWS_DEFAULT_LOCATION is the default location of the I2P router on Windows
// Moved from: constant.go (non-platform-specific)
WINDOWS_DEFAULT_LOCATION string = `C:\\Program Files\i2p\i2psvc.exe`
// WINDOWS_ZERO_NSIS_DEFAULT_LOCATION is the default location of the I2P Zero router on Windows
// Moved from: constant.go (non-platform-specific)
WINDOWS_ZERO_NSIS_DEFAULT_LOCATION string = `C:\\Program Files\I2P-Zero\router\i2p-zero.exe`
// I2PD_WINDOWS_DEFAULT_LOCATION is the default location of the I2Pd router on Windows
// Moved from: constant.go (non-platform-specific)
I2PD_WINDOWS_DEFAULT_LOCATION string = `C:\\Program Files\I2Pd\i2pd.exe`
// LINUX_SYSTEM_LOCATION is the default location of the I2P router on Linux
// Moved from: constant.go (non-platform-specific)
LINUX_SYSTEM_LOCATION []string = []string{"/usr/bin/i2prouter", "/usr/sbin/i2prouter"}
// I2PD_LINUX_SYSTEM_LOCATION is the default location of the I2Pd router on Linux
// Moved from: constant.go (non-platform-specific)
I2PD_LINUX_SYSTEM_LOCATION []string = []string{"/usr/sbin/i2pd", "/usr/bin/i2pd"}
// I2P_ASUSER_HOME_LOCATION This is the path to the default I2P config directory when running as a user
// Moved from: constant.go (non-platform-specific)
I2P_ASUSER_HOME_LOCATION string = Inithome(Home())
// HOME_DIRECTORY_LOCATION can use config/run from a user's $HOME directory, this is the path to that router
// Moved from: constant.go (non-platform-specific)
HOME_DIRECTORY_LOCATION string = Inithome("/i2p/i2prouter")
// OSX_DEFAULT_LOCATION is the default location of the I2P router on OSX
// Moved from: constant.go (non-platform-specific)
OSX_DEFAULT_LOCATION string = Inithome("/Library/Application Support/i2p/clients.config")
)

View File

@@ -1,48 +0,0 @@
package util
import (
"fmt"
"log"
)
// FindI2PIsInstalledDefaultLocation looks in various locations for the
// presence of an I2P router, reporting back the location
func FindI2PIsInstalledDefaultLocation() (string, error) {
if CheckFileExists(I2PD_WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2pd router detected")
return I2PD_WINDOWS_DEFAULT_LOCATION, nil
}
if CheckFileExists(I2PD_LINUX_SYSTEM_LOCATION[0]) {
log.Println("Linux i2pd router detected")
return I2PD_LINUX_SYSTEM_LOCATION[0], nil
}
if CheckFileExists(I2PD_LINUX_SYSTEM_LOCATION[1]) {
log.Println("Linux i2pd router detected")
return I2PD_LINUX_SYSTEM_LOCATION[1], nil
}
if CheckFileExists(WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2p router detected")
return WINDOWS_DEFAULT_LOCATION, nil
}
if CheckFileExists(WINDOWS_ZERO_NSIS_DEFAULT_LOCATION) {
log.Println("Windows i2p router detected")
return WINDOWS_ZERO_NSIS_DEFAULT_LOCATION, nil
}
if CheckFileExists(LINUX_SYSTEM_LOCATION[0]) {
log.Println("Linux i2p router detected")
return LINUX_SYSTEM_LOCATION[0], nil
}
if CheckFileExists(LINUX_SYSTEM_LOCATION[1]) {
log.Println("Linux i2p router detected")
return LINUX_SYSTEM_LOCATION[1], nil
}
if CheckFileExists(HOME_DIRECTORY_LOCATION) {
log.Println("Linux i2p router detected")
return HOME_DIRECTORY_LOCATION, nil
}
if CheckFileExists(OSX_DEFAULT_LOCATION) {
log.Println("OSX i2p router detected")
return OSX_DEFAULT_LOCATION, nil
}
return "", fmt.Errorf("i2p router not found")
}

84
util/finder.go Normal file
View File

@@ -0,0 +1,84 @@
// finder.go
package util
import (
"fmt"
"log"
)
// Router Detection Functions
// All functions moved from: find.go (non-platform-specific)
// checkI2PDRouterLocations checks for I2PD (i2pd) router installations
func checkI2PDRouterLocations() (string, bool) {
if CheckFileExists(I2PD_WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2pd router detected")
return I2PD_WINDOWS_DEFAULT_LOCATION, true
}
if CheckFileExists(I2PD_LINUX_SYSTEM_LOCATION[0]) {
log.Println("Linux i2pd router detected")
return I2PD_LINUX_SYSTEM_LOCATION[0], true
}
if CheckFileExists(I2PD_LINUX_SYSTEM_LOCATION[1]) {
log.Println("Linux i2pd router detected")
return I2PD_LINUX_SYSTEM_LOCATION[1], true
}
return "", false
}
// checkJavaI2PWindowsLocations checks for Java I2P router installations on Windows
func checkJavaI2PWindowsLocations() (string, bool) {
if CheckFileExists(WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2p router detected")
return WINDOWS_DEFAULT_LOCATION, true
}
if CheckFileExists(WINDOWS_ZERO_NSIS_DEFAULT_LOCATION) {
log.Println("Windows i2p router detected")
return WINDOWS_ZERO_NSIS_DEFAULT_LOCATION, true
}
return "", false
}
// checkJavaI2PLinuxLocations checks for Java I2P router installations on Linux
func checkJavaI2PLinuxLocations() (string, bool) {
if CheckFileExists(LINUX_SYSTEM_LOCATION[0]) {
log.Println("Linux i2p router detected")
return LINUX_SYSTEM_LOCATION[0], true
}
if CheckFileExists(LINUX_SYSTEM_LOCATION[1]) {
log.Println("Linux i2p router detected")
return LINUX_SYSTEM_LOCATION[1], true
}
return "", false
}
// checkUserDirectoryLocations checks for I2P router installations in user directories
func checkUserDirectoryLocations() (string, bool) {
if CheckFileExists(HOME_DIRECTORY_LOCATION) {
log.Println("Linux i2p router detected")
return HOME_DIRECTORY_LOCATION, true
}
if CheckFileExists(OSX_DEFAULT_LOCATION) {
log.Println("OSX i2p router detected")
return OSX_DEFAULT_LOCATION, true
}
return "", false
}
// FindI2PIsInstalledDefaultLocation looks in various locations for the
// presence of an I2P router, reporting back the location
func FindI2PIsInstalledDefaultLocation() (string, error) {
if location, found := checkI2PDRouterLocations(); found {
return location, nil
}
if location, found := checkJavaI2PWindowsLocations(); found {
return location, nil
}
if location, found := checkJavaI2PLinuxLocations(); found {
return location, nil
}
if location, found := checkUserDirectoryLocations(); found {
return location, nil
}
return "", fmt.Errorf("i2p router not found")
}

View File

@@ -1,3 +1,4 @@
// firewall_utils.go
package util
import (
@@ -7,6 +8,9 @@ import (
"strings"
)
// Firewall Configuration Functions
// All functions moved from: firewall.go (non-platform-specific)
// GetFirewallPort finds the configured UDP port of your I2P router to help
// configure firewalls. It does this by finding the router.config and reading
// it. This function will not work on I2Pd routers yet but it should be easy

7
util/freebsd.go Normal file
View File

@@ -0,0 +1,7 @@
//go:build freebsd
package util
func IsHeadless() (bool, error) {
return true, nil
}

View File

@@ -1,46 +1,82 @@
// launcher_utils.go
package util
import (
"log"
)
// CheckI2PIsInstalledDefaultLocation looks in various locations for the
// presence of an I2P router.
func CheckI2PIsInstalledDefaultLocation() (bool, error) {
// Launcher Detection Functions
// All functions moved from: launch.go (non-platform-specific)
// checkI2PdRouterInstallation checks for i2pd router installations on Windows and Linux.
func checkI2PdRouterInstallation() bool {
if CheckFileExists(I2PD_WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2pd router detected")
return true, nil
return true
}
if CheckFileExists(I2PD_LINUX_SYSTEM_LOCATION[0]) {
log.Println("Linux i2pd router detected")
return true, nil
return true
}
if CheckFileExists(I2PD_LINUX_SYSTEM_LOCATION[1]) {
log.Println("Linux i2pd router detected")
return true, nil
return true
}
return false
}
// checkJavaI2PWindowsInstallation checks for Java I2P router installations on Windows.
func checkJavaI2PWindowsInstallation() bool {
if CheckFileExists(WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2p router detected")
return true, nil
return true
}
if CheckFileExists(WINDOWS_ZERO_NSIS_DEFAULT_LOCATION) {
log.Println("Windows i2p zero router detected")
return true, nil
return true
}
return false
}
// checkJavaI2PLinuxInstallation checks for Java I2P router installations on Linux.
func checkJavaI2PLinuxInstallation() bool {
if CheckFileExists(LINUX_SYSTEM_LOCATION[0]) {
log.Println("Linux i2p router detected")
return true, nil
return true
}
if CheckFileExists(LINUX_SYSTEM_LOCATION[1]) {
log.Println("Linux i2p router detected")
return true, nil
return true
}
return false
}
// checkUserDirectoryInstallation checks for I2P router installations in user directories.
func checkUserDirectoryInstallation() bool {
if CheckFileExists(HOME_DIRECTORY_LOCATION) {
log.Println("Linux i2p router detected")
return true, nil
return true
}
if CheckFileExists(OSX_DEFAULT_LOCATION) {
log.Println("OSX i2p router detected")
return true
}
return false
}
// CheckI2PIsInstalledDefaultLocation looks in various locations for the
// presence of an I2P router.
func CheckI2PIsInstalledDefaultLocation() (bool, error) {
if checkI2PdRouterInstallation() {
return true, nil
}
if checkJavaI2PWindowsInstallation() {
return true, nil
}
if checkJavaI2PLinuxInstallation() {
return true, nil
}
if checkUserDirectoryInstallation() {
return true, nil
}
return false, nil

7
util/openbsd.go Normal file
View File

@@ -0,0 +1,7 @@
//go:build openbsd
package util
func IsHeadless() (bool, error) {
return true, nil
}

View File

@@ -1,3 +1,4 @@
// system_utils.go
package util
import (
@@ -10,6 +11,7 @@ import (
// Inithome returns the path to the user's home directory
// with the given string appended to the end.
// It panics if the user's home directory cannot be found.
// Moved from: util.go (non-platform-specific)
func Inithome(str string) string {
s, e := os.UserHomeDir()
if e != nil {
@@ -23,6 +25,7 @@ func Inithome(str string) string {
// CheckFileExists checks to see if a file exists at the given path
// and returns a boolean value.
// It returns true if the file exists, false otherwise.
// Moved from: util.go (non-platform-specific)
func CheckFileExists(path string) bool {
_, err := os.Stat(path)
return !os.IsNotExist(err)
@@ -31,6 +34,7 @@ func CheckFileExists(path string) bool {
// Home returns the path to the I2P(Java) home directory
// based on the current operating system.
// It returns a string containing the path to the I2P home directory.
// Moved from: util.go (non-platform-specific)
func Home() string {
if runtime.GOOS == "windows" {
return "\\i2p"
@@ -45,6 +49,7 @@ func Home() string {
// it calls a platform-specific function in the background.
// it returns true if the system appears to be headless, false otherwise
// and any error encountered during detection.
// Moved from: util.go (non-platform-specific)
func CheckHeadlessness() (bool, error) {
switch runtime.GOOS {
case "windows":

View File

@@ -1,63 +0,0 @@
package util
import (
"log"
"os"
"os/user"
)
// UserFind makes sure that we never mis-identify the user account because of
// sudo
func UserFind() string {
if os.Geteuid() == 0 {
str := os.Getenv("SUDO_USER")
return str
}
if un, err := user.Current(); err == nil {
return un.Name
}
return ""
}
// CheckI2PUserName looks in various locations for the
// presence of an I2P router and guesses the username it
// should run under. On Windows it returns the EXE name.
func CheckI2PUserName() (string, error) {
if CheckFileExists(I2PD_WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2pd router detected")
return "i2pd", nil
}
if CheckFileExists(I2PD_LINUX_SYSTEM_LOCATION[0]) {
log.Println("Linux i2pd router detected")
return "i2pd", nil
}
if CheckFileExists(I2PD_LINUX_SYSTEM_LOCATION[1]) {
log.Println("Linux i2pd router detected")
return "i2pd", nil
}
if CheckFileExists(WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2p router detected")
return "i2psvc", nil
}
if CheckFileExists(WINDOWS_ZERO_NSIS_DEFAULT_LOCATION) {
log.Println("Windows i2p router detected")
return "i2p-zero", nil
}
if CheckFileExists(LINUX_SYSTEM_LOCATION[0]) {
log.Println("Linux i2p router detected")
return "i2psvc", nil
}
if CheckFileExists(LINUX_SYSTEM_LOCATION[1]) {
log.Println("Linux i2p router detected")
return "i2psvc", nil
}
if CheckFileExists(HOME_DIRECTORY_LOCATION) {
log.Println("Linux i2p router detected")
return UserFind(), nil
}
if CheckFileExists(OSX_DEFAULT_LOCATION) {
log.Println("OSX i2p router detected")
return UserFind(), nil
}
return "", nil
}

87
util/user_utils.go Normal file
View File

@@ -0,0 +1,87 @@
// user_utils.go
package util
import (
"log"
"os"
"os/user"
)
// User and Authentication Functions
// All functions moved from: user.go (non-platform-specific)
// UserFind makes sure that we never misidentify the user account because of
// sudo
func UserFind() string {
if os.Geteuid() == 0 {
str := os.Getenv("SUDO_USER")
return str
}
if un, err := user.Current(); err == nil {
return un.Name
}
return ""
}
// CheckI2PUserName looks in various locations for the
// presence of an I2P router and guesses the username it
// should run under. On Windows it returns the EXE name.
func CheckI2PUserName() (string, error) {
if username := checkWindowsRouters(); username != "" {
return username, nil
}
if username := checkLinuxSystemRouters(); username != "" {
return username, nil
}
if username := checkUserDirectoryRouters(); username != "" {
return username, nil
}
return "", nil
}
// checkWindowsRouters detects Windows-based I2P router installations.
func checkWindowsRouters() string {
if CheckFileExists(I2PD_WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2pd router detected")
return "i2pd"
}
if CheckFileExists(WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2p router detected")
return "i2psvc"
}
if CheckFileExists(WINDOWS_ZERO_NSIS_DEFAULT_LOCATION) {
log.Println("Windows i2p router detected")
return "i2p-zero"
}
return ""
}
// checkLinuxSystemRouters detects system-level Linux I2P router installations.
func checkLinuxSystemRouters() string {
for _, location := range I2PD_LINUX_SYSTEM_LOCATION {
if CheckFileExists(location) {
log.Println("Linux i2pd router detected")
return "i2pd"
}
}
for _, location := range LINUX_SYSTEM_LOCATION {
if CheckFileExists(location) {
log.Println("Linux i2p router detected")
return "i2psvc"
}
}
return ""
}
// checkUserDirectoryRouters detects user-directory I2P router installations.
func checkUserDirectoryRouters() string {
if CheckFileExists(HOME_DIRECTORY_LOCATION) {
log.Println("Linux i2p router detected")
return UserFind()
}
if CheckFileExists(OSX_DEFAULT_LOCATION) {
log.Println("OSX i2p router detected")
return UserFind()
}
return ""
}