// UpsertReverseTunnel upserts reverse tunnel entry temporarily or permanently
516094
func (s *PresenceService) UpsertReverseTunnel(tunnel services.ReverseTunnel) error {
	if err := tunnel.Check(); err != nil {
		return trace.Wrap(err)
	}
	value, err := services.GetReverseTunnelMarshaler().MarshalReverseTunnel(tunnel)
	if err != nil {
		return trace.Wrap(err)
	}
	_, err = s.Put(context.TODO(), backend.Item{
		Key:     backend.Key(reverseTunnelsPrefix, tunnel.GetName()),
		Value:   value,
		Expires: tunnel.Expiry(),
		ID:      tunnel.GetResourceID(),
	})
	return trace.Wrap(err)
}
1088459
func (spec MutateInSpec) UpsertFull(val interface{}, opts *MutateInSpecUpsertFullOptions) MutateInOp {
	if opts == nil {
		opts = &MutateInSpecUpsertFullOptions{}
	}

	encoder := opts.Encoder
	if opts.Encoder == nil {
		encoder = JSONEncode
	}

	marshaled, _, err := encoder(val)
	if err != nil {
		return MutateInOp{err: err}
	}

	op := gocbcore.SubDocOp{
		Op:    gocbcore.SubDocOpSetDoc,
		Flags: gocbcore.SubdocFlag(SubdocFlagNone),
		Value: marshaled,
	}

	return MutateInOp{op: op}
}
693363
func (d *disseminator) tryStartReverseFullSync(target string, timeout time.Duration) {
	// occupy a job, return if none are available
	select {
	case d.reverseFullSyncJobs <- struct{}{}:
		// continue if job is available
	default:
		d.logger.WithFields(log.Fields{
			"remote": target,
		}).Info("omit bidirectional full sync, too many already running")

		d.node.EmitEvent(OmitReverseFullSyncEvent{Target: target})
		return
	}

	// start reverse full sync
	go func() {
		d.reverseFullSync(target, timeout)

		// create a new vacancy when the job is done
		<-d.reverseFullSyncJobs
	}()
}
515793
func (az *Cloud) createOrUpdateInterfaceWithRetry(service *v1.Service, nic network.Interface) error {
	return wait.ExponentialBackoff(az.requestBackoff(), func() (bool, error) {
		ctx, cancel := getContextWithCancel()
		defer cancel()

		resp, err := az.InterfacesClient.CreateOrUpdate(ctx, az.ResourceGroup, *nic.Name, nic)
		klog.V(10).Infof("InterfacesClient.CreateOrUpdate(%s): end", *nic.Name)
		return az.processHTTPRetryResponse(service, "CreateOrUpdateInterface", resp, err)
	})
}
448257
func (r Network_Subnet) CreateReverseDomainRecords() (resp datatypes.Dns_Domain_Reverse, err error) {
	err = r.Session.DoRequest("SoftLayer_Network_Subnet", "createReverseDomainRecords", nil, &r.Options, &resp)
	return
}
479028
func (p *Proxy) handleTunnel(session sockjs.Session, req *http.Request) {
	tokenString := req.URL.Query().Get("token")

	getPublicKey := func(token *jwt.Token) (interface{}, error) {
		if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
			return nil, errors.New("invalid signing method")
		}

		return jwt.ParseRSAPublicKeyFromPEM([]byte(p.pubKey))
	}

	token, err := jwt.Parse(tokenString, getPublicKey)
	if err != nil {
		p.Kite.Log.Error("Invalid token: \"%s\"", tokenString)
		return
	}

	kiteID := token.Claims.(jwt.MapClaims)["sub"].(string)
	seq := uint64(token.Claims.(jwt.MapClaims)["seq"].(float64))

	client, ok := p.kites[kiteID]
	if !ok {
		p.Kite.Log.Error("Remote kite is not found: %s", kiteID)
		return
	}

	tunnel, ok := client.tunnels[seq]
	if !ok {
		p.Kite.Log.Error("Tunnel not found: %d", seq)
	}

	go tunnel.Run(session)

	<-tunnel.CloseNotify()

}
668691
func (c *Connector) Upsert(ctx context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error {
	if c.Next == nil {
		return NewErrNoMoreConnector()
	}
	return c.Next.Upsert(ctx, ei, values)
}
829775
func (p *ExtraStructs) Upsert(param string, paramType reflect.Type) *ExtraStruct {
	t := *p
	for i, extraStruct := range t {
		if extraStruct.FieldName == param {
			t[i].FieldType = paramType
			return t[i]
		}
	}
	extraStruct := &ExtraStruct{
		FieldName: param,
	}
	if paramType != nil {
		extraStruct.FieldType = paramType
	}
	*p = append(t, extraStruct)
	return (*p)[len(*p)-1]
}
524395
func (w *Wrapper) UpsertTunnelConnection(conn services.TunnelConnection) error {
	return w.Write.UpsertTunnelConnection(conn)
}
754749
func (l *PacketIntervalList) PushBack(v PacketInterval) *PacketIntervalElement {
	l.lazyInit()
	return l.insertValue(v, l.root.prev)
}
764727
func (conn *connection) reverseProxyRequest(w http.ResponseWriter,
	r *http.Request, path string, auth Auth) error {
	target, err := url.Parse(conn.url)
	if err != nil {
		return err
	}
	if auth != nil {
		auth.AddAuthHeaders(r)
	}
	director := func(req *http.Request) {
		req.URL.Scheme = target.Scheme
		req.URL.Host = target.Host
		req.URL.Path = singleJoiningSlash(target.Path, path)
	}
	rp := &httputil.ReverseProxy{Director: director}
	rp.ServeHTTP(w, r)
	return nil
}
520611
func (c *Connector) Upsert(ctx context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error {
	ev, err := fieldValueMapFromClientMap(values)
	if err != nil {
		return err
	}

	ttl := dosa.NoTTL().Nanoseconds()
	if ei.TTL != nil {
		ttl = ei.TTL.Nanoseconds()
	}

	upsertRequest := dosarpc.UpsertRequest{
		Ref:          entityInfoToSchemaRef(ei),
		EntityValues: ev,
		TTL:          &ttl,
	}

	err = c.client.Upsert(ctx, &upsertRequest, getHeaders(c.headers)...)

	if !dosarpc.Dosa_Upsert_Helper.IsException(err) {
		return errors.Wrap(err, "failed to Upsert due to network issue")
	}

	return errors.Wrap(err, "failed to Upsert")
}
758564
func (s *APIServer) upsertTunnelConnection(auth ClientI, w http.ResponseWriter, r *http.Request, p httprouter.Params, version string) (interface{}, error) {
	var req upsertTunnelConnectionRawReq
	if err := httplib.ReadJSON(r, &req); err != nil {
		return nil, trace.Wrap(err)
	}
	conn, err := services.UnmarshalTunnelConnection(req.TunnelConnection)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	if err := auth.UpsertTunnelConnection(conn); err != nil {
		return nil, trace.Wrap(err)
	}
	return message("ok"), nil
}
1065234
func (s *StateStore) UpsertJob(index uint64, job *structs.Job) error {
	txn := s.db.Txn(true)
	defer txn.Abort()
	if err := s.upsertJobImpl(index, job, false, txn); err != nil {
		return err
	}
	txn.Commit()
	return nil
}
1239348
func (c *Client) GetReverseTunnel(name string, opts ...services.MarshalOption) (services.ReverseTunnel, error) {
	return nil, trace.NotImplemented("not implemented")
}
582345
func (s *PresenceService) DeleteAllReverseTunnels() error {
	startKey := backend.Key(reverseTunnelsPrefix)
	return s.DeleteRange(context.TODO(), startKey, backend.RangeEnd(startKey))
}
312932
func (s *Server) StartTunnel() error {
	tunnel := &http.Server{
		Addr:    fmt.Sprintf("%s:%d", s.URL.Hostname(), s.Tunnel),
		Handler: http.HandlerFunc(s.proxy),
	}

	l, err := net.Listen("tcp", tunnel.Addr)
	if err != nil {
		return err
	}

	if s.Tunnel == 0 {
		s.Tunnel = l.Addr().(*net.TCPAddr).Port
	}

	// Set client proxy port (defaults to vCenter host port 80 in real life)
	q := s.URL.Query()
	q.Set("GOVMOMI_TUNNEL_PROXY_PORT", strconv.Itoa(s.Tunnel))
	s.URL.RawQuery = q.Encode()

	go tunnel.Serve(l)

	return nil
}