Skip to content

Commit

Permalink
renamed xxxWithPrivateKey/xxxWithSk to xxxUsingPrivateKey
Browse files Browse the repository at this point in the history
  • Loading branch information
sstanculeanu committed Aug 30, 2022
1 parent 7823d6d commit 704702e
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion consensus/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type BroadcastMessenger interface {
// P2PMessenger defines a subset of the p2p.Messenger interface
type P2PMessenger interface {
Broadcast(topic string, buff []byte)
BroadcastWithPrivateKey(topic string, buff []byte, pid core.PeerID, skBytes []byte)
BroadcastUsingPrivateKey(topic string, buff []byte, pid core.PeerID, skBytes []byte)
IsInterfaceNil() bool
}

Expand Down
12 changes: 6 additions & 6 deletions consensus/mock/messengerStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import "github.com/ElrondNetwork/elrond-go-core/core"

// MessengerStub -
type MessengerStub struct {
BroadcastWithPrivateKeyCalled func(topic string, buff []byte, pid core.PeerID, skBytes []byte)
BroadcastCalled func(topic string, buff []byte)
BroadcastUsingPrivateKeyCalled func(topic string, buff []byte, pid core.PeerID, skBytes []byte)
BroadcastCalled func(topic string, buff []byte)
}

// Broadcast -
func (ms *MessengerStub) Broadcast(topic string, buff []byte) {
ms.BroadcastCalled(topic, buff)
}

// BroadcastWithPrivateKey -
func (ms *MessengerStub) BroadcastWithPrivateKey(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
if ms.BroadcastWithPrivateKeyCalled != nil {
ms.BroadcastWithPrivateKeyCalled(topic, buff, pid, skBytes)
// BroadcastUsingPrivateKey -
func (ms *MessengerStub) BroadcastUsingPrivateKey(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
if ms.BroadcastUsingPrivateKeyCalled != nil {
ms.BroadcastUsingPrivateKeyCalled(topic, buff, pid, skBytes)
}
}

Expand Down
4 changes: 2 additions & 2 deletions heartbeat/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
// P2PMessenger defines a subset of the p2p.Messenger interface
type P2PMessenger interface {
Broadcast(topic string, buff []byte)
BroadcastWithPrivateKey(topic string, buff []byte, pid core.PeerID, skBytes []byte)
BroadcastUsingPrivateKey(topic string, buff []byte, pid core.PeerID, skBytes []byte)
ID() core.PeerID
Sign(payload []byte) ([]byte, error)
SignWithPrivateKey(skBytes []byte, payload []byte) ([]byte, error)
SignUsingPrivateKey(skBytes []byte, payload []byte) ([]byte, error)
IsInterfaceNil() bool
}

Expand Down
28 changes: 14 additions & 14 deletions heartbeat/mock/messengerStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (

// MessengerStub -
type MessengerStub struct {
IDCalled func() core.PeerID
BroadcastCalled func(topic string, buff []byte)
BroadcastWithPrivateKeyCalled func(topic string, buff []byte, pid core.PeerID, skBytes []byte)
SignCalled func(payload []byte) ([]byte, error)
SignWithPrivateKeyCalled func(skBytes []byte, payload []byte) ([]byte, error)
VerifyCalled func(payload []byte, pid core.PeerID, signature []byte) error
IDCalled func() core.PeerID
BroadcastCalled func(topic string, buff []byte)
BroadcastUsingPrivateKeyCalled func(topic string, buff []byte, pid core.PeerID, skBytes []byte)
SignCalled func(payload []byte) ([]byte, error)
SignUsingPrivateKeyCalled func(skBytes []byte, payload []byte) ([]byte, error)
VerifyCalled func(payload []byte, pid core.PeerID, signature []byte) error
}

// ID -
Expand All @@ -30,10 +30,10 @@ func (ms *MessengerStub) Broadcast(topic string, buff []byte) {
}
}

// BroadcastWithPrivateKey -
func (ms *MessengerStub) BroadcastWithPrivateKey(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
if ms.BroadcastWithPrivateKeyCalled != nil {
ms.BroadcastWithPrivateKeyCalled(topic, buff, pid, skBytes)
// BroadcastUsingPrivateKey -
func (ms *MessengerStub) BroadcastUsingPrivateKey(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
if ms.BroadcastUsingPrivateKeyCalled != nil {
ms.BroadcastUsingPrivateKeyCalled(topic, buff, pid, skBytes)
}
}

Expand All @@ -46,10 +46,10 @@ func (ms *MessengerStub) Sign(payload []byte) ([]byte, error) {
return make([]byte, 0), nil
}

// SignWithPrivateKey -
func (ms *MessengerStub) SignWithPrivateKey(skBytes []byte, payload []byte) ([]byte, error) {
if ms.SignWithPrivateKeyCalled != nil {
return ms.SignWithPrivateKeyCalled(skBytes, payload)
// SignUsingPrivateKey -
func (ms *MessengerStub) SignUsingPrivateKey(skBytes []byte, payload []byte) ([]byte, error) {
if ms.SignUsingPrivateKeyCalled != nil {
return ms.SignUsingPrivateKeyCalled(skBytes, payload)
}

return make([]byte, 0), nil
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/sender/commonPeerAuthenticationSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (cpas *commonPeerAuthenticationSender) generateMessageBytes(
msg.Payload = payloadBytes

if p2pSkBytes != nil {
msg.PayloadSignature, err = cpas.messenger.SignWithPrivateKey(p2pSkBytes, payloadBytes)
msg.PayloadSignature, err = cpas.messenger.SignUsingPrivateKey(p2pSkBytes, payloadBytes)
if err != nil {
return nil, isTriggered, err
}
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/sender/multikeyPeerAuthenticationSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (sender *multikeyPeerAuthenticationSender) sendData(pkBytes []byte, data []
log.Error("could not get identity for pk", "pk", hex.EncodeToString(pkBytes), "error", err)
return
}
sender.messenger.BroadcastWithPrivateKey(sender.topic, data, pid, p2pSk)
sender.messenger.BroadcastUsingPrivateKey(sender.topic, data, pid, p2pSk)

nextTimeToCheck, err := sender.keysHolder.GetNextPeerAuthenticationTime(pkBytes)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions heartbeat/sender/multikeyPeerAuthenticationSender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func createMockMultikeyPeerAuthenticationSenderArgsSemiIntegrationTests(
}

messenger := &mock.MessengerStub{
SignWithPrivateKeyCalled: func(skBytes []byte, payload []byte) ([]byte, error) {
SignUsingPrivateKeyCalled: func(skBytes []byte, payload []byte) ([]byte, error) {
p2pSk, _ := keyGenForP2P.PrivateKeyFromByteArray(skBytes)

return signerMessenger.Sign(p2pSk, payload)
Expand Down Expand Up @@ -332,7 +332,7 @@ func TestNewMultikeyPeerAuthenticationSender_Execute(t *testing.T) {
var skBytesBroadcast [][]byte

args, messenger := createMockMultikeyPeerAuthenticationSenderArgsSemiIntegrationTests(numKeys)
messenger.BroadcastWithPrivateKeyCalled = func(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
messenger.BroadcastUsingPrivateKeyCalled = func(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
assert.Equal(t, args.topic, topic)

mutData.Lock()
Expand All @@ -359,7 +359,7 @@ func TestNewMultikeyPeerAuthenticationSender_Execute(t *testing.T) {
var skBytesBroadcast [][]byte

args, messenger := createMockMultikeyPeerAuthenticationSenderArgsSemiIntegrationTests(numKeys)
messenger.BroadcastWithPrivateKeyCalled = func(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
messenger.BroadcastUsingPrivateKeyCalled = func(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
assert.Equal(t, args.topic, topic)

mutData.Lock()
Expand Down Expand Up @@ -404,7 +404,7 @@ func TestNewMultikeyPeerAuthenticationSender_Execute(t *testing.T) {
var skBytesBroadcast [][]byte

args, messenger := createMockMultikeyPeerAuthenticationSenderArgsSemiIntegrationTests(numKeys)
messenger.BroadcastWithPrivateKeyCalled = func(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
messenger.BroadcastUsingPrivateKeyCalled = func(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
assert.Equal(t, args.topic, topic)

mutData.Lock()
Expand Down Expand Up @@ -463,7 +463,7 @@ func TestNewMultikeyPeerAuthenticationSender_Execute(t *testing.T) {
var skBytesBroadcast [][]byte

args, messenger := createMockMultikeyPeerAuthenticationSenderArgsSemiIntegrationTests(numKeys)
messenger.BroadcastWithPrivateKeyCalled = func(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
messenger.BroadcastUsingPrivateKeyCalled = func(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
assert.Equal(t, args.topic, topic)

mutData.Lock()
Expand Down Expand Up @@ -526,7 +526,7 @@ func TestNewMultikeyPeerAuthenticationSender_Execute(t *testing.T) {
var skBytesBroadcast [][]byte

args, messenger := createMockMultikeyPeerAuthenticationSenderArgsSemiIntegrationTests(numKeys)
messenger.BroadcastWithPrivateKeyCalled = func(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
messenger.BroadcastUsingPrivateKeyCalled = func(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
assert.Equal(t, args.topic, topic)

mutData.Lock()
Expand Down Expand Up @@ -589,7 +589,7 @@ func TestNewMultikeyPeerAuthenticationSender_Execute(t *testing.T) {
var skBytesBroadcast [][]byte

args, messenger := createMockMultikeyPeerAuthenticationSenderArgsSemiIntegrationTests(numKeys)
messenger.BroadcastWithPrivateKeyCalled = func(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
messenger.BroadcastUsingPrivateKeyCalled = func(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
assert.Equal(t, args.topic, topic)

mutData.Lock()
Expand Down
4 changes: 2 additions & 2 deletions p2p/crypto/p2pSigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func (signer *p2pSigner) Verify(payload []byte, pid core.PeerID, signature []byt
return nil
}

// SignWithPrivateKey will sign the payload with provided private key bytes
func (signer *p2pSigner) SignWithPrivateKey(skBytes []byte, payload []byte) ([]byte, error) {
// SignUsingPrivateKey will sign the payload with provided private key bytes
func (signer *p2pSigner) SignUsingPrivateKey(skBytes []byte, payload []byte) ([]byte, error) {
sk, err := libp2pCrypto.UnmarshalPrivateKey(skBytes)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions p2p/crypto/p2pSigner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestP2pSigner_Verify(t *testing.T) {
})
}

func TestP2PSigner_SignWithPrivateKey(t *testing.T) {
func TestP2PSigner_SignUsingPrivateKey(t *testing.T) {
t.Parallel()

payload := []byte("payload")
Expand All @@ -120,10 +120,10 @@ func TestP2PSigner_SignWithPrivateKey(t *testing.T) {

p2pSigner := &p2pSigner{}

sig1, err := p2pSigner.SignWithPrivateKey(skBytes1, payload)
sig1, err := p2pSigner.SignUsingPrivateKey(skBytes1, payload)
assert.Nil(t, err)

sig2, err := p2pSigner.SignWithPrivateKey(skBytes2, payload)
sig2, err := p2pSigner.SignUsingPrivateKey(skBytes2, payload)
assert.Nil(t, err)
assert.NotEqual(t, sig1, sig2)

Expand Down Expand Up @@ -165,7 +165,7 @@ func TestP2pSigner_ConcurrentOperations(t *testing.T) {
errVerify := signer.Verify(payload1, pid, sig1)
assert.Nil(t, errVerify)
case 2:
_, errSignWithSK := signer.SignWithPrivateKey(skBytes, payload3)
_, errSignWithSK := signer.SignUsingPrivateKey(skBytes, payload3)
assert.Nil(t, errSignWithSK)
}

Expand Down
2 changes: 1 addition & 1 deletion p2p/libp2p/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ type PeerDiscovererWithSharder interface {
type p2pSigner interface {
Sign(payload []byte) ([]byte, error)
Verify(payload []byte, pid core.PeerID, signature []byte) error
SignWithPrivateKey(skBytes []byte, payload []byte) ([]byte, error)
SignUsingPrivateKey(skBytes []byte, payload []byte) ([]byte, error)
}
16 changes: 8 additions & 8 deletions p2p/libp2p/netMessenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,9 @@ func (netMes *networkMessenger) Broadcast(topic string, buff []byte) {
netMes.BroadcastOnChannel(topic, topic, buff)
}

// BroadcastOnChannelBlockingWithPrivateKey tries to send a byte buffer onto a topic using provided channel
// BroadcastOnChannelBlockingUsingPrivateKey tries to send a byte buffer onto a topic using provided channel
// It is a blocking method. It needs to be launched on a go routine
func (netMes *networkMessenger) BroadcastOnChannelBlockingWithPrivateKey(
func (netMes *networkMessenger) BroadcastOnChannelBlockingUsingPrivateKey(
channel string,
topic string,
buff []byte,
Expand Down Expand Up @@ -963,30 +963,30 @@ func (netMes *networkMessenger) BroadcastOnChannelBlockingWithPrivateKey(
return nil
}

// BroadcastOnChannelWithPrivateKey tries to send a byte buffer onto a topic using provided channel
func (netMes *networkMessenger) BroadcastOnChannelWithPrivateKey(
// BroadcastOnChannelUsingPrivateKey tries to send a byte buffer onto a topic using provided channel
func (netMes *networkMessenger) BroadcastOnChannelUsingPrivateKey(
channel string,
topic string,
buff []byte,
pid core.PeerID,
skBytes []byte,
) {
go func() {
err := netMes.BroadcastOnChannelBlockingWithPrivateKey(channel, topic, buff, pid, skBytes)
err := netMes.BroadcastOnChannelBlockingUsingPrivateKey(channel, topic, buff, pid, skBytes)
if err != nil {
log.Warn("p2p broadcast", "error", err.Error())
}
}()
}

// BroadcastWithPrivateKey tries to send a byte buffer onto a topic using the topic name as channel
func (netMes *networkMessenger) BroadcastWithPrivateKey(
// BroadcastUsingPrivateKey tries to send a byte buffer onto a topic using the topic name as channel
func (netMes *networkMessenger) BroadcastUsingPrivateKey(
topic string,
buff []byte,
pid core.PeerID,
skBytes []byte,
) {
netMes.BroadcastOnChannelWithPrivateKey(topic, topic, buff, pid, skBytes)
netMes.BroadcastOnChannelUsingPrivateKey(topic, topic, buff, pid, skBytes)
}

// RegisterMessageProcessor registers a message process on a topic. The function allows registering multiple handlers
Expand Down
4 changes: 2 additions & 2 deletions p2p/libp2p/netMessenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ func TestLibp2pMessenger_ConnectionTopic(t *testing.T) {
})
}

func TestNetworkMessenger_BroadcastWithPrivateKey(t *testing.T) {
func TestNetworkMessenger_BroadcastUsingPrivateKey(t *testing.T) {
if testing.Short() {
t.Skip("this is not a short test")
}
Expand Down Expand Up @@ -1969,7 +1969,7 @@ func TestNetworkMessenger_BroadcastWithPrivateKey(t *testing.T) {
assert.Nil(t, err)
fmt.Printf("new identity: %s\n", pid.Pretty())

mes1.BroadcastWithPrivateKey(topic, msg, pid, skBuff)
mes1.BroadcastUsingPrivateKey(topic, msg, pid, skBuff)

time.Sleep(time.Second * 2)

Expand Down
6 changes: 3 additions & 3 deletions p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ type Messenger interface {
// through a specified channel.
BroadcastOnChannel(channel string, topic string, buff []byte)

// BroadcastWithPrivateKey tries to send a byte buffer onto a topic using the topic name as channel
BroadcastWithPrivateKey(topic string, buff []byte, pid core.PeerID, skBytes []byte)
// BroadcastUsingPrivateKey tries to send a byte buffer onto a topic using the topic name as channel
BroadcastUsingPrivateKey(topic string, buff []byte, pid core.PeerID, skBytes []byte)

// Broadcast is a convenience function that calls BroadcastOnChannelBlocking,
// but implicitly sets the channel to be identical to the specified topic.
Expand All @@ -172,7 +172,7 @@ type Messenger interface {
WaitForConnections(maxWaitingTime time.Duration, minNumOfPeers uint32)
Sign(payload []byte) ([]byte, error)
Verify(payload []byte, pid core.PeerID, signature []byte) error
SignWithPrivateKey(skBytes []byte, payload []byte) ([]byte, error)
SignUsingPrivateKey(skBytes []byte, payload []byte) ([]byte, error)

// IsInterfaceNil returns true if there is no value under the interface
IsInterfaceNil() bool
Expand Down
20 changes: 10 additions & 10 deletions testscommon/p2pmocks/messengerStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type MessengerStub struct {
WaitForConnectionsCalled func(maxWaitingTime time.Duration, minNumOfPeers uint32)
SignCalled func(payload []byte) ([]byte, error)
VerifyCalled func(payload []byte, pid core.PeerID, signature []byte) error
BroadcastWithPrivateKeyCalled func(topic string, buff []byte, pid core.PeerID, skBytes []byte)
SignWithPrivateKeyCalled func(skBytes []byte, payload []byte) ([]byte, error)
BroadcastUsingPrivateKeyCalled func(topic string, buff []byte, pid core.PeerID, skBytes []byte)
SignUsingPrivateKeyCalled func(skBytes []byte, payload []byte) ([]byte, error)
}

// ConnectedFullHistoryPeersOnTopic -
Expand Down Expand Up @@ -337,17 +337,17 @@ func (ms *MessengerStub) Verify(payload []byte, pid core.PeerID, signature []byt
return nil
}

// BroadcastWithPrivateKey -
func (ms *MessengerStub) BroadcastWithPrivateKey(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
if ms.BroadcastWithPrivateKeyCalled != nil {
ms.BroadcastWithPrivateKeyCalled(topic, buff, pid, skBytes)
// BroadcastUsingPrivateKey -
func (ms *MessengerStub) BroadcastUsingPrivateKey(topic string, buff []byte, pid core.PeerID, skBytes []byte) {
if ms.BroadcastUsingPrivateKeyCalled != nil {
ms.BroadcastUsingPrivateKeyCalled(topic, buff, pid, skBytes)
}
}

// SignWithPrivateKey -
func (ms *MessengerStub) SignWithPrivateKey(skBytes []byte, payload []byte) ([]byte, error) {
if ms.SignWithPrivateKeyCalled != nil {
return ms.SignWithPrivateKeyCalled(skBytes, payload)
// SignUsingPrivateKey -
func (ms *MessengerStub) SignUsingPrivateKey(skBytes []byte, payload []byte) ([]byte, error) {
if ms.SignUsingPrivateKeyCalled != nil {
return ms.SignUsingPrivateKeyCalled(skBytes, payload)
}

return make([]byte, 0), nil
Expand Down

0 comments on commit 704702e

Please sign in to comment.