| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| package main |
| |
| import ( |
| "fmt" |
| |
| "v.io/v23" |
| "v.io/x/lib/cmdline" |
| "v.io/x/lib/vlog" |
| |
| "v.io/v23/context" |
| "v.io/v23/rpc" |
| "v.io/v23/security" |
| |
| "v.io/x/ref/lib/signals" |
| "v.io/x/ref/lib/v23cmd" |
| "v.io/x/ref/lib/xrpc" |
| _ "v.io/x/ref/runtime/factories/roaming" |
| "v.io/x/ref/services/mounttable/mounttablelib" |
| "v.io/x/ref/test/discovery/b" |
| ) |
| |
| var ( |
| mtPort int |
| nhName string |
| ) |
| |
| func init() { |
| cmdRun.Flags.IntVar(&mtPort, "mtport", 9000, "port number of mounttable to run") |
| cmdRun.Flags.StringVar(&nhName, "nhname", "", "neighborhood mt name") |
| } |
| |
| var cmdRun = &cmdline.Command{ |
| Runner: v23cmd.RunnerFunc(runServer), |
| Name: "run", |
| Short: "Run a server for testing discovery", |
| } |
| |
| func runServer(ctx *context.T, env *cmdline.Env, args []string) error { |
| mtName, stopMT, err := startMounttable(ctx) |
| if err != nil { |
| return err |
| } |
| defer stopMT() |
| ctx, _, err = v23.WithNewNamespace(ctx, mtName) |
| if err != nil { |
| return err |
| } |
| server, err := xrpc.NewServer(ctx, "test/x", b.AnotherServiceServer(&impl{}), security.AllowEveryone()) |
| if err != nil { |
| ctx.Fatalf("NewServer failed: %v", err) |
| } |
| ctx.Infof("Listening on %s", server.Status().Endpoints[0].Name()) |
| <-signals.ShutdownOnSignals(ctx) |
| return nil |
| } |
| |
| func startMounttable(ctx *context.T) (string, func(), error) { |
| listenSpec := rpc.ListenSpec{Addrs: rpc.ListenAddrs{{"wsh", fmt.Sprintf(":%d", mtPort)}}} |
| mtName, stopMT, err := mounttablelib.StartServers(ctx, listenSpec, "", nhName, "", "", "mounttable") |
| if err != nil { |
| vlog.Errorf("mounttablelib.StartServers failed: %v", err) |
| return "", nil, err |
| } |
| vlog.Infof("Started local mounttable at: %v", mtName) |
| return mtName, stopMT, nil |
| } |
| |
| type impl struct{} |
| |
| func (i *impl) AMethod(_ *context.T, _ rpc.ServerCall) error { return nil } |
| func (i *impl) AnotherMethod(_ *context.T, _ rpc.ServerCall) error { return nil } |
| |
| func main() { |
| cmdline.HideGlobalFlagsExcept() |
| cmdline.Main(cmdRun) |
| } |