-
Notifications
You must be signed in to change notification settings - Fork 2
/
mystnode.go
102 lines (94 loc) · 2.47 KB
/
mystnode.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
97
98
99
100
101
102
package main
import (
"errors"
"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"github.com/rivo/tview"
"github.com/toqueteos/webbrowser"
)
const (
MYST_IMAGE_NAME = "mysteriumnetwork/myst:latest"
MYST_REFERRAL_LINK = "https://mystnodes.co/?referral_code=ijIy8nJv8xqVoshRmJjKATvoZZYKZ3jhzOY3FWy6"
)
type MystConfig struct {
Configured bool
}
func (i *MystConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, app *tview.Application) {
enabled := i.Configured
form.AddCheckbox("Enable Myst", i.Configured, func(checked bool) {
enabled = checked
})
form.AddButton("Save", func() {
i.Configured = enabled
returnToMenu(frame, app)
})
form.AddButton("Cancel", func() {
returnToMenu(frame, app)
})
form.AddButton("Register", func() {
modal := tview.NewModal().
SetText("Register on Mysterium Nodes\n" + MYST_REFERRAL_LINK).
AddButtons([]string{"Open", "Cancel"}).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
if buttonLabel == "Open" {
webbrowser.Open(MYST_REFERRAL_LINK)
}
app.SetRoot(form, true)
})
app.SetRoot(modal, true)
})
}
func (i *MystConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (string, error) {
switch kind {
case KIND_DOCKER_COMPOSE:
return `myst:
image: ` + MYST_IMAGE_NAME + `
environment:
- MYSTNODE_DUMMY=''
command: service --agreed-terms-and-conditions
network_mode: host
cap_add:
- NET_ADMIN
ports:
- "4449:4449"
volumes:
- myst-data:/var/lib/mysterium-node
restart: unless-stopped
`, nil
case KIND_DIRECTLY_CONFIGURE_DOCKER:
containerConfig := &container.Config{
Image: MYST_IMAGE_NAME,
Env: []string{
"MYSTNODE_DUMMY=",
},
Cmd: []string{"service", "--agreed-terms-and-conditions"},
Volumes: map[string]struct{}{
"/var/lib/mysterium-node": {},
},
}
hostConfig := &container.HostConfig{
RestartPolicy: container.RestartPolicy{
Name: "unless-stopped",
},
CapAdd: []string{"NET_ADMIN"},
NetworkMode: "host",
PortBindings: map[nat.Port][]nat.PortBinding{
nat.Port("4449/tcp"): {
{
HostPort: "4449",
},
},
},
}
return "", createContainer("myst", containerConfig, hostConfig, form)
}
return "", errors.New("unknown kind")
}
func (i *MystConfig) IsConfigured() bool {
return i.Configured
}
func (i *MystConfig) PostConfigure(form *tview.Form, app *tview.Application) {
form.AddButton("Open Myst Node URL", func() {
webbrowser.Open("http://127.0.0.1:4449/")
})
}