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-12-23 20:34:59 +00:00
|
|
|
"github.com/gogo/protobuf/proto"
|
2019-03-08 02:37:15 +00:00
|
|
|
peer "github.com/libp2p/go-libp2p-peer"
|
2018-08-29 16:32:54 +00:00
|
|
|
)
|
|
|
|
|
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.
|
2019-03-08 02:37:15 +00:00
|
|
|
Peer peer.ID
|
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()
|
|
|
|
}
|