whisper: shorten constants to TTL and PoW

This commit is contained in:
Péter Szilágyi 2015-04-14 15:16:02 +03:00
parent 1a4cfc173e
commit f6efdd8aad
5 changed files with 15 additions and 15 deletions

View File

@ -69,10 +69,10 @@ func selfSend(shh *whisper.Whisper, payload []byte) error {
}) })
// Wrap the payload and encrypt it // Wrap the payload and encrypt it
msg := whisper.NewMessage(payload) msg := whisper.NewMessage(payload)
envelope, err := msg.Wrap(whisper.DefaultProofOfWork, whisper.Options{ envelope, err := msg.Wrap(whisper.DefaultPoW, whisper.Options{
From: id, From: id,
To: &id.PublicKey, To: &id.PublicKey,
TTL: whisper.DefaultTimeToLive, TTL: whisper.DefaultTTL,
}) })
if err != nil { if err != nil {
return fmt.Errorf("failed to seal message: %v", err) return fmt.Errorf("failed to seal message: %v", err)

View File

@ -62,7 +62,7 @@ func NewMessage(payload []byte) *Message {
func (self *Message) Wrap(pow time.Duration, options Options) (*Envelope, error) { func (self *Message) Wrap(pow time.Duration, options Options) (*Envelope, error) {
// Use the default TTL if non was specified // Use the default TTL if non was specified
if options.TTL == 0 { if options.TTL == 0 {
options.TTL = DefaultTimeToLive options.TTL = DefaultTTL
} }
// Sign and encrypt the message if requested // Sign and encrypt the message if requested
if options.From != nil { if options.From != nil {

View File

@ -13,7 +13,7 @@ func TestMessageSimpleWrap(t *testing.T) {
payload := []byte("hello world") payload := []byte("hello world")
msg := NewMessage(payload) msg := NewMessage(payload)
if _, err := msg.Wrap(DefaultProofOfWork, Options{}); err != nil { if _, err := msg.Wrap(DefaultPoW, Options{}); err != nil {
t.Fatalf("failed to wrap message: %v", err) t.Fatalf("failed to wrap message: %v", err)
} }
if msg.Flags&signatureFlag != 0 { if msg.Flags&signatureFlag != 0 {
@ -36,7 +36,7 @@ func TestMessageCleartextSignRecover(t *testing.T) {
payload := []byte("hello world") payload := []byte("hello world")
msg := NewMessage(payload) msg := NewMessage(payload)
if _, err := msg.Wrap(DefaultProofOfWork, Options{ if _, err := msg.Wrap(DefaultPoW, Options{
From: key, From: key,
}); err != nil { }); err != nil {
t.Fatalf("failed to sign message: %v", err) t.Fatalf("failed to sign message: %v", err)
@ -69,7 +69,7 @@ func TestMessageAnonymousEncryptDecrypt(t *testing.T) {
payload := []byte("hello world") payload := []byte("hello world")
msg := NewMessage(payload) msg := NewMessage(payload)
envelope, err := msg.Wrap(DefaultProofOfWork, Options{ envelope, err := msg.Wrap(DefaultPoW, Options{
To: &key.PublicKey, To: &key.PublicKey,
}) })
if err != nil { if err != nil {
@ -104,7 +104,7 @@ func TestMessageFullCrypto(t *testing.T) {
payload := []byte("hello world") payload := []byte("hello world")
msg := NewMessage(payload) msg := NewMessage(payload)
envelope, err := msg.Wrap(DefaultProofOfWork, Options{ envelope, err := msg.Wrap(DefaultPoW, Options{
From: fromKey, From: fromKey,
To: &toKey.PublicKey, To: &toKey.PublicKey,
}) })

View File

@ -30,8 +30,8 @@ const (
) )
const ( const (
DefaultTimeToLive = 50 * time.Second DefaultTTL = 50 * time.Second
DefaultProofOfWork = 50 * time.Millisecond DefaultPoW = 50 * time.Millisecond
) )
type MessageEvent struct { type MessageEvent struct {

View File

@ -83,10 +83,10 @@ func TestSelfMessage(t *testing.T) {
}) })
// Send a dummy message to oneself // Send a dummy message to oneself
msg := NewMessage([]byte("self whisper")) msg := NewMessage([]byte("self whisper"))
envelope, err := msg.Wrap(DefaultProofOfWork, Options{ envelope, err := msg.Wrap(DefaultPoW, Options{
From: self, From: self,
To: &self.PublicKey, To: &self.PublicKey,
TTL: DefaultTimeToLive, TTL: DefaultTTL,
}) })
if err != nil { if err != nil {
t.Fatalf("failed to wrap message: %v", err) t.Fatalf("failed to wrap message: %v", err)
@ -126,10 +126,10 @@ func TestDirectMessage(t *testing.T) {
}) })
// Send a dummy message from the sender // Send a dummy message from the sender
msg := NewMessage([]byte("direct whisper")) msg := NewMessage([]byte("direct whisper"))
envelope, err := msg.Wrap(DefaultProofOfWork, Options{ envelope, err := msg.Wrap(DefaultPoW, Options{
From: senderId, From: senderId,
To: &recipientId.PublicKey, To: &recipientId.PublicKey,
TTL: DefaultTimeToLive, TTL: DefaultTTL,
}) })
if err != nil { if err != nil {
t.Fatalf("failed to wrap message: %v", err) t.Fatalf("failed to wrap message: %v", err)
@ -184,9 +184,9 @@ func testBroadcast(anonymous bool, t *testing.T) {
} }
// Send a dummy message from the sender // Send a dummy message from the sender
msg := NewMessage([]byte("broadcast whisper")) msg := NewMessage([]byte("broadcast whisper"))
envelope, err := msg.Wrap(DefaultProofOfWork, Options{ envelope, err := msg.Wrap(DefaultPoW, Options{
Topics: NewTopicsFromStrings("broadcast topic"), Topics: NewTopicsFromStrings("broadcast topic"),
TTL: DefaultTimeToLive, TTL: DefaultTTL,
}) })
if err != nil { if err != nil {
t.Fatalf("failed to wrap message: %v", err) t.Fatalf("failed to wrap message: %v", err)