-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtor.go
43 lines (39 loc) · 896 Bytes
/
tor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// tor.go - start an instance of little-t-tor.
//
// To the extent possible under law, Ivan Markin waived all copyright
// and related or neighboring rights to this module of onionize, using the creative
// commons "cc0" public domain dedication. See LICENSE or
// <http://creativecommons.org/publicdomain/zero/1.0/> for full details.
package onionize
import (
"net"
"os"
"os/exec"
"strings"
"time"
)
const torrc = `RunAsDaemon 0
SOCKSPort 0
ControlPort 9999
AvoidDiskWrites 1
`
func runTor(ready chan<- struct{}) error {
cmd := exec.Command("tor", "-f", "-")
cmd.Stdin = strings.NewReader(torrc)
cmd.Stderr = os.Stderr
err := cmd.Start()
if err != nil {
return err
}
t := time.NewTicker(500 * time.Millisecond)
for range t.C {
c, err := net.Dial("tcp", "127.0.0.1:9999")
if err == nil {
c.Close()
t.Stop()
ready <- struct{}{}
break
}
}
return cmd.Wait()
}