Remove apparently redundant context params

This commit is contained in:
Samuel Hawksby-Robinson 2020-04-30 12:24:11 +01:00
parent 6346cc5105
commit 557dbd0d64
No known key found for this signature in database
GPG Key ID: 64CF99D4A64A1205
5 changed files with 43 additions and 48 deletions

View File

@ -1,8 +1,6 @@
package gethbridge
import (
"context"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/status-im/status-go/eth-node/types"
@ -26,18 +24,18 @@ func NewGethPublicWakuAPIWrapper(api *waku.PublicWakuAPI) types.PublicWakuAPI {
}
// AddPrivateKey imports the given private key.
func (w *gethPublicWakuAPIWrapper) AddPrivateKey(ctx context.Context, privateKey types.HexBytes) (string, error) {
return w.api.AddPrivateKey(ctx, hexutil.Bytes(privateKey))
func (w *gethPublicWakuAPIWrapper) AddPrivateKey(privateKey types.HexBytes) (string, error) {
return w.api.AddPrivateKey(hexutil.Bytes(privateKey))
}
// GenerateSymKeyFromPassword derives a key from the given password, stores it, and returns its ID.
func (w *gethPublicWakuAPIWrapper) GenerateSymKeyFromPassword(ctx context.Context, passwd string) (string, error) {
return w.api.GenerateSymKeyFromPassword(ctx, passwd)
func (w *gethPublicWakuAPIWrapper) GenerateSymKeyFromPassword(passwd string) (string, error) {
return w.api.GenerateSymKeyFromPassword(passwd)
}
// DeleteKeyPair removes the key with the given key if it exists.
func (w *gethPublicWakuAPIWrapper) DeleteKeyPair(ctx context.Context, key string) (bool, error) {
return w.api.DeleteKeyPair(ctx, key)
func (w *gethPublicWakuAPIWrapper) DeleteKeyPair(key string) (bool, error) {
return w.api.DeleteKeyPair(key)
}
// NewMessageFilter creates a new filter that can be used to poll for
@ -87,7 +85,7 @@ func (w *gethPublicWakuAPIWrapper) GetFilterMessages(id string) ([]*types.Messag
// Post posts a message on the network.
// returns the hash of the message in case of success.
func (w *gethPublicWakuAPIWrapper) Post(ctx context.Context, req types.NewMessage) ([]byte, error) {
func (w *gethPublicWakuAPIWrapper) Post(req types.NewMessage) ([]byte, error) {
msg := waku.NewMessage{
SymKeyID: req.SymKeyID,
PublicKey: req.PublicKey,
@ -100,5 +98,5 @@ func (w *gethPublicWakuAPIWrapper) Post(ctx context.Context, req types.NewMessag
PowTarget: req.PowTarget,
TargetPeer: req.TargetPeer,
}
return w.api.Post(ctx, msg)
return w.api.Post(msg)
}

View File

@ -68,15 +68,15 @@ type PublicWhisperAPI interface {
// use publicly without security implications.
type PublicWakuAPI interface {
// AddPrivateKey imports the given private key.
AddPrivateKey(ctx context.Context, privateKey HexBytes) (string, error)
AddPrivateKey(privateKey HexBytes) (string, error)
// GenerateSymKeyFromPassword derives a key from the given password, stores it, and returns its ID.
GenerateSymKeyFromPassword(ctx context.Context, passwd string) (string, error)
GenerateSymKeyFromPassword(passwd string) (string, error)
// DeleteKeyPair removes the key with the given key if it exists.
DeleteKeyPair(ctx context.Context, key string) (bool, error)
DeleteKeyPair(key string) (bool, error)
// Post posts a message on the Whisper network.
// returns the hash of the message in case of success.
Post(ctx context.Context, req NewMessage) ([]byte, error)
Post(req NewMessage) ([]byte, error)
// NewMessageFilter creates a new filter that can be used to poll for
// (new) messages that satisfy the given criteria.

View File

@ -1,7 +1,6 @@
package waku
import (
"context"
"errors"
"sync"
@ -259,7 +258,7 @@ func (m *EnvelopesMonitor) handleEnvelopeFailure(hash types.Hash, err error) {
}
if attempt < m.maxAttempts {
m.logger.Debug("retrying to send a message", zap.String("hash", hash.String()), zap.Int("attempt", attempt+1))
hex, err := m.api.Post(context.TODO(), *message)
hex, err := m.api.Post(*message)
if err != nil {
m.logger.Error("failed to retry sending message", zap.String("hash", hash.String()), zap.Int("attempt", attempt+1), zap.Error(err))
if m.handler != nil {

View File

@ -96,7 +96,7 @@ func NewTransport(
envelopesMonitor.Start()
}
var api types.PublicWhisperAPI
var api types.PublicWakuAPI
if waku != nil {
api = waku.PublicWakuAPI()
}
@ -277,7 +277,7 @@ func (a *Transport) RetrieveRawAll() (map[transport.Filter][]*types.Message, err
// SendPublic sends a new message using the Whisper service.
// For public filters, chat name is used as an ID as well as
// a topic.
func (a *Transport) SendPublic(ctx context.Context, newMessage *types.NewMessage, chatName string) ([]byte, error) {
func (a *Transport) SendPublic(newMessage *types.NewMessage, chatName string) ([]byte, error) {
if err := a.addSig(newMessage); err != nil {
return nil, err
}
@ -290,10 +290,10 @@ func (a *Transport) SendPublic(ctx context.Context, newMessage *types.NewMessage
newMessage.SymKeyID = filter.SymKeyID
newMessage.Topic = filter.Topic
return a.api.Post(ctx, *newMessage)
return a.api.Post(*newMessage)
}
func (a *Transport) SendPrivateWithSharedSecret(ctx context.Context, newMessage *types.NewMessage, publicKey *ecdsa.PublicKey, secret []byte) ([]byte, error) {
func (a *Transport) SendPrivateWithSharedSecret(newMessage *types.NewMessage, publicKey *ecdsa.PublicKey, secret []byte) ([]byte, error) {
if err := a.addSig(newMessage); err != nil {
return nil, err
}
@ -310,10 +310,10 @@ func (a *Transport) SendPrivateWithSharedSecret(ctx context.Context, newMessage
newMessage.Topic = filter.Topic
newMessage.PublicKey = nil
return a.api.Post(ctx, *newMessage)
return a.api.Post(*newMessage)
}
func (a *Transport) SendPrivateWithPartitioned(ctx context.Context, newMessage *types.NewMessage, publicKey *ecdsa.PublicKey) ([]byte, error) {
func (a *Transport) SendPrivateWithPartitioned(newMessage *types.NewMessage, publicKey *ecdsa.PublicKey) ([]byte, error) {
if err := a.addSig(newMessage); err != nil {
return nil, err
}
@ -326,10 +326,10 @@ func (a *Transport) SendPrivateWithPartitioned(ctx context.Context, newMessage *
newMessage.Topic = filter.Topic
newMessage.PublicKey = crypto.FromECDSAPub(publicKey)
return a.api.Post(ctx, *newMessage)
return a.api.Post(*newMessage)
}
func (a *Transport) SendPrivateOnDiscovery(ctx context.Context, newMessage *types.NewMessage, publicKey *ecdsa.PublicKey) ([]byte, error) {
func (a *Transport) SendPrivateOnDiscovery(newMessage *types.NewMessage, publicKey *ecdsa.PublicKey) ([]byte, error) {
if err := a.addSig(newMessage); err != nil {
return nil, err
}
@ -343,7 +343,7 @@ func (a *Transport) SendPrivateOnDiscovery(ctx context.Context, newMessage *type
newMessage.Topic = types.BytesToTopic(transport.ToTopic(transport.DiscoveryTopic()))
newMessage.PublicKey = crypto.FromECDSAPub(publicKey)
return a.api.Post(ctx, *newMessage)
return a.api.Post(*newMessage)
}
func (a *Transport) addSig(newMessage *types.NewMessage) error {

View File

@ -70,10 +70,8 @@ type Info struct {
MaxMessageSize uint32 `json:"maxMessageSize"` // Maximum accepted message size
}
// TODO does anyone know why all the PublicWakuAPI methods have an unused context.Context?
// Doesn't seem to be an interface implementation hangover.
// Info returns diagnostic information about the waku node.
func (api *PublicWakuAPI) Info(ctx context.Context) Info {
func (api *PublicWakuAPI) Info() Info {
return Info{
Messages: len(api.w.msgQueue) + len(api.w.p2pMsgQueue),
MinPow: api.w.MinPow(),
@ -83,23 +81,23 @@ func (api *PublicWakuAPI) Info(ctx context.Context) Info {
// SetMaxMessageSize sets the maximum message size that is accepted.
// Upper limit is defined by MaxMessageSize.
func (api *PublicWakuAPI) SetMaxMessageSize(ctx context.Context, size uint32) (bool, error) {
func (api *PublicWakuAPI) SetMaxMessageSize(size uint32) (bool, error) {
return true, api.w.SetMaxMessageSize(size)
}
// SetMinPoW sets the minimum PoW, and notifies the peers.
func (api *PublicWakuAPI) SetMinPoW(ctx context.Context, pow float64) (bool, error) {
func (api *PublicWakuAPI) SetMinPoW(pow float64) (bool, error) {
return true, api.w.SetMinimumPoW(pow, true)
}
// SetBloomFilter sets the new value of bloom filter, and notifies the peers.
func (api *PublicWakuAPI) SetBloomFilter(ctx context.Context, bloom hexutil.Bytes) (bool, error) {
func (api *PublicWakuAPI) SetBloomFilter(bloom hexutil.Bytes) (bool, error) {
return true, api.w.SetBloomFilter(bloom)
}
// MarkTrustedPeer marks a 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 (api *PublicWakuAPI) MarkTrustedPeer(ctx context.Context, url string) (bool, error) {
func (api *PublicWakuAPI) MarkTrustedPeer(url string) (bool, error) {
n, err := enode.Parse(enode.ValidSchemes, url)
if err != nil {
return false, err
@ -109,12 +107,12 @@ func (api *PublicWakuAPI) MarkTrustedPeer(ctx context.Context, url string) (bool
// NewKeyPair generates a new public and private key pair for message decryption and encryption.
// It returns an ID that can be used to refer to the keypair.
func (api *PublicWakuAPI) NewKeyPair(ctx context.Context) (string, error) {
func (api *PublicWakuAPI) NewKeyPair() (string, error) {
return api.w.NewKeyPair()
}
// AddPrivateKey imports the given private key.
func (api *PublicWakuAPI) AddPrivateKey(ctx context.Context, privateKey hexutil.Bytes) (string, error) {
func (api *PublicWakuAPI) AddPrivateKey(privateKey hexutil.Bytes) (string, error) {
key, err := crypto.ToECDSA(privateKey)
if err != nil {
return "", err
@ -123,7 +121,7 @@ func (api *PublicWakuAPI) AddPrivateKey(ctx context.Context, privateKey hexutil.
}
// DeleteKeyPair removes the key with the given key if it exists.
func (api *PublicWakuAPI) DeleteKeyPair(ctx context.Context, key string) (bool, error) {
func (api *PublicWakuAPI) DeleteKeyPair(key string) (bool, error) {
if ok := api.w.DeleteKeyPair(key); ok {
return true, nil
}
@ -131,13 +129,13 @@ func (api *PublicWakuAPI) DeleteKeyPair(ctx context.Context, key string) (bool,
}
// HasKeyPair returns an indication if the node has a key pair that is associated with the given id.
func (api *PublicWakuAPI) HasKeyPair(ctx context.Context, id string) bool {
func (api *PublicWakuAPI) HasKeyPair(id string) bool {
return api.w.HasKeyPair(id)
}
// GetPublicKey returns the public key associated with the given key. The key is the hex
// encoded representation of a key in the form specified in section 4.3.6 of ANSI X9.62.
func (api *PublicWakuAPI) GetPublicKey(ctx context.Context, id string) (hexutil.Bytes, error) {
func (api *PublicWakuAPI) GetPublicKey(id string) (hexutil.Bytes, error) {
key, err := api.w.GetPrivateKey(id)
if err != nil {
return hexutil.Bytes{}, err
@ -147,7 +145,7 @@ func (api *PublicWakuAPI) GetPublicKey(ctx context.Context, id string) (hexutil.
// GetPrivateKey returns the private key associated with the given key. The key is the hex
// encoded representation of a key in the form specified in section 4.3.6 of ANSI X9.62.
func (api *PublicWakuAPI) GetPrivateKey(ctx context.Context, id string) (hexutil.Bytes, error) {
func (api *PublicWakuAPI) GetPrivateKey(id string) (hexutil.Bytes, error) {
key, err := api.w.GetPrivateKey(id)
if err != nil {
return hexutil.Bytes{}, err
@ -158,46 +156,46 @@ func (api *PublicWakuAPI) GetPrivateKey(ctx context.Context, id string) (hexutil
// NewSymKey generate a random symmetric key.
// It returns an ID that can be used to refer to the key.
// Can be used encrypting and decrypting messages where the key is known to both parties.
func (api *PublicWakuAPI) NewSymKey(ctx context.Context) (string, error) {
func (api *PublicWakuAPI) NewSymKey() (string, error) {
return api.w.GenerateSymKey()
}
// AddSymKey import a symmetric key.
// It returns an ID that can be used to refer to the key.
// Can be used encrypting and decrypting messages where the key is known to both parties.
func (api *PublicWakuAPI) AddSymKey(ctx context.Context, key hexutil.Bytes) (string, error) {
return api.w.AddSymKeyDirect([]byte(key))
func (api *PublicWakuAPI) AddSymKey(key hexutil.Bytes) (string, error) {
return api.w.AddSymKeyDirect(key)
}
// GenerateSymKeyFromPassword derive a key from the given password, stores it, and returns its ID.
func (api *PublicWakuAPI) GenerateSymKeyFromPassword(ctx context.Context, passwd string) (string, error) {
func (api *PublicWakuAPI) GenerateSymKeyFromPassword(passwd string) (string, error) {
return api.w.AddSymKeyFromPassword(passwd)
}
// HasSymKey returns an indication if the node has a symmetric key associated with the given key.
func (api *PublicWakuAPI) HasSymKey(ctx context.Context, id string) bool {
func (api *PublicWakuAPI) HasSymKey(id string) bool {
return api.w.HasSymKey(id)
}
// GetSymKey returns the symmetric key associated with the given id.
func (api *PublicWakuAPI) GetSymKey(ctx context.Context, id string) (hexutil.Bytes, error) {
func (api *PublicWakuAPI) GetSymKey(id string) (hexutil.Bytes, error) {
return api.w.GetSymKey(id)
}
// DeleteSymKey deletes the symmetric key that is associated with the given id.
func (api *PublicWakuAPI) DeleteSymKey(ctx context.Context, id string) bool {
func (api *PublicWakuAPI) DeleteSymKey(id string) bool {
return api.w.DeleteSymKey(id)
}
// MakeLightClient turns the node into light client, which does not forward
// any incoming messages, and sends only messages originated in this node.
func (api *PublicWakuAPI) MakeLightClient(ctx context.Context) bool {
func (api *PublicWakuAPI) MakeLightClient() bool {
api.w.SetLightClientMode(true)
return api.w.LightClientMode()
}
// CancelLightClient cancels light client mode.
func (api *PublicWakuAPI) CancelLightClient(ctx context.Context) bool {
func (api *PublicWakuAPI) CancelLightClient() bool {
api.w.SetLightClientMode(false)
return !api.w.LightClientMode()
}
@ -220,7 +218,7 @@ type NewMessage struct {
// Post posts a message on the Waku network.
// returns the hash of the message in case of success.
func (api *PublicWakuAPI) Post(ctx context.Context, req NewMessage) (hexutil.Bytes, error) {
func (api *PublicWakuAPI) Post(req NewMessage) (hexutil.Bytes, error) {
var (
symKeyGiven = len(req.SymKeyID) > 0
pubKeyGiven = len(req.PublicKey) > 0