You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
785 B

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. package peer
  2. import (
  3. )
  4. /* Server */
  5. type Server struct {
  6. listener Listener
  7. client *Client
  8. }
  9. func NewServer(protocol string, laddr string, c *Client) *Server {
  10. l := NewDefaultListener(protocol, laddr)
  11. s := &Server{
  12. listener: l,
  13. client: c,
  14. }
  15. go s.IncomingConnectionHandler()
  16. return s
  17. }
  18. func (s *Server) LocalAddress() *NetAddress {
  19. return s.listener.LocalAddress()
  20. }
  21. // meant to run in a goroutine
  22. func (s *Server) IncomingConnectionHandler() {
  23. for conn := range s.listener.Connections() {
  24. log.Infof("New connection found: %v", conn)
  25. s.client.AddPeerWithConnection(conn, false)
  26. }
  27. }
  28. func (s *Server) Stop() {
  29. log.Infof("Stopping server")
  30. s.listener.Stop()
  31. s.client.Stop()
  32. }