aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/mailserver
diff options
context:
space:
mode:
authorgluk256 <gluk256@users.noreply.github.com>2017-04-10 05:49:22 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-04-10 05:49:22 +0800
commit9cd713551627a9b48e04a77f64a15ea6f829dcf4 (patch)
treef1849e61cd8269dfe9c70861f49216cf78acec3b /whisper/mailserver
parent8570ef19eb8dfe4e2a450525c589dec291f3a517 (diff)
downloaddexon-9cd713551627a9b48e04a77f64a15ea6f829dcf4.tar.gz
dexon-9cd713551627a9b48e04a77f64a15ea6f829dcf4.tar.zst
dexon-9cd713551627a9b48e04a77f64a15ea6f829dcf4.zip
whisper: big refactoring (#13852)
* whisper: GetMessages fixed; size restriction updated * whisper: made PoW and MaxMsgSize customizable * whisper: test added * whisper: sym key management changed * whisper: identity management refactored * whisper: API refactoring (Post and Filter) * whisper: big refactoring complete * whisper: spelling fix * whisper: variable topic size allowed for a filter * whisper: final update * whisper: formatting * whisper: file exchange introduced in wnode * whisper: bugfix * whisper: API updated + new tests * whisper: statistics updated * whisper: wnode server updated * whisper: allowed filtering for variable topic size * whisper: tests added * whisper: resolving merge conflicts * whisper: refactoring (documenting mostly) * whsiper: tests fixed * whisper: down cased error messages * whisper: documenting the API functions * whisper: logging fixed * whisper: fixed wnode parameters * whisper: logs fixed (typos)
Diffstat (limited to 'whisper/mailserver')
-rw-r--r--whisper/mailserver/mailserver.go9
-rw-r--r--whisper/mailserver/server_test.go20
2 files changed, 21 insertions, 8 deletions
diff --git a/whisper/mailserver/mailserver.go b/whisper/mailserver/mailserver.go
index 6533c56c2..d705c622f 100644
--- a/whisper/mailserver/mailserver.go
+++ b/whisper/mailserver/mailserver.go
@@ -31,8 +31,6 @@ import (
"github.com/syndtr/goleveldb/leveldb/util"
)
-const MailServerKeyName = "958e04ab302fb36ad2616a352cbac79d"
-
type WMailServer struct {
db *leveldb.DB
w *whisper.Whisper
@@ -75,11 +73,14 @@ func (s *WMailServer) Init(shh *whisper.Whisper, path string, password string, p
s.w = shh
s.pow = pow
- err = s.w.AddSymKey(MailServerKeyName, []byte(password))
+ MailServerKeyID, err := s.w.AddSymKeyFromPassword(password)
if err != nil {
utils.Fatalf("Failed to create symmetric key for MailServer: %s", err)
}
- s.key = s.w.GetSymKey(MailServerKeyName)
+ s.key, err = s.w.GetSymKey(MailServerKeyID)
+ if err != nil {
+ utils.Fatalf("Failed to save symmetric key for MailServer")
+ }
}
func (s *WMailServer) Close() {
diff --git a/whisper/mailserver/server_test.go b/whisper/mailserver/server_test.go
index 8b58a826f..ffdff3191 100644
--- a/whisper/mailserver/server_test.go
+++ b/whisper/mailserver/server_test.go
@@ -30,8 +30,8 @@ import (
)
const powRequirement = 0.00001
-const keyName = "6d604bac5401ce9a6b995f1b45a4ab"
+var keyID string
var shh *whisper.Whisper
var seed = time.Now().Unix()
@@ -90,7 +90,7 @@ func TestMailServer(t *testing.T) {
server.Init(shh, dir, password, powRequirement)
defer server.Close()
- err = shh.AddSymKey(keyName, []byte(password))
+ keyID, err = shh.AddSymKeyFromPassword(password)
if err != nil {
t.Fatalf("Failed to create symmetric key for mail request: %s", err)
}
@@ -102,7 +102,14 @@ func TestMailServer(t *testing.T) {
}
func deliverTest(t *testing.T, server *WMailServer, env *whisper.Envelope) {
- testPeerID := shh.NewIdentity()
+ id, err := shh.NewKeyPair()
+ if err != nil {
+ t.Fatalf("failed to generate new key pair with seed %d: %s.", seed, err)
+ }
+ testPeerID, err := shh.GetPrivateKey(id)
+ if err != nil {
+ t.Fatalf("failed to retrieve new key pair with seed %d: %s.", seed, err)
+ }
birth := env.Expiry - env.TTL
p := &ServerTestParams{
topic: env.Topic,
@@ -167,8 +174,13 @@ func createRequest(t *testing.T, p *ServerTestParams) *whisper.Envelope {
binary.BigEndian.PutUint32(data[4:], p.upp)
copy(data[8:], p.topic[:])
+ key, err := shh.GetSymKey(keyID)
+ if err != nil {
+ t.Fatalf("failed to retrieve sym key with seed %d: %s.", seed, err)
+ }
+
params := &whisper.MessageParams{
- KeySym: shh.GetSymKey(keyName),
+ KeySym: key,
Topic: p.topic,
Payload: data,
PoW: powRequirement * 2,