MCPcopy Create free account
hub / github.com/encodeous/nylon / main

Function main

polyamide/main_windows.go:27–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25)
26
27func main() {
28 if len(os.Args) != 2 {
29 os.Exit(ExitSetupFailed)
30 }
31 interfaceName := os.Args[1]
32
33 fmt.Fprintln(os.Stderr, "Warning: this is a test program for Windows, mainly used for debugging this Go package. For a real WireGuard for Windows client, the repo you want is <https://git.zx2c4.com/wireguard-windows/>, which includes this code as a module.")
34
35 logger := device.NewLogger(
36 device.LogLevelVerbose,
37 fmt.Sprintf("(%s) ", interfaceName),
38 )
39 logger.Verbosef("Starting wireguard-go version %s", Version)
40
41 tun, err := tun.CreateTUN(interfaceName, 0)
42 if err == nil {
43 realInterfaceName, err2 := tun.Name()
44 if err2 == nil {
45 interfaceName = realInterfaceName
46 }
47 } else {
48 logger.Errorf("Failed to create TUN device: %v", err)
49 os.Exit(ExitSetupFailed)
50 }
51
52 device := device.NewDevice(tun, conn.NewDefaultBind(), logger)
53 err = device.Up()
54 if err != nil {
55 logger.Errorf("Failed to bring up device: %v", err)
56 os.Exit(ExitSetupFailed)
57 }
58 logger.Verbosef("Device started")
59
60 uapi, err := ipc.UAPIListen(interfaceName)
61 if err != nil {
62 logger.Errorf("Failed to listen on uapi socket: %v", err)
63 os.Exit(ExitSetupFailed)
64 }
65
66 errs := make(chan error)
67 term := make(chan os.Signal, 1)
68
69 go func() {
70 for {
71 conn, err := uapi.Accept()
72 if err != nil {
73 errs <- err
74 return
75 }
76 go device.IpcHandle(conn)
77 }
78 }()
79 logger.Verbosef("UAPI listener started")
80
81 // wait for program to terminate
82
83 signal.Notify(term, os.Interrupt)
84 signal.Notify(term, os.Kill)

Callers

nothing calls this directly

Calls 10

UpMethod · 0.95
IpcHandleMethod · 0.95
WaitMethod · 0.95
CloseMethod · 0.95
CreateTUNFunction · 0.92
NewDefaultBindFunction · 0.92
UAPIListenFunction · 0.92
NameMethod · 0.65
CloseMethod · 0.65
AcceptMethod · 0.45

Tested by

no test coverage detected