tendermint/peer/server.go

40 lines
785 B
Go
Raw Normal View History

2014-06-24 17:28:40 -07:00
package peer
import (
)
/* Server */
type Server struct {
listener Listener
client *Client
}
func NewServer(protocol string, laddr string, c *Client) *Server {
2014-06-28 13:09:04 -07:00
l := NewDefaultListener(protocol, laddr)
2014-06-24 17:28:40 -07:00
s := &Server{
listener: l,
client: c,
}
2014-06-25 21:37:20 -07:00
go s.IncomingConnectionHandler()
2014-06-24 17:28:40 -07:00
return s
}
func (s *Server) LocalAddress() *NetAddress {
return s.listener.LocalAddress()
}
2014-06-24 17:28:40 -07:00
// meant to run in a goroutine
func (s *Server) IncomingConnectionHandler() {
for conn := range s.listener.Connections() {
2014-06-29 00:35:16 -07:00
log.Infof("New connection found: %v", conn)
2014-06-25 21:37:20 -07:00
s.client.AddPeerWithConnection(conn, false)
2014-06-24 17:28:40 -07:00
}
}
func (s *Server) Stop() {
2014-06-29 00:35:16 -07:00
log.Infof("Stopping server")
2014-06-24 17:28:40 -07:00
s.listener.Stop()
s.client.Stop()
}