Skip to content

Commit

Permalink
Merge 6dd5b7b into 165b24a
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau committed Sep 13, 2023
2 parents 165b24a + 6dd5b7b commit 656ea2d
Show file tree
Hide file tree
Showing 19 changed files with 285 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processingOnlyNode
package chainSimulator

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processingOnlyNode
package chainSimulator

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processingOnlyNode
package chainSimulator

import (
"fmt"
Expand Down
72 changes: 72 additions & 0 deletions node/chainSimulator/disabled/antiflooder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package disabled

import (
"time"

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

type antiFlooder struct {
}

// NewAntiFlooder creates a new instance of disabled antiflooder
func NewAntiFlooder() *antiFlooder {
return &antiFlooder{}
}

// CanProcessMessage returns nil
func (a *antiFlooder) CanProcessMessage(_ p2p.MessageP2P, _ core.PeerID) error {
return nil
}

// IsOriginatorEligibleForTopic does nothing and returns nil
func (a *antiFlooder) IsOriginatorEligibleForTopic(_ core.PeerID, _ string) error {
return nil
}

// CanProcessMessagesOnTopic does nothing and returns nil
func (a *antiFlooder) CanProcessMessagesOnTopic(_ core.PeerID, _ string, _ uint32, _ uint64, _ []byte) error {
return nil
}

// ApplyConsensusSize does nothing
func (a *antiFlooder) ApplyConsensusSize(_ int) {
}

// SetDebugger does nothing and returns nil
func (a *antiFlooder) SetDebugger(_ process.AntifloodDebugger) error {
return nil
}

// BlacklistPeer does nothing
func (a *antiFlooder) BlacklistPeer(_ core.PeerID, _ string, _ time.Duration) {
}

// ResetForTopic does nothing
func (a *antiFlooder) ResetForTopic(_ string) {
}

// SetMaxMessagesForTopic does nothing
func (a *antiFlooder) SetMaxMessagesForTopic(_ string, _ uint32) {
}

// SetPeerValidatorMapper does nothing and returns nil
func (a *antiFlooder) SetPeerValidatorMapper(_ process.PeerValidatorMapper) error {
return nil
}

// SetTopicsForAll does nothing
func (a *antiFlooder) SetTopicsForAll(_ ...string) {
}

// Close does nothing and returns nil
func (a *antiFlooder) Close() error {
return nil
}

// IsInterfaceNil returns true if there is no value under the interface
func (a *antiFlooder) IsInterfaceNil() bool {
return a == nil
}
23 changes: 23 additions & 0 deletions node/chainSimulator/disabled/peerHonesty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package disabled

type peerHonesty struct {
}

// NewPeerHonesty creates a new instance of disabled peer honesty
func NewPeerHonesty() *peerHonesty {
return &peerHonesty{}
}

// ChangeScore does nothing
func (p *peerHonesty) ChangeScore(_ string, _ string, _ int) {
}

// Close does nothing and returns nil
func (p *peerHonesty) Close() error {
return nil
}

// IsInterfaceNil returns true if there is no value under the interface
func (p *peerHonesty) IsInterfaceNil() bool {
return p == nil
}
21 changes: 21 additions & 0 deletions node/chainSimulator/disabled/peersRatingMonitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package disabled

import "github.com/multiversx/mx-chain-go/p2p"

type peersRatingMonitor struct {
}

// NewPeersRatingMonitor will create a new disabled peersRatingMonitor instance
func NewPeersRatingMonitor() *peersRatingMonitor {
return &peersRatingMonitor{}
}

// GetConnectedPeersRatings returns an empty string since it is a disabled component
func (monitor *peersRatingMonitor) GetConnectedPeersRatings(_ p2p.ConnectionsHandler) (string, error) {
return "", nil
}

// IsInterfaceNil returns true if there is no value under the interface
func (monitor *peersRatingMonitor) IsInterfaceNil() bool {
return monitor == nil
}
13 changes: 13 additions & 0 deletions node/chainSimulator/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package chainSimulator

import "github.com/multiversx/mx-chain-core-go/core"

// SyncedBroadcastNetworkHandler defines the synced network interface
type SyncedBroadcastNetworkHandler interface {
RegisterMessageReceiver(handler messageReceiver, pid core.PeerID)
Broadcast(pid core.PeerID, topic string, buff []byte)
SendDirectly(from core.PeerID, topic string, buff []byte, to core.PeerID) error
GetConnectedPeers() []core.PeerID
GetConnectedPeersOnTopic(topic string) []core.PeerID
IsInterfaceNil() bool
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processingOnlyNode
package chainSimulator

import (
"github.com/multiversx/mx-chain-go/storage"
Expand Down
108 changes: 108 additions & 0 deletions node/chainSimulator/networkComponents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package chainSimulator

import (
disabledBootstrap "github.com/multiversx/mx-chain-go/epochStart/bootstrap/disabled"
"github.com/multiversx/mx-chain-go/factory"
disabledFactory "github.com/multiversx/mx-chain-go/factory/disabled"
"github.com/multiversx/mx-chain-go/node/chainSimulator/disabled"
"github.com/multiversx/mx-chain-go/p2p"
disabledP2P "github.com/multiversx/mx-chain-go/p2p/disabled"
"github.com/multiversx/mx-chain-go/process"
disabledAntiflood "github.com/multiversx/mx-chain-go/process/throttle/antiflood/disabled"
)

type networkComponentsHolder struct {
networkMessenger p2p.Messenger
inputAntiFloodHandler factory.P2PAntifloodHandler
outputAntiFloodHandler factory.P2PAntifloodHandler
pubKeyCacher process.TimeCacher
peerBlackListHandler process.PeerBlackListCacher
peerHonestyHandler factory.PeerHonestyHandler
preferredPeersHolderHandler factory.PreferredPeersHolderHandler
peersRatingHandler p2p.PeersRatingHandler
peersRatingMonitor p2p.PeersRatingMonitor
fullArchiveNetworkMessenger p2p.Messenger
fullArchivePreferredPeersHolderHandler factory.PreferredPeersHolderHandler
}

// CreateNetworkComponentsHolder creates a new networkComponentsHolder instance
func CreateNetworkComponentsHolder(network SyncedBroadcastNetworkHandler) (*networkComponentsHolder, error) {
messenger, err := NewSyncedMessenger(network)
if err != nil {
return nil, err

Check warning on line 32 in node/chainSimulator/networkComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/networkComponents.go#L32

Added line #L32 was not covered by tests
}

return &networkComponentsHolder{
networkMessenger: messenger,
inputAntiFloodHandler: disabled.NewAntiFlooder(),
outputAntiFloodHandler: disabled.NewAntiFlooder(),
pubKeyCacher: &disabledAntiflood.TimeCache{},
peerBlackListHandler: &disabledAntiflood.PeerBlacklistCacher{},
peerHonestyHandler: disabled.NewPeerHonesty(),
preferredPeersHolderHandler: disabledFactory.NewPreferredPeersHolder(),
peersRatingHandler: disabledBootstrap.NewDisabledPeersRatingHandler(),
peersRatingMonitor: disabled.NewPeersRatingMonitor(),
fullArchiveNetworkMessenger: disabledP2P.NewNetworkMessenger(),
fullArchivePreferredPeersHolderHandler: disabledFactory.NewPreferredPeersHolder(),
}, nil
}

// NetworkMessenger returns the network messenger
func (holder *networkComponentsHolder) NetworkMessenger() p2p.Messenger {
return holder.networkMessenger

Check warning on line 52 in node/chainSimulator/networkComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/networkComponents.go#L51-L52

Added lines #L51 - L52 were not covered by tests
}

// InputAntiFloodHandler returns the input antiflooder
func (holder *networkComponentsHolder) InputAntiFloodHandler() factory.P2PAntifloodHandler {
return holder.inputAntiFloodHandler

Check warning on line 57 in node/chainSimulator/networkComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/networkComponents.go#L56-L57

Added lines #L56 - L57 were not covered by tests
}

// OutputAntiFloodHandler returns the output antiflooder
func (holder *networkComponentsHolder) OutputAntiFloodHandler() factory.P2PAntifloodHandler {
return holder.outputAntiFloodHandler

Check warning on line 62 in node/chainSimulator/networkComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/networkComponents.go#L61-L62

Added lines #L61 - L62 were not covered by tests
}

// PubKeyCacher returns the public key cacher
func (holder *networkComponentsHolder) PubKeyCacher() process.TimeCacher {
return holder.pubKeyCacher

Check warning on line 67 in node/chainSimulator/networkComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/networkComponents.go#L66-L67

Added lines #L66 - L67 were not covered by tests
}

// PeerBlackListHandler returns the peer blacklist handler
func (holder *networkComponentsHolder) PeerBlackListHandler() process.PeerBlackListCacher {
return holder.peerBlackListHandler

Check warning on line 72 in node/chainSimulator/networkComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/networkComponents.go#L71-L72

Added lines #L71 - L72 were not covered by tests
}

// PeerHonestyHandler returns the peer honesty handler
func (holder *networkComponentsHolder) PeerHonestyHandler() factory.PeerHonestyHandler {
return holder.peerHonestyHandler

Check warning on line 77 in node/chainSimulator/networkComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/networkComponents.go#L76-L77

Added lines #L76 - L77 were not covered by tests
}

// PreferredPeersHolderHandler returns the preferred peers holder
func (holder *networkComponentsHolder) PreferredPeersHolderHandler() factory.PreferredPeersHolderHandler {
return holder.preferredPeersHolderHandler

Check warning on line 82 in node/chainSimulator/networkComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/networkComponents.go#L81-L82

Added lines #L81 - L82 were not covered by tests
}

// PeersRatingHandler returns the peers rating handler
func (holder *networkComponentsHolder) PeersRatingHandler() p2p.PeersRatingHandler {
return holder.peersRatingHandler

Check warning on line 87 in node/chainSimulator/networkComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/networkComponents.go#L86-L87

Added lines #L86 - L87 were not covered by tests
}

// PeersRatingMonitor returns the peers rating monitor
func (holder *networkComponentsHolder) PeersRatingMonitor() p2p.PeersRatingMonitor {
return holder.peersRatingMonitor

Check warning on line 92 in node/chainSimulator/networkComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/networkComponents.go#L91-L92

Added lines #L91 - L92 were not covered by tests
}

// FullArchiveNetworkMessenger returns the full archive network messenger
func (holder *networkComponentsHolder) FullArchiveNetworkMessenger() p2p.Messenger {
return holder.fullArchiveNetworkMessenger

Check warning on line 97 in node/chainSimulator/networkComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/networkComponents.go#L96-L97

Added lines #L96 - L97 were not covered by tests
}

// FullArchivePreferredPeersHolderHandler returns the full archive preferred peers holder
func (holder *networkComponentsHolder) FullArchivePreferredPeersHolderHandler() factory.PreferredPeersHolderHandler {
return holder.fullArchivePreferredPeersHolderHandler

Check warning on line 102 in node/chainSimulator/networkComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/networkComponents.go#L101-L102

Added lines #L101 - L102 were not covered by tests
}

// IsInterfaceNil returns true if there is no value under the interface
func (holder *networkComponentsHolder) IsInterfaceNil() bool {
return holder == nil

Check warning on line 107 in node/chainSimulator/networkComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/networkComponents.go#L106-L107

Added lines #L106 - L107 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processingOnlyNode
package chainSimulator

import (
chainData "github.com/multiversx/mx-chain-core-go/data"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processingOnlyNode
package chainSimulator

import (
"time"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processingOnlyNode
package chainSimulator

import (
"github.com/multiversx/mx-chain-core-go/core"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processingOnlyNode
package chainSimulator

import (
"github.com/multiversx/mx-chain-go/dataRetriever"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processingOnlyNode
package chainSimulator

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processingOnlyNode
package chainSimulator

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processingOnlyNode
package chainSimulator

import (
"bytes"
Expand Down Expand Up @@ -29,24 +29,15 @@ var (
errInvalidSignature = errors.New("invalid signature")
)

type syncedBroadcastNetworkHandler interface {
RegisterMessageReceiver(handler messageReceiver, pid core.PeerID)
Broadcast(pid core.PeerID, topic string, buff []byte)
SendDirectly(from core.PeerID, topic string, buff []byte, to core.PeerID) error
GetConnectedPeers() []core.PeerID
GetConnectedPeersOnTopic(topic string) []core.PeerID
IsInterfaceNil() bool
}

type syncedMessenger struct {
mutOperation sync.RWMutex
topics map[string]map[string]p2p.MessageProcessor
network syncedBroadcastNetworkHandler
network SyncedBroadcastNetworkHandler
pid core.PeerID
}

// NewSyncedMessenger creates a new synced network messenger
func NewSyncedMessenger(network syncedBroadcastNetworkHandler) (*syncedMessenger, error) {
func NewSyncedMessenger(network SyncedBroadcastNetworkHandler) (*syncedMessenger, error) {
if check.IfNil(network) {
return nil, errNilNetwork
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package processingOnlyNode
package chainSimulator

import (
"fmt"
Expand Down

0 comments on commit 656ea2d

Please sign in to comment.