1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-08-31 02:10:55 +00:00

Combine config objects, improve first-run ux

This commit is contained in:
Kane York 2015-10-26 22:16:03 -07:00
parent a6508d32ab
commit 4eee83a561
5 changed files with 104 additions and 98 deletions

View file

@ -11,7 +11,6 @@ import (
"log"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"sync"
@ -29,7 +28,7 @@ var serverId int
var messageBufferPool sync.Pool
func SetupBackend(config *Config) {
func SetupBackend(config *ConfigFile) {
backendHttpClient.Timeout = 60 * time.Second
backendUrl = config.BackendUrl
if responseCache != nil {
@ -41,21 +40,10 @@ func SetupBackend(config *Config) {
messageBufferPool.New = New4KByteBuffer
var keys CryptoKeysBuf
file, err := os.Open(config.NaclKeysFile)
if err != nil {
log.Fatal(err)
}
dec := json.NewDecoder(file)
err = dec.Decode(&keys)
if err != nil {
log.Fatal(err)
}
var theirPublic, ourPrivate [32]byte
copy(theirPublic[:], keys.TheirPublicKey)
copy(ourPrivate[:], keys.OurPrivateKey)
serverId = keys.ServerId
copy(theirPublic[:], config.BackendPublicKey)
copy(ourPrivate[:], config.OurPrivateKey)
serverId = config.ServerId
box.Precompute(&backendSharedKey, &theirPublic, &ourPrivate)
}
@ -193,7 +181,7 @@ func FetchBacklogData(chatSubs []string) ([]ClientMessage, error) {
func GenerateKeys(outputFile, serverId, theirPublicStr string) {
var err error
output := CryptoKeysBuf{}
output := ConfigFile{}
output.ServerId, err = strconv.Atoi(serverId)
if err != nil {
@ -212,19 +200,16 @@ func GenerateKeys(outputFile, serverId, theirPublicStr string) {
if err != nil {
log.Fatal(err)
}
output.TheirPublicKey = theirPublic
output.BackendPublicKey = theirPublic
}
file, err := os.Create(outputFile)
fmt.Println(ourPublic, ourPrivate)
bytes, err := json.MarshalIndent(output, "", "\t")
if err != nil {
log.Fatal(err)
}
enc := json.NewEncoder(file)
err = enc.Encode(output)
if err != nil {
log.Fatal(err)
}
err = file.Close()
fmt.Println(string(bytes))
err = ioutil.WriteFile(outputFile, bytes, 0600)
if err != nil {
log.Fatal(err)
}