prysm-pulse/sharding/p2p/feed.go
Raul Jordan 1ddb19bba6 Handle and Simulate Collation Body Requests/Responses (#172)
sharding: create a syncer and a simulator package

Former-commit-id: b392885510ba5a96e61278cbbe2c0ec6f9722ee8 [formerly 3a435eaf6805d02beae55656f155b2c3a66ee663]
Former-commit-id: 0f6f3f2053ae77711e2072848b727b0dc9b92276
2018-06-20 22:03:02 -05:00

34 lines
1020 B
Go

package p2p
import (
"reflect"
"github.com/ethereum/go-ethereum/event"
)
// P2P feed is a one to many subscription feed of the argument type.
//
// Messages received via p2p protocol are sent to subscribers by these event
// feeds. Message consumers should not use event feeds to reply to or broadcast
// messages. The p2p server will not relay them to peers. Rather, use the
// Send() or Broadcast() method on p2p.Server.
//
// Event feeds from p2p will always be of type p2p.Message. The message
// contains information about the sender, aka the peer, and the message payload
// itself.
//
// feed, err := ps.Feed(MyMessage{})
// ch := make(chan p2p.Message, 100) // Choose a reasonable buffer size!
// sub := feed.Subscribe(ch)
//
// // Wait until my message comes from a peer.
// msg := <- ch
// fmt.Printf("Message received: %v", msg.Data)
func (s *Server) Feed(msg interface{}) *event.Feed {
t := reflect.TypeOf(msg)
if s.feeds[t] == nil {
s.feeds[t] = new(event.Feed)
}
return s.feeds[t]
}