2018-08-29 16:32:54 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
2018-12-23 20:34:59 +00:00
|
|
|
"github.com/gogo/protobuf/proto"
|
2018-11-08 03:22:31 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
2018-09-20 11:46:35 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/cmd"
|
2018-08-29 16:32:54 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/p2p"
|
2018-11-15 12:54:45 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/p2p/adapter/metric"
|
2018-09-20 11:46:35 +00:00
|
|
|
"github.com/urfave/cli"
|
2018-08-29 16:32:54 +00:00
|
|
|
)
|
|
|
|
|
2018-09-09 22:15:24 +00:00
|
|
|
var topicMappings = map[pb.Topic]proto.Message{
|
2018-11-21 18:00:36 +00:00
|
|
|
pb.Topic_BEACON_BLOCK_ANNOUNCE: &pb.BeaconBlockAnnounce{},
|
2018-09-09 22:15:24 +00:00
|
|
|
pb.Topic_BEACON_BLOCK_REQUEST: &pb.BeaconBlockRequest{},
|
|
|
|
pb.Topic_BEACON_BLOCK_REQUEST_BY_SLOT_NUMBER: &pb.BeaconBlockRequestBySlotNumber{},
|
|
|
|
pb.Topic_BEACON_BLOCK_RESPONSE: &pb.BeaconBlockResponse{},
|
2018-12-26 14:16:46 +00:00
|
|
|
pb.Topic_BATCHED_BEACON_BLOCK_REQUEST: &pb.BatchedBeaconBlockRequest{},
|
|
|
|
pb.Topic_BATCHED_BEACON_BLOCK_RESPONSE: &pb.BatchedBeaconBlockResponse{},
|
2018-11-19 01:59:11 +00:00
|
|
|
pb.Topic_CHAIN_HEAD_REQUEST: &pb.ChainHeadRequest{},
|
|
|
|
pb.Topic_CHAIN_HEAD_RESPONSE: &pb.ChainHeadResponse{},
|
2018-12-01 22:09:12 +00:00
|
|
|
pb.Topic_BEACON_STATE_HASH_ANNOUNCE: &pb.BeaconStateHashAnnounce{},
|
|
|
|
pb.Topic_BEACON_STATE_REQUEST: &pb.BeaconStateRequest{},
|
|
|
|
pb.Topic_BEACON_STATE_RESPONSE: &pb.BeaconStateResponse{},
|
2019-03-20 03:54:16 +00:00
|
|
|
pb.Topic_ATTESTATION_ANNOUNCE: &pb.AttestationAnnounce{},
|
|
|
|
pb.Topic_ATTESTATION_REQUEST: &pb.AttestationRequest{},
|
|
|
|
pb.Topic_ATTESTATION_RESPONSE: &pb.AttestationResponse{},
|
2018-08-29 16:32:54 +00:00
|
|
|
}
|
|
|
|
|
2018-09-20 11:46:35 +00:00
|
|
|
func configureP2P(ctx *cli.Context) (*p2p.Server, error) {
|
2018-11-25 16:55:02 +00:00
|
|
|
s, err := p2p.NewServer(&p2p.ServerConfig{
|
|
|
|
BootstrapNodeAddr: ctx.GlobalString(cmd.BootstrapNode.Name),
|
|
|
|
RelayNodeAddr: ctx.GlobalString(cmd.RelayNode.Name),
|
2018-11-26 02:54:02 +00:00
|
|
|
Port: ctx.GlobalInt(cmd.P2PPort.Name),
|
2018-11-25 16:55:02 +00:00
|
|
|
})
|
2018-08-29 16:32:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-03-17 02:56:05 +00:00
|
|
|
adapters := []p2p.Adapter{}
|
2018-11-15 12:54:45 +00:00
|
|
|
if !ctx.GlobalBool(cmd.DisableMonitoringFlag.Name) {
|
|
|
|
adapters = append(adapters, metric.New())
|
|
|
|
}
|
|
|
|
|
2018-08-29 16:32:54 +00:00
|
|
|
for k, v := range topicMappings {
|
|
|
|
s.RegisterTopic(k.String(), v, adapters...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return s, nil
|
|
|
|
}
|