Пример #1
0
// TODO(sjr): support cachedTime in Java
func (s *blessingStore) Discharge(caveat security.Caveat, impetus security.DischargeImpetus) (security.Discharge, time.Time) {
	env, freeFunc := jutil.GetEnv()
	defer freeFunc()
	jCaveat, err := JavaCaveat(env, caveat)
	if err != nil {
		log.Printf("Couldn't get Java caveat: %v", err)
		return security.Discharge{}, time.Time{}
	}
	jImpetus, err := jutil.JVomCopy(env, impetus, jDischargeImpetusClass)
	if err != nil {
		log.Printf("Couldn't get Java DischargeImpetus: %v", err)
		return security.Discharge{}, time.Time{}
	}
	jDischarge, err := jutil.CallObjectMethod(env, s.jBlessingStore, "discharge", []jutil.Sign{caveatSign, dischargeImpetusSign}, dischargeSign, jCaveat, jImpetus)
	if err != nil {
		log.Printf("Couldn't call Java discharge method: %v", err)
		return security.Discharge{}, time.Time{}
	}
	discharge, err := GoDischarge(env, jDischarge)
	if err != nil {
		log.Printf("Couldn't convert Java discharge to Go: %v", err)
		return security.Discharge{}, time.Time{}
	}
	return discharge, time.Time{}
}
Пример #2
0
//export Java_io_v_impl_google_lib_discovery_DiscoveryImpl_nativeAdvertise
func Java_io_v_impl_google_lib_discovery_DiscoveryImpl_nativeAdvertise(jenv *C.JNIEnv, _ C.jobject, goRef C.jlong, jCtx C.jobject, jAdObj C.jobject, jVisibilityObj C.jobject, jCbObj C.jobject) {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jCtx))))
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}

	d := *(*discovery.T)(jutil.GoRefValue(jutil.Ref(goRef)))
	jAd := jutil.Object(uintptr(unsafe.Pointer(jAdObj)))
	jVisibility := jutil.Object(uintptr(unsafe.Pointer(jVisibilityObj)))

	var ad discovery.Advertisement
	if err := jutil.GoVomCopy(env, jAd, jAdvertisementClass, &ad); err != nil {
		jutil.JThrowV(env, err)
		return
	}

	jVisibilityList, err := jutil.GoObjectList(env, jVisibility)
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	visibility := make([]security.BlessingPattern, len(jVisibilityList))
	for i, jPattern := range jVisibilityList {
		if err := jutil.GoVomCopy(env, jPattern, jBlessingPatternClass, &visibility[i]); err != nil {
			jutil.JThrowV(env, err)
			return
		}
	}

	done, err := d.Advertise(ctx, &ad, visibility)
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}

	// Copy back the advertisement id.
	jId, err := jutil.JVomCopy(env, &ad.Id, jAdIdClass)
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	if err = jutil.CallVoidMethod(env, jAd, "setId", []jutil.Sign{adIdSign}, jId); err != nil {
		jutil.JThrowV(env, err)
		return
	}

	jCb := jutil.Object(uintptr(unsafe.Pointer(jCbObj)))
	jutil.DoAsyncCall(env, jCb, func() (jutil.Object, error) {
		<-done
		return jutil.NullObject, nil
	})
}
Пример #3
0
// javaUpdate converts a Go update instance into a Java update instance.
func javaUpdate(env jutil.Env, update discovery.Update) (jutil.Object, error) {
	jAd, err := jutil.JVomCopy(env, update.Advertisement(), jAdvertisementClass)
	if err != nil {
		return jutil.NullObject, err
	}
	ref := jutil.GoNewRef(&update) // Un-refed when jUpdate is finalized.
	jUpdate, err := jutil.NewObject(env, jUpdateImplClass, []jutil.Sign{jutil.LongSign, jutil.BoolSign, advertisementSign, jutil.LongSign},
		int64(ref), update.IsLost(), jAd, update.Timestamp().UnixNano())
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jUpdate, nil
}
Пример #4
0
func doResolveToMountTable(n namespace.T, context *context.T, name string, options []naming.NamespaceOpt) (jutil.Object, error) {
	entry, err := n.ResolveToMountTable(context, name, options...)
	if err != nil {
		return jutil.NullObject, err
	}
	env, freeFunc := jutil.GetEnv()
	defer freeFunc()
	jEntry, err := jutil.JVomCopy(env, entry, JMountEntryClass)
	if err != nil {
		return jutil.NullObject, err
	}
	// Must grab a global reference as we free up the env and all local references that come along
	// with it.
	return jutil.NewGlobalRef(env, jEntry), nil // Un-refed in DoAsyncCall
}
Пример #5
0
//export Java_io_v_impl_google_namespace_NamespaceImpl_nativeGlob
func Java_io_v_impl_google_namespace_NamespaceImpl_nativeGlob(jenv *C.JNIEnv, jNamespaceClass C.jclass, goRef C.jlong, jContext C.jobject, jPattern C.jstring, jOptions C.jobject) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	n := *(*namespace.T)(jutil.GoRefValue(jutil.Ref(goRef)))
	ctx, cancel, pattern, opts, err := globArgs(env, jContext, jPattern, jOptions)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	var globChannel <-chan naming.GlobReply
	var globError error
	globDone := make(chan bool)
	go func() {
		globChannel, globError = n.Glob(ctx, pattern, opts...)
		close(globDone)
	}()
	jChannel, err := jchannel.JavaInputChannel(env, ctx, cancel, func() (jutil.Object, error) {
		// A few blocking calls below - don't call GetEnv() before they complete.
		<-globDone
		if globError != nil {
			return jutil.NullObject, globError
		}
		globReply, ok := <-globChannel
		if !ok {
			return jutil.NullObject, verror.NewErrEndOfFile(ctx)
		}
		env, freeFunc := jutil.GetEnv()
		defer freeFunc()
		jReply, err := jutil.JVomCopy(env, globReply, jGlobReplyClass)
		if err != nil {
			return jutil.NullObject, err
		}
		// Must grab a global reference as we free up the env and all local references that come
		// along with it.
		return jutil.NewGlobalRef(env, jReply), nil // Un-refed by InputChannelImpl_nativeRecv
	})
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jChannel))
}
Пример #6
0
func doGetPermissions(n namespace.T, context *context.T, name string, options []naming.NamespaceOpt) (jutil.Object, error) {
	permissions, version, err := n.GetPermissions(context, name, options...)
	if err != nil {
		return jutil.NullObject, err
	}
	env, freeFunc := jutil.GetEnv()
	defer freeFunc()
	jPermissions, err := jutil.JVomCopy(env, permissions, jPermissionsClass)
	if err != nil {
		return jutil.NullObject, err
	}
	result := make(map[jutil.Object]jutil.Object)
	result[jutil.JString(env, version)] = jPermissions
	jResult, err := jutil.JObjectMap(env, result)
	if err != nil {
		return jutil.NullObject, err
	}
	// Must grab a global reference as we free up the env and all local references that come along
	// with it.
	return jutil.NewGlobalRef(env, jResult), nil // Un-refed in DoAsyncCall
}
Пример #7
0
func (s *blessingStore) CacheDischarge(discharge security.Discharge, caveat security.Caveat, impetus security.DischargeImpetus) {
	env, freeFunc := jutil.GetEnv()
	defer freeFunc()
	jDischarge, err := JavaDischarge(env, discharge)
	if err != nil {
		log.Printf("Couldn't get Java discharge: %v", err)
		return
	}
	jCaveat, err := JavaCaveat(env, caveat)
	if err != nil {
		log.Printf("Couldn't get Java caveat: %v", err)
		return
	}
	jImpetus, err := jutil.JVomCopy(env, impetus, jDischargeImpetusClass)
	if err != nil {
		log.Printf("Couldn't get Java DischargeImpetus: %v", err)
		return
	}
	err = jutil.CallVoidMethod(env, s.jBlessingStore, "cacheDischarge", []jutil.Sign{dischargeSign, caveatSign, dischargeImpetusSign}, jDischarge, jCaveat, jImpetus)
	if err != nil {
		log.Printf("Couldn't call cacheDischarge: %v", err)
	}
}
Пример #8
0
// JavaWireBlessings converts the provided Go WireBlessings into Java WireBlessings.
func JavaWireBlessings(env jutil.Env, wire security.WireBlessings) (jutil.Object, error) {
	return jutil.JVomCopy(env, wire, jWireBlessingsClass)
}
Пример #9
0
// JavaDischarge converts the provided Go Discharge into a Java discharge.
func JavaDischarge(env jutil.Env, discharge security.Discharge) (jutil.Object, error) {
	return jutil.JVomCopy(env, discharge, jDischargeClass)
}