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