func()

in internal/sshd/sshd.go [107:141]


func (s *Server) listen(ctx context.Context) error {
	sshListener, err := net.Listen("tcp", s.Config.Server.Listen)
	if err != nil {
		return fmt.Errorf("failed to listen for connection: %w", err)
	}

	if s.Config.Server.ProxyProtocol {
		policy, err := s.proxyPolicy()
		if err != nil {
			return fmt.Errorf("invalid policy configuration: %w", err)
		}

		sshListener = &proxyproto.Listener{
			Listener:          sshListener,
			Policy:            policy,
			ReadHeaderTimeout: time.Duration(s.Config.Server.ProxyHeaderTimeout),
		}

		log.ContextLogger(ctx).Info("Proxy protocol is enabled")
	}

	fields := log.Fields{
		"tcp_address": sshListener.Addr().String(),
	}

	if len(s.serverConfig.cfg.Server.PublicKeyAlgorithms) > 0 {
		fields["supported_public_key_algorithms"] = s.serverConfig.cfg.Server.PublicKeyAlgorithms
	}

	log.WithContextFields(ctx, fields).Info("Listening for SSH connections")

	s.listener = sshListener

	return nil
}