2018-06-13 02:06:59 +00:00
|
|
|
package p2p
|
|
|
|
|
2018-08-29 16:32:54 +00:00
|
|
|
import (
|
2018-09-20 11:46:35 +00:00
|
|
|
"context"
|
2018-09-09 22:15:24 +00:00
|
|
|
"reflect"
|
|
|
|
|
2018-08-29 16:32:54 +00:00
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
)
|
|
|
|
|
2018-06-13 02:06:59 +00:00
|
|
|
// Message represents a message received from an external peer.
|
|
|
|
type Message struct {
|
2018-09-20 11:46:35 +00:00
|
|
|
// Ctx message context.
|
|
|
|
Ctx context.Context
|
2018-06-13 02:06:59 +00:00
|
|
|
// Peer represents the sender of the message.
|
|
|
|
Peer Peer
|
2018-07-17 18:39:04 +00:00
|
|
|
// Data can be any type of message found in sharding/p2p/proto package.
|
2018-08-29 16:32:54 +00:00
|
|
|
Data proto.Message
|
2018-06-13 02:06:59 +00:00
|
|
|
}
|
2018-09-09 22:15:24 +00:00
|
|
|
|
|
|
|
// messageType returns the underlying struct type for a given proto.message.
|
|
|
|
func messageType(msg proto.Message) reflect.Type {
|
|
|
|
// proto.Message is a pointer and we need to dereference the pointer
|
|
|
|
// and take the type of the original struct. Otherwise reflect.TypeOf will
|
|
|
|
// create a new value of type **pb.BeaconBlockHashAnnounce for example.
|
|
|
|
return reflect.ValueOf(msg).Elem().Type()
|
|
|
|
}
|