Use new Bine CmdCreatorFunc to make a ProcessCreator to hide Tor dos window.
the build was successful
Details
the build was successful
Details
Also hide it in checkTorVersion
This commit is contained in:
parent
79a1ff9161
commit
7c828d3916
|
@ -0,0 +1,9 @@
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package connectivity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
var sysProcAttr = &syscall.SysProcAttr{}
|
|
@ -0,0 +1,9 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package connectivity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
var sysProcAttr = &syscall.SysProcAttr{HideWindow: true}
|
|
@ -1,10 +1,12 @@
|
||||||
package connectivity
|
package connectivity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/utils"
|
"git.openprivacy.ca/openprivacy/libricochet-go/utils"
|
||||||
"github.com/cretz/bine/control"
|
"github.com/cretz/bine/control"
|
||||||
|
"github.com/cretz/bine/process"
|
||||||
"github.com/cretz/bine/tor"
|
"github.com/cretz/bine/tor"
|
||||||
bineed255192 "github.com/cretz/bine/torutil/ed25519"
|
bineed255192 "github.com/cretz/bine/torutil/ed25519"
|
||||||
"golang.org/x/crypto/ed25519"
|
"golang.org/x/crypto/ed25519"
|
||||||
|
@ -213,6 +215,17 @@ func StartTor(appDirectory string, bundledTorPath string) (ACN, error) {
|
||||||
return tp, err
|
return tp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newHideCmd creates a Creator function for bine which generates a cmd that one windows will hide the dosbox
|
||||||
|
func newHideCmd(exePath string) process.Creator {
|
||||||
|
return process.CmdCreatorFunc(func(ctx context.Context, args ...string) (*exec.Cmd, error) {
|
||||||
|
cmd := exec.CommandContext(ctx, exePath, args...)
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.SysProcAttr = sysProcAttr
|
||||||
|
return cmd, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func startTor(appDirectory string, bundledTorPath string) (*torProvider, error) {
|
func startTor(appDirectory string, bundledTorPath string) (*torProvider, error) {
|
||||||
dataDir := path.Join(appDirectory, "tor")
|
dataDir := path.Join(appDirectory, "tor")
|
||||||
os.MkdirAll(dataDir, 0700)
|
os.MkdirAll(dataDir, 0700)
|
||||||
|
@ -239,7 +252,7 @@ func startTor(appDirectory string, bundledTorPath string) (*torProvider, error)
|
||||||
|
|
||||||
// if not, try running system tor
|
// if not, try running system tor
|
||||||
if checkCmdlineTorVersion("tor") {
|
if checkCmdlineTorVersion("tor") {
|
||||||
t, err := tor.Start(nil, &tor.StartConf{EnableNetwork: true, DataDir: dataDir, DebugWriter: nil})
|
t, err := tor.Start(nil, &tor.StartConf{EnableNetwork: true, DataDir: dataDir, DebugWriter: nil, ProcessCreator: newHideCmd("tor")})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
tp.t = t
|
tp.t = t
|
||||||
return tp, nil
|
return tp, nil
|
||||||
|
@ -250,7 +263,7 @@ func startTor(appDirectory string, bundledTorPath string) (*torProvider, error)
|
||||||
// try running bundledTor
|
// try running bundledTor
|
||||||
if bundledTorPath != "" && checkCmdlineTorVersion(bundledTorPath) {
|
if bundledTorPath != "" && checkCmdlineTorVersion(bundledTorPath) {
|
||||||
log.Debugln("using bundled tor '" + bundledTorPath + "'")
|
log.Debugln("using bundled tor '" + bundledTorPath + "'")
|
||||||
t, err := tor.Start(nil, &tor.StartConf{EnableNetwork: true, DataDir: dataDir, ExePath: bundledTorPath, DebugWriter: nil})
|
t, err := tor.Start(nil, &tor.StartConf{EnableNetwork: true, DataDir: dataDir, ExePath: bundledTorPath, DebugWriter: nil, ProcessCreator: newHideCmd(bundledTorPath)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Error running bundled tor: %v\n", err)
|
log.Debugf("Error running bundled tor: %v\n", err)
|
||||||
}
|
}
|
||||||
|
@ -341,6 +354,7 @@ func createFromExisting(controlport *control.Conn, datadir string) *tor.Tor {
|
||||||
|
|
||||||
func checkCmdlineTorVersion(torCmd string) bool {
|
func checkCmdlineTorVersion(torCmd string) bool {
|
||||||
cmd := exec.Command(torCmd, "--version")
|
cmd := exec.Command(torCmd, "--version")
|
||||||
|
cmd.SysProcAttr = sysProcAttr
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
re := regexp.MustCompile("[0-1]\\.[0-9]\\.[0-9]\\.[0-9]")
|
re := regexp.MustCompile("[0-1]\\.[0-9]\\.[0-9]\\.[0-9]")
|
||||||
sysTorVersion := re.Find(out)
|
sysTorVersion := re.Find(out)
|
||||||
|
|
|
@ -15,10 +15,11 @@ func getStatusCallback(progChan chan int) func(int, string) {
|
||||||
func TestTorProvider(t *testing.T) {
|
func TestTorProvider(t *testing.T) {
|
||||||
progChan := make(chan int)
|
progChan := make(chan int)
|
||||||
acn, err := StartTor(".", "")
|
acn, err := StartTor(".", "")
|
||||||
acn.SetStatusCallback(getStatusCallback(progChan))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
acn.SetStatusCallback(getStatusCallback(progChan))
|
||||||
|
|
||||||
progress := 0
|
progress := 0
|
||||||
for progress < 100 {
|
for progress < 100 {
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -2,7 +2,7 @@ module git.openprivacy.ca/openprivacy/libricochet-go
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412
|
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412
|
||||||
github.com/cretz/bine v0.1.0
|
github.com/cretz/bine v0.1.1-0.20200124154328-f9f678b84cca
|
||||||
github.com/golang/protobuf v1.2.0
|
github.com/golang/protobuf v1.2.0
|
||||||
github.com/stretchr/testify v1.3.0 // indirect
|
github.com/stretchr/testify v1.3.0 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20190128193316-c7b33c32a30b
|
golang.org/x/crypto v0.0.0-20190128193316-c7b33c32a30b
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -2,6 +2,8 @@ github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7I
|
||||||
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
|
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
|
||||||
github.com/cretz/bine v0.1.0 h1:1/fvhLE+fk0bPzjdO5Ci+0ComYxEMuB1JhM4X5skT3g=
|
github.com/cretz/bine v0.1.0 h1:1/fvhLE+fk0bPzjdO5Ci+0ComYxEMuB1JhM4X5skT3g=
|
||||||
github.com/cretz/bine v0.1.0/go.mod h1:6PF6fWAvYtwjRGkAuDEJeWNOv3a2hUouSP/yRYXmvHw=
|
github.com/cretz/bine v0.1.0/go.mod h1:6PF6fWAvYtwjRGkAuDEJeWNOv3a2hUouSP/yRYXmvHw=
|
||||||
|
github.com/cretz/bine v0.1.1-0.20200124154328-f9f678b84cca h1:Q2r7AxHdJwWfLtBZwvW621M3sPqxPc6ITv2j1FGsYpw=
|
||||||
|
github.com/cretz/bine v0.1.1-0.20200124154328-f9f678b84cca/go.mod h1:6PF6fWAvYtwjRGkAuDEJeWNOv3a2hUouSP/yRYXmvHw=
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||||
|
|
Reference in New Issue