tendermint/peer/server.go

37 lines
718 B
Go
Raw Normal View History

2014-06-24 17:28:40 -07:00
package peer
/* Server */
type Server struct {
2014-07-01 14:50:24 -07:00
listener Listener
client *Client
2014-06-24 17:28:40 -07:00
}
func NewServer(protocol string, laddr string, c *Client) *Server {
2014-07-01 14:50:24 -07:00
l := NewDefaultListener(protocol, laddr)
s := &Server{
listener: l,
client: c,
}
go s.IncomingConnectionHandler()
return s
2014-06-24 17:28:40 -07:00
}
2014-07-04 19:29:02 -07:00
func (s *Server) ExternalAddress() *NetAddress {
return s.listener.ExternalAddress()
}
2014-06-24 17:28:40 -07:00
// meant to run in a goroutine
func (s *Server) IncomingConnectionHandler() {
2014-07-01 14:50:24 -07:00
for conn := range s.listener.Connections() {
log.Infof("New connection found: %v", conn)
s.client.AddPeerWithConnection(conn, false)
}
2014-06-24 17:28:40 -07:00
}
// stops the server, not the client.
2014-06-24 17:28:40 -07:00
func (s *Server) Stop() {
2014-07-01 14:50:24 -07:00
log.Infof("Stopping server")
s.listener.Stop()
2014-06-24 17:28:40 -07:00
}