-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathclient.go
52 lines (42 loc) · 1.08 KB
/
client.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
44
45
46
47
48
49
50
51
52
package torproxy
import (
"context"
"fmt"
"io"
"log"
"strconv"
"github.com/cretz/bine/tor"
)
func (t *Tor) Start() {
torInstance, err := tor.Start(nil, t.starterConfig(t.debugger))
if err != nil {
log.Panicf("Unable to start Tor: %v", err)
}
listenCtx := context.Background()
onion, err := torInstance.Listen(listenCtx, &tor.ListenConf{LocalPort: 8868, RemotePorts: []int{80}})
if err != nil {
log.Panicf("Unable to start onion service: %v", err)
}
t.onion = onion
t.instance = torInstance
}
// Stop stops the tor instance, context listener and the onion service
func (t *Tor) Stop() error {
if err := t.instance.Close(); err != nil {
return fmt.Errorf("[torproxy]: Couldn't close the tor instance. %s", err.Error())
}
t.onion.Close()
return nil
}
func (t *Tor) starterConfig(debugger io.Writer) *tor.StartConf {
config := &tor.StartConf{
NoAutoSocksPort: true,
ExtraArgs: []string{"--SocksPort", strconv.Itoa(t.Port)},
TempDataDirBase: t.DataDir,
TorrcFile: t.Torrc,
}
if debugger != nil {
config.DebugWriter = debugger
}
return config
}