Files
checki2cp/i2pdbundle/launch_windows.go

92 lines
2.3 KiB
Go
Raw Permalink Normal View History

2020-05-14 18:04:53 -04:00
package i2pd
2020-05-15 13:15:56 -04:00
import (
"fmt"
"log"
2020-05-15 17:49:28 -04:00
//"os"
2020-05-15 13:15:56 -04:00
"os/exec"
"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()
if err != nil {
return "", err
}
2020-05-15 18:59:58 -04:00
if err := FileOK(filepath.Join(path, "i2pd.exe")); err != nil {
2020-05-15 13:15:56 -04:00
return "", err
}
2020-05-15 18:59:58 -04:00
return filepath.Join(path, "i2pd.exe"), nil
2020-05-15 13:15:56 -04:00
}
2020-05-15 18:59:58 -04:00
// UnpackI2Pd unpacks a working version of i2pd and some supporting libraries to the directory of the executable
2020-05-15 13:15:56 -04:00
// that will start i2pd
func UnpackI2Pd() error {
dir, err := UnpackI2PdPath()
if err != nil {
return err
}
err = WriteAllFiles(dir)
if err != nil {
return err
}
return nil
}
2020-05-15 19:32:12 -04:00
// LaunchI2PdConditional will check for specific services and if they are not found, start a standalone router
2020-05-15 13:15:56 -04:00
func LaunchI2PdConditional(needI2CP, needProxy, needSAM bool) (*exec.Cmd, error) {
if needI2CP {
if notRunning, inError := checki2p.CheckI2PIsRunning(); inError != nil {
return nil, inError
} else if notRunning {
return nil, fmt.Errorf("I2P is already running with an open I2CP port")
}
}
if needProxy {
if checkproxy.ProxyDotI2P() {
return nil, fmt.Errorf("I2P is already running with an open HTTP proxy")
}
}
if needSAM {
if checksam.CheckSAMAvailable("") {
return nil, fmt.Errorf("I2P is already running with an open SAM API")
}
}
return LaunchI2PdForce()
}
// LaunchI2Pd will look for a running I2P router and if one is not found, it will start the embedded I2P router
func LaunchI2Pd() (*exec.Cmd, error) {
return LaunchI2PdConditional(true, true, true)
}
2020-05-15 19:32:12 -04:00
// LaunchI2PdForce attempts to launch the embedded I2P router no matter what.
2020-05-15 13:15:56 -04:00
func LaunchI2PdForce() (*exec.Cmd, error) {
i2pd, err := FindI2Pd()
2020-05-15 18:59:58 -04:00
if err := FileOK(i2pd); err != nil {
2020-05-15 13:15:56 -04:00
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",
)
log.Printf("running command: %v %s", cmd.Env, cmd.String())
if err := cmd.Start(); err != nil {
log.Fatal(err)
}
return cmd, nil
}