From 71e676ec866f0419bcc90d4486386d753c1b7179 Mon Sep 17 00:00:00 2001 From: Eugene Valeyev Date: Thu, 28 Dec 2017 13:20:19 +0300 Subject: [PATCH 1/6] mobile: created a draft of shh client wrapper --- mobile/shhclient.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 mobile/shhclient.go diff --git a/mobile/shhclient.go b/mobile/shhclient.go new file mode 100644 index 0000000000..ac9c1c4805 --- /dev/null +++ b/mobile/shhclient.go @@ -0,0 +1,40 @@ +// Copyright 2017 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +// Contains a wrapper for the Whisper client. + +package geth + +import ( + "github.com/ethereum/go-ethereum/whisper/shhclient" +) + +// WhisperClient provides access to the Ethereum APIs. +type WhisperClient struct { + client *shhclient.Client +} + +// NewWhisperClient connects a client to the given URL. +func NewWhisperClient(rawurl string) (client *WhisperClient, _ error) { + rawClient, err := shhclient.Dial(rawurl) + return &WhisperClient{rawClient}, err +} + +// Version returns the Whisper sub-protocol version. +func (ec *WhisperClient) Version(ctx *Context) (version string, _ error) { + rawVersion, err := ec.client.Version(ctx.context) + return string(rawVersion), err +} From 090599568f0390f14b9b17cc2e125e6f73ecdeac Mon Sep 17 00:00:00 2001 From: Eugene Valeyev Date: Fri, 29 Dec 2017 11:16:14 +0300 Subject: [PATCH 2/6] mobile: implemented all methods of shh wrapper --- mobile/shhclient.go | 172 +++++++++++++++++++++++++++++++++++++++++++- mobile/types.go | 26 +++++++ 2 files changed, 195 insertions(+), 3 deletions(-) diff --git a/mobile/shhclient.go b/mobile/shhclient.go index ac9c1c4805..cada62e581 100644 --- a/mobile/shhclient.go +++ b/mobile/shhclient.go @@ -20,6 +20,7 @@ package geth import ( "github.com/ethereum/go-ethereum/whisper/shhclient" + whisper "github.com/ethereum/go-ethereum/whisper/whisperv5" ) // WhisperClient provides access to the Ethereum APIs. @@ -33,8 +34,173 @@ func NewWhisperClient(rawurl string) (client *WhisperClient, _ error) { return &WhisperClient{rawClient}, err } -// Version returns the Whisper sub-protocol version. -func (ec *WhisperClient) Version(ctx *Context) (version string, _ error) { - rawVersion, err := ec.client.Version(ctx.context) +// GetVersion returns the Whisper sub-protocol version. +func (wc *WhisperClient) GetVersion(ctx *Context) (version string, _ error) { + rawVersion, err := wc.client.Version(ctx.context) return string(rawVersion), err } + +// Info returns diagnostic information about the whisper node. +func (wc *WhisperClient) GetInfo(ctx *Context) (info *Info, _ error) { + rawInfo, err := wc.client.Info(ctx.context) + return &Info{&rawInfo}, err +} + +// SetMaxMessageSize sets the maximal message size allowed by this node. Incoming +// and outgoing messages with a larger size will be rejected. Whisper message size +// can never exceed the limit imposed by the underlying P2P protocol (10 Mb). +func (wc *WhisperClient) SetMaxMessageSize(ctx *Context, size int32) error { + return wc.client.SetMaxMessageSize(ctx.context, uint32(size)) +} + +// SetMinimumPoW (experimental) sets the minimal PoW required by this node. + +// This experimental function was introduced for the future dynamic adjustment of +// PoW requirement. If the node is overwhelmed with messages, it should raise the +// PoW requirement and notify the peers. The new value should be set relative to +// the old value (e.g. double). The old value could be obtained via shh_info call. +func (wc *WhisperClient) SetMinimumPoW(ctx *Context, pow float64) error { + return wc.client.SetMinimumPoW(ctx.context, pow) +} + +// Marks specific peer trusted, which will allow it to send historic (expired) messages. +// Note This function is not adding new nodes, the node needs to exists as a peer. +func (wc *WhisperClient) MarkTrustedPeer(ctx *Context, enode string) error { + return wc.client.MarkTrustedPeer(ctx.context, enode) +} + +// NewKeyPair generates a new public and private key pair for message decryption and encryption. +// It returns an identifier that can be used to refer to the key. +func (wc *WhisperClient) NewKeyPair(ctx *Context) (string, error) { + rawNewKeyPair, err := wc.client.NewKeyPair(ctx.context) + return string(rawNewKeyPair), err +} + +// AddPrivateKey stored the key pair, and returns its ID. +func (wc *WhisperClient) AddPrivateKey(ctx *Context, key []byte) (string, error) { + rawAddPrivateKey, err := wc.client.AddPrivateKey(ctx.context, key) + return string(rawAddPrivateKey), err +} + +// DeleteKeyPair delete the specifies key. +func (wc *WhisperClient) DeleteKeyPair(ctx *Context, id string) (string, error) { + rawDeletePrivateKey, err := wc.client.DeleteKeyPair(ctx.context, id) + return string(rawDeletePrivateKey), err +} + +// HasKeyPair returns an indication if the node has a private key or +// key pair matching the given ID. +func (wc *WhisperClient) HasKeyPair(ctx *Context, id string) (bool, error) { + rawHasKeyPair, err := wc.client.HasKeyPair(ctx.context, id) + return bool(rawHasKeyPair), err +} + +// GetPublicKey return the public key for a key ID. +func (wc *WhisperClient) GetPublicKey(ctx *Context, id string) ([]byte, error) { + return wc.client.PublicKey(ctx.context, id) +} + +// GetPrivateKey return the private key for a key ID. +func (wc *WhisperClient) GetPrivateKey(ctx *Context, id string) ([]byte, error) { + return wc.client.PrivateKey(ctx.context, id) +} + +// NewSymmetricKey generates a random symmetric key and returns its identifier. +// Can be used encrypting and decrypting messages where the key is known to both parties. +func (wc *WhisperClient) NewSymmetricKey(ctx *Context) (string, error) { + rawNewSymmetricKey, err := wc.client.NewSymmetricKey(ctx.context) + return string(rawNewSymmetricKey), err +} + +// AddSymmetricKey stores the key, and returns its identifier. +func (wc *WhisperClient) AddSymmetricKey(ctx *Context, key []byte) (string, error) { + rawAddSymmetricKey, err := wc.client.AddSymmetricKey(ctx.context, key) + return string(rawAddSymmetricKey), err +} + +// GenerateSymmetricKeyFromPassword generates the key from password, stores it, and returns its identifier. +func (wc *WhisperClient) GenerateSymmetricKeyFromPassword(ctx *Context, passwd []byte) (string, error) { + rawVersion, err := wc.client.Version(ctx.context) + return string(rawVersion), err +} + +// HasSymmetricKey returns an indication if the key associated with the given id is stored in the node. +func (wc *WhisperClient) HasSymmetricKey(ctx *Context, id string) (bool, error) { + rawHasSymmetricKey, err := wc.client.HasSymmetricKey(ctx.context, id) + return bool(rawHasSymmetricKey), err +} + +// GetSymmetricKey returns the symmetric key associated with the given identifier. +func (wc *WhisperClient) GetSymmetricKey(ctx *Context, id string) ([]byte, error) { + return wc.client.GetSymmetricKey(ctx.context, id) +} + +// DeleteSymmetricKey deletes the symmetric key associated with the given identifier. +func (wc *WhisperClient) DeleteSymmetricKey(ctx *Context, id string) error { + return wc.client.DeleteSymmetricKey(ctx.context, id) +} + +// Post a message onto the network. +func (wc *WhisperClient) Post(ctx *Context, message *NewMessage) error { + return wc.client.Post(ctx.context, *message.newMessage) +} + +// NewHeadHandler is a client-side subscription callback to invoke on events and +// subscription failure. +type NewMessageHandler interface { + OnNewMessage(message *Message) + OnError(failure string) +} + +// SubscribeMessages subscribes to messages that match the given criteria. This method +// is only supported on bi-directional connections such as websockets and IPC. +// NewMessageFilter uses polling and is supported over HTTP. +func (wc *WhisperClient) SubscribeMessages(ctx *Context, criteria *Criteria, handler NewMessageHandler, buffer int) (*Subscription, error) { + // Subscribe to the event internally + ch := make(chan *whisper.Message, buffer) + rawSub, err := wc.client.SubscribeMessages(ctx.context, *criteria.criteria, ch) + if err != nil { + return nil, err + } + // Start up a dispatcher to feed into the callback + go func() { + for { + select { + case message := <-ch: + handler.OnNewMessage(&Message{message}) + + case err := <-rawSub.Err(): + handler.OnError(err.Error()) + return + } + } + }() + return &Subscription{rawSub}, nil +} + +// NewMessageFilter creates a filter within the node. This filter can be used to poll +// for new messages (see FilterMessages) that satisfy the given criteria. A filter can +// timeout when it was polled for in whisper.filterTimeout. +func (wc *WhisperClient) NewMessageFilter(ctx *Context, criteria *Criteria) (string, error) { + rawNewMessageFilter, err := wc.client.NewMessageFilter(ctx.context, *criteria.criteria) + return string(rawNewMessageFilter), err +} + +// DeleteMessageFilter removes the filter associated with the given id. +func (wc *WhisperClient) DeleteMessageFilter(ctx *Context, id string) error { + return wc.client.DeleteMessageFilter(ctx.context, id) +} + +// GetFilterMessages retrieves all messages that are received between the last call to +// this function and match the criteria that where given when the filter was created. +func (wc *WhisperClient) GetFilterMessages(ctx *Context, id string) (*Messages, error) { + rawFilterMessages, err := wc.client.FilterMessages(ctx.context, id) + if err != nil { + return nil, err + } + res := make([]*Message, len(rawFilterMessages)) + for i := range rawFilterMessages { + res[i] = &Message{rawFilterMessages[i]} + } + return &Messages{res}, nil +} diff --git a/mobile/types.go b/mobile/types.go index 4790afceff..83ac5b8e4e 100644 --- a/mobile/types.go +++ b/mobile/types.go @@ -26,6 +26,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rlp" + whisper "github.com/ethereum/go-ethereum/whisper/whisperv5" ) // A Nonce is a 64-bit hash which proves (combined with the mix-hash) that @@ -360,3 +361,28 @@ func (r *Receipt) GetLogs() *Logs { return &Logs{r.receipt.Logs} } func (r *Receipt) GetTxHash() *Hash { return &Hash{r.receipt.TxHash} } func (r *Receipt) GetContractAddress() *Address { return &Address{r.receipt.ContractAddress} } func (r *Receipt) GetGasUsed() int64 { return int64(r.receipt.GasUsed) } + +// Info represents a diagnostic information about the whisper node. +type Info struct { + info *whisper.Info +} + +// NewMessage represents a new whisper message that is posted through the RPC. +type NewMessage struct { + newMessage *whisper.NewMessage +} + +// Message represents a whisper message. +type Message struct { + message *whisper.Message +} + +// Messagea represents an array of messages. +type Messages struct { + messages []*Message +} + +// Criteria holds various filter options for inbound messages. +type Criteria struct { + criteria *whisper.Criteria +} From d38b08bfcc2450da7f0b7e21a6326e4ffbab276a Mon Sep 17 00:00:00 2001 From: Eugene Valeyev Date: Thu, 11 Jan 2018 12:54:22 +0300 Subject: [PATCH 3/6] mobile: fixed generation of sym key from password --- mobile/shhclient.go | 10 +++++----- mobile/types.go | 4 ++-- whisper/shhclient/client.go | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mobile/shhclient.go b/mobile/shhclient.go index cada62e581..573aa47554 100644 --- a/mobile/shhclient.go +++ b/mobile/shhclient.go @@ -119,9 +119,9 @@ func (wc *WhisperClient) AddSymmetricKey(ctx *Context, key []byte) (string, erro } // GenerateSymmetricKeyFromPassword generates the key from password, stores it, and returns its identifier. -func (wc *WhisperClient) GenerateSymmetricKeyFromPassword(ctx *Context, passwd []byte) (string, error) { - rawVersion, err := wc.client.Version(ctx.context) - return string(rawVersion), err +func (wc *WhisperClient) GenerateSymmetricKeyFromPassword(ctx *Context, passwd string) (string, error) { + rawSymKeyID, err := wc.client.GenerateSymmetricKeyFromPassword(ctx.context, passwd) + return string(rawSymKeyID), err } // HasSymmetricKey returns an indication if the key associated with the given id is stored in the node. @@ -198,9 +198,9 @@ func (wc *WhisperClient) GetFilterMessages(ctx *Context, id string) (*Messages, if err != nil { return nil, err } - res := make([]*Message, len(rawFilterMessages)) + res := make([]*whisper.Message, len(rawFilterMessages)) for i := range rawFilterMessages { - res[i] = &Message{rawFilterMessages[i]} + res[i] = rawFilterMessages[i] } return &Messages{res}, nil } diff --git a/mobile/types.go b/mobile/types.go index 83ac5b8e4e..80403f3d89 100644 --- a/mobile/types.go +++ b/mobile/types.go @@ -377,9 +377,9 @@ type Message struct { message *whisper.Message } -// Messagea represents an array of messages. +// Messages represents an array of messages. type Messages struct { - messages []*Message + messages []*whisper.Message } // Criteria holds various filter options for inbound messages. diff --git a/whisper/shhclient/client.go b/whisper/shhclient/client.go index 61b4775d95..aa96e6491a 100644 --- a/whisper/shhclient/client.go +++ b/whisper/shhclient/client.go @@ -136,9 +136,9 @@ func (sc *Client) AddSymmetricKey(ctx context.Context, key []byte) (string, erro } // GenerateSymmetricKeyFromPassword generates the key from password, stores it, and returns its identifier. -func (sc *Client) GenerateSymmetricKeyFromPassword(ctx context.Context, passwd []byte) (string, error) { +func (sc *Client) GenerateSymmetricKeyFromPassword(ctx context.Context, passwd string) (string, error) { var id string - return id, sc.c.CallContext(ctx, &id, "shh_generateSymKeyFromPassword", hexutil.Bytes(passwd)) + return id, sc.c.CallContext(ctx, &id, "shh_generateSymKeyFromPassword", passwd) } // HasSymmetricKey returns an indication if the key associated with the given id is stored in the node. From 978346e438373692814667e31fae56441b327592 Mon Sep 17 00:00:00 2001 From: Eugene Valeyev Date: Thu, 11 Jan 2018 17:18:43 +0300 Subject: [PATCH 4/6] mobile: added accessors for wrapper-types --- mobile/types.go | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/mobile/types.go b/mobile/types.go index 80403f3d89..05acb2b9ee 100644 --- a/mobile/types.go +++ b/mobile/types.go @@ -372,17 +372,82 @@ type NewMessage struct { newMessage *whisper.NewMessage } +func NewNewMessage() (*NewMessage) { + nm := &NewMessage{ + newMessage: new(whisper.NewMessage), + } + return nm +} + +func (nm *NewMessage) GetSymKeyID() string { return nm.newMessage.SymKeyID } +func (nm *NewMessage) SetSymKeyID(symKeyID string) { nm.newMessage.SymKeyID = symKeyID } +func (nm *NewMessage) GetPublicKey() []byte { return nm.newMessage.PublicKey } +func (nm *NewMessage) SetPublicKey(publicKey []byte) { nm.newMessage.PublicKey = publicKey } +func (nm *NewMessage) GetSig() string { return nm.newMessage.Sig } +func (nm *NewMessage) SetSig(sig string) { nm.newMessage.Sig = sig } +func (nm *NewMessage) GetTTL() int32 { return int32(nm.newMessage.TTL) } +func (nm *NewMessage) SetTTL(ttl int32) { nm.newMessage.TTL = uint32(ttl) } +func (nm *NewMessage) GetPayload() []byte { return nm.newMessage.Payload } +func (nm *NewMessage) SetPayload(payload []byte) { nm.newMessage.Payload = payload } +func (nm *NewMessage) GetPowTime() int32 { return int32(nm.newMessage.PowTime) } +func (nm *NewMessage) SetPowTime(powTime int32) { nm.newMessage.PowTime = uint32(powTime) } +func (nm *NewMessage) GetPowTarget() float64 { return nm.newMessage.PowTarget } +func (nm *NewMessage) SetPowTarget(powTarget float64) { nm.newMessage.PowTarget = powTarget } +func (nm *NewMessage) GetTargetPeer() string { return nm.newMessage.TargetPeer } +func (nm *NewMessage) SetTargetPeer(targetPeer string) { nm.newMessage.TargetPeer = targetPeer } +func (nm *NewMessage) GetTopic() []byte { return nm.newMessage.Topic[:] } +func (nm *NewMessage) SetTopic(topic []byte) { nm.newMessage.Topic = whisper.BytesToTopic(topic) } + // Message represents a whisper message. type Message struct { message *whisper.Message } +func (m *Message) GetSig() []byte { return m.message.Sig } +func (m *Message) GetTTL() int32 { return int32(m.message.TTL) } +func (m *Message) GetTimestamp() int32 { return int32(m.message.Timestamp) } +func (m *Message) GetPayload() []byte { return m.message.Payload } +func (m *Message) GetPoW() float64 { return m.message.PoW } +func (m *Message) GetHash() []byte { return m.message.Hash } +func (m *Message) GetDst() []byte { return m.message.Dst } + // Messages represents an array of messages. type Messages struct { messages []*whisper.Message } +// Size returns the number of messages in the slice. +func (m *Messages) Size() int { + return len(m.messages) +} + +// Get returns the message at the given index from the slice. +func (m *Messages) Get(index int) (message *Message, _ error) { + if index < 0 || index >= len(m.messages) { + return nil, errors.New("index out of bounds") + } + return &Message{m.messages[index]}, nil +} + // Criteria holds various filter options for inbound messages. type Criteria struct { criteria *whisper.Criteria } + +func NewCriteria(topic []byte) (*Criteria) { + c := &Criteria{ + criteria: new(whisper.Criteria), + } + encodedTopic := whisper.BytesToTopic(topic) + c.criteria.Topics = []whisper.TopicType{ encodedTopic } + return c +} + +func (c *Criteria) GetSymKeyID() string { return c.criteria.SymKeyID } +func (c *Criteria) SetSymKeyID(symKeyID string) { c.criteria.SymKeyID = symKeyID } +func (c *Criteria) GetPrivateKeyID() string { return c.criteria.PrivateKeyID } +func (c *Criteria) SetPrivateKeyID(privateKeyID string) { c.criteria.PrivateKeyID = privateKeyID } +func (c *Criteria) GetSig() []byte { return c.criteria.Sig } +func (c *Criteria) SetSig(sig []byte) { c.criteria.Sig = sig } +func (c *Criteria) GetMinPow() float64 { return c.criteria.MinPow } +func (c *Criteria) SetMinPow(pow float64) { c.criteria.MinPow = pow } From f22a3e94517c81e11b4aec0c2dc1388a2dbfa96f Mon Sep 17 00:00:00 2001 From: Eugene Valeyev Date: Fri, 12 Jan 2018 12:10:55 +0300 Subject: [PATCH 5/6] mobile: performed gofmt --- mobile/shhclient.go | 2 +- mobile/types.go | 36 +++++++++++++-------------- vendor/gopkg.in/check.v1/benchmark.go | 6 ++--- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/mobile/shhclient.go b/mobile/shhclient.go index 573aa47554..53b1be762d 100644 --- a/mobile/shhclient.go +++ b/mobile/shhclient.go @@ -158,7 +158,7 @@ type NewMessageHandler interface { func (wc *WhisperClient) SubscribeMessages(ctx *Context, criteria *Criteria, handler NewMessageHandler, buffer int) (*Subscription, error) { // Subscribe to the event internally ch := make(chan *whisper.Message, buffer) - rawSub, err := wc.client.SubscribeMessages(ctx.context, *criteria.criteria, ch) + rawSub, err := wc.client.SubscribeMessages(ctx.context, *criteria.criteria, ch) if err != nil { return nil, err } diff --git a/mobile/types.go b/mobile/types.go index 05acb2b9ee..9a8f9ba961 100644 --- a/mobile/types.go +++ b/mobile/types.go @@ -372,7 +372,7 @@ type NewMessage struct { newMessage *whisper.NewMessage } -func NewNewMessage() (*NewMessage) { +func NewNewMessage() *NewMessage { nm := &NewMessage{ newMessage: new(whisper.NewMessage), } @@ -403,13 +403,13 @@ type Message struct { message *whisper.Message } -func (m *Message) GetSig() []byte { return m.message.Sig } -func (m *Message) GetTTL() int32 { return int32(m.message.TTL) } -func (m *Message) GetTimestamp() int32 { return int32(m.message.Timestamp) } -func (m *Message) GetPayload() []byte { return m.message.Payload } -func (m *Message) GetPoW() float64 { return m.message.PoW } -func (m *Message) GetHash() []byte { return m.message.Hash } -func (m *Message) GetDst() []byte { return m.message.Dst } +func (m *Message) GetSig() []byte { return m.message.Sig } +func (m *Message) GetTTL() int32 { return int32(m.message.TTL) } +func (m *Message) GetTimestamp() int32 { return int32(m.message.Timestamp) } +func (m *Message) GetPayload() []byte { return m.message.Payload } +func (m *Message) GetPoW() float64 { return m.message.PoW } +func (m *Message) GetHash() []byte { return m.message.Hash } +func (m *Message) GetDst() []byte { return m.message.Dst } // Messages represents an array of messages. type Messages struct { @@ -434,20 +434,20 @@ type Criteria struct { criteria *whisper.Criteria } -func NewCriteria(topic []byte) (*Criteria) { +func NewCriteria(topic []byte) *Criteria { c := &Criteria{ criteria: new(whisper.Criteria), } encodedTopic := whisper.BytesToTopic(topic) - c.criteria.Topics = []whisper.TopicType{ encodedTopic } + c.criteria.Topics = []whisper.TopicType{encodedTopic} return c } -func (c *Criteria) GetSymKeyID() string { return c.criteria.SymKeyID } -func (c *Criteria) SetSymKeyID(symKeyID string) { c.criteria.SymKeyID = symKeyID } -func (c *Criteria) GetPrivateKeyID() string { return c.criteria.PrivateKeyID } -func (c *Criteria) SetPrivateKeyID(privateKeyID string) { c.criteria.PrivateKeyID = privateKeyID } -func (c *Criteria) GetSig() []byte { return c.criteria.Sig } -func (c *Criteria) SetSig(sig []byte) { c.criteria.Sig = sig } -func (c *Criteria) GetMinPow() float64 { return c.criteria.MinPow } -func (c *Criteria) SetMinPow(pow float64) { c.criteria.MinPow = pow } +func (c *Criteria) GetSymKeyID() string { return c.criteria.SymKeyID } +func (c *Criteria) SetSymKeyID(symKeyID string) { c.criteria.SymKeyID = symKeyID } +func (c *Criteria) GetPrivateKeyID() string { return c.criteria.PrivateKeyID } +func (c *Criteria) SetPrivateKeyID(privateKeyID string) { c.criteria.PrivateKeyID = privateKeyID } +func (c *Criteria) GetSig() []byte { return c.criteria.Sig } +func (c *Criteria) SetSig(sig []byte) { c.criteria.Sig = sig } +func (c *Criteria) GetMinPow() float64 { return c.criteria.MinPow } +func (c *Criteria) SetMinPow(pow float64) { c.criteria.MinPow = pow } diff --git a/vendor/gopkg.in/check.v1/benchmark.go b/vendor/gopkg.in/check.v1/benchmark.go index 46ea9dc6da..b2d351948d 100644 --- a/vendor/gopkg.in/check.v1/benchmark.go +++ b/vendor/gopkg.in/check.v1/benchmark.go @@ -1,9 +1,9 @@ // Copyright (c) 2012 The Go Authors. All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: -// +// // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above @@ -13,7 +13,7 @@ // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR From 9b03dae49908dce96546ae70f60e3b32b92b2589 Mon Sep 17 00:00:00 2001 From: Eugene Valeyev Date: Mon, 15 Jan 2018 13:10:10 +0300 Subject: [PATCH 6/6] mobile: fixed lint warnings --- mobile/shhclient.go | 34 +++++++++++----------------------- mobile/types.go | 12 ++++++------ 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/mobile/shhclient.go b/mobile/shhclient.go index 53b1be762d..c970c7f98c 100644 --- a/mobile/shhclient.go +++ b/mobile/shhclient.go @@ -36,8 +36,7 @@ func NewWhisperClient(rawurl string) (client *WhisperClient, _ error) { // GetVersion returns the Whisper sub-protocol version. func (wc *WhisperClient) GetVersion(ctx *Context) (version string, _ error) { - rawVersion, err := wc.client.Version(ctx.context) - return string(rawVersion), err + return wc.client.Version(ctx.context) } // Info returns diagnostic information about the whisper node. @@ -72,27 +71,23 @@ func (wc *WhisperClient) MarkTrustedPeer(ctx *Context, enode string) error { // NewKeyPair generates a new public and private key pair for message decryption and encryption. // It returns an identifier that can be used to refer to the key. func (wc *WhisperClient) NewKeyPair(ctx *Context) (string, error) { - rawNewKeyPair, err := wc.client.NewKeyPair(ctx.context) - return string(rawNewKeyPair), err + return wc.client.NewKeyPair(ctx.context) } // AddPrivateKey stored the key pair, and returns its ID. func (wc *WhisperClient) AddPrivateKey(ctx *Context, key []byte) (string, error) { - rawAddPrivateKey, err := wc.client.AddPrivateKey(ctx.context, key) - return string(rawAddPrivateKey), err + return wc.client.AddPrivateKey(ctx.context, key) } // DeleteKeyPair delete the specifies key. func (wc *WhisperClient) DeleteKeyPair(ctx *Context, id string) (string, error) { - rawDeletePrivateKey, err := wc.client.DeleteKeyPair(ctx.context, id) - return string(rawDeletePrivateKey), err + return wc.client.DeleteKeyPair(ctx.context, id) } // HasKeyPair returns an indication if the node has a private key or // key pair matching the given ID. func (wc *WhisperClient) HasKeyPair(ctx *Context, id string) (bool, error) { - rawHasKeyPair, err := wc.client.HasKeyPair(ctx.context, id) - return bool(rawHasKeyPair), err + return wc.client.HasKeyPair(ctx.context, id) } // GetPublicKey return the public key for a key ID. @@ -108,26 +103,22 @@ func (wc *WhisperClient) GetPrivateKey(ctx *Context, id string) ([]byte, error) // NewSymmetricKey generates a random symmetric key and returns its identifier. // Can be used encrypting and decrypting messages where the key is known to both parties. func (wc *WhisperClient) NewSymmetricKey(ctx *Context) (string, error) { - rawNewSymmetricKey, err := wc.client.NewSymmetricKey(ctx.context) - return string(rawNewSymmetricKey), err + return wc.client.NewSymmetricKey(ctx.context) } // AddSymmetricKey stores the key, and returns its identifier. func (wc *WhisperClient) AddSymmetricKey(ctx *Context, key []byte) (string, error) { - rawAddSymmetricKey, err := wc.client.AddSymmetricKey(ctx.context, key) - return string(rawAddSymmetricKey), err + return wc.client.AddSymmetricKey(ctx.context, key) } // GenerateSymmetricKeyFromPassword generates the key from password, stores it, and returns its identifier. func (wc *WhisperClient) GenerateSymmetricKeyFromPassword(ctx *Context, passwd string) (string, error) { - rawSymKeyID, err := wc.client.GenerateSymmetricKeyFromPassword(ctx.context, passwd) - return string(rawSymKeyID), err + return wc.client.GenerateSymmetricKeyFromPassword(ctx.context, passwd) } // HasSymmetricKey returns an indication if the key associated with the given id is stored in the node. func (wc *WhisperClient) HasSymmetricKey(ctx *Context, id string) (bool, error) { - rawHasSymmetricKey, err := wc.client.HasSymmetricKey(ctx.context, id) - return bool(rawHasSymmetricKey), err + return wc.client.HasSymmetricKey(ctx.context, id) } // GetSymmetricKey returns the symmetric key associated with the given identifier. @@ -182,8 +173,7 @@ func (wc *WhisperClient) SubscribeMessages(ctx *Context, criteria *Criteria, han // for new messages (see FilterMessages) that satisfy the given criteria. A filter can // timeout when it was polled for in whisper.filterTimeout. func (wc *WhisperClient) NewMessageFilter(ctx *Context, criteria *Criteria) (string, error) { - rawNewMessageFilter, err := wc.client.NewMessageFilter(ctx.context, *criteria.criteria) - return string(rawNewMessageFilter), err + return wc.client.NewMessageFilter(ctx.context, *criteria.criteria) } // DeleteMessageFilter removes the filter associated with the given id. @@ -199,8 +189,6 @@ func (wc *WhisperClient) GetFilterMessages(ctx *Context, id string) (*Messages, return nil, err } res := make([]*whisper.Message, len(rawFilterMessages)) - for i := range rawFilterMessages { - res[i] = rawFilterMessages[i] - } + copy(res, rawFilterMessages) return &Messages{res}, nil } diff --git a/mobile/types.go b/mobile/types.go index 9a8f9ba961..4a6b3b9e63 100644 --- a/mobile/types.go +++ b/mobile/types.go @@ -385,12 +385,12 @@ func (nm *NewMessage) GetPublicKey() []byte { return nm.newMessage.Pu func (nm *NewMessage) SetPublicKey(publicKey []byte) { nm.newMessage.PublicKey = publicKey } func (nm *NewMessage) GetSig() string { return nm.newMessage.Sig } func (nm *NewMessage) SetSig(sig string) { nm.newMessage.Sig = sig } -func (nm *NewMessage) GetTTL() int32 { return int32(nm.newMessage.TTL) } -func (nm *NewMessage) SetTTL(ttl int32) { nm.newMessage.TTL = uint32(ttl) } +func (nm *NewMessage) GetTTL() int64 { return int64(nm.newMessage.TTL) } +func (nm *NewMessage) SetTTL(ttl int64) { nm.newMessage.TTL = uint32(ttl) } func (nm *NewMessage) GetPayload() []byte { return nm.newMessage.Payload } func (nm *NewMessage) SetPayload(payload []byte) { nm.newMessage.Payload = payload } -func (nm *NewMessage) GetPowTime() int32 { return int32(nm.newMessage.PowTime) } -func (nm *NewMessage) SetPowTime(powTime int32) { nm.newMessage.PowTime = uint32(powTime) } +func (nm *NewMessage) GetPowTime() int64 { return int64(nm.newMessage.PowTime) } +func (nm *NewMessage) SetPowTime(powTime int64) { nm.newMessage.PowTime = uint32(powTime) } func (nm *NewMessage) GetPowTarget() float64 { return nm.newMessage.PowTarget } func (nm *NewMessage) SetPowTarget(powTarget float64) { nm.newMessage.PowTarget = powTarget } func (nm *NewMessage) GetTargetPeer() string { return nm.newMessage.TargetPeer } @@ -404,8 +404,8 @@ type Message struct { } func (m *Message) GetSig() []byte { return m.message.Sig } -func (m *Message) GetTTL() int32 { return int32(m.message.TTL) } -func (m *Message) GetTimestamp() int32 { return int32(m.message.Timestamp) } +func (m *Message) GetTTL() int64 { return int64(m.message.TTL) } +func (m *Message) GetTimestamp() int64 { return int64(m.message.Timestamp) } func (m *Message) GetPayload() []byte { return m.message.Payload } func (m *Message) GetPoW() float64 { return m.message.PoW } func (m *Message) GetHash() []byte { return m.message.Hash }