2018-06-12 22:06:59 -04:00
|
|
|
package p2p
|
|
|
|
|
2018-08-29 12:32:54 -04:00
|
|
|
import (
|
2018-09-20 17:16:35 +05:30
|
|
|
"context"
|
2018-09-09 18:15:24 -04:00
|
|
|
"reflect"
|
|
|
|
|
2018-12-23 15:34:59 -05:00
|
|
|
"github.com/gogo/protobuf/proto"
|
2018-08-29 12:32:54 -04:00
|
|
|
)
|
|
|
|
|
2018-06-12 22:06:59 -04:00
|
|
|
// Message represents a message received from an external peer.
|
|
|
|
type Message struct {
|
2018-09-20 17:16:35 +05:30
|
|
|
// Ctx message context.
|
|
|
|
Ctx context.Context
|
2018-06-12 22:06:59 -04:00
|
|
|
// Peer represents the sender of the message.
|
|
|
|
Peer Peer
|
2018-07-17 14:39:04 -04:00
|
|
|
// Data can be any type of message found in sharding/p2p/proto package.
|
2018-08-29 12:32:54 -04:00
|
|
|
Data proto.Message
|
2018-06-12 22:06:59 -04:00
|
|
|
}
|
2018-09-09 18:15:24 -04: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()
|
|
|
|
}
|