Also check for SAM Proxy and for I2PControl

This commit is contained in:
idk
2020-05-14 23:28:24 -04:00
parent 23e38e8cc1
commit 69ba077931
4 changed files with 95 additions and 54 deletions

4
go.mod
View File

@ -5,15 +5,19 @@ go 1.13
require (
github.com/andybalholm/brotli v1.0.0 // indirect
github.com/eyedeekay/go-i2cp v0.0.0-20190716135428-6d41bed718b0
github.com/eyedeekay/go-i2pcontrol v0.0.0-20200110011336-510cca77e350
github.com/eyedeekay/sam3 v0.32.2
github.com/golang/gddo v0.0.0-20200324184333-3c2cc9a6329d // indirect
github.com/klauspost/compress v1.10.5 // indirect
github.com/klauspost/pgzip v1.2.3 // indirect
github.com/kr/fs v0.1.0
github.com/majestrate/i2p-tools v0.0.0-20170507194519-afc8e46afa95
github.com/mholt/archiver v3.1.1+incompatible // indirect
github.com/mholt/archiver/v3 v3.3.0
github.com/nwaples/rardecode v1.1.0 // indirect
github.com/pierrec/lz4 v2.5.2+incompatible // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
github.com/ulikunitz/xz v0.5.7 // indirect
github.com/ybbus/jsonrpc v2.1.2+incompatible // indirect
github.com/zserge/lorca v0.1.9 // indirect
)

11
go.sum
View File

@ -12,6 +12,12 @@ github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5Jflh
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
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=
github.com/eyedeekay/go-i2pcontrol v0.0.0-20200110011336-510cca77e350 h1:LxSh6dLIeiDfXxex1B+jFh7YyI7OuBza+IXS+SFzuLQ=
github.com/eyedeekay/go-i2pcontrol v0.0.0-20200110011336-510cca77e350/go.mod h1:bhIQsVpbNNXMtcoZ9UF4hLQleOjaCgKGXiRRhNc8TOA=
github.com/eyedeekay/ramp v0.0.0-20190429201811-305b382042ab h1:EfTRHxGSbiaEyxNzvKRBWVIDw3mD8xXGxj4gvwFzY7Q=
github.com/eyedeekay/ramp v0.0.0-20190429201811-305b382042ab/go.mod h1:h7mvUAMgZ/rtRDUOkvKTK+8LnDMeUhJSoa5EPdB51fc=
github.com/eyedeekay/sam3 v0.32.2 h1:xODDY5nBVg0oK7KaYk7ofkXFoHPsmI1umhSv1TZlS7s=
github.com/eyedeekay/sam3 v0.32.2/go.mod h1:Y3igFVzN4ybqkkpfUWULGhw7WRp8lieq0ORXbLBbcZM=
github.com/fsnotify/fsnotify v1.4.3-0.20170329110642-4da3e2cfbabc/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/garyburd/redigo v1.1.1-0.20170914051019-70e1b1943d4f/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
github.com/go-stack/stack v1.6.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
@ -45,6 +51,8 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.7.4-0.20170902060319-8d7837e64d3c/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/majestrate/i2p-tools v0.0.0-20170507194519-afc8e46afa95 h1:0gOlqFaTE6hucF8xnutcIlWjuWAQ58kTFkvhKb8pE4g=
github.com/majestrate/i2p-tools v0.0.0-20170507194519-afc8e46afa95/go.mod h1:e/TZ1O6X9t0qitnKc3xvHq8VXDpm/FmYuFf21epEkUc=
github.com/mattn/go-colorable v0.0.10-0.20170816031813-ad5389df28cd/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.2/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mholt/archiver v1.1.2 h1:xukR55YIrnhDHp10lrNtRSsAK5THpWrOCuviweNSBw4=
@ -78,6 +86,9 @@ github.com/ulikunitz/xz v0.5.7 h1:YvTNdFzX6+W5m9msiYg/zpkSURPPtOlzbqYjrFn7Yt4=
github.com/ulikunitz/xz v0.5.7/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
github.com/ybbus/jsonrpc v1.1.1 h1:43DAq5ijbxDPEXmlNpAwT74vFBR5VxQRqRWhWQPz9O0=
github.com/ybbus/jsonrpc v2.1.2+incompatible h1:V4mkE9qhbDQ92/MLMIhlhMSbz8jNXdagC3xBR5NDwaQ=
github.com/ybbus/jsonrpc v2.1.2+incompatible/go.mod h1:XJrh1eMSzdIYFbM08flv0wp5G35eRniyeGut1z+LSiE=
github.com/zserge/lorca v0.1.9 h1:vbDdkqdp2/rmeg8GlyCewY2X8Z+b0s7BqWyIQL/gakc=
github.com/zserge/lorca v0.1.9/go.mod h1:bVmnIbIRlOcoV285KIRSe4bUABKi7R7384Ycuum6e4A=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

View File

@ -37,39 +37,49 @@ verify = true
subscriptions = http://inr.i2p/export/alive-hosts.txt,http://identiguy.i2p/hosts.txt,http://stats.i2p/cgi-bin/newhosts.txt,http://i2p-projekt.i2p/hosts.txt
### REASONING FOR CHANGING DEFAULT CONSOLE PORT
##
## We want to co-exist with other router projects peacefully inluding those that are on the same machine. This is a UI
## improvement project, not a router improvement project, and as such we will allow the use of any underlying I2P router.
[http]
enabled = true
address = 127.0.0.1
port = 7472
### REASONING FOR CHANGING DEFAULT HTTP PROXY PORT and DISABLING HTTP PROXY
##
## We want to co-exist with other router projects peacefully inluding those that are on the same machine. Disabling is
## the primary method of deferring to the parent router's SOCKS port. We change it in the example in case people using
## the embedded router want to re-enable it.
[httpproxy]
enabled = false
#address = 127.0.0.1
#port = 4454
### REASONING FOR CHANGING DEFAULT SOCKS PROXY PORT and DISABLING SOCKS PROXY
##
## We want to co-exist with other router projects peacefully inluding those that are on the same machine. Disabling is
## the primary method of deferring to the parent router's SOCKS port. We change it in the example in case people using
## the embedded router want to re-enable it.
[socksproxy]
enabled = false
#address = 127.0.0.1
#port = 4457
### REASONING FOR NOT CHANGING DEFAULT SAM PORT
##
## SAM clients do not normally require a password, so if a SAM hanshake can happen, it will more ofthen than not,
## succeed, causing the bundle start to fail if SAM is available. Regardless, we need a SAM on this port to run, leaving
## it here leaves us router-agnostic.
[sam]
enabled = true
address = 127.0.0.1
port = 7656
### REASONING FOR ENABLING I2PCONTROL and NOT CHANGING DEFAULT I2PCONTROL PORT
##
### REASONING FOR ENABLING I2PCONTROL and CHANGING DEFAULT I2PCONTROL PORT
## Java I2P provides I2PControl via an embedded application which is available under localhost 7657, whereas I2Pd
## makes it available at localhost:7650 as it's own service. In order to resolve this, our application will need to
## proxy requests to the underlying router. The port can't matter to the client behind the proxy, but we need to
## guarantee one if we need to start an embedded router
[i2pcontrol]
enabled = true
address = 127.0.0.1
port = 7650
port = 4450
#password = itoopie
`
@ -80,7 +90,7 @@ var tunnelFile = `#
// Set the environment variable I2P_DIRECTORY_PATH to override the path returned by UnpackI2PdDir
var I2P_DIRECTORY_PATH = ""
//
// Returns nil if a file exists and an error for everything else. Used to check for file existence.
func FileOK(path string) error {
if _, err := os.Stat(path); err == nil {
return nil
@ -125,22 +135,29 @@ var walkFn = func(path string, fi os.FileInfo, r io.ReadSeeker, err error) error
return nil
}
//WriteConfOptions generates a default config file for the bundle
func WriteConfOptions(targetdir string) error {
err := ioutil.WriteFile(filepath.Join(filepath.Dir(targetdir), "i2pd.conf"), []byte(configFile), 0644)
if err != nil {
return err
if FileOK(filepath.Join(filepath.Dir(targetdir), "i2pd.conf")) != nil {
err := ioutil.WriteFile(filepath.Join(filepath.Dir(targetdir), "i2pd.conf"), []byte(configFile), 0644)
if err != nil {
return err
}
}
return nil
}
//WritetunnelOptions generates a default tunnel config file for the bundle
func WriteTunnelOptions(targetdir string) error {
err := ioutil.WriteFile(filepath.Join(filepath.Dir(targetdir), "tunnels.conf"), []byte(tunnelFile), 0644)
if err != nil {
return err
if FileOK(filepath.Join(filepath.Dir(targetdir), "tunnels.conf")) != nil {
err := ioutil.WriteFile(filepath.Join(filepath.Dir(targetdir), "tunnels.conf"), []byte(tunnelFile), 0644)
if err != nil {
return err
}
}
return nil
}
//WriteAllFiles generates an I2Pd installation and configuration for the bundle
func WriteAllFiles(targetdir string) error {
if err := vfsutil.WalkFiles(FS, "/", walkFn); err != nil {
return err
@ -154,6 +171,7 @@ func WriteAllFiles(targetdir string) error {
return nil
}
//
func UnpackI2PdPath() (string, error) {
dirPath, err := UnpackI2PdDir()
if err != nil {
@ -163,6 +181,7 @@ func UnpackI2PdPath() (string, error) {
return ri2pd, nil
}
//
func UnpackI2PdLibPath() (string, error) {
dirPath, err := UnpackI2PdDir()
if err != nil {
@ -172,9 +191,10 @@ func UnpackI2PdLibPath() (string, error) {
return rlib, nil
}
//
func UnpackI2PdDir() (string, error) {
if I2P_PATH != "" {
return I2P_PATH, nil
if I2P_DIRECTORY_PATH != "" {
return I2P_DIRECTORY_PATH, nil
}
executablePath, err := os.Executable()
if err != nil {

View File

@ -8,9 +8,10 @@ import (
"path/filepath"
"github.com/eyedeekay/checki2cp"
"github.com/eyedeekay/checki2cp/proxycheck"
"github.com/eyedeekay/checki2cp/samcheck"
)
// FindI2P returns the absolute path to the i2pd executable
func FindI2Pd() (string, error) {
path, err := UnpackI2PdPath()
@ -24,7 +25,7 @@ func FindI2Pd() (string, error) {
}
// UnpackI2Pd unpacks a working version of i2pd and some supporting libraries to a the directory of the executable
// that will start i2pd
// that will start i2pd
func UnpackI2Pd() error {
dir, err := UnpackI2PdPath()
if err != nil {
@ -43,41 +44,46 @@ func LaunchI2Pd() (*exec.Cmd, error) {
return nil, inError
} else if notRunning {
return nil, fmt.Errorf("I2P is already running with an open I2CP port")
} else {
libPath, err := UnpackI2PdLibPath()
if err != nil {
return nil, err
}
if err := FileOK(libPath); err != nil {
return nil, err
}
i2pd, err := FindI2Pd()
if err := FileOK(libPath); err != nil {
return nil, err
}
err = os.Setenv("LD_LIBRARY_PATH", libPath)
if err != nil {
return nil, err
}
log.Println(i2pd)
runDir, err := UnpackI2PdDir()
if err != nil {
return nil, err
}
cmd := exec.Command(
i2pd,
"--datadir="+runDir,
"--conf="+filepath.Join(runDir, "i2pd.conf"),
"--tunconf="+filepath.Join(runDir, "tunnels.conf"),
"--log=none",
)
cmd.Env = append(os.Environ(),
"LD_LIBRARY_PATH="+libPath, // ignored
)
log.Printf("running command: %v %s", cmd.Env, cmd.String())
if err := cmd.Start(); err != nil {
log.Fatal(err)
}
return cmd, nil
}
if checkproxy.ProxyDotI2P() {
return nil, fmt.Errorf("I2P is already running with an open HTTP proxy")
}
if checksam.CheckSAMAvailable("") {
return nil, fmt.Errorf("I2P is already running with an open SAM API")
}
libPath, err := UnpackI2PdLibPath()
if err != nil {
return nil, err
}
if err := FileOK(libPath); err != nil {
return nil, err
}
i2pd, err := FindI2Pd()
if err := FileOK(libPath); err != nil {
return nil, err
}
err = os.Setenv("LD_LIBRARY_PATH", libPath)
if err != nil {
return nil, err
}
log.Println(i2pd)
runDir, err := UnpackI2PdDir()
if err != nil {
return nil, err
}
cmd := exec.Command(
i2pd,
"--datadir="+runDir,
"--conf="+filepath.Join(runDir, "i2pd.conf"),
"--tunconf="+filepath.Join(runDir, "tunnels.conf"),
"--log=none",
)
cmd.Env = append(os.Environ(),
"LD_LIBRARY_PATH="+libPath, // ignored
)
log.Printf("running command: %v %s", cmd.Env, cmd.String())
if err := cmd.Start(); err != nil {
log.Fatal(err)
}
return cmd, nil
}