2018-01-17 20:07:45 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/geth/params"
|
|
|
|
)
|
|
|
|
|
2018-01-17 21:40:14 +00:00
|
|
|
// whisperConfig creates node configuration object from flags
|
2018-01-17 20:07:45 +00:00
|
|
|
func whisperConfig(nodeConfig *params.NodeConfig) (*params.NodeConfig, error) {
|
|
|
|
whisperConfig := nodeConfig.WhisperConfig
|
|
|
|
whisperConfig.Enabled = true
|
|
|
|
whisperConfig.EnableMailServer = *enableMailServer
|
2018-03-02 09:25:30 +00:00
|
|
|
whisperConfig.LightClient = *lightClient
|
2018-01-17 20:07:45 +00:00
|
|
|
whisperConfig.MinimumPoW = *minPow
|
|
|
|
whisperConfig.TTL = *ttl
|
|
|
|
|
|
|
|
if whisperConfig.EnableMailServer {
|
|
|
|
if *passwordFile == "" {
|
|
|
|
return nil, errors.New("passwordfile should be specified if MailServer is enabled")
|
|
|
|
}
|
|
|
|
|
|
|
|
password, err := readFile(*passwordFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("password file: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
whisperConfig.Password = string(password)
|
|
|
|
}
|
|
|
|
|
|
|
|
// firebase configuration
|
|
|
|
firebaseConfig := whisperConfig.FirebaseConfig
|
|
|
|
firebaseConfig.AuthorizationKeyFile = *firebaseAuth
|
|
|
|
if firebaseConfig.AuthorizationKeyFile != "" {
|
|
|
|
if _, err := firebaseConfig.ReadAuthorizationKeyFile(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nodeConfig, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func readFile(path string) ([]byte, error) {
|
|
|
|
data, err := ioutil.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
data = bytes.TrimRight(data, "\n")
|
|
|
|
|
|
|
|
if len(data) == 0 {
|
|
|
|
return nil, errors.New("file is empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
return data, nil
|
|
|
|
}
|