prysm-pulse/beacon-chain/node/p2p_config.go
Preston Van Loon 82efca9b6f
Move p2p to deprecated-p2p (#3191)
* move to deprecated-p2p

* fix lint

* lint?

* fix lint

* lint

* lint

* lint

* lint
2019-08-13 14:52:04 -04:00

76 lines
2.9 KiB
Go

package node
import (
"strings"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/prysm/beacon-chain/flags"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/cmd"
p2p "github.com/prysmaticlabs/prysm/shared/deprecated-p2p"
"github.com/prysmaticlabs/prysm/shared/deprecated-p2p/adapter/metric"
"github.com/urfave/cli"
)
// Deprecated: Do not use. See #3147.
var deprecatedTopicMappings = map[pb.Topic]proto.Message{
pb.Topic_BEACON_BLOCK_ANNOUNCE: &pb.BeaconBlockAnnounce{},
pb.Topic_BEACON_BLOCK_REQUEST: &pb.BeaconBlockRequest{},
pb.Topic_BEACON_BLOCK_REQUEST_BY_SLOT_NUMBER: &pb.BeaconBlockRequestBySlotNumber{},
pb.Topic_BEACON_BLOCK_RESPONSE: &pb.BeaconBlockResponse{},
pb.Topic_BATCHED_BEACON_BLOCK_REQUEST: &pb.BatchedBeaconBlockRequest{},
pb.Topic_BATCHED_BEACON_BLOCK_RESPONSE: &pb.BatchedBeaconBlockResponse{},
pb.Topic_CHAIN_HEAD_REQUEST: &pb.ChainHeadRequest{},
pb.Topic_CHAIN_HEAD_RESPONSE: &pb.ChainHeadResponse{},
pb.Topic_BEACON_STATE_HASH_ANNOUNCE: &pb.BeaconStateHashAnnounce{},
pb.Topic_BEACON_STATE_REQUEST: &pb.BeaconStateRequest{},
pb.Topic_BEACON_STATE_RESPONSE: &pb.BeaconStateResponse{},
pb.Topic_BEACON_ATTESTATION: &ethpb.Attestation{},
}
// Deprecated: Do not use. See #3147.
func deprecatedConfigureP2P(ctx *cli.Context) (*p2p.Server, error) {
contractAddress := ctx.GlobalString(flags.DepositContractFlag.Name)
if contractAddress == "" {
var err error
contractAddress, err = fetchDepositContract()
if err != nil {
return nil, err
}
}
staticPeers := []string{}
for _, entry := range ctx.GlobalStringSlice(cmd.StaticPeers.Name) {
peers := strings.Split(entry, ",")
staticPeers = append(staticPeers, peers...)
}
s, err := p2p.NewServer(&p2p.ServerConfig{
NoDiscovery: ctx.GlobalBool(cmd.NoDiscovery.Name),
StaticPeers: staticPeers,
BootstrapNodeAddr: ctx.GlobalString(cmd.BootstrapNode.Name),
RelayNodeAddr: ctx.GlobalString(cmd.RelayNode.Name),
HostAddress: ctx.GlobalString(cmd.P2PHost.Name),
Port: ctx.GlobalInt(cmd.P2PPort.Name),
MaxPeers: ctx.GlobalInt(cmd.P2PMaxPeers.Name),
PrvKey: ctx.GlobalString(cmd.P2PPrivKey.Name),
DepositContractAddress: contractAddress,
WhitelistCIDR: ctx.GlobalString(cmd.P2PWhitelist.Name),
EnableUPnP: ctx.GlobalBool(cmd.EnableUPnPFlag.Name),
})
if err != nil {
return nil, err
}
adapters := []p2p.Adapter{}
if !ctx.GlobalBool(cmd.DisableMonitoringFlag.Name) {
adapters = append(adapters, metric.New())
}
for k, v := range deprecatedTopicMappings {
s.RegisterTopic(k.String(), v, adapters...)
}
return s, nil
}