aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Daniluk <ivan.daniluk@gmail.com>2018-05-04 17:10:18 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-05-04 17:10:18 +0800
commitd2fe83dc5c0b32dfbe45e77817478e06f928ff8a (patch)
tree65674f324d9006655eafc0dcf4c8c22296fba086
parent16f3c31773c6daf57afe718719821a897fa1a2c7 (diff)
downloaddexon-d2fe83dc5c0b32dfbe45e77817478e06f928ff8a.tar
dexon-d2fe83dc5c0b32dfbe45e77817478e06f928ff8a.tar.gz
dexon-d2fe83dc5c0b32dfbe45e77817478e06f928ff8a.tar.bz2
dexon-d2fe83dc5c0b32dfbe45e77817478e06f928ff8a.tar.lz
dexon-d2fe83dc5c0b32dfbe45e77817478e06f928ff8a.tar.xz
dexon-d2fe83dc5c0b32dfbe45e77817478e06f928ff8a.tar.zst
dexon-d2fe83dc5c0b32dfbe45e77817478e06f928ff8a.zip
whisper/mailserver: pass init error to the caller (#16671)
* whisper/mailserver: pass init error to the caller * whisper/mailserver: add returns to fmt.Errorf * whisper/mailserver: check err in mailserver init test
-rw-r--r--cmd/wnode/main.go4
-rw-r--r--whisper/mailserver/mailserver.go14
-rw-r--r--whisper/mailserver/server_test.go5
3 files changed, 14 insertions, 9 deletions
diff --git a/cmd/wnode/main.go b/cmd/wnode/main.go
index 988c50ce3..5031a088c 100644
--- a/cmd/wnode/main.go
+++ b/cmd/wnode/main.go
@@ -271,7 +271,9 @@ func initialize() {
if *mailServerMode {
shh.RegisterServer(&mailServer)
- mailServer.Init(shh, *argDBPath, msPassword, *argServerPoW)
+ if err := mailServer.Init(shh, *argDBPath, msPassword, *argServerPoW); err != nil {
+ utils.Fatalf("Failed to init MailServer: %s", err)
+ }
}
server = &p2p.Server{
diff --git a/whisper/mailserver/mailserver.go b/whisper/mailserver/mailserver.go
index 57e6505ad..d32eaddec 100644
--- a/whisper/mailserver/mailserver.go
+++ b/whisper/mailserver/mailserver.go
@@ -20,7 +20,6 @@ import (
"encoding/binary"
"fmt"
- "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
@@ -54,19 +53,19 @@ func NewDbKey(t uint32, h common.Hash) *DBKey {
return &k
}
-func (s *WMailServer) Init(shh *whisper.Whisper, path string, password string, pow float64) {
+func (s *WMailServer) Init(shh *whisper.Whisper, path string, password string, pow float64) error {
var err error
if len(path) == 0 {
- utils.Fatalf("DB file is not specified")
+ return fmt.Errorf("DB file is not specified")
}
if len(password) == 0 {
- utils.Fatalf("Password is not specified for MailServer")
+ return fmt.Errorf("password is not specified")
}
s.db, err = leveldb.OpenFile(path, nil)
if err != nil {
- utils.Fatalf("Failed to open DB file: %s", err)
+ return fmt.Errorf("open DB file: %s", err)
}
s.w = shh
@@ -74,12 +73,13 @@ func (s *WMailServer) Init(shh *whisper.Whisper, path string, password string, p
MailServerKeyID, err := s.w.AddSymKeyFromPassword(password)
if err != nil {
- utils.Fatalf("Failed to create symmetric key for MailServer: %s", err)
+ return fmt.Errorf("create symmetric key: %s", err)
}
s.key, err = s.w.GetSymKey(MailServerKeyID)
if err != nil {
- utils.Fatalf("Failed to save symmetric key for MailServer")
+ return fmt.Errorf("save symmetric key: %s", err)
}
+ return nil
}
func (s *WMailServer) Close() {
diff --git a/whisper/mailserver/server_test.go b/whisper/mailserver/server_test.go
index d5b993afb..edb817cc7 100644
--- a/whisper/mailserver/server_test.go
+++ b/whisper/mailserver/server_test.go
@@ -92,7 +92,10 @@ func TestMailServer(t *testing.T) {
shh = whisper.New(&whisper.DefaultConfig)
shh.RegisterServer(&server)
- server.Init(shh, dir, password, powRequirement)
+ err = server.Init(shh, dir, password, powRequirement)
+ if err != nil {
+ t.Fatal(err)
+ }
defer server.Close()
keyID, err = shh.AddSymKeyFromPassword(password)