tendermint/peer/server.go

40 lines
721 B
Go
Raw Normal View History

2014-06-24 17:28:40 -07:00
package peer
import (
"sync/atomic"
"net"
2014-06-24 17:28:40 -07:00
)
/* Server */
type Server struct {
listener Listener
client *Client
}
func NewServer(protocol string, laddr string, c *Client) *Server {
l := NewListener(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-25 21:37:20 -07:00
s.client.AddPeerWithConnection(conn, false)
2014-06-24 17:28:40 -07:00
}
}
func (s *Server) Stop() {
s.listener.Stop()
s.client.Stop()
}