// LBInterfaceInit initialises the load balancing interface for a Seesaw Node.
1475
func (ncc *SeesawNCC) LBInterfaceInit(iface *ncctypes.LBInterface, out *int) error {
	netIface, err := iface.Interface()
	if err != nil {
		return fmt.Errorf("Failed to get network interface: %v", err)
	}
	nodeIface, err := net.InterfaceByName(iface.NodeInterface)
	if err != nil {
		return fmt.Errorf("Failed to get node interface: %v", err)
	}

	if iface.RoutingTableID < 1 || iface.RoutingTableID > 250 {
		return fmt.Errorf("Invalid routing table ID: %d", iface.RoutingTableID)
	}

	vmac, err := net.ParseMAC(vrrpMAC)
	if err != nil {
		return fmt.Errorf("Failed to parse VRRP MAC %q: %v", vrrpMAC, err)
	}

	// The last byte of the VRRP MAC is determined by the VRID.
	vmac[len(vmac)-1] = iface.VRID
	netIface.HardwareAddr = vmac

	log.Infof("Initialising load balancing interface %s - VRID %d (VMAC %s)", iface.Name, iface.VRID, vmac)

	// Ensure interface is down and set VMAC address.
	if err := ifaceFastDown(netIface); err != nil {
		return fmt.Errorf("Failed to down interface: %v", err)
	}
	if err := ifaceSetMAC(netIface); err != nil {
		return fmt.Errorf("Failed to set MAC: %v", err)
	}

	// Remove VLAN interfaces associated with the load balancing interface.
	if err := ifaceFlushVLANs(netIface); err != nil {
		return fmt.Errorf("Failed to flush VLAN interfaces: %v", err)
	}

	// Configure sysctls for load balancing.
	if err := sysctlInitLB(nodeIface, netIface); err != nil {
		return fmt.Errorf("Failed to initialise sysctls: %v", err)
	}

	// Flush existing IP addresses and add cluster VIPs.
	if err := ifaceFlushIPAddr(netIface); err != nil {
		return fmt.Errorf("Failed to flush IP addresses: %v", err)
	}

	if iface.ClusterVIP.IPv4Addr != nil {
		if err := addClusterVIP(iface, netIface, nodeIface, iface.ClusterVIP.IPv4Addr); err != nil {
			return fmt.Errorf("Failed to add IPv4 cluster VIP: %v", err)
		}
	}
	if iface.ClusterVIP.IPv6Addr != nil {
		if err := addClusterVIP(iface, netIface, nodeIface, iface.ClusterVIP.IPv6Addr); err != nil {
			return fmt.Errorf("Failed to add IPv6 cluster VIP: %v", err)
		}
	}

	// Initialise iptables rules.
	if err := iptablesInit(iface.ClusterVIP); err != nil {
		return err
	}

	// Setup dummy interface.
	dummyIface, err := net.InterfaceByName(iface.DummyInterface)
	if err != nil {
		return fmt.Errorf("Failed to get dummy interface: %v", err)
	}
	if err := ifaceFastDown(dummyIface); err != nil {
		return fmt.Errorf("Failed to down dummy interface: %v", err)
	}
	if err := ifaceFlushIPAddr(dummyIface); err != nil {
		return fmt.Errorf("Failed to flush dummy interface: %v", err)
	}
	if err := ifaceUp(dummyIface); err != nil {
		return fmt.Errorf("Failed to up dummy interface: %v", err)
	}

	return nil
}
1178188
func (p LogicalWindow) Init(ctx sessionctx.Context) *LogicalWindow {
	p.baseLogicalPlan = newBaseLogicalPlan(ctx, TypeWindow, &p)
	return &p
}
772409
func (b *LRUCache) Init(capacity uint) {
	b.table = make(map[string]*entry, capacity)
	b.priorityQueue = make([]*entry, 0, capacity)
	b.lruList.Init()
	b.freeList.Init()
	heap.Init(&b.priorityQueue)

	// Reserve all the entries in one giant continous block of memory
	arrayOfEntries := make([]entry, capacity)
	for i := uint(0); i < capacity; i++ {
		e := &arrayOfEntries[i]
		e.element.Value = e
		e.index = -1
		b.freeList.PushElementBack(&e.element)
	}
}
375765
func Init(homeDir, mobileSharedHome, logFile, runModeStr string,
	accessGroupOverride bool, externalDNSNSFetcher ExternalDNSNSFetcher, nvh NativeVideoHelper) (err error) {
	defer func() {
		err = flattenError(err)
		if err == nil {
			setInited()
		}
	}()

	fmt.Printf("Go: Initializing: home: %s mobileSharedHome: %s\n", homeDir, mobileSharedHome)
	var ekLogFile string
	if logFile != "" {
		fmt.Printf("Go: Using log: %s\n", logFile)
		ekLogFile = logFile + ".ek"
		fmt.Printf("Go: Using eklog: %s\n", ekLogFile)
	}

	// Reduce OS threads on mobile so we don't have too much contention with JS thread
	oldProcs := runtime.GOMAXPROCS(0)
	newProcs := oldProcs / 2
	runtime.GOMAXPROCS(newProcs)
	fmt.Printf("Go: setting GOMAXPROCS to: %d previous: %d\n", newProcs, oldProcs)

	startTrace(logFile)

	dnsNSFetcher := newDNSNSFetcher(externalDNSNSFetcher)
	dnsServers := dnsNSFetcher.GetServers()
	for _, srv := range dnsServers {
		fmt.Printf("Go: DNS Server: %s\n", srv)
	}

	kbCtx = libkb.NewGlobalContext()
	kbCtx.Init()
	kbCtx.SetProofServices(externals.NewProofServices(kbCtx))

	// 10k uid -> FullName cache entries allowed
	kbCtx.SetUIDMapper(uidmap.NewUIDMap(10000))
	usage := libkb.Usage{
		Config:    true,
		API:       true,
		KbKeyring: true,
	}
	runMode, err := libkb.StringToRunMode(runModeStr)
	if err != nil {
		return err
	}
	config := libkb.AppConfig{
		HomeDir:                        homeDir,
		MobileSharedHomeDir:            mobileSharedHome,
		LogFile:                        logFile,
		EKLogFile:                      ekLogFile,
		RunMode:                        runMode,
		Debug:                          true,
		LocalRPCDebug:                  "",
		VDebugSetting:                  "mobile", // use empty string for same logging as desktop default
		SecurityAccessGroupOverride:    accessGroupOverride,
		ChatInboxSourceLocalizeThreads: 5,
		LinkCacheSize:                  1000,
	}
	err = kbCtx.Configure(config, usage)
	if err != nil {
		return err
	}

	svc := service.NewService(kbCtx, false)
	err = svc.StartLoopbackServer()
	if err != nil {
		return err
	}
	kbCtx.SetService()
	uir := service.NewUIRouter(kbCtx)
	kbCtx.SetUIRouter(uir)
	kbCtx.SetDNSNameServerFetcher(dnsNSFetcher)
	svc.SetupCriticalSubServices()
	svc.SetupChatModules(nil)
	svc.RunBackgroundOperations(uir)
	kbChatCtx = svc.ChatContextified.ChatG()
	kbChatCtx.NativeVideoHelper = newVideoHelper(nvh)

	logs := libkb.Logs{
		Service: config.GetLogFile(),
		EK:      config.GetEKLogFile(),
	}

	fmt.Printf("Go: Using config: %+v\n", kbCtx.Env.GetLogFileConfig(config.GetLogFile()))

	logSendContext = libkb.LogSendContext{
		Contextified: libkb.NewContextified(kbCtx),
		Logs:         logs,
	}

	// open the connection
	if err = Reset(); err != nil {
		return err
	}

	go func() {
		kbfsCtx := env.NewContextFromGlobalContext(kbCtx)
		kbfsParams := libkbfs.DefaultInitParams(kbfsCtx)
		// Setting this flag will enable KBFS debug logging to always
		// be true in a mobile setting. Change these back to the
		// commented-out values if we need to make a mobile release
		// before KBFS-on-mobile is ready.
		kbfsParams.Debug = true                         // false
		kbfsParams.Mode = libkbfs.InitConstrainedString // libkbfs.InitMinimalString
		kbfsConfig, _ = libkbfs.Init(
			context.Background(), kbfsCtx, kbfsParams, serviceCn{}, func() error { return nil },
			kbCtx.Log)
	}()

	return nil
}
26898
func (p PhysicalHashJoin) Init(ctx sessionctx.Context, stats *property.StatsInfo, props ...*property.PhysicalProperty) *PhysicalHashJoin {
	tp := TypeHashRightJoin
	if p.InnerChildIdx == 1 {
		tp = TypeHashLeftJoin
	}
	p.basePhysicalPlan = newBasePhysicalPlan(ctx, tp, &p)
	p.childrenReqProps = props
	p.stats = stats
	return &p
}
1270975
func (p *priorityPlugin) ValidateInitialization() error {
	if p.client == nil {
		return fmt.Errorf("%s requires a client", PluginName)
	}
	if p.lister == nil {
		return fmt.Errorf("%s requires a lister", PluginName)
	}
	return nil
}
899497
func Init() bool {
	initializer, exists := registeredInitializers[os.Args[0]]
	if exists {
		initializer()

		return true
	}
	return false
}
352245
func (s *InternalLBService) StartInternalLoadBalancerVM(p *StartInternalLoadBalancerVMParams) (*StartInternalLoadBalancerVMResponse, error) {
	resp, err := s.cs.newRequest("startInternalLoadBalancerVM", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r StartInternalLoadBalancerVMResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		b, err = getRawValue(b)
		if err != nil {
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
525128
func (b *BigtableIdx) InitBare() error {
	ctx := context.Background()
	if b.cfg.CreateCF {
		adminClient, err := bigtable.NewAdminClient(ctx, b.cfg.GcpProject, b.cfg.BigtableInstance)
		if err != nil {
			log.Errorf("bigtable-idx: failed to create bigtable admin client: %s", err)
			return err
		}
		tables, err := adminClient.Tables(ctx)
		if err != nil {
			log.Errorf("bigtable-idx: failed to list tables: %s", err)
			return err
		}
		found := false
		for _, t := range tables {
			if t == b.cfg.TableName {
				found = true
				break
			}
		}
		if !found {
			log.Infof("bigtable-idx: table %q does not yet exist. Creating it.", b.cfg.TableName)
			table := bigtable.TableConf{
				TableID: b.cfg.TableName,
				Families: map[string]bigtable.GCPolicy{
					COLUMN_FAMILY: bigtable.MaxVersionsPolicy(1),
				},
			}
			err := adminClient.CreateTableFromConf(ctx, &table)
			if err != nil {
				log.Errorf("bigtable-idx: failed to create table %q: %s", b.cfg.TableName, err)
				return err
			}
		} else {
			log.Infof("bigtable-idx: table %s exists.", b.cfg.TableName)
			// table exists.  Lets make sure that it has all of the CF's we need.
			table, err := adminClient.TableInfo(ctx, b.cfg.TableName)
			if err != nil {
				log.Errorf("bigtable-idx: failed to get tableInfo of %q: %s", b.cfg.TableName, err)
				return err
			}
			existingFamilies := make(map[string]string)
			for _, cf := range table.FamilyInfos {
				existingFamilies[cf.Name] = cf.GCPolicy
			}
			policy, ok := existingFamilies[COLUMN_FAMILY]
			if !ok {
				log.Infof("bigtable-idx: column family %s/%s does not exist. Creating it.", b.cfg.TableName, COLUMN_FAMILY)
				err = adminClient.CreateColumnFamily(ctx, b.cfg.TableName, COLUMN_FAMILY)
				if err != nil {
					log.Errorf("bigtable-idx: failed to create cf %s/%s: %s", b.cfg.TableName, COLUMN_FAMILY, err)
					return err
				}
				err = adminClient.SetGCPolicy(ctx, b.cfg.TableName, COLUMN_FAMILY, bigtable.MaxVersionsPolicy(1))
				if err != nil {
					log.Errorf("bigtable-idx: failed to set GCPolicy of %s/%s: %s", b.cfg.TableName, COLUMN_FAMILY, err)
					return err
				}
			} else if policy == "" {
				log.Infof("bigtable-idx: column family %s/%s exists but has no GCPolicy. Creating it.", b.cfg.TableName, COLUMN_FAMILY)
				err = adminClient.SetGCPolicy(ctx, b.cfg.TableName, COLUMN_FAMILY, bigtable.MaxVersionsPolicy(1))
				if err != nil {
					log.Errorf("bigtable-idx: failed to set GCPolicy of %s/%s: %s", b.cfg.TableName, COLUMN_FAMILY, err)
					return err
				}
			}
		}
	}
	client, err := bigtable.NewClient(ctx, b.cfg.GcpProject, b.cfg.BigtableInstance)
	if err != nil {
		log.Errorf("bigtable-idx: failed to create bigtable client: %s", err)
		return err
	}

	b.client = client
	b.tbl = client.Open(b.cfg.TableName)
	return nil
}
263533
func (s *HlsContentProtection) SetInitializationVector(v string) *HlsContentProtection {
	s.InitializationVector = &v
	return s
}
334965
func (n *switchingNetworking) NetworkInterfaces(instId instance.Id) ([]network.InterfaceInfo, error) {
	if err := n.initNetworking(); err != nil {
		return nil, errors.Trace(err)
	}
	return n.networking.NetworkInterfaces(instId)
}
958091
func (s *server) initBinary() error {
	s.network.Handle("InsertTriples", s.handleInsertTriples)
	s.network.Handle("QueryRequest", s.handleQueryRequest)

	return nil
}
659495
func (ncc *SeesawNCC) LBInterfaceAddVIP(vip *ncctypes.LBInterfaceVIP, out *int) error {
	switch vip.Type {
	case seesaw.UnicastVIP:
		netIface, err := vip.Iface.Interface()
		if err != nil {
			return err
		}
		iface, network, err := selectInterfaceNetwork(netIface, vip.IP.IP())
		if err != nil {
			return fmt.Errorf("Failed to select interface and network for %v: %v", vip.VIP, err)
		}
		log.Infof("Adding VIP %s to %s", vip.IP.IP(), iface.Name)
		if err := ifaceAddIPAddr(iface, vip.IP.IP(), network.Mask); err != nil {
			return err
		}
		return routeLocal(iface, vip.IP.IP(), vip.Iface.Node)
	case seesaw.AnycastVIP, seesaw.DedicatedVIP:
		dummyIface, err := net.InterfaceByName(vip.Iface.DummyInterface)
		if err != nil {
			return fmt.Errorf("Failed to find dummy interface: %v", err)
		}
		prefixLen := net.IPv6len * 8
		if vip.IP.IP().To4() != nil {
			prefixLen = net.IPv4len * 8
		}
		mask := net.CIDRMask(prefixLen, prefixLen)
		log.Infof("Adding VIP %s to %s", vip.IP.IP(), dummyIface.Name)
		if err := ifaceAddIPAddr(dummyIface, vip.IP.IP(), mask); err != nil {
			return err
		}
		return routeLocal(dummyIface, vip.IP.IP(), vip.Iface.Node)
	default:
		return fmt.Errorf("Unknown VIPType for %v: %v", vip.VIP, vip.Type)
	}
}
1054778
func (o *Disk) SetInterface(v *string) *Disk {
	if o.Interface = v; o.Interface == nil {
		o.nullFields = append(o.nullFields, "Interface")
	}
	return o
}
196587
func waitForHostDeviceWhenReady(ifaceName string) error {
	for i := 0; ; i++ {
		if i%10 == 0 {
			log.WithField(logfields.Interface, ifaceName).
				Info("Waiting for the underlying interface to be initialized with containers")
		}
		_, err := netlink.LinkByName(ifaceName)
		if err == nil {
			log.WithField(logfields.Interface, ifaceName).
				Info("Underlying interface initialized with containers!")
			break
		}
		select {
		case <-cleanUPSig:
			return errors.New("clean up signal triggered")
		default:
			time.Sleep(time.Second)
		}
	}
	return nil
}
399490
func (r *Router) useInterface(mw middleware) {
	r.middlewares = append(r.middlewares, mw)
}
1344139
func (t *TCB) Init(initialSyn header.TCP) Result {
	t.handlerInbound = synSentStateInbound
	t.handlerOutbound = synSentStateOutbound

	iss := seqnum.Value(initialSyn.SequenceNumber())
	t.outbound.una = iss
	t.outbound.nxt = iss.Add(logicalLen(initialSyn))
	t.outbound.end = t.outbound.nxt

	// Even though "end" is a sequence number, we don't know the initial
	// receive sequence number yet, so we store the window size until we get
	// a SYN from the peer.
	t.inbound.una = 0
	t.inbound.nxt = 0
	t.inbound.end = seqnum.Value(initialSyn.WindowSize())
	t.state = ResultConnecting
	return t.state
}