don't create so many Tor clients, build mirroring into the system, download to subdir of i2psnark dir
This commit is contained in:
44
get/get.go
44
get/get.go
@ -396,6 +396,8 @@ func unSetupProxy() {
|
||||
http.DefaultClient.Transport = nil
|
||||
}
|
||||
|
||||
var t *tor.Tor
|
||||
|
||||
func SetupProxy(mirror, tp string) error {
|
||||
var d proxy.Dialer
|
||||
http.DefaultClient.Transport = nil
|
||||
@ -416,28 +418,34 @@ func SetupProxy(mirror, tp string) error {
|
||||
}
|
||||
http.DefaultClient.Transport = tr
|
||||
} else {
|
||||
if !strings.Contains(mirror, "127.0.0.1") && !strings.Contains(mirror, "localhost") {
|
||||
if tmp, torerr := net.Listen("tcp", "127.0.0.1:9050"); torerr != nil {
|
||||
log.Println("System Tor is running, downloading over that because obviously.")
|
||||
t, err := tor.Start(context.Background(), StartConf(tp))
|
||||
if err != nil {
|
||||
nut := os.Getenv("TOR_MANAGER_NEVER_USE_TOR")
|
||||
if nut != "true" {
|
||||
if !strings.Contains(mirror, "127.0.0.1") && !strings.Contains(mirror, "localhost") {
|
||||
if tmp, torerr := net.Listen("tcp", "127.0.0.1:9050"); torerr != nil {
|
||||
log.Println("System Tor is running, downloading over that because obviously.")
|
||||
var err error
|
||||
if t == nil {
|
||||
t, err = tor.Start(context.Background(), StartConf(tp))
|
||||
if err != nil {
|
||||
if t == nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
//defer t.Close()
|
||||
// Wait at most a minute to start network and get
|
||||
dialCtx, _ := context.WithTimeout(context.Background(), time.Minute)
|
||||
//defer dialCancel()
|
||||
// Make connection
|
||||
dialer, err := t.Dialer(dialCtx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tr := &http.Transport{DialContext: dialer.DialContext}
|
||||
http.DefaultClient.Transport = tr
|
||||
} else {
|
||||
tmp.Close()
|
||||
}
|
||||
//defer t.Close()
|
||||
// Wait at most a minute to start network and get
|
||||
dialCtx, _ := context.WithTimeout(context.Background(), time.Minute)
|
||||
//defer dialCancel()
|
||||
// Make connection
|
||||
dialer, err := t.Dialer(dialCtx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tr := &http.Transport{DialContext: dialer.DialContext}
|
||||
http.DefaultClient.Transport = tr
|
||||
} else {
|
||||
tmp.Close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,8 @@ func (t *TBDownloader) GenerateMissingTorrents() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
snark = filepath.Join(snark, "torbrowser")
|
||||
os.MkdirAll(snark, 0755)
|
||||
sf := filepath.Join(snark, f)
|
||||
sfp := filepath.Join(snark, f+".torrent")
|
||||
if !FileExists(sf) {
|
||||
@ -260,7 +262,7 @@ func TorrentDownloaded(ietf, rtpair string) bool {
|
||||
}
|
||||
version, err := GetTorBrowserVersionFromUpdateURL()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return false
|
||||
}
|
||||
log.Println("Tor Browser Version", version, ietf)
|
||||
extension := "exe"
|
||||
@ -277,7 +279,7 @@ func TorrentDownloaded(ietf, rtpair string) bool {
|
||||
}
|
||||
found := false
|
||||
if dir, err := FindSnarkDirectory(); err == nil {
|
||||
err := filepath.Walk(dir,
|
||||
err := filepath.Walk(dir+"/torbrowser",
|
||||
func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
|
14
main.go
14
main.go
@ -118,6 +118,8 @@ var (
|
||||
nounpack = flag.Bool("nounpack", false, "Do not unpack the Tor Browser")
|
||||
ptop = flag.Bool("p2p", tbget.TorrentDownloaded(defaultLang(), OS()+ARCH()), "Use bittorrent over I2P to download the initial copy of Tor Browser")
|
||||
torversion = flag.Bool("torversion", false, "Print the version of Tor Browser that will be downloaded and exit")
|
||||
mirrorall = flag.Bool("mirrorall", false, "Download and mirror every language and OS/arch combination")
|
||||
nevertor = flag.Bool("nevertor", false, "Never use Tor for downloading Tor Browser")
|
||||
)
|
||||
|
||||
func Clearnet() bool {
|
||||
@ -221,6 +223,18 @@ func main() {
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
flag.Parse()
|
||||
if *nevertor {
|
||||
err := os.Setenv("TOR_MANAGER_NEVER_USE_TOR", "true")
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
}
|
||||
if *mirrorall {
|
||||
err := mirrorAll()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
if *torversion {
|
||||
torbrowserversion, err := tbget.GetTorBrowserVersionFromUpdateURL()
|
||||
if err != nil {
|
||||
|
69
mirror.go
Normal file
69
mirror.go
Normal file
@ -0,0 +1,69 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
tbget "i2pgit.org/idk/i2p.plugins.tor-manager/get"
|
||||
)
|
||||
|
||||
func mirrorAll() error {
|
||||
log.Println("Mirroring all languages, platforms, and architectures")
|
||||
for x, l := range tbget.Languages() {
|
||||
log.Println("Mirroring language:", l, "(", x, ")", "of", len(tbget.Languages()), "languages complete")
|
||||
err := mirrorLang(l)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func mirrorLang(ietf string) error {
|
||||
// get the path to myself(the executable)
|
||||
path, err := os.Executable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// set the environment variables
|
||||
//TOR_MANAGER_CLEARNET_MIRROR=true
|
||||
err = os.Setenv("TOR_MANAGER_CLEARNET_MIRROR", "true")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//TOR_MANAGER_REQUIRE_PASSWORD=false
|
||||
err = os.Setenv("TOR_MANAGER_REQUIRE_PASSWORD", "false")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = mirrorPlatform(path, ietf, "linux", "64")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = mirrorPlatform(path, ietf, "linux", "32")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = mirrorPlatform(path, ietf, "win", "64")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = mirrorPlatform(path, ietf, "win", "32")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = mirrorPlatform(path, ietf, "osx", "64")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func mirrorPlatform(path, ietf, platform, arch string) error {
|
||||
cmd := exec.Command(path, "-nounpack", "-notor", "-os", platform, "-lang="+ietf, "-arch="+arch, "-p2p=false", "-nevertor")
|
||||
cmd.Env = os.Environ()
|
||||
cmd.Env = append(cmd.Env, "TOR_MANAGER_CLEARNET_MIRROR=true")
|
||||
cmd.Env = append(cmd.Env, "TOR_MANAGER_REQUIRE_PASSWORD=false")
|
||||
return cmd.Run()
|
||||
}
|
Reference in New Issue
Block a user