-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4414 from ElrondNetwork/peer_auth_sender_factory
Peer authentication sender factory
- Loading branch information
Showing
24 changed files
with
415 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package sender | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/ElrondNetwork/covalent-indexer-go/process" | ||
crypto "github.com/ElrondNetwork/elrond-go-crypto" | ||
"github.com/ElrondNetwork/elrond-go/heartbeat" | ||
) | ||
|
||
type argPeerAuthenticationSenderFactory struct { | ||
argBaseSender | ||
nodesCoordinator heartbeat.NodesCoordinator | ||
peerSignatureHandler crypto.PeerSignatureHandler | ||
hardforkTrigger heartbeat.HardforkTrigger | ||
hardforkTimeBetweenSends time.Duration | ||
hardforkTriggerPubKey []byte | ||
keysHolder heartbeat.KeysHolder | ||
timeBetweenChecks time.Duration | ||
shardCoordinator process.ShardCoordinator | ||
privKey crypto.PrivateKey | ||
redundancyHandler heartbeat.NodeRedundancyHandler | ||
} | ||
|
||
func createPeerAuthenticationSender(args argPeerAuthenticationSenderFactory) (peerAuthenticationSenderHandler, error) { | ||
pk := args.privKey.GeneratePublic() | ||
pkBytes, err := pk.ToByteArray() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
keysMap := args.keysHolder.GetManagedKeysByCurrentNode() | ||
isMultikeyMode := len(keysMap) > 0 | ||
_, _, err = args.nodesCoordinator.GetValidatorWithPublicKey(pkBytes) | ||
if err == nil { | ||
if isMultikeyMode { | ||
return nil, fmt.Errorf("%w while creating peer authentication, could not determine node's type", heartbeat.ErrInvalidConfiguration) | ||
} | ||
|
||
return createRegularSender(args) | ||
} | ||
|
||
if !isMultikeyMode { | ||
return createRegularSender(args) | ||
} | ||
|
||
return createMultikeySender(args) | ||
} | ||
|
||
func createRegularSender(args argPeerAuthenticationSenderFactory) (*peerAuthenticationSender, error) { | ||
argsSender := argPeerAuthenticationSender{ | ||
argBaseSender: args.argBaseSender, | ||
nodesCoordinator: args.nodesCoordinator, | ||
peerSignatureHandler: args.peerSignatureHandler, | ||
privKey: args.privKey, | ||
redundancyHandler: args.redundancyHandler, | ||
hardforkTrigger: args.hardforkTrigger, | ||
hardforkTimeBetweenSends: args.hardforkTimeBetweenSends, | ||
hardforkTriggerPubKey: args.hardforkTriggerPubKey, | ||
} | ||
|
||
return newPeerAuthenticationSender(argsSender) | ||
} | ||
|
||
func createMultikeySender(args argPeerAuthenticationSenderFactory) (*multikeyPeerAuthenticationSender, error) { | ||
argsSender := argMultikeyPeerAuthenticationSender{ | ||
argBaseSender: args.argBaseSender, | ||
nodesCoordinator: args.nodesCoordinator, | ||
peerSignatureHandler: args.peerSignatureHandler, | ||
hardforkTrigger: args.hardforkTrigger, | ||
hardforkTimeBetweenSends: args.hardforkTimeBetweenSends, | ||
hardforkTriggerPubKey: args.hardforkTriggerPubKey, | ||
keysHolder: args.keysHolder, | ||
timeBetweenChecks: args.timeBetweenChecks, | ||
shardCoordinator: args.shardCoordinator, | ||
} | ||
|
||
return newMultikeyPeerAuthenticationSender(argsSender) | ||
} |
Oops, something went wrong.