2018-06-04 21:10:59 +00:00
|
|
|
// Package p2p handles peer-to-peer networking for the sharding package.
|
|
|
|
package p2p
|
|
|
|
|
|
|
|
import (
|
2018-06-12 12:33:00 +00:00
|
|
|
"reflect"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/event"
|
2018-06-04 21:10:59 +00:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Server is a placeholder for a shardp2p service. To be designed.
|
2018-06-12 12:33:00 +00:00
|
|
|
type Server struct {
|
|
|
|
feeds map[reflect.Type]*event.Feed
|
|
|
|
}
|
2018-06-04 21:10:59 +00:00
|
|
|
|
|
|
|
// NewServer creates a new shardp2p service instance.
|
|
|
|
func NewServer() (*Server, error) {
|
2018-06-12 12:33:00 +00:00
|
|
|
return &Server{
|
|
|
|
feeds: make(map[reflect.Type]*event.Feed),
|
|
|
|
}, nil
|
2018-06-04 21:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start the main routine for an shardp2p server.
|
|
|
|
func (s *Server) Start() error {
|
|
|
|
log.Info("Starting shardp2p server")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop the main shardp2p loop..
|
|
|
|
func (s *Server) Stop() error {
|
|
|
|
log.Info("Stopping shardp2p server")
|
|
|
|
return nil
|
|
|
|
}
|
2018-06-12 12:33:00 +00:00
|
|
|
|
|
|
|
// Feed returns a event feed for the given message type.
|
|
|
|
// TODO(prestonvanloon): Add more to this GoDoc before merging.
|
|
|
|
func (s *Server) Feed(msg interface{}) (*event.Feed, error) {
|
|
|
|
t := reflect.TypeOf(msg)
|
2018-06-12 12:48:46 +00:00
|
|
|
if s.feeds[t] == nil {
|
2018-06-12 12:33:00 +00:00
|
|
|
s.feeds[t] = new(event.Feed)
|
|
|
|
}
|
|
|
|
return s.feeds[t], nil
|
|
|
|
}
|