// newLogDogStreamServerForPlatform creates a StreamServer instance usable on
// POSIX.
196686
func newLogDogStreamServerForPlatform(ctx context.Context, workDir string) (streamserver.StreamServer, error) {
	// POSIX, use UNIX domain socket.
	return streamserver.NewUNIXDomainSocketServer(ctx, filepath.Join(workDir, "ld.sock"))
}
423863
func resolveLogDogAnnotations(c context.Context, tagsRaw []string) (*types.StreamAddr, error) {
	addr, err := resolveLogDogStreamAddrFromTags(swarmingTags(tagsRaw))
	if err != nil {
		logging.WithError(err).Debugf(c, "Could not resolve stream address from tags.")
		return nil, grpcutil.NotFound
	}
	return addr, nil
}
447201
func NewLoggerFromLoggingConfig(loggingConfig *logconfig.LoggingConfig) (*logging.Logger, error) {
	if loggingConfig == nil {
		return NewStdErrLogger()
	} else {
		outputLogger, errCh, err := loggerFromLoggingConfig(loggingConfig)
		if err != nil {
			return nil, err
		}
		logger := logging.NewLogger(outputLogger)
		if !loggingConfig.Trace {
			logger.Trace = log.NewNopLogger()
		}
		go func() {
			err := <-errCh.Out()
			if err != nil {
				fmt.Printf("Logging error: %v", err)
			}
		}()
		return logger, nil
	}
}
845710
func NewPostgresAdapter(schema string, log *logger.Logger) *PostgresAdapter {
	return &PostgresAdapter{
		Log:    log,
		Schema: schema,
	}
}
26108
func NewObvForStream(priceStream gotrade.DOHLCVStreamSubscriber) (indicator *Obv, err error) {
	ind, err := NewObv()
	priceStream.AddTickSubscription(ind)
	return ind, err
}
1083589
func NewRocPForStream(priceStream gotrade.DOHLCVStreamSubscriber, timePeriod int, selectData gotrade.DOHLCVDataSelectionFunc) (indicator *RocP, err error) {
	ind, err := NewRocP(timePeriod, selectData)
	priceStream.AddTickSubscription(ind)
	return ind, err
}
1261104
func (as *Step) AddLogdogStreamLink(server, label string, prefix, name types.StreamName) {
	link := as.getOrCreateLinkForLabel(label)
	link.Value = &milo.Link_LogdogStream{&milo.LogdogStream{
		Name:   string(name),
		Server: server,
		Prefix: string(prefix),
	}}
}
1075840
func NewServerLogger(config *Config, logger *log.Logger, tokens *token.Store, tlsConfigurator *tlsutil.Configurator) (*Server, error) {
	// Check the protocol version.
	if err := config.CheckProtocolVersion(); err != nil {
		return nil, err
	}

	// Check for a data directory.
	if config.DataDir == "" && !config.DevMode {
		return nil, fmt.Errorf("Config must provide a DataDir")
	}

	// Sanity check the ACLs.
	if err := config.CheckACL(); err != nil {
		return nil, err
	}

	// Ensure we have a log output and create a logger.
	if config.LogOutput == nil {
		config.LogOutput = os.Stderr
	}
	if logger == nil {
		logger = log.New(config.LogOutput, "", log.LstdFlags)
	}

	// Check if TLS is enabled
	if config.CAFile != "" || config.CAPath != "" {
		config.UseTLS = true
	}

	// Set the primary DC if it wasn't set.
	if config.PrimaryDatacenter == "" {
		if config.ACLDatacenter != "" {
			config.PrimaryDatacenter = config.ACLDatacenter
		} else {
			config.PrimaryDatacenter = config.Datacenter
		}
	}

	// Create the tombstone GC.
	gc, err := state.NewTombstoneGC(config.TombstoneTTL, config.TombstoneTTLGranularity)
	if err != nil {
		return nil, err
	}

	// Create the shutdown channel - this is closed but never written to.
	shutdownCh := make(chan struct{})

	connPool := &pool.ConnPool{
		SrcAddr:    config.RPCSrcAddr,
		LogOutput:  config.LogOutput,
		MaxTime:    serverRPCCache,
		MaxStreams: serverMaxStreams,
		TLSWrapper: tlsConfigurator.OutgoingRPCWrapper(),
		ForceTLS:   config.VerifyOutgoing,
	}

	// Create server.
	s := &Server{
		config:           config,
		tokens:           tokens,
		connPool:         connPool,
		eventChLAN:       make(chan serf.Event, serfEventChSize),
		eventChWAN:       make(chan serf.Event, serfEventChSize),
		logger:           logger,
		leaveCh:          make(chan struct{}),
		reconcileCh:      make(chan serf.Member, reconcileChSize),
		router:           router.NewRouter(logger, config.Datacenter),
		rpcServer:        rpc.NewServer(),
		rpcTLS:           tlsConfigurator.IncomingRPCConfig(),
		reassertLeaderCh: make(chan chan error),
		segmentLAN:       make(map[string]*serf.Serf, len(config.Segments)),
		sessionTimers:    NewSessionTimers(),
		tombstoneGC:      gc,
		serverLookup:     NewServerLookup(),
		shutdownCh:       shutdownCh,
	}

	// Initialize enterprise specific server functionality
	if err := s.initEnterprise(); err != nil {
		s.Shutdown()
		return nil, err
	}

	configReplicatorConfig := ReplicatorConfig{
		Name:        "Config Entry",
		ReplicateFn: s.replicateConfig,
		Rate:        s.config.ConfigReplicationRate,
		Burst:       s.config.ConfigReplicationBurst,
		Logger:      logger,
	}
	s.configReplicator, err = NewReplicator(&configReplicatorConfig)
	if err != nil {
		s.Shutdown()
		return nil, err
	}

	// Initialize the stats fetcher that autopilot will use.
	s.statsFetcher = NewStatsFetcher(logger, s.connPool, s.config.Datacenter)

	s.sentinel = sentinel.New(logger)
	s.useNewACLs = 0
	aclConfig := ACLResolverConfig{
		Config:      config,
		Delegate:    s,
		CacheConfig: serverACLCacheConfig,
		AutoDisable: false,
		Logger:      logger,
		Sentinel:    s.sentinel,
	}
	// Initialize the ACL resolver.
	if s.acls, err = NewACLResolver(&aclConfig); err != nil {
		s.Shutdown()
		return nil, fmt.Errorf("Failed to create ACL resolver: %v", err)
	}

	// Initialize the RPC layer.
	if err := s.setupRPC(tlsConfigurator.OutgoingRPCWrapper()); err != nil {
		s.Shutdown()
		return nil, fmt.Errorf("Failed to start RPC layer: %v", err)
	}

	// Initialize any extra RPC listeners for segments.
	segmentListeners, err := s.setupSegmentRPC()
	if err != nil {
		s.Shutdown()
		return nil, fmt.Errorf("Failed to start segment RPC layer: %v", err)
	}

	// Initialize the Raft server.
	if err := s.setupRaft(); err != nil {
		s.Shutdown()
		return nil, fmt.Errorf("Failed to start Raft: %v", err)
	}

	// Serf and dynamic bind ports
	//
	// The LAN serf cluster announces the port of the WAN serf cluster
	// which creates a race when the WAN cluster is supposed to bind to
	// a dynamic port (port 0). The current memberlist implementation will
	// update the bind port in the configuration after the memberlist is
	// created, so we can pull it out from there reliably, even though it's
	// a little gross to be reading the updated config.

	// Initialize the WAN Serf if enabled
	serfBindPortWAN := -1
	if config.SerfWANConfig != nil {
		serfBindPortWAN = config.SerfWANConfig.MemberlistConfig.BindPort
		s.serfWAN, err = s.setupSerf(config.SerfWANConfig, s.eventChWAN, serfWANSnapshot, true, serfBindPortWAN, "", s.Listener)
		if err != nil {
			s.Shutdown()
			return nil, fmt.Errorf("Failed to start WAN Serf: %v", err)
		}
		// See big comment above why we are doing this.
		if serfBindPortWAN == 0 {
			serfBindPortWAN = config.SerfWANConfig.MemberlistConfig.BindPort
			if serfBindPortWAN == 0 {
				return nil, fmt.Errorf("Failed to get dynamic bind port for WAN Serf")
			}
			s.logger.Printf("[INFO] agent: Serf WAN TCP bound to port %d", serfBindPortWAN)
		}
	}

	// Initialize the LAN segments before the default LAN Serf so we have
	// updated port information to publish there.
	if err := s.setupSegments(config, serfBindPortWAN, segmentListeners); err != nil {
		s.Shutdown()
		return nil, fmt.Errorf("Failed to setup network segments: %v", err)
	}

	// Initialize the LAN Serf for the default network segment.
	s.serfLAN, err = s.setupSerf(config.SerfLANConfig, s.eventChLAN, serfLANSnapshot, false, serfBindPortWAN, "", s.Listener)
	if err != nil {
		s.Shutdown()
		return nil, fmt.Errorf("Failed to start LAN Serf: %v", err)
	}
	go s.lanEventHandler()

	// Start the flooders after the LAN event handler is wired up.
	s.floodSegments(config)

	// Add a "static route" to the WAN Serf and hook it up to Serf events.
	if s.serfWAN != nil {
		if err := s.router.AddArea(types.AreaWAN, s.serfWAN, s.connPool, s.config.VerifyOutgoing); err != nil {
			s.Shutdown()
			return nil, fmt.Errorf("Failed to add WAN serf route: %v", err)
		}
		go router.HandleSerfEvents(s.logger, s.router, types.AreaWAN, s.serfWAN.ShutdownCh(), s.eventChWAN)

		// Fire up the LAN <-> WAN join flooder.
		portFn := func(s *metadata.Server) (int, bool) {
			if s.WanJoinPort > 0 {
				return s.WanJoinPort, true
			}
			return 0, false
		}
		go s.Flood(nil, portFn, s.serfWAN)
	}

	// Start enterprise specific functionality
	if err := s.startEnterprise(); err != nil {
		s.Shutdown()
		return nil, err
	}

	// Initialize Autopilot. This must happen before starting leadership monitoring
	// as establishing leadership could attempt to use autopilot and cause a panic.
	s.initAutopilot(config)

	// Start monitoring leadership. This must happen after Serf is set up
	// since it can fire events when leadership is obtained.
	go s.monitorLeadership()

	// Start listening for RPC requests.
	go s.listen(s.Listener)

	// Start listeners for any segments with separate RPC listeners.
	for _, listener := range segmentListeners {
		go s.listen(listener)
	}

	// Start the metrics handlers.
	go s.sessionStats()

	return s, nil
}
567225
func NewRocForStream(priceStream gotrade.DOHLCVStreamSubscriber, timePeriod int, selectData gotrade.DOHLCVDataSelectionFunc) (indicator *Roc, err error) {
	ind, err := NewRoc(timePeriod, selectData)
	priceStream.AddTickSubscription(ind)
	return ind, err
}
331339
func NewSyslogLineParser(mode string, processList string) (*SyslogLineParser, error) {
	var supportedProcesses map[string]struct{}
	// if a list of process
	if processList != "" {
		supportedProcesses = make(map[string]struct{})
		for _, process := range strings.Split(processList, ",") {
			supportedProcesses[strings.TrimSpace(process)] = struct{}{}
		}
	}
	if mode == "rfc3164" || mode == "rfc5424" {
		return &SyslogLineParser{
			mode:               mode,
			supportedProcesses: supportedProcesses,
		}, nil
	}

	return nil, fmt.Errorf("unsupported mode %s, see --help", mode)
}
347926
func NewDefaultLogBuffer(message_buffer int) *LogBuffer {
	return NewLogBuffer(message_buffer, []*log.Logger{log.StandardLogger(), golib.Log})
}
735828
func NewPlainFileLogger(name, file string, l LevelInfo) (Sender, error) {
	s, err := MakePlainFileLogger(file)
	if err != nil {
		return nil, err
	}

	return setup(s, name, l)
}
401658
func NewStreamFileBuilder(writer io.Writer) *StreamFileBuilder {
	return &StreamFileBuilder{
		zipWriter:          zip.NewWriter(writer),
		xlsxFile:           NewFile(),
		cellTypeToStyleIds: make(map[CellType]int),
		maxStyleId:         initMaxStyleId,
	}
}
1037091
func NewLogFile(logPath string, capacity int64, maxFiles int, compress bool, marshaller logger.MarshalFunc, decodeFunc makeDecoderFunc, perms os.FileMode, getTailReader GetTailReaderFunc) (*LogFile, error) {
	log, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, perms)
	if err != nil {
		return nil, err
	}

	size, err := log.Seek(0, os.SEEK_END)
	if err != nil {
		return nil, err
	}

	return &LogFile{
		f:               log,
		capacity:        capacity,
		currentSize:     size,
		maxFiles:        maxFiles,
		compress:        compress,
		filesRefCounter: refCounter{counter: make(map[string]int)},
		notifyRotate:    pubsub.NewPublisher(0, 1),
		marshal:         marshaller,
		createDecoder:   decodeFunc,
		perms:           perms,
		getTailReader:   getTailReader,
	}, nil
}
569333
func NewClient(c *prpc.Client) *Client {
	return &Client{
		C:    logdog.NewLogsPRPCClient(c),
		Host: c.Host,
	}
}
16971
func NewPlainLogger(name string, l LevelInfo) (Sender, error) {
	return setup(MakePlainLogger(), name, l)
}
311818
func NewDefaultAdxForStream(priceStream gotrade.DOHLCVStreamSubscriber) (indicator *Adx, err error) {
	ind, err := NewDefaultAdx()
	priceStream.AddTickSubscription(ind)
	return ind, err
}