-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmenu.go
More file actions
223 lines (213 loc) · 7.17 KB
/
menu.go
File metadata and controls
223 lines (213 loc) · 7.17 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package main
import (
"bufio"
"fmt"
"os"
"strings"
"time"
)
// inputHandler This is a basic input loop that listens for
// a few words that correspond to functions in the app. When
// a command isn't understood, it displays the help menu and
// returns to listening to input.
func inputHandler(keyCollection *ED25519Keys) {
reader := bufio.NewReader(os.Stdin)
fmt.Printf("\n\n%v%v%v\n", white+"Type '", brightgreen+"menu", white+"' to view a list of commands")
for {
// if isCoordinator {
fmt.Print(brightred + "#> " + nc)
// }
// if !isCoordinator {
// fmt.Print(brightgreen + "$> " + nc)
// }
text, _ := reader.ReadString('\n')
text = strings.TrimSpace(text)
if strings.Compare("help", text) == 0 {
menu()
} else if strings.Compare("?", text) == 0 {
menu()
} else if strings.Compare("peer", text) == 0 {
fmt.Printf(brightcyan + "Peer ID: ")
fmt.Printf(cyan+"%s\n", keyCollection.publicKey)
} else if strings.Compare("menu", text) == 0 {
menu()
} else if strings.Compare("version", text) == 0 {
menuVersion()
} else if strings.Compare("license", text) == 0 {
printLicense()
} else if strings.Compare("a", text) == 0 {
start := time.Now()
txint := 50
addBulkTransactions(txint)
elapsed := time.Since(start)
fmt.Printf("\nWriting %v objects to memory took %s seconds.\n", txint, elapsed)
} else if strings.HasPrefix(text, "ban ") {
bannedPeer := strings.TrimPrefix(text, "ban ")
banPeer(bannedPeer)
} else if strings.HasPrefix(text, "unban ") {
unBannedPeer := strings.TrimPrefix(text, "unban ")
unBanPeer(unBannedPeer)
} else if strings.HasPrefix(text, "blacklist") {
blackList()
} else if strings.Compare("clear blacklist", text) == 0 {
clearBlackList()
} else if strings.Compare("clear peerlist", text) == 0 {
clearPeerList()
} else if strings.Compare("peerlist", text) == 0 {
whiteList()
} else if strings.Compare("exit", text) == 0 {
menuExit()
} else if strings.Compare("generate-pointer", text) == 0 {
generatePointer()
} else if strings.Compare("quit", text) == 0 {
menuExit()
} else if strings.Compare("close", text) == 0 {
menuExit()
}
}
}
// func inputHandler(keyCollection *ED25519Keys) {
// reader := bufio.NewReader(os.Stdin)
// var conn *websocket.Conn
// fmt.Printf("\n\n%v%v%v\n", white+"Type '", brightgreen+"menu", white+"' to view a list of commands")
// for {
// // if isCoordinator {
// fmt.Print(brightred + "#> " + nc)
// // }
// // if !isCoordinator {
// // fmt.Print(brightgreen + "$> " + nc)
// // }
// text, _ := reader.ReadString('\n')
// text = strings.TrimSpace(text)
// if strings.Compare("help", text) == 0 {
// menu()
// } else if strings.Compare("?", text) == 0 {
// menu()
// } else if strings.Compare("peer", text) == 0 {
// fmt.Printf(brightcyan + "Peer ID: ")
// fmt.Printf(cyan+"%s\n", keyCollection.publicKey)
// } else if strings.Compare("menu", text) == 0 {
// menu()
// } else if strings.Compare("version", text) == 0 {
// menuVersion()
// } else if strings.Compare("license", text) == 0 {
// printLicense()
// } else if strings.Compare("upgrade", text) == 0 {
// returnMessage(conn, keyCollection.publicKey)
// } else if strings.Compare("a", text) == 0 {
// // if isCoordinator {
// start := time.Now()
// txint := 50
// addBulkTransactions(txint)
// elapsed := time.Since(start)
// fmt.Printf("\nWriting %v objects to memory took %s seconds.\n", txint, elapsed)
// // } else {
// // fmt.Printf("It looks like you're not a channel coordinator. \nRun Karai with '-coordinator' option to run this command.\n")
// // }
// } else if strings.HasPrefix(text, "connect") {
// ktxAddressString := strings.TrimPrefix(text, "connect ")
// if strings.Contains(ktxAddressString, ":") {
// var justTheDomainPartNotThePort = strings.Split(ktxAddressString, ":")
// var ktxCertFileName = certPathDir + "/remote/" + justTheDomainPartNotThePort[0] + ".cert"
// if !fileExists(ktxCertFileName) {
// joinChannel(ktxAddressString, keyCollection.publicKey, keyCollection.signedKey, "", keyCollection)
// }
// if fileExists(ktxCertFileName) {
// isFNG = false
// joinChannel(ktxAddressString, keyCollection.publicKey, keyCollection.signedKey, ktxCertFileName, keyCollection)
// }
// }
// if !strings.Contains(ktxAddressString, ":") {
// fmt.Printf("\nDid you forget to include the port?\n")
// }
// } else if strings.HasPrefix(text, "ban ") {
// bannedPeer := strings.TrimPrefix(text, "ban ")
// banPeer(bannedPeer)
// } else if strings.HasPrefix(text, "unban ") {
// unBannedPeer := strings.TrimPrefix(text, "unban ")
// unBanPeer(unBannedPeer)
// } else if strings.HasPrefix(text, "blacklist") {
// blackList()
// } else if strings.Compare("clear blacklist", text) == 0 {
// clearBlackList()
// } else if strings.Compare("clear peerlist", text) == 0 {
// clearPeerList()
// } else if strings.Compare("peerlist", text) == 0 {
// whiteList()
// } else if strings.Compare("exit", text) == 0 {
// menuExit()
// } else if strings.Compare("create-channel", text) == 0 {
// fmt.Printf(brightcyan + "Creating channel...\n" + white)
// // spawnChannel()
// } else if strings.Compare("generate-pointer", text) == 0 {
// generatePointer()
// } else if strings.Compare("quit", text) == 0 {
// menuExit()
// } else if strings.Compare("close", text) == 0 {
// menuExit()
// }
// }
// }
func menu() {
menuOptions := []string{"LAUNCH_PARAMETERS", "CHANNEL_OPTIONS", "WALLET_API_OPTIONS", "KARAI_OPTIONS", "GENERAL_OPTIONS"}
menuData := map[string][][]string{
"LAUNCH_PARAMETERS": {
{
"-https \t\t\t Use HTTPS for Coordinator API",
"-matrix \t\t Send event messages to Matrix homeserver",
"-matrixtoken \t\t Matrix homeserver token string",
"-matrixurl \t\t Matrix homeserver URL string",
"-matrixroomid \t\t Room ID string for matrix publishd events",
"-apiport \t\t Coordinator API port integer",
},
{},
},
"CHANNEL_OPTIONS": {
{
"generate-pointer \t Generate a Karai <=> TRTL pointer",
},
{},
},
"WALLET_API_OPTIONS": {
{},
{
// "open-wallet \t\t Open a TRTL wallet",
// "open-wallet-info \t Show wallet and connection info",
// "create-wallet \t\t Create a TRTL wallet",
// "wallet-balance \t\t Displays wallet balance",
},
},
"KARAI_OPTIONS": {
{
"peerlist \t\t Lists known peers.",
"blacklist \t\t Lists banned peers.",
"clear blacklist \t Unbans all blacklist peer certificates.",
"clear peerlist \t\t Purges all whitelist peer certificates.",
"ban <pubkey> \t\t Ban user certificate by pubkey.",
"unban <pubkey> \t\t Unban user certificate by pubkey.",
},
},
"GENERAL_OPTIONS": {
{
"version \t\t Displays version",
"license \t\t Displays license",
"exit \t\t\t Quit immediately",
},
},
}
for _, opt := range menuOptions {
fmt.Printf(brightgreen + "\n" + opt)
for menuOptionColor, options := range menuData[opt] {
switch menuOptionColor {
case 0:
fmt.Printf(brightwhite)
case 1:
fmt.Printf(brightblack)
}
for _, message := range options {
fmt.Printf("\n" + message)
}
}
}
fmt.Printf("\n")
}