Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

whisper/mailserver: pass init error to the caller #16671

Merged
merged 3 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/wnode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
14 changes: 7 additions & 7 deletions whisper/mailserver/mailserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -54,32 +53,33 @@ 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
s.pow = pow

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() {
Expand Down
5 changes: 4 additions & 1 deletion whisper/mailserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down