34 Commits

Author SHA1 Message Date
idk
0395860c7c Explain this whole... experiment in the readme. 2020-04-08 21:00:43 -04:00
idk
69b9f4a6e5 start the actual import package 2020-04-08 19:58:13 -04:00
idk
57caf7c8a5 start the actual import package 2020-04-08 19:48:34 -04:00
idk
8e3c3933cf start the actual import package 2020-04-08 19:41:24 -04:00
idk
d46e7e76a1 start the actual import package 2020-04-08 18:58:21 -04:00
idk
3f96e9240a start the actual import package 2020-04-08 18:56:15 -04:00
idk
d998e46dc7 start the actual import package 2020-04-08 18:54:59 -04:00
idk
51e976fc2b start the actual import package 2020-04-08 18:43:30 -04:00
idk
fc9ff2e443 start the actual import package 2020-04-08 18:37:59 -04:00
idk
9258a782f1 start the actual import package 2020-04-08 18:37:37 -04:00
idk
69a1415faa start the actual import package 2020-04-08 18:36:52 -04:00
idk
2fad4bb6a9 start the actual import package 2020-04-08 18:17:03 -04:00
idk
66313bb7f0 fix path for zerobundle experiment 2020-04-08 18:02:06 -04:00
idk
40e6aac44e fix path for zerobundle experiment 2020-04-08 17:50:34 -04:00
idk
3f4bea6c35 see about whether zero is a vaiable bundling tool for this use-case 2020-04-08 17:32:41 -04:00
idk
7eea40c5aa Check i2p running status before attempting to start the router 2020-04-03 20:51:59 -04:00
idk
3bff02397e Check i2p running status before attempting to start the router 2020-04-03 20:51:29 -04:00
idk
b46f04344d Check i2p running status before attempting to start the router 2020-04-03 20:42:45 -04:00
idk
dbb85e950b Check i2p running status before attempting to start the router 2020-04-03 20:41:15 -04:00
idk
e6e48920d8 Check i2p running status before attempting to start the router 2020-04-03 20:40:14 -04:00
idk
acc8d4e0f5 Fix that module 2020-04-03 19:43:24 -04:00
idk
750ce7e6d8 Add i2prouter start function 2020-04-03 17:33:08 -04:00
idk
643d7991fd Add i2prouter start function 2020-04-03 17:30:48 -04:00
idk
44d5506a8f Add find i2p function 2020-04-03 17:18:07 -04:00
idk
4d5f344b88 Add find i2p function 2020-04-03 17:07:24 -04:00
idk
759a5aec9c Add find i2p function 2020-04-03 17:07:05 -04:00
idk
a3982e2904 Add find i2p function 2020-04-03 17:05:54 -04:00
idk
5dea25453c fix release 2020-01-21 21:40:49 -05:00
idk
775052865c fix releas 2020-01-21 21:39:16 -05:00
idk
c67d91fa2c do a new release 2020-01-21 21:36:28 -05:00
idk
37c918804a do a new release 2020-01-21 21:36:06 -05:00
idk
f528ab6e38 add checkfirewallport 2020-01-21 21:33:10 -05:00
idk
138f1b4882 use user.Current to determine user when not root 2019-10-27 13:34:19 -04:00
idk
2595c6833a windows fixes 2019-10-26 23:13:06 -04:00
16 changed files with 236 additions and 32 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
zerobundle/i2p-zero
zerobundle/mac/assets.go
zerobundle/windows/assets.go
zerobundle/linux/assets.go

View File

@ -2,20 +2,20 @@
GO111MODULE=on
VERSION=0.0.01
VERSION=0.0.12
USER_GH=eyedeekay
version:
gothub release -s $(GITHUB_TOKEN) -u $(USER_GH) -r checki2cp -t v$(VERSION) -d "I2P Router Checking CLI utility"
fmt:
gofmt -w *.go canal/main.go
delete:
gothub delete -s $(GITHUB_TOKEN) -u $(USER_GH) -r checki2cp -t v$(VERSION)
GO_COMPILER_OPTS = -a -tags netgo -ldflags '-w -extldflags "-static"'
build: fmt test clean
cd ./i2cpcheck && go build $(GO_COMPILER_OPTS) && \
GOOS=windows GOARCH=amd64 go build $(GO_COMPILER_OPTS) -buildmode=exe -o i2cpcheck.exe
cd ./i2cpcheck && go build $(GO_COMPILER_OPTS)
cd ./i2cpcheck && GOOS=windows GOARCH=amd64 go build $(GO_COMPILER_OPTS) -buildmode=exe -o i2cpcheck.exe
test:
go test -v
@ -28,3 +28,35 @@ clean:
fmt:
find . -name '*.go' -exec gofmt -w -s {} \;
i2p-zero:
cd zerobundle && git clone https://github.com/i2p-zero/i2p-zero.git; \
cd i2p-zero && \
git fetch --all --tags && \
git checkout $(ZERO_VERSION)
zero-build: i2p-zero
cd zerobundle/i2p-zero && \
./bin/build-all-and-zip.sh
zero-zip:
zero-bundle: zero-zip
cd zerobundle && \
go run --tags generate ./gen/gen.go
ZERO_VERSION=z9.46.12
zero-assets:
gothub release -p -u eyedeekay -r "checki2cp" -t $(ZERO_VERSION) -n "I2P Zero pre-encoded assets" -d "assets.go file containing a zipped bundle of I2P Zero"
gothub upload -R -u eyedeekay -r "checki2cp" -t $(ZERO_VERSION) -n "assets_windows.go" -f "zerobundle/windows/assets.go"
gothub upload -R -u eyedeekay -r "checki2cp" -t $(ZERO_VERSION) -n "assets_darwin.go" -f "zerobundle/mac/assets.go"
gothub upload -R -u eyedeekay -r "checki2cp" -t $(ZERO_VERSION) -n "assets_linux.go" -f "zerobundle/linux/assets.go"
I2PD_VERSION=d9.46.12
i2pd-assets:
#gothub release -p -u eyedeekay -r "checki2cp" -t $(I2PD_VERSION) -n "i2pd C++ pre-encoded assets" -d "assets.go file containing a zipped bundle of I2P Zero"
#gothub upload -R -u eyedeekay -r "checki2cp" -t $(I2PD_VERSION) -n "assets_windows.go" -f "i2pdbundle/windows/assets.go"
#gothub upload -R -u eyedeekay -r "checki2cp" -t $(I2PD_VERSION) -n "assets_darwin.go" -f "i2pdbundle/mac/assets.go"
#gothub upload -R -u eyedeekay -r "checki2cp" -t $(I2PD_VERSION) -n "assets_linux.go" -f "i2pdbundle/linux/assets.go"

View File

@ -1,17 +1,37 @@
# checki2cp
checki2cp
=========
Library and terminal application which checks for the presence of a usable i2p
router by attempting to connect to i2cp. Yet another tiny but essential function
I don't want to be bothered with writing a billion times.
It contains just two functions, for helping Go applications confirm the presence
of an I2P router on the system. The first is *CheckI2PIsRunning*, which attempts
to connect to the I2CP Port, generate a destination, and quit. If this is
successful, an i2p router is obviously installed. The second is
*CheckI2PIsInstalledDefaultLocation* which checks the default locations for
the I2P router on various platforms to confirm whether an i2p router is present.
Both of these functions return a bool and an error. If a router is present, they
return true amd nil, if not, they return false and an error.
Well like most things, it grew in complexity. Now it does about 5 or 6 things,
it determines presence, running state, path, router "Style"(Java I2P, i2pd,
Zero) and it can start(but not stop) an I2P router. If you want to stop it,
use i2pcontrol.
It does not launch the router or anything else to do with managing the router.
It is solely for checking whether a router is present.
Here's where things get a little wierder.
-----------------------------------------
Have you ever wondered whether it's possible to compile a 200-ish Gigabyte .go
file? Because before today, I hadn't. Turns out, it's looking... kinda possible.
But it's a sonafagun to actually accomplish. Let me back up, today, I wanted to
see if I could bundle I2P-Zero inside of a Go package wholesale. To do this, I
went ahead and used lorca's embedding code to do so, because that's what I've
been using for other things that this will be used in. Also it's easy to use.
That means it takes the whole, compiled I2P-Zero package(zip file or whatever)
encodes it as a string, and puts it in an object inside a Go file. Those, you
can find on the releases page, under releases starting with z, followed by the
corresponding Java I2P Major and Minor version, followed by the i2cpcheck
version. So:
z9.46.12
for example.
Download all 3 of those to the zerobundle directory and compile them. You now
have a virtual filesystem, containing the I2P Zero application as a zip file,
which you can unpack to the disk at a desirable install location. Convenience
functions to pack and unpack the data will be provided when I am done evaluating
non-lorca options that might achieve smaller files, since I know I can achieve
much smaller files with i2pd anyway.

View File

@ -3,8 +3,12 @@ package checki2p
import (
"fmt"
"github.com/eyedeekay/go-i2cp"
"io/ioutil"
"log"
"os"
"os/exec"
"os/user"
"runtime"
"strings"
)
@ -25,15 +29,23 @@ func checkfileexists(path string) bool {
return false
}
func home() string {
if runtime.GOOS == "windows" {
return "\\i2p"
}
return "/.i2p"
}
var (
I2CP_HOST string = ""
I2CP_PORT string = ""
WINDOWS_DEFAULT_LOCATION string = `C:\\Program Files\i2p\i2psvc.exe`
I2PD_WINDOWS_DEFAULT_LOCATION string = `C:\\Program Files\I2Pd\i2pd.exe`
LINUX_SYSTEM_LOCATION string = "/usr/bin/i2prouter"
I2PD_LINUX_SYSTEM_LOCATION string = "/usr/sbin/i2pd"
HOME_DIRECTORY_LOCATION string = inithome("/i2p/i2prouter")
OSX_DEFAULT_LOCATION string = inithome("/Library/Application Support/i2p/clients.config")
I2CP_HOST string = ""
I2CP_PORT string = ""
WINDOWS_DEFAULT_LOCATION string = `C:\\Program Files\i2p\i2psvc.exe`
I2PD_WINDOWS_DEFAULT_LOCATION string = `C:\\Program Files\I2Pd\i2pd.exe`
LINUX_SYSTEM_LOCATION []string = []string{"/usr/bin/i2prouter", "/usr/sbin/i2prouter"}
I2PD_LINUX_SYSTEM_LOCATION string = "/usr/sbin/i2pd"
I2P_ASUSER_HOME_LOCATION string = inithome(home())
HOME_DIRECTORY_LOCATION string = inithome("/i2p/i2prouter")
OSX_DEFAULT_LOCATION string = inithome("/Library/Application Support/i2p/clients.config")
)
// CheckIC2PIsRunning is frequently the only thing I need a reliable, non-SAM
@ -70,7 +82,11 @@ func CheckI2PIsInstalledDefaultLocation() (bool, error) {
log.Println("Windows i2p router detected")
return true, nil
}
if checkfileexists(LINUX_SYSTEM_LOCATION) {
if checkfileexists(LINUX_SYSTEM_LOCATION[0]) {
log.Println("Linux i2p router detected")
return true, nil
}
if checkfileexists(LINUX_SYSTEM_LOCATION[1]) {
log.Println("Linux i2p router detected")
return true, nil
}
@ -90,9 +106,8 @@ func UserFind() string {
str := os.Getenv("SUDO_USER")
return str
}
if str, err := os.UserHomeDir(); err == nil {
x := strings.Split(str, "/")
return strings.Replace(x[len(x)-1], "/", "", -1)
if un, err := user.Current(); err == nil {
return un.Name
}
return ""
}
@ -103,7 +118,7 @@ func UserFind() string {
func CheckI2PUserName() (string, error) {
if checkfileexists(I2PD_WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2pd router detected")
return "i2pd.exe", nil
return "i2pd", nil
}
if checkfileexists(I2PD_LINUX_SYSTEM_LOCATION) {
log.Println("Linux i2pd router detected")
@ -111,9 +126,13 @@ func CheckI2PUserName() (string, error) {
}
if checkfileexists(WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2p router detected")
return "i2psvc.exe", nil
return "i2psvc", nil
}
if checkfileexists(LINUX_SYSTEM_LOCATION) {
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
}
@ -127,3 +146,90 @@ func CheckI2PUserName() (string, error) {
}
return "", nil
}
// 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.
func GetFirewallPort() (string, error) {
log.Println(I2P_ASUSER_HOME_LOCATION)
file, err := ioutil.ReadFile(I2P_ASUSER_HOME_LOCATION + "/router.config")
if err != nil {
return "", err
}
lines := strings.Split(string(file), "\n")
for index, line := range lines {
if strings.HasPrefix(line, "i2np.udp.port") {
log.Println(line, index)
return strings.Replace(line, "i2np.udp.port=", "", -1), nil
}
}
return "", fmt.Errorf("Improperly formed router.config file")
}
// 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) {
log.Println("Linux i2pd router detected")
return I2PD_LINUX_SYSTEM_LOCATION, nil
}
if checkfileexists(WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2p router detected")
return WINDOWS_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.")
}
func ConditionallyLaunchI2P() (bool, error) {
ok, err := CheckI2PIsInstalledDefaultLocation()
if err != nil {
return false, err
}
if ok {
if ok, err := CheckI2PIsRunning(); err == nil {
if !ok {
path, err := FindI2PIsInstalledDefaultLocation()
if err != nil {
return false, err
}
if strings.HasSuffix(path, "i2prouter") {
cmd := exec.Command(path, "start")
if err := cmd.Start(); err != nil {
return false, fmt.Errorf("I2P router startup failure", err)
}
} else {
cmd := exec.Command(path, "--daemon")
if err := cmd.Start(); err != nil {
return false, fmt.Errorf("I2P router startup failure", err)
}
}
return true, nil
}
return true, nil
} else {
return false, err
}
} else {
return false, fmt.Errorf("I2P is not a default location, please set $I2P environment variable")
}
}

View File

@ -27,3 +27,11 @@ func TestRouter(t *testing.T) {
t.Log("I2P is in a default location, user feedback is needed")
}
}
func TestFirewallPort(t *testing.T) {
port, err := GetFirewallPort()
if err != nil {
t.Fatal(err)
}
t.Log("Port was", port)
}

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module github.com/eyedeekay/checki2cp
go 1.13
require github.com/eyedeekay/go-i2cp v0.0.0-20190716135428-6d41bed718b0

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
github.com/eyedeekay/go-i2cp v0.0.0-20190716135428-6d41bed718b0 h1:rnn9OlD/3+tATEZNuiMR1C84O5CX8bZL2qqgttprKrw=
github.com/eyedeekay/go-i2cp v0.0.0-20190716135428-6d41bed718b0/go.mod h1:+P0fIhkqIYjo7exMJRTlSteRMbRyHbiBiKw+YlPWk+c=

Binary file not shown.

BIN
i2cpcheck/i2cpcheck.exe Executable file

Binary file not shown.

View File

@ -13,19 +13,30 @@ func main() {
}
if ok {
log.Println("I2P is running, successfully confirmed I2CP")
os.Exit(0)
} else {
log.Println("I2P is not running, further testing is needed")
}
firewallport, err := checki2p.GetFirewallPort()
if err != nil {
log.Fatal(err)
}
log.Println("I2P's firewall port is:", firewallport)
ok, err = checki2p.CheckI2PIsInstalledDefaultLocation()
if err != nil {
log.Fatal(err)
}
if ok {
log.Println("I2P is installed, successfully confirmed")
path, err := checki2p.FindI2PIsInstalledDefaultLocation()
if err != nil {
log.Fatal(err)
}
log.Println("I2P is installed at:", path)
os.Exit(0)
} else {
log.Println("I2P is not a default location, user feedback is needed")
os.Exit(1)
}
}

14
zerobundle/gen/gen.go Normal file
View File

@ -0,0 +1,14 @@
//+build generate
package main
import "github.com/zserge/lorca"
func main() {
// You can also run "npm build" or webpack here, or compress assets, or
// generate manifests, or do other preparations for your assets.
lorca.Embed("zero", "linux/assets.go", "i2p-zero/dist-zip/i2p-zero-linux.v1.16.zip")
lorca.Embed("zero", "mac/assets.go", "i2p-zero/dist-zip/i2p-zero-mac.v1.16.zip")
lorca.Embed("zero", "windows/assets.go", "i2p-zero/dist-zip/i2p-zero-win.v1.16.zip")
}

0
zerobundle/linux/keep Normal file
View File

0
zerobundle/mac/keep Normal file
View File

1
zerobundle/run.go Normal file
View File

@ -0,0 +1 @@
package zero

1
zerobundle/unpack.go Normal file
View File

@ -0,0 +1 @@
package zero

0
zerobundle/windows/keep Normal file
View File