// New creates a new Queue with the given queue id.
960487
func New(queueID uint16, maxPacketsInQueue uint32, packetSize uint32) (nfq *Queue, err error) {
	nfq = &Queue{
		ID: queueID,
		// TODO: what should the chan size be?
		packets: make(chan *RawPacket, 1024),
	}
	var ret C.int

	defer func() {
		if err != nil && nfq != nil {
			if nfq.qh != nil {
				C.nfq_destroy_queue(nfq.qh)
			}

			if nfq.h != nil {
				C.nfq_close(nfq.h)
			}
		}
	}()

	if nfq.h, err = C.nfq_open(); err != nil {
		err = errors.Wrap(err, "netfilter: unable to open nfq queue handle.")
		return
	}

	if ret, err = C.nfq_unbind_pf(nfq.h, AF_INET); err != nil || ret < 0 {
		err = errors.Wrap(err, "netfilter: unable to unbind existing nfq handler.")
		return
	}

	if ret, err = C.nfq_bind_pf(nfq.h, AF_INET); err != nil || ret < 0 {
		err = errors.Wrap(err, "netfilter: unable to bind to AF_INET protocol family.")
		return
	}

	if nfq.qh, err = C.CreateQueue(nfq.h, C.u_int16_t(queueID)); err != nil || nfq.qh == nil {
		err = errors.Wrap(err, "netfilter: unable to create nfq queue.")
		return
	}

	if ret, err = C.nfq_set_queue_maxlen(nfq.qh, C.u_int32_t(maxPacketsInQueue)); err != nil || ret < 0 {
		err = errors.Wrap(err, "netfilter: unable to set nfq max queue length.")
		return
	}

	if C.nfq_set_mode(nfq.qh, C.u_int8_t(2), C.uint(packetSize)) < 0 {
		err = errors.Wrap(err, "netfilter: unable to set packet copy mode.")
		return
	}

	if nfq.fd, err = C.nfq_fd(nfq.h); err != nil {
		err = errors.Wrap(err, "netfilter: unable to get nfq queue file-descriptor.")
		return

	}

	// TODO: error handling
	// me: https://i.imgur.com/Lmy5P.gif
	C.nfnl_rcvbufsiz(C.nfq_nfnlh(nfq.h), 1024*16384)

	// register this queue object with the global dispatcher
	register(queueID, nfq.packets)

	return
}
971413
func New(m *GinJWTMiddleware) (*GinJWTMiddleware, error) {
	if err := m.MiddlewareInit(); err != nil {
		return nil, err
	}

	return m, nil
}
206
func New(id manifold.ID) (string, string) {
	idBytes := id[2:]

	offset := 0
	adj, offset := fetchWord(idBytes, data.Adjectives, offset, aShare)
	color, offset := fetchWord(idBytes, data.Colors, offset, cShare)
	shape, _ := fetchWord(idBytes, data.Shapes, offset, sShare)

	name := strings.Title(adj + " " + color + " " + shape)
	label := strings.Replace(strings.ToLower(name), " ", "-", -1)
	return name, label
}
296744
func NewQueue(handler Handler, concurrencyLimit int) *Queue {

	q := &Queue{
		&queue{
			Handler:          handler,
			ConcurrencyLimit: concurrencyLimit,
			push:             make(chan interface{}),
			pop:              make(chan struct{}),
			suspend:          make(chan bool),
			stop:             make(chan struct{}),
		},
	}

	go q.run()
	runtime.SetFinalizer(q, (*Queue).Stop)
	return q
}
287189
func New(c *client.Client, id string, pubKey string) (api.Key, error) {
	req := api.KeyCreateRequest{ID: id, Public: pubKey}
	body, err := json.Marshal(req)

	resBody, err := c.BasicRequest("POST", "/v1/keys/", body)

	if err != nil {
		return api.Key{}, err
	}

	key := api.Key{}
	if err = json.Unmarshal([]byte(resBody), &key); err != nil {
		return api.Key{}, err
	}

	return key, nil
}
417409
func New(errMsg string) Error {
	uidv4, _ := uuid.NewV4() // skip error.
	return Error{
		ID:      uidv4.String(),
		Message: Prefix + errMsg,
	}
}
1190226
func New(id string, runtime *runc.Runc, stdio proc.Stdio) *Init {
	p := &Init{
		id:        id,
		runtime:   runtime,
		stdio:     stdio,
		status:    0,
		waitBlock: make(chan struct{}),
	}
	p.initState = &createdState{p: p}
	return p
}
695460
func CreateQueue(redisHost, redisPort, redisPassword string, redisDB int64, name string) *Queue {
	return newQueue(redisHost, redisPort, redisPassword, redisDB, name)
}
1129070
func New(workers int, jobQueue ...int) *WorkerPool {
	q := 0
	if len(jobQueue) > 0 && jobQueue[0] > 0 {
		q = jobQueue[0]
	}
	if workers < 0 {
		workers = runtime.NumCPU()
	}
	pool := WorkerPool{
		pool: make(chan chan func(), workers),
		jobs: make(chan func(), q),
		quit: make(chan struct{}),
		wg:   sync.WaitGroup{},
	}
	for i := 0; i < workers; i++ {
		initWorker(pool.pool, 0, nil, pool.quit, &pool.wg)
	}
	go pool.dispatch()
	return &pool
}
208671
func New(awsConfig *aws.Config, queueURL string) *Adapter {
	return &Adapter{getClient(awsConfig), queueURL}
}
172227
func New() Definition {
	var q Definition
	q.Where = make(map[string]interface{})
	q.Sort = make(map[string]interface{})
	return q
}
548477
func New(client RedisClient, key string, opts *Options) *Locker {
	var o Options
	if opts != nil {
		o = *opts
	}
	o.normalize()

	return &Locker{client: client, key: key, opts: o}
}
553407
func (r *TasksService) New(swarmingrpcsnewtaskrequest *SwarmingRpcsNewTaskRequest) *TasksNewCall {
	c := &TasksNewCall{s: r.s, urlParams_: make(gensupport.URLParams)}
	c.swarmingrpcsnewtaskrequest = swarmingrpcsnewtaskrequest
	return c
}
426371
func New(t T) *I {
	return &I{t, t.FailNow, os.Stdout, !noColorFlag}
}
163065
func New(queueName string, sess *session.Session) (*SQS, error) {
	s := &SQS{
		session:  sess,
		queueURL: &queueName,
	}

	resp, err := s.client().GetQueueUrl(&sqs.GetQueueUrlInput{
		QueueName: aws.String(queueName),
	})
	if err != nil {
		return nil, err

	}

	s.queueURL = resp.QueueUrl
	return s, nil
}
341506
func New(w io.Writer, bufferSize int64) io.WriteCloser {
	buf, _ := circbuf.NewBuffer(bufferSize)
	c := &circbufWriter{
		buf:     buf,
		wr:      w,
		flushCh: make(chan struct{}, 1),
	}
	go c.flushLoop()
	return c
}
843341
func New(
	mutualAuth bool,
	filterQueue *fqconfig.FilterQueue,
	collector collector.EventCollector,
	serverID string,
	validity time.Duration,
	service packetprocessor.PacketProcessor,
	secrets secrets.Secrets,
	mode constants.ModeType,
	procMountPoint string,
	ExternalIPCacheTimeout time.Duration,
	packetLogs bool,
	tokenaccessor tokenaccessor.TokenAccessor,
	puFromContextID cache.DataStore,
	cfg *runtime.Configuration,
) *Datapath {

	if ExternalIPCacheTimeout <= 0 {
		var err error
		ExternalIPCacheTimeout, err = time.ParseDuration(enforcerconstants.DefaultExternalIPTimeout)
		if err != nil {
			ExternalIPCacheTimeout = time.Second
		}
	}

	if mode == constants.RemoteContainer || mode == constants.LocalServer {
		// Make conntrack liberal for TCP

		sysctlCmd, err := exec.LookPath("sysctl")
		if err != nil {
			zap.L().Fatal("sysctl command must be installed", zap.Error(err))
		}

		cmd := exec.Command(sysctlCmd, "-w", "net.netfilter.nf_conntrack_tcp_be_liberal=1")
		if err := cmd.Run(); err != nil {
			zap.L().Fatal("Failed to set conntrack options", zap.Error(err))
		}

		if mode == constants.LocalServer && !buildflags.IsLegacyKernel() {
			cmd = exec.Command(sysctlCmd, "-w", "net.ipv4.ip_early_demux=0")
			if err := cmd.Run(); err != nil {
				zap.L().Fatal("Failed to set early demux options", zap.Error(err))
			}
		}
	}

	contextIDFromTCPPort := portcache.NewPortCache("contextIDFromTCPPort")
	contextIDFromUDPPort := portcache.NewPortCache("contextIDFromUDPPort")

	udpSocketWriter, err := GetUDPRawSocket(afinetrawsocket.ApplicationRawSocketMark, "udp")
	if err != nil {
		zap.L().Fatal("Unable to create raw socket for udp packet transmission", zap.Error(err))
	}

	d := &Datapath{
		puFromMark:           cache.NewCache("puFromMark"),
		puFromUser:           cache.NewCache("puFromUser"),
		contextIDFromTCPPort: contextIDFromTCPPort,
		contextIDFromUDPPort: contextIDFromUDPPort,

		puFromContextID: puFromContextID,

		sourcePortConnectionCache: cache.NewCacheWithExpiration("sourcePortConnectionCache", time.Second*24),
		appOrigConnectionTracker:  cache.NewCacheWithExpiration("appOrigConnectionTracker", time.Second*24),
		appReplyConnectionTracker: cache.NewCacheWithExpiration("appReplyConnectionTracker", time.Second*24),
		netOrigConnectionTracker:  cache.NewCacheWithExpiration("netOrigConnectionTracker", time.Second*24),
		netReplyConnectionTracker: cache.NewCacheWithExpiration("netReplyConnectionTracker", time.Second*24),

		udpSourcePortConnectionCache: cache.NewCacheWithExpiration("udpSourcePortConnectionCache", time.Second*60),
		udpAppOrigConnectionTracker:  cache.NewCacheWithExpiration("udpAppOrigConnectionTracker", time.Second*60),
		udpAppReplyConnectionTracker: cache.NewCacheWithExpiration("udpAppReplyConnectionTracker", time.Second*60),
		udpNetOrigConnectionTracker:  cache.NewCacheWithExpiration("udpNetOrigConnectionTracker", time.Second*60),
		udpNetReplyConnectionTracker: cache.NewCacheWithExpiration("udpNetReplyConnectionTracker", time.Second*60),
		udpNatConnectionTracker:      cache.NewCacheWithExpiration("udpNatConnectionTracker", time.Second*60),
		udpFinPacketTracker:          cache.NewCacheWithExpiration("udpFinPacketTracker", time.Second*60),

		packetTracingCache:     cache.NewCache("PacketTracingCache"),
		targetNetworks:         acls.NewACLCache(),
		ExternalIPCacheTimeout: ExternalIPCacheTimeout,
		filterQueue:            filterQueue,
		mutualAuthorization:    mutualAuth,
		service:                service,
		collector:              collector,
		tokenAccessor:          tokenaccessor,
		secrets:                secrets,
		ackSize:                secrets.AckSize(),
		mode:                   mode,
		procMountPoint:         procMountPoint,
		packetLogs:             packetLogs,
		udpSocketWriter:        udpSocketWriter,
		puToPortsMap:           map[string]map[string]bool{},
	}

	if err = d.SetTargetNetworks(cfg); err != nil {
		zap.L().Error("Error adding target networks to the ACLs", zap.Error(err))
	}

	packet.PacketLogLevel = packetLogs

	d.nflogger = nflog.NewNFLogger(11, 10, d.puInfoDelegate, collector)

	if mode != constants.RemoteContainer {
		go d.autoPortDiscovery()
	}

	return d
}