MCPcopy Create free account
hub / github.com/coder/coder / vpnDaemonRun

Method vpnDaemonRun

cli/vpndaemon_darwin.go:13–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11)
12
13func (*RootCmd) vpnDaemonRun() *serpent.Command {
14 var (
15 rpcReadFD int64
16 rpcWriteFD int64
17 )
18
19 cmd := &serpent.Command{
20 Use: "run",
21 Short: "Run the VPN daemon on macOS.",
22 Middleware: serpent.Chain(
23 serpent.RequireNArgs(0),
24 ),
25 Options: serpent.OptionSet{
26 {
27 Flag: "rpc-read-fd",
28 Env: "CODER_VPN_DAEMON_RPC_READ_FD",
29 Description: "The file descriptor for the pipe to read from the RPC connection.",
30 Value: serpent.Int64Of(&rpcReadFD),
31 Required: true,
32 },
33 {
34 Flag: "rpc-write-fd",
35 Env: "CODER_VPN_DAEMON_RPC_WRITE_FD",
36 Description: "The file descriptor for the pipe to write to the RPC connection.",
37 Value: serpent.Int64Of(&rpcWriteFD),
38 Required: true,
39 },
40 },
41 Handler: func(inv *serpent.Invocation) error {
42 ctx := inv.Context()
43
44 if rpcReadFD < 0 || rpcWriteFD < 0 {
45 return xerrors.Errorf("rpc-read-fd (%v) and rpc-write-fd (%v) must be positive", rpcReadFD, rpcWriteFD)
46 }
47 if rpcReadFD == rpcWriteFD {
48 return xerrors.Errorf("rpc-read-fd (%v) and rpc-write-fd (%v) must be different", rpcReadFD, rpcWriteFD)
49 }
50
51 pipe, err := vpn.NewBidirectionalPipe(uintptr(rpcReadFD), uintptr(rpcWriteFD))
52 if err != nil {
53 return xerrors.Errorf("create bidirectional RPC pipe: %w", err)
54 }
55 defer pipe.Close()
56
57 tunnel, err := vpn.NewTunnel(ctx, slog.Make().Leveled(slog.LevelDebug), pipe,
58 vpn.NewClient(),
59 vpn.UseOSNetworkingStack(),
60 vpn.UseAsLogger(),
61 )
62 if err != nil {
63 return xerrors.Errorf("create new tunnel for client: %w", err)
64 }
65 defer tunnel.Close()
66
67 <-ctx.Done()
68 return nil
69 },
70 }

Callers 1

vpnDaemonMethod · 0.95

Calls 10

CloseMethod · 0.95
NewBidirectionalPipeFunction · 0.92
NewTunnelFunction · 0.92
NewClientFunction · 0.92
UseOSNetworkingStackFunction · 0.92
UseAsLoggerFunction · 0.92
ContextMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected