forked from jessfraz/onion
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
91 lines (75 loc) · 1.71 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
package main
import (
"flag"
"fmt"
"os"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/pidfile"
"github.com/docker/go-plugins-helpers/network"
"github.com/flungo-docker/libnetwork-container/tor"
)
const (
// BANNER is what is printed for help/info output
BANNER = `libnetwork-container
Docker network driver for routing through another container
Version: %s
`
// VERSION is the binary version.
VERSION = "v0.1.0-dev"
defaultPidFile = "/var/run/libnetwork-container.pid"
)
var (
debug bool
version bool
pidFile string
)
func init() {
// parse flags
flag.BoolVar(&version, "version", false, "print version and exit")
flag.BoolVar(&version, "v", false, "print version and exit (shorthand)")
flag.BoolVar(&debug, "d", false, "run in debug mode")
flag.StringVar(&pidFile, "pidfile", defaultPidFile, "path to use for plugin's PID file")
flag.Usage = func() {
fmt.Fprint(os.Stderr, fmt.Sprintf(BANNER, VERSION))
flag.PrintDefaults()
}
flag.Parse()
if version {
fmt.Printf("%s", VERSION)
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("root", "container")
}
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)
}