This repository has been archived by the owner on Jun 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.go
96 lines (79 loc) · 1.8 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"flag"
"fmt"
"os"
"github.com/docker/docker/pkg/pidfile"
"github.com/docker/go-plugins-helpers/network"
"github.com/jessfraz/onion/tor"
"github.com/jessfraz/onion/version"
"github.com/sirupsen/logrus"
)
const (
// BANNER is what is printed for help/info output
BANNER = ` _
___ _ __ (_) ___ _ __
/ _ \| '_ \| |/ _ \| '_ \
| (_) | | | | | (_) | | | |
\___/|_| |_|_|\___/|_| |_|
Tor networking plugin for docker containers
Version: %s
Build: %s
`
defaultPidFile = "/var/run/onion.pid"
)
var (
debug bool
vrsn bool
pidFile string
)
func init() {
// parse flags
flag.StringVar(&pidFile, "pidfile", defaultPidFile, "path to use for plugin's PID file")
flag.BoolVar(&vrsn, "version", false, "print version and exit")
flag.BoolVar(&vrsn, "v", false, "print version and exit (shorthand)")
flag.BoolVar(&debug, "d", false, "run in debug mode")
flag.Usage = func() {
fmt.Fprint(os.Stderr, fmt.Sprintf(BANNER, version.VERSION, version.GITCOMMIT))
flag.PrintDefaults()
}
flag.Parse()
if vrsn {
fmt.Printf("pepper version %s, build %s", version.VERSION, version.GITCOMMIT)
os.Exit(0)
}
// set log level
if debug {
logrus.SetLevel(logrus.DebugLevel)
}
}
func main() {
// setup the PID file if passed
if pidFile != "" {
pf, err := pidfile.New(pidFile)
if err != nil {
logrus.Fatalf("Error starting daemon: %v", err)
}
pfile := pf
defer func() {
if err := pfile.Remove(); err != nil {
logrus.Error(err)
}
}()
}
d, err := tor.NewDriver()
if err != nil {
logrus.Fatal(err)
}
h := network.NewHandler(d)
h.ServeUnix("tor", 0)
}
func usageAndExit(message string, exitCode int) {
if message != "" {
fmt.Fprintf(os.Stderr, message)
fmt.Fprintf(os.Stderr, "\n\n")
}
flag.Usage()
fmt.Fprintf(os.Stderr, "\n")
os.Exit(exitCode)
}