Skip to content

Commit

Permalink
add trusted peers flag
Browse files Browse the repository at this point in the history
  • Loading branch information
minhd-vu committed Aug 14, 2023
1 parent b898915 commit b627cc7
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions cmd/p2p/sensor/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type (
Bootnodes string
NetworkID uint64
NodesFile string
TrustedNodesFile string
ProjectID string
SensorID string
MaxPeers int
Expand All @@ -54,11 +55,12 @@ type (
NAT string
QuickStart bool

bootnodes []*enode.Node
nodes []*enode.Node
privateKey *ecdsa.PrivateKey
genesis core.Genesis
nat nat.Interface
bootnodes []*enode.Node
nodes []*enode.Node
trustedNodes []*enode.Node
privateKey *ecdsa.PrivateKey
genesis core.Genesis
nat nat.Interface
}
)

Expand All @@ -80,6 +82,13 @@ var SensorCmd = &cobra.Command{
log.Warn().Err(err).Msgf("Creating nodes file %v because it does not exist", inputSensorParams.NodesFile)
}

if len(inputSensorParams.TrustedNodesFile) > 0 {
inputSensorParams.trustedNodes, err = p2p.ReadNodeSet(inputSensorParams.TrustedNodesFile)
if err != nil {
log.Warn().Err(err).Msgf("Trusted nodes file %v not found", inputSensorParams.TrustedNodesFile)
}
}

if len(inputSensorParams.Bootnodes) > 0 {
inputSensorParams.bootnodes, err = p2p.ParseBootnodes(inputSensorParams.Bootnodes)
if err != nil {
Expand Down Expand Up @@ -175,6 +184,7 @@ var SensorCmd = &cobra.Command{
config := ethp2p.Config{
PrivateKey: inputSensorParams.privateKey,
BootstrapNodes: inputSensorParams.bootnodes,
TrustedNodes: inputSensorParams.trustedNodes,
MaxPeers: inputSensorParams.MaxPeers,
ListenAddr: fmt.Sprintf(":%d", inputSensorParams.Port),
DiscAddr: fmt.Sprintf(":%d", inputSensorParams.DiscoveryPort),
Expand Down Expand Up @@ -269,7 +279,7 @@ func getLatestBlock(url string) (*rpctypes.RawBlockResponse, error) {
}

func init() {
SensorCmd.PersistentFlags().StringVarP(&inputSensorParams.Bootnodes, "bootnodes", "b", "", `Comma separated nodes used for bootstrapping`)
SensorCmd.PersistentFlags().StringVarP(&inputSensorParams.Bootnodes, "bootnodes", "b", "", "Comma separated nodes used for bootstrapping")
SensorCmd.PersistentFlags().Uint64VarP(&inputSensorParams.NetworkID, "network-id", "n", 0, "Filter discovered nodes by this network ID")
if err := SensorCmd.MarkPersistentFlagRequired("network-id"); err != nil {
log.Error().Err(err).Msg("Failed to mark network-id as required persistent flag")
Expand Down Expand Up @@ -308,4 +318,5 @@ connections to be dialed. Setting this to 0 defaults it to 3.`)
`Whether to load the nodes.json as static nodes to quickly start the network.
This produces faster development cycles but can prevent the sensor from being to
connect to new peers if the nodes.json file is large.`)
SensorCmd.PersistentFlags().StringVar(&inputSensorParams.TrustedNodesFile, "trusted-nodes", "", "Trusted nodes file")
}

0 comments on commit b627cc7

Please sign in to comment.