2018-08-29 16:32:54 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
2018-09-09 22:15:24 +00:00
|
|
|
"github.com/golang/protobuf/proto"
|
2018-11-08 03:22:31 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/sharding/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-09-20 11:46:35 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/p2p/adapter/tracer"
|
|
|
|
"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{
|
|
|
|
pb.Topic_COLLATION_BODY_REQUEST: &pb.CollationBodyRequest{},
|
|
|
|
pb.Topic_COLLATION_BODY_RESPONSE: &pb.CollationBodyResponse{},
|
|
|
|
pb.Topic_TRANSACTIONS: &pb.Transaction{},
|
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
|
|
|
|
}
|
|
|
|
|
2018-09-20 11:46:35 +00:00
|
|
|
traceAdapter, err := tracer.New("validator",
|
|
|
|
ctx.GlobalString(cmd.TracingEndpointFlag.Name),
|
|
|
|
ctx.GlobalFloat64(cmd.TraceSampleFractionFlag.Name),
|
|
|
|
ctx.GlobalBool(cmd.EnableTracingFlag.Name))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-09-20 04:14:31 +00:00
|
|
|
// TODO(437): Define default adapters for logging, monitoring, etc.
|
2018-09-20 11:46:35 +00:00
|
|
|
adapters := []p2p.Adapter{traceAdapter}
|
2018-08-29 16:32:54 +00:00
|
|
|
for k, v := range topicMappings {
|
|
|
|
s.RegisterTopic(k.String(), v, adapters...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return s, nil
|
|
|
|
}
|