示例#1
0
func (d *delegate) Initialize(mctx application.Context) {
	// TODO(bjornick): Calling init multiple times in the same process
	// will be bad.  For now, this is ok because this is the only
	// vanadium service that will be used in the demos and each go library
	// will be in its own process.
	roaming.SetArgs(mctx)
	d.ctx, d.shutdown = v23.Init()

	if *flagTestMode {
		// Inject a mock plugin.
		df, _ := idiscovery.NewFactory(d.ctx, mock.New())
		fdiscovery.InjectFactory(df)

		// Start a mounttable and set the namespace roots.
		//
		// Note that we need to listen on a local IP address in order to
		// accept connections within a GCE instance.
		d.ctx = v23.WithListenSpec(d.ctx, rpc.ListenSpec{Addrs: rpc.ListenAddrs{{Protocol: "tcp", Address: "127.0.0.1:0"}}})
		name, _, err := mounttablelib.StartServers(d.ctx, v23.GetListenSpec(d.ctx), "", "", "", "", "mounttable")
		if err != nil {
			panic(err)
		}
		ns := v23.GetNamespace(d.ctx)
		ns.SetRoots(name)
	}
}
示例#2
0
// StartMounttable starts a local mounttable server with an authorization
// policy that allows all principals to "Resolve" names, but restricts all
// other operations to the principal specified by the provided context.
//
// The mounttable makes itself visible in the local neighborhood under the
// name LockNeighborhoodPrefix + <nhName>.
//
// Returns the endpoint of the mounttable server and a callback to
// be invoked to shutdown the mounttable server on success, or an error
// on failure.
func StartMounttable(ctx *context.T, configDir string, nhName string) (string, func(), error) {
	if len(configDir) == 0 {
		return "", nil, errors.New("could not start mounttable, config directory not provided")
	}
	permFilePath := filepath.Join(configDir, permsFile)
	if err := initPermissions(permFilePath); err != nil {
		return "", nil, fmt.Errorf("could not initialize permissions file (%v) for mounttable: %v", permFilePath, err)
	}
	mtName, stopMT, err := mounttablelib.StartServers(ctx, v23.GetListenSpec(ctx), "", nhName, permFilePath, "", "mounttable")
	if err != nil {
		vlog.Errorf("mounttablelib.StartServers failed: %v", err)
		return "", nil, err
	}
	vlog.Infof("Started local mounttable at: %v", mtName)
	return mtName, func() {
		vlog.Infof("Stopping mounttable...")
		stopMT()
		vlog.Infof("Stopped mounttable.")
	}, nil
}