-
Notifications
You must be signed in to change notification settings - Fork 308
/
command.go
51 lines (42 loc) · 1006 Bytes
/
command.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
package command_run
import (
"github.com/mysterium/node/bytescount_client"
"github.com/mysterium/node/openvpn"
"github.com/mysterium/node/server"
"io"
"time"
)
type commandRun struct {
output io.Writer
outputError io.Writer
mysteriumClient server.Client
vpnClient *openvpn.Client
}
func (cmd *commandRun) Run(options CommandOptions) error {
vpnSession, err := cmd.mysteriumClient.SessionCreate(options.NodeKey)
if err != nil {
return err
}
vpnConfig, err := openvpn.NewClientConfigFromString(
vpnSession.ConnectionConfig,
options.DirectoryRuntime+"/client.ovpn",
)
if err != nil {
return err
}
cmd.vpnClient = openvpn.NewClient(
vpnConfig,
options.DirectoryRuntime,
bytescount_client.NewMiddleware(cmd.mysteriumClient, vpnSession.Id, 1*time.Minute),
)
if err := cmd.vpnClient.Start(); err != nil {
return err
}
return nil
}
func (cmd *commandRun) Wait() error {
return cmd.vpnClient.Wait()
}
func (cmd *commandRun) Kill() {
cmd.vpnClient.Stop()
}