Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mx-chain-p2p-go #5037

Merged
merged 3 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cmd/keygenerator/converter/pidPubkeyConverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ import (
crypto "github.com/multiversx/mx-chain-crypto-go"
"github.com/multiversx/mx-chain-crypto-go/signing"
"github.com/multiversx/mx-chain-crypto-go/signing/secp256k1"
"github.com/multiversx/mx-chain-go/p2p"
"github.com/multiversx/mx-chain-go/p2p/factory"
logger "github.com/multiversx/mx-chain-logger-go"
)

var log = logger.GetOrCreate("cmd/keygenerator/converter")

type pidPubkeyConverter struct {
keyGen crypto.KeyGenerator
keyGen crypto.KeyGenerator
p2PKeyConverter p2p.P2PKeyConverter
}

// NewPidPubkeyConverter creates a new instance of a public key converter that can handle conversions involving core.PeerID string representations
func NewPidPubkeyConverter() *pidPubkeyConverter {
return &pidPubkeyConverter{
keyGen: signing.NewKeyGenerator(secp256k1.NewSecp256k1()),
keyGen: signing.NewKeyGenerator(secp256k1.NewSecp256k1()),
p2PKeyConverter: factory.NewP2PKeyConverter(),
}
}

Expand Down Expand Up @@ -51,7 +54,7 @@ func (converter *pidPubkeyConverter) encode(pkBytes []byte) (string, error) {
return "", err
}

pid, err := factory.ConvertPublicKeyToPeerID(pk)
pid, err := converter.p2PKeyConverter.ConvertPublicKeyToPeerID(pk)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/multiversx/mx-chain-crypto-go v1.2.5
github.com/multiversx/mx-chain-es-indexer-go v1.3.12
github.com/multiversx/mx-chain-logger-go v1.0.11
github.com/multiversx/mx-chain-p2p-go v1.0.11
github.com/multiversx/mx-chain-p2p-go v1.0.13
github.com/multiversx/mx-chain-storage-go v1.0.7
github.com/multiversx/mx-chain-vm-common-go v1.3.37
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.50
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,8 @@ github.com/multiversx/mx-chain-es-indexer-go v1.3.12 h1:b7B8KMrCHM0Ghh4W0s1jXLI5
github.com/multiversx/mx-chain-es-indexer-go v1.3.12/go.mod h1:IV42GfhkqQ5vVO0OzGaF/ejp8TQrLkNo4LSB3TPnVhg=
github.com/multiversx/mx-chain-logger-go v1.0.11 h1:DFsHa+sc5fKwhDR50I8uBM99RTDTEW68ESyr5ALRDwE=
github.com/multiversx/mx-chain-logger-go v1.0.11/go.mod h1:1srDkP0DQucWQ+rYfaq0BX2qLnULsUdRPADpYUTM6dA=
github.com/multiversx/mx-chain-p2p-go v1.0.11 h1:lzGLvE/liPmNtJxbmEAWKWP9iy2XB6DNjCw0ZogLtTk=
github.com/multiversx/mx-chain-p2p-go v1.0.11/go.mod h1:j9Ueo2ptCnL7TQvQg6KS/KWAoJEJpjkPgE5ZTaqEAn4=
github.com/multiversx/mx-chain-p2p-go v1.0.13 h1:woIlYkDFCKYyJQ5urDcOzz8HUFGsSEhTfUXDDxNI2zM=
github.com/multiversx/mx-chain-p2p-go v1.0.13/go.mod h1:j9Ueo2ptCnL7TQvQg6KS/KWAoJEJpjkPgE5ZTaqEAn4=
github.com/multiversx/mx-chain-storage-go v1.0.7 h1:UqLo/OLTD3IHiE/TB/SEdNRV1GG2f1R6vIP5ehHwCNw=
github.com/multiversx/mx-chain-storage-go v1.0.7/go.mod h1:gtKoV32Cg2Uy8deHzF8Ud0qAl0zv92FvWgPSYIP0Zmg=
github.com/multiversx/mx-chain-vm-common-go v1.3.34/go.mod h1:sZ2COLCxvf2GxAAJHGmGqWybObLtFuk2tZUyGqnMXE8=
Expand Down
8 changes: 3 additions & 5 deletions p2p/factory/factory.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package factory

import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-crypto-go"
"github.com/multiversx/mx-chain-go/p2p"
"github.com/multiversx/mx-chain-p2p-go/libp2p"
p2pCrypto "github.com/multiversx/mx-chain-p2p-go/libp2p/crypto"
Expand Down Expand Up @@ -45,9 +43,9 @@ func NewPeersHolder(preferredConnectionAddresses []string) (p2p.PreferredPeersHo
return peersHolder.NewPeersHolder(preferredConnectionAddresses)
}

// ConvertPublicKeyToPeerID will convert a public key to core.PeerID
func ConvertPublicKeyToPeerID(pk crypto.PublicKey) (core.PeerID, error) {
return p2pCrypto.ConvertPublicKeyToPeerID(pk)
// NewP2PKeyConverter returns a new instance of p2pKeyConverter
func NewP2PKeyConverter() p2p.P2PKeyConverter {
return p2pCrypto.NewP2PKeyConverter()
}

// NewMessageVerifier will return a new instance of messages verifier
Expand Down
8 changes: 8 additions & 0 deletions p2p/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/multiversx/mx-chain-core-go/core"
crypto "github.com/multiversx/mx-chain-crypto-go"
p2p "github.com/multiversx/mx-chain-p2p-go"
)

Expand Down Expand Up @@ -112,3 +113,10 @@ type IdentityGenerator interface {
CreateRandomP2PIdentity() ([]byte, core.PeerID, error)
IsInterfaceNil() bool
}

// P2PKeyConverter defines what a p2p key converter can do
type P2PKeyConverter interface {
ConvertPeerIDToPublicKey(keyGen crypto.KeyGenerator, pid core.PeerID) (crypto.PublicKey, error)
ConvertPublicKeyToPeerID(pk crypto.PublicKey) (core.PeerID, error)
IsInterfaceNil() bool
}