veyron/runtimes/google/ipc: new Serve method to replace Register+Publish.
Change-Id: Icc69645e753a3e84c5d87a3e9d2d4abd36275fff
diff --git a/services/mgmt/application/applicationd/main.go b/services/mgmt/application/applicationd/main.go
index f5bf624..d5e0a33 100644
--- a/services/mgmt/application/applicationd/main.go
+++ b/services/mgmt/application/applicationd/main.go
@@ -34,16 +34,12 @@
if err != nil {
vlog.Fatalf("NewDispatcher() failed: %v", err)
}
- suffix := ""
- if err := server.Register(suffix, dispatcher); err != nil {
- vlog.Fatalf("Register(%v, %v) failed: %v", suffix, dispatcher, err)
- }
endpoint, err := server.Listen(protocol, address)
if err != nil {
vlog.Fatalf("Listen(%v, %v) failed: %v", protocol, address, err)
}
- if err := server.Publish(name); err != nil {
- vlog.Fatalf("Publish(%v) failed: %v", name, err)
+ if err := server.Serve(name, dispatcher); err != nil {
+ vlog.Fatalf("Serve(%v) failed: %v", name, err)
}
vlog.VI(0).Infof("Application manager published at %v/%v", endpoint, name)
diff --git a/services/mgmt/application/impl/impl_test.go b/services/mgmt/application/impl/impl_test.go
index cee0cdb..76a0fd6 100644
--- a/services/mgmt/application/impl/impl_test.go
+++ b/services/mgmt/application/impl/impl_test.go
@@ -24,24 +24,30 @@
if err != nil {
t.Fatalf("NewServer() failed: %v", err)
}
+ defer server.Stop()
// Setup and start a store server.
- name, cleanup := testutil.NewStore(t, server, runtime.Identity().PublicID())
+ store, cleanup := testutil.NewStore(t, server, runtime.Identity().PublicID())
defer cleanup()
- dispatcher, err := NewDispatcher(name, nil)
+ server, err = runtime.NewServer()
+ if err != nil {
+ t.Fatalf("NewServer() failed: %v", err)
+ }
+
+ dispatcher, err := NewDispatcher(store, nil)
if err != nil {
t.Fatalf("NewDispatcher() failed: %v", err)
}
- suffix := ""
- if err := server.Register(suffix, dispatcher); err != nil {
- t.Fatalf("Register(%v, %v) failed: %v", suffix, dispatcher, err)
- }
+
protocol, hostname := "tcp", "localhost:0"
endpoint, err := server.Listen(protocol, hostname)
if err != nil {
t.Fatalf("Listen(%v, %v) failed: %v", protocol, hostname, err)
}
+ if err := server.Serve("", dispatcher); err != nil {
+ t.Fatalf("Serve(%v) failed: %v", dispatcher, err)
+ }
// Create client stubs for talking to the server.
stub, err := repository.BindApplication(naming.JoinAddressName(endpoint.String(), "//search"))
diff --git a/services/mgmt/node/impl/impl_test.go b/services/mgmt/node/impl/impl_test.go
index 5a2d08b..361f399 100644
--- a/services/mgmt/node/impl/impl_test.go
+++ b/services/mgmt/node/impl/impl_test.go
@@ -262,10 +262,7 @@
if err != nil {
vlog.Fatalf("NewServer() failed: %v", err)
}
- suffix, dispatcher := "", ipc.SoloDispatcher(repository.NewServerApplication(&arInvoker{}), nil)
- if err := server.Register(suffix, dispatcher); err != nil {
- vlog.Fatalf("Register(%v, %v) failed: %v", suffix, dispatcher, err)
- }
+ dispatcher := ipc.SoloDispatcher(repository.NewServerApplication(&arInvoker{}), nil)
protocol, hostname := "tcp", "localhost:0"
endpoint, err := server.Listen(protocol, hostname)
if err != nil {
@@ -273,8 +270,8 @@
}
vlog.VI(1).Infof("Application repository running at endpoint: %s", endpoint)
name := "ar"
- if err := server.Publish(name); err != nil {
- vlog.Fatalf("Publish(%v) failed: %v", name, err)
+ if err := server.Serve(name, dispatcher); err != nil {
+ vlog.Fatalf("Serve(%v) failed: %v", name, err)
}
return name, func() {
if err := server.Stop(); err != nil {
@@ -288,10 +285,7 @@
if err != nil {
vlog.Fatalf("NewServer() failed: %v", err)
}
- suffix, dispatcher := "", ipc.SoloDispatcher(repository.NewServerBinary(&crInvoker{}), nil)
- if err := server.Register(suffix, dispatcher); err != nil {
- vlog.Fatalf("Register(%v, %v) failed: %v", suffix, dispatcher, err)
- }
+ dispatcher := ipc.SoloDispatcher(repository.NewServerContent(&crInvoker{}), nil)
protocol, hostname := "tcp", "localhost:0"
endpoint, err := server.Listen(protocol, hostname)
if err != nil {
@@ -299,8 +293,8 @@
}
vlog.VI(1).Infof("Binary repository running at endpoint: %s", endpoint)
name := "cr"
- if err := server.Publish(name); err != nil {
- vlog.Fatalf("Publish(%v) failed: %v", name, err)
+ if err := server.Serve(name, dispatcher); err != nil {
+ vlog.Fatalf("Serve(%v) failed: %v", name, err)
}
return name, func() {
if err := server.Stop(); err != nil {
@@ -318,16 +312,15 @@
if err != nil {
t.Fatalf("NewMountTable() failed: %v", err)
}
- suffix := "mt"
- if err := server.Register(suffix, dispatcher); err != nil {
- t.Fatalf("Register(%v, %v) failed: %v", suffix, dispatcher, err)
- }
protocol, hostname := "tcp", "localhost:0"
endpoint, err := server.Listen(protocol, hostname)
if err != nil {
t.Fatalf("Listen(%v, %v) failed: %v", protocol, hostname, err)
}
- name := naming.JoinAddressName(endpoint.String(), suffix)
+ if err := server.Serve("", dispatcher); err != nil {
+ t.Fatalf("Serve(%v) failed: %v", dispatcher, err)
+ }
+ name := naming.JoinAddressName(endpoint.String(), "")
vlog.VI(1).Infof("Mount table name: %v", name)
return name, func() {
if err := server.Stop(); err != nil {
@@ -346,18 +339,15 @@
if err != nil {
vlog.Fatalf("Listen(%v, %v) failed: %v", protocol, hostname, err)
}
- suffix, envelope := "", &application.Envelope{}
- name := naming.MakeTerminal(naming.JoinAddressName(endpoint.String(), suffix))
+ envelope := &application.Envelope{}
+ name := naming.MakeTerminal(naming.JoinAddressName(endpoint.String(), ""))
vlog.VI(0).Infof("Node manager name: %v", name)
// TODO(jsimsa): Replace <PreviousEnv> with a command-line flag when
// command-line flags in tests are supported.
dispatcher := impl.NewDispatcher(nil, envelope, name, os.Getenv(impl.PreviousEnv))
- if err := server.Register(suffix, dispatcher); err != nil {
- vlog.Fatalf("Register(%v, %v) failed: %v", suffix, dispatcher, err)
- }
publishAs := "nm"
- if err := server.Publish(publishAs); err != nil {
- vlog.Fatalf("Publish(%v) failed: %v", publishAs, err)
+ if err := server.Serve(publishAs, dispatcher); err != nil {
+ vlog.Fatalf("Serve(%v) failed: %v", publishAs, err)
}
fmt.Printf("ready\n")
return name, func() {
@@ -408,7 +398,7 @@
ns := runtime.Namespace()
// The local, client-side Namespace is now relative to the
// MountTable server started above.
- ns.SetRoots([]string{mtName})
+ ns.SetRoots(mtName)
// Spawn a node manager with an identity blessed by the MountTable's
// identity under the name "test", and obtain its address.
//
diff --git a/services/mgmt/node/noded/main.go b/services/mgmt/node/noded/main.go
index ec9762b..af7c5d2 100644
--- a/services/mgmt/node/noded/main.go
+++ b/services/mgmt/node/noded/main.go
@@ -44,13 +44,8 @@
// TODO(jsimsa): Replace <PreviousEnv> with a command-line flag when
// command-line flags are supported in tests.
dispatcher := impl.NewDispatcher(vflag.NewAuthorizerOrDie(), envelope, name, os.Getenv(impl.PreviousEnv))
- if err := server.Register(suffix, dispatcher); err != nil {
- vlog.Fatalf("Register(%v, %v) failed: %v", suffix, dispatcher, err)
- }
- if len(publishAs) > 0 {
- if err := server.Publish(publishAs); err != nil {
- vlog.Fatalf("Publish(%v) failed: %v", publishAs, err)
- }
+ if err := server.Serve(publishAs, dispatcher); err != nil {
+ vlog.Fatalf("Serve(%v) failed: %v", publishAs, err)
}
handle, _ := exec.GetChildHandle()
if handle != nil {
diff --git a/services/mgmt/profile/impl/impl_test.go b/services/mgmt/profile/impl/impl_test.go
index 777444c..6822260 100644
--- a/services/mgmt/profile/impl/impl_test.go
+++ b/services/mgmt/profile/impl/impl_test.go
@@ -35,29 +35,31 @@
if err != nil {
t.Fatalf("NewServer() failed: %v", err)
}
+ defer server.Stop()
// Setup and start a store server.
mountPoint, cleanup := testutil.NewStore(t, server, runtime.Identity().PublicID())
defer cleanup()
+ // Setup and start the profile server.
+ server, err = runtime.NewServer()
+ if err != nil {
+ t.Fatalf("NewServer() failed: %v", err)
+ }
+
dispatcher, err := NewDispatcher(mountPoint, nil)
if err != nil {
t.Fatalf("NewDispatcher() failed: %v", err)
}
- suffix := ""
- if err := server.Register(suffix, dispatcher); err != nil {
- t.Fatalf("Register(%v, %v) failed: %v", suffix, dispatcher, err)
- }
protocol, hostname := "tcp", "localhost:0"
endpoint, err := server.Listen(protocol, hostname)
if err != nil {
t.Fatalf("Listen(%v, %v) failed: %v", protocol, hostname, err)
}
- name := ""
- if err := server.Publish(name); err != nil {
- t.Fatalf("Publish(%v) failed: %v", name, err)
+ if err := server.Serve("", dispatcher); err != nil {
+ t.Fatalf("Serve failed: %v", err)
}
- t.Logf("Profile repository published at %v/%v", endpoint, name)
+ t.Logf("Profile repository at %v", endpoint)
// Create client stubs for talking to the server.
stub, err := repository.BindProfile(naming.JoinAddressName(endpoint.String(), "//linux/base"))
diff --git a/services/mgmt/profile/profiled/main.go b/services/mgmt/profile/profiled/main.go
index 51ca649..cc33f62 100644
--- a/services/mgmt/profile/profiled/main.go
+++ b/services/mgmt/profile/profiled/main.go
@@ -33,16 +33,13 @@
if err != nil {
vlog.Fatalf("NewDispatcher() failed: %v", err)
}
- suffix := ""
- if err := server.Register(suffix, dispatcher); err != nil {
- vlog.Fatalf("Register(%v, %v) failed: %v", suffix, dispatcher, err)
- }
+
endpoint, err := server.Listen(protocol, address)
if err != nil {
vlog.Fatalf("Listen(%v, %v) failed: %v", protocol, address, err)
}
- if err := server.Publish(name); err != nil {
- vlog.Fatalf("Publish(%v) failed: %v", name, err)
+ if err := server.Serve(name, dispatcher); err != nil {
+ vlog.Fatalf("Serve(%v) failed: %v", name, err)
}
vlog.VI(0).Infof("Profile manager published at %v/%v", endpoint, name)
diff --git a/services/mgmt/root/rootd/main.go b/services/mgmt/root/rootd/main.go
index d28b6f4..ae4b33a 100644
--- a/services/mgmt/root/rootd/main.go
+++ b/services/mgmt/root/rootd/main.go
@@ -17,11 +17,7 @@
return
}
defer server.Stop()
- suffix, dispatcher := "", impl.NewDispatcher()
- if err := server.Register(suffix, dispatcher); err != nil {
- vlog.Errorf("Register(%v, %v) failed: %v", suffix, dispatcher, err)
- return
- }
+ dispatcher := impl.NewDispatcher()
protocol, hostname := "tcp", "localhost:0"
ep, err := server.Listen(protocol, hostname)
if err != nil {
@@ -30,8 +26,8 @@
}
vlog.VI(0).Infof("Listening on %v", ep)
name := ""
- if err := server.Publish(name); err != nil {
- vlog.Errorf("Publish(%v) failed: %v", name, err)
+ if err := server.Serve(name, dispatcher); err != nil {
+ vlog.Errorf("Serve(%v) failed: %v", name, err)
return
}
diff --git a/services/mounttable/lib/mounttable_test.go b/services/mounttable/lib/mounttable_test.go
index f8744bc..e961bc5 100644
--- a/services/mounttable/lib/mounttable_test.go
+++ b/services/mounttable/lib/mounttable_test.go
@@ -102,10 +102,14 @@
return nil, errors.New("Glob is not implemented in this MountTable")
}
-func (s stupidNS) SetRoots([]string) error {
+func (s stupidNS) SetRoots(...string) error {
return nil
}
+func (s stupidNS) Roots() []string {
+ return []string{}
+}
+
func doMount(t *testing.T, name, service string, shouldSucceed bool, id ipc.ClientOpt) {
mtpt, err := mounttable.BindMountTable(name, quuxClient(id))
if err != nil {
@@ -164,90 +168,108 @@
}
}
-func newServer(acl string, t *testing.T) (ipc.Server, string) {
+func newMT(t *testing.T, acl string) (ipc.Server, string) {
r := rt.Init()
- server, err := r.NewServer()
+ server, err := r.NewServer(veyron2.ServesMountTableOpt(true))
if err != nil {
boom(t, "r.NewServer: %s", err)
}
-
// Add mount table service.
mt, err := NewMountTable(acl)
if err != nil {
boom(t, "NewMountTable: %v", err)
}
- if err := server.Register("mounttable", mt); err != nil {
- boom(t, "Failed to register mount table: %s", err)
- }
-
// Start serving on a loopback address.
e, err := server.Listen("tcp", "127.0.0.1:0")
if err != nil {
boom(t, "Failed to Listen mount table: %s", err)
}
+ if err := server.Serve("", mt); err != nil {
+ boom(t, "Failed to register mock collection: %s", err)
+ }
+ estr := e.String()
+ t.Logf("endpoint %s", estr)
+ return server, estr
+}
+
+func newCollection(t *testing.T, acl string) (ipc.Server, string) {
+ r := rt.Init()
+ server, err := r.NewServer()
+ if err != nil {
+ boom(t, "r.NewServer: %s", err)
+ }
+ // Start serving on a loopback address.
+ e, err := server.Listen("tcp", "127.0.0.1:0")
+ if err != nil {
+ boom(t, "Failed to Listen mount table: %s", err)
+ }
+ // Add a collection service. This is just a service we can mount
+ // and test against.
+ cPrefix := "collection"
+ if err := server.Serve(cPrefix, newCollectionServer()); err != nil {
+ boom(t, "Failed to register mock collection: %s", err)
+ }
estr := e.String()
t.Logf("endpoint %s", estr)
return server, estr
}
func TestMountTable(t *testing.T) {
- server, estr := newServer("testdata/test.acl", t)
- defer server.Stop()
- // Add a collection service. This is just a service we can mount
- // and test against.
- cPrefix := "collection"
- if err := server.Register(cPrefix, newCollectionServer()); err != nil {
- boom(t, "Failed to register mock collection: %s", err)
- }
+ mt, mtAddr := newMT(t, "testdata/test.acl")
+ defer mt.Stop()
+ collection, collectionAddr := newCollection(t, "testdata/test.acl")
+ defer collection.Stop()
+
+ collectionName := naming.JoinAddressName(collectionAddr, "collection")
// Mount the collection server into the mount table.
- doMount(t, naming.JoinAddressName(estr, "//mounttable/stuff"), naming.JoinAddressName(estr, "collection"), true, rootID)
+ doMount(t, naming.JoinAddressName(mtAddr, "//mounttable/stuff"), collectionName, true, rootID)
// Create a few objects and make sure we can read them.
- create(t, naming.JoinAddressName(estr, "mounttable/stuff/the/rain"), "the rain")
- create(t, naming.JoinAddressName(estr, "mounttable/stuff/in/spain"), "in spain")
- create(t, naming.JoinAddressName(estr, "mounttable/stuff/falls"), "falls mainly on the plain")
- checkContents(t, naming.JoinAddressName(estr, "mounttable/stuff/the/rain"), "the rain", true, rootID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/stuff/in/spain"), "in spain", true, rootID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/stuff/falls"), "falls mainly on the plain", true, rootID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable//stuff/falls"), "falls mainly on the plain", false, rootID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/stuff/nonexistant"), "falls mainly on the plain", false, rootID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/stuff/the/rain"), "the rain", true, bobID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/stuff/the/rain"), "the rain", false, aliceID)
+ create(t, naming.JoinAddressName(mtAddr, "mounttable/stuff/the/rain"), "the rain")
+ create(t, naming.JoinAddressName(mtAddr, "mounttable/stuff/in/spain"), "in spain")
+ create(t, naming.JoinAddressName(mtAddr, "mounttable/stuff/falls"), "falls mainly on the plain")
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/stuff/the/rain"), "the rain", true, rootID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/stuff/in/spain"), "in spain", true, rootID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/stuff/falls"), "falls mainly on the plain", true, rootID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable//stuff/falls"), "falls mainly on the plain", false, rootID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/stuff/nonexistant"), "falls mainly on the plain", false, rootID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/stuff/the/rain"), "the rain", true, bobID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/stuff/the/rain"), "the rain", false, aliceID)
// Test multiple mounts.
- doMount(t, naming.JoinAddressName(estr, "//mounttable//a/b"), naming.JoinAddressName(estr, "collection"), true, rootID)
- doMount(t, naming.JoinAddressName(estr, "//mounttable/x/y"), naming.JoinAddressName(estr, "collection"), true, rootID)
- doMount(t, naming.JoinAddressName(estr, "//mounttable/alpha//beta"), naming.JoinAddressName(estr, "collection"), true, rootID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/stuff/falls"), "falls mainly on the plain", true, rootID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/a/b/falls"), "falls mainly on the plain", true, rootID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/x/y/falls"), "falls mainly on the plain", true, rootID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/alpha/beta/falls"), "falls mainly on the plain", true, rootID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/a/b/falls"), "falls mainly on the plain", true, aliceID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/a/b/falls"), "falls mainly on the plain", false, bobID)
+ doMount(t, naming.JoinAddressName(mtAddr, "//mounttable//a/b"), collectionName, true, rootID)
+ doMount(t, naming.JoinAddressName(mtAddr, "//mounttable/x/y"), collectionName, true, rootID)
+ doMount(t, naming.JoinAddressName(mtAddr, "//mounttable/alpha//beta"), collectionName, true, rootID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/stuff/falls"), "falls mainly on the plain", true, rootID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/a/b/falls"), "falls mainly on the plain", true, rootID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/x/y/falls"), "falls mainly on the plain", true, rootID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/alpha/beta/falls"), "falls mainly on the plain", true, rootID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/a/b/falls"), "falls mainly on the plain", true, aliceID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/a/b/falls"), "falls mainly on the plain", false, bobID)
// Test generic unmount.
- doUnmount(t, naming.JoinAddressName(estr, "//mounttable/a/b"), "", true, rootID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/a/b/falls"), "falls mainly on the plain", false, rootID)
+ doUnmount(t, naming.JoinAddressName(mtAddr, "//mounttable/a/b"), "", true, rootID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/a/b/falls"), "falls mainly on the plain", false, rootID)
// Test specific unmount.
- doMount(t, naming.JoinAddressName(estr, "//mounttable/a/b"), naming.JoinAddressName(estr, "collection"), true, rootID)
- doUnmount(t, naming.JoinAddressName(estr, "//mounttable/a/b"), naming.JoinAddressName(estr, "collection"), true, rootID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/a/b/falls"), "falls mainly on the plain", false, rootID)
+ doMount(t, naming.JoinAddressName(mtAddr, "//mounttable/a/b"), collectionName, true, rootID)
+ doUnmount(t, naming.JoinAddressName(mtAddr, "//mounttable/a/b"), collectionName, true, rootID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/a/b/falls"), "falls mainly on the plain", false, rootID)
// Try timing out a mount.
ft := NewFakeTimeClock()
setServerListClock(ft)
- doMount(t, naming.JoinAddressName(estr, "//mounttable/stuffWithTTL"), naming.JoinAddressName(estr, "collection"), true, rootID)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/stuffWithTTL/the/rain"), "the rain", true, rootID)
+ doMount(t, naming.JoinAddressName(mtAddr, "//mounttable/stuffWithTTL"), collectionName, true, rootID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/stuffWithTTL/the/rain"), "the rain", true, rootID)
ft.advance(time.Duration(ttlSecs+4) * time.Second)
- checkContents(t, naming.JoinAddressName(estr, "mounttable/stuffWithTTL/the/rain"), "the rain", false, rootID)
+ checkContents(t, naming.JoinAddressName(mtAddr, "mounttable/stuffWithTTL/the/rain"), "the rain", false, rootID)
// test unauthorized mount
- doMount(t, naming.JoinAddressName(estr, "//mounttable//a/b"), naming.JoinAddressName(estr, "collection"), false, bobID)
- doMount(t, naming.JoinAddressName(estr, "//mounttable//a/b"), naming.JoinAddressName(estr, "collection"), false, aliceID)
+ doMount(t, naming.JoinAddressName(mtAddr, "//mounttable//a/b"), collectionName, false, bobID)
+ doMount(t, naming.JoinAddressName(mtAddr, "//mounttable//a/b"), collectionName, false, aliceID)
- doUnmount(t, naming.JoinAddressName(estr, "//mounttable/x/y"), naming.JoinAddressName(estr, "collection"), false, bobID)
+ doUnmount(t, naming.JoinAddressName(mtAddr, "//mounttable/x/y"), collectionName, false, bobID)
}
func doGlob(t *testing.T, name, pattern string, id ipc.ClientOpt) []string {
@@ -287,14 +309,14 @@
}
func TestGlob(t *testing.T) {
- server, estr := newServer("", t)
+ server, estr := newMT(t, "")
defer server.Stop()
// set up a mount space
fakeServer := naming.JoinAddressName(estr, "quux")
- doMount(t, naming.JoinAddressName(estr, "//mounttable/one/bright/day"), fakeServer, true, rootID)
- doMount(t, naming.JoinAddressName(estr, "//mounttable/in/the/middle"), fakeServer, true, rootID)
- doMount(t, naming.JoinAddressName(estr, "//mounttable/of/the/night"), fakeServer, true, rootID)
+ doMount(t, naming.JoinAddressName(estr, "//one/bright/day"), fakeServer, true, rootID)
+ doMount(t, naming.JoinAddressName(estr, "//in/the/middle"), fakeServer, true, rootID)
+ doMount(t, naming.JoinAddressName(estr, "//of/the/night"), fakeServer, true, rootID)
// Try various globs.
tests := []struct {
@@ -311,19 +333,19 @@
{"", []string{""}},
}
for _, test := range tests {
- out := doGlob(t, naming.JoinAddressName(estr, "//mounttable"), test.in, rootID)
+ out := doGlob(t, naming.JoinAddressName(estr, "//"), test.in, rootID)
checkMatch(t, test.expected, out)
}
}
func TestGlobACLs(t *testing.T) {
- server, estr := newServer("testdata/test.acl", t)
+ server, estr := newMT(t, "testdata/test.acl")
defer server.Stop()
// set up a mount space
fakeServer := naming.JoinAddressName(estr, "quux")
- doMount(t, naming.JoinAddressName(estr, "//mounttable/one/bright/day"), fakeServer, true, rootID)
- doMount(t, naming.JoinAddressName(estr, "//mounttable/a/b/c"), fakeServer, true, rootID)
+ doMount(t, naming.JoinAddressName(estr, "//one/bright/day"), fakeServer, true, rootID)
+ doMount(t, naming.JoinAddressName(estr, "//a/b/c"), fakeServer, true, rootID)
// Try various globs.
tests := []struct {
@@ -339,13 +361,13 @@
{bobID, "*/...", []string{"one", "one/bright", "one/bright/day"}},
}
for _, test := range tests {
- out := doGlob(t, naming.JoinAddressName(estr, "//mounttable"), test.in, test.id)
+ out := doGlob(t, naming.JoinAddressName(estr, "//"), test.in, test.id)
checkMatch(t, test.expected, out)
}
}
func TestServerFormat(t *testing.T) {
- server, estr := newServer("", t)
+ server, estr := newMT(t, "")
defer server.Stop()
doMount(t, naming.JoinAddressName(estr, "//mounttable/endpoint"), naming.JoinAddressName(estr, "life/on/the/mississippi"), true, rootID)
@@ -357,15 +379,19 @@
}
func TestExpiry(t *testing.T) {
- server, estr := newServer("", t)
+ server, estr := newMT(t, "")
defer server.Stop()
+ collection, collectionAddr := newCollection(t, "testdata/test.acl")
+ defer collection.Stop()
+
+ collectionName := naming.JoinAddressName(collectionAddr, "collection")
ft := NewFakeTimeClock()
setServerListClock(ft)
- doMount(t, naming.JoinAddressName(estr, "//mounttable/a1/b1"), naming.JoinAddressName(estr, "collection"), true, rootID)
- doMount(t, naming.JoinAddressName(estr, "//mounttable/a1/b2"), naming.JoinAddressName(estr, "collection"), true, rootID)
- doMount(t, naming.JoinAddressName(estr, "//mounttable/a2/b1"), naming.JoinAddressName(estr, "collection"), true, rootID)
- doMount(t, naming.JoinAddressName(estr, "//mounttable/a2/b2/c"), naming.JoinAddressName(estr, "collection"), true, rootID)
+ doMount(t, naming.JoinAddressName(estr, "//mounttable/a1/b1"), collectionName, true, rootID)
+ doMount(t, naming.JoinAddressName(estr, "//mounttable/a1/b2"), collectionName, true, rootID)
+ doMount(t, naming.JoinAddressName(estr, "//mounttable/a2/b1"), collectionName, true, rootID)
+ doMount(t, naming.JoinAddressName(estr, "//mounttable/a2/b2/c"), collectionName, true, rootID)
checkMatch(t, []string{"a1/b1", "a2/b1"}, doGlob(t, naming.JoinAddressName(estr, "//mounttable"), "*/b1/...", rootID))
ft.advance(time.Duration(ttlSecs/2) * time.Second)
@@ -373,7 +399,7 @@
checkMatch(t, []string{"c"}, doGlob(t, naming.JoinAddressName(estr, "//mounttable/a2/b2"), "*", rootID))
// Refresh only a1/b1. All the other mounts will expire upon the next
// ft advance.
- doMount(t, naming.JoinAddressName(estr, "//mounttable/a1/b1"), naming.JoinAddressName(estr, "collection"), true, rootID)
+ doMount(t, naming.JoinAddressName(estr, "//mounttable/a1/b1"), collectionName, true, rootID)
ft.advance(time.Duration(ttlSecs/2+4) * time.Second)
checkMatch(t, []string{"a1"}, doGlob(t, naming.JoinAddressName(estr, "//mounttable"), "*", rootID))
checkMatch(t, []string{"a1/b1"}, doGlob(t, naming.JoinAddressName(estr, "//mounttable"), "*/b1/...", rootID))
diff --git a/services/mounttable/lib/neighborhood.go b/services/mounttable/lib/neighborhood.go
index b11588e..5f3a110 100644
--- a/services/mounttable/lib/neighborhood.go
+++ b/services/mounttable/lib/neighborhood.go
@@ -24,7 +24,6 @@
// neighborhood defines a set of machines on the same multicast media.
type neighborhood struct {
mdns *mdns.MDNS
- prefix string // mount point in the process namespace
nelems int
}
@@ -59,7 +58,7 @@
return uint16(port)
}
-func newNeighborhoodServer(prefix, host string, addresses []string, loopback bool) (*neighborhood, error) {
+func newNeighborhoodServer(host string, addresses []string, loopback bool) (*neighborhood, error) {
// Create the TXT contents with addresses to announce. Also pick up a port number.
var txt []string
var port uint16
@@ -87,20 +86,19 @@
mdns.AddService("veyron", "", port, txt...)
nh := &neighborhood{
- mdns: mdns,
- prefix: prefix,
+ mdns: mdns,
}
return nh, nil
}
// NewLoopbackNeighborhoodServer creates a new instance of a neighborhood server on loopback interfaces for testing.
-func NewLoopbackNeighborhoodServer(prefix, host string, addresses ...string) (*neighborhood, error) {
- return newNeighborhoodServer(prefix, host, addresses, true)
+func NewLoopbackNeighborhoodServer(host string, addresses ...string) (*neighborhood, error) {
+ return newNeighborhoodServer(host, addresses, true)
}
// NewNeighborhoodServer creates a new instance of a neighborhood server.
-func NewNeighborhoodServer(prefix, host string, addresses ...string) (*neighborhood, error) {
- return newNeighborhoodServer(prefix, host, addresses, false)
+func NewNeighborhoodServer(host string, addresses ...string) (*neighborhood, error) {
+ return newNeighborhoodServer(host, addresses, false)
}
// Lookup implements ipc.Dispatcher.Lookup.
diff --git a/services/mounttable/lib/neighborhood_test.go b/services/mounttable/lib/neighborhood_test.go
index 707241b..471edba 100644
--- a/services/mounttable/lib/neighborhood_test.go
+++ b/services/mounttable/lib/neighborhood_test.go
@@ -31,6 +31,7 @@
if err != nil {
boom(t, "r.NewServer: %s", err)
}
+ defer server.Stop()
// Start serving on a loopback address.
e, err := server.Listen("tcp", "127.0.0.1:0")
@@ -44,20 +45,19 @@
naming.JoinAddressName(estr, "suffix2"),
}
// Add neighborhood server.
- nhPrefix := "neighborhood"
- nhd, err := NewLoopbackNeighborhoodServer(nhPrefix, "joeblow", addresses...)
+ nhd, err := NewLoopbackNeighborhoodServer("joeblow", addresses...)
if err != nil {
boom(t, "Failed to create neighborhood server: %s\n", err)
}
defer nhd.Stop()
- if err := server.Register(nhPrefix, nhd); err != nil {
+ if err := server.Serve("", nhd); err != nil {
boom(t, "Failed to register neighborhood server: %s", err)
}
// Wait for the mounttable to appear in mdns
L:
for tries := 1; tries < 2; tries++ {
- names := doGlob(t, naming.JoinAddressName(estr, "//"+nhPrefix), "*", id)
+ names := doGlob(t, naming.JoinAddressName(estr, "//"), "*", id)
t.Logf("names %v", names)
for _, n := range names {
if n == "joeblow" {
@@ -67,18 +67,18 @@
time.Sleep(1 * time.Second)
}
- want, got := []string{"joeblow"}, doGlob(t, naming.JoinAddressName(estr, "//neighborhood"), "*", id)
+ want, got := []string{"joeblow"}, doGlob(t, naming.JoinAddressName(estr, "//"), "*", id)
if !reflect.DeepEqual(want, got) {
t.Errorf("Unexpected Glob result want: %q, got: %q", want, got)
}
- want, got = []string{""}, doGlob(t, naming.JoinAddressName(estr, "//neighborhood/joeblow"), "", id)
+ want, got = []string{""}, doGlob(t, naming.JoinAddressName(estr, "//joeblow"), "", id)
if !reflect.DeepEqual(want, got) {
t.Errorf("Unexpected Glob result want: %q, got: %q", want, got)
}
// Make sure we can resolve through the neighborhood.
expectedSuffix := "a/b"
- objectPtr, err := mounttable.BindMountTable(naming.JoinAddressName(estr, "//neighborhood/joeblow"+"/"+expectedSuffix), quuxClient(id))
+ objectPtr, err := mounttable.BindMountTable(naming.JoinAddressName(estr, "//joeblow"+"/"+expectedSuffix), quuxClient(id))
if err != nil {
boom(t, "BindMountTable: %s", err)
}
diff --git a/services/mounttable/mounttabled/mounttable.go b/services/mounttable/mounttabled/mounttable.go
index 6d2061d..fadc4a8 100644
--- a/services/mounttable/mounttabled/mounttable.go
+++ b/services/mounttable/mounttabled/mounttable.go
@@ -6,7 +6,6 @@
"fmt"
"net"
"os"
- "time"
"veyron2"
"veyron2/naming"
@@ -22,7 +21,6 @@
mountName = flag.String("name", "", "Name to mount this mountable as. Empty means don't mount.")
// TODO(rthellend): Remove the address flag when the config manager is working.
address = flag.String("address", ":0", "Address to listen on. Default is to use a randomly assigned port")
- prefix = flag.String("prefix", "mt", "The prefix to register the mounttable at.")
aclFile = flag.String("acls", "", "ACL file. Default is to allow all access.")
nhName = flag.String("neighborhood_name", "", "If non-empty, publish in the local neighborhood under this name.")
)
@@ -44,7 +42,7 @@
<nh name>, if provided, will enable sharing with the local neighborhood with
the provided name. The address of this mounttable will be published to the
neighboorhood and everything in the neighborhood will be visible on this
- mounttable with the "nh" prefix.
+ mounttable.
`
func Usage() {
@@ -52,8 +50,6 @@
}
func main() {
- // TODO(cnicolaou): fix Usage so that it includes the flags defined by
- // the runtime
flag.Usage = Usage
r := rt.Init()
defer r.Shutdown()
@@ -69,15 +65,22 @@
vlog.Errorf("r.NewMountTable failed: %v", err)
return
}
- if err := mtServer.Register(*prefix, mt); err != nil {
- vlog.Errorf("mtServer.Register failed to register mount table: %v", err)
- return
- }
mtEndpoint, err := mtServer.Listen("tcp", *address)
if err != nil {
vlog.Errorf("mtServer.Listen failed: %v", err)
return
}
+ name := *mountName
+ if err := mtServer.Serve(name, mt); err != nil {
+ vlog.Errorf("Serve(%v) failed: %v", name, err)
+ return
+ }
+ mtAddr := naming.JoinAddressName(mtEndpoint.String(), "")
+ r.Namespace().SetRoots(mtAddr)
+
+ vlog.Infof("Mount table service at: %q (%s)",
+ name,
+ naming.JoinAddressName(mtEndpoint.String(), ""))
if len(*nhName) > 0 {
nhServer, err := r.NewServer(veyron2.ServesMountTableOpt(true))
@@ -91,45 +94,19 @@
vlog.Errorf("parsing of address(%q) failed: %v", *address, err)
return
}
- nhEndpoint, err := nhServer.Listen("tcp", net.JoinHostPort(host, "0"))
- if err != nil {
+ if _, err = nhServer.Listen("tcp", net.JoinHostPort(host, "0")); err != nil {
vlog.Errorf("nhServer.Listen failed: %v", err)
return
}
- mtAddr := naming.JoinAddressName(mtEndpoint.String(), *prefix)
-
nh, err := mounttable.NewNeighborhoodServer("", *nhName, mtAddr)
if err != nil {
vlog.Errorf("NewNeighborhoodServer failed: %v", err)
return
}
- if err := nhServer.Register("", nh); err != nil {
- vlog.Errorf("nhServer.Register failed to register neighborhood: %v", err)
+ if err := nhServer.Serve("nh", nh); err != nil {
+ vlog.Errorf("nhServer.Serve failed to register neighborhood: %v", err)
return
}
- nhAddr := naming.JoinAddressName(nhEndpoint.String(), "")
- nhMount := naming.Join(mtAddr, "nh")
-
- ns := rt.R().Namespace()
- forever := time.Duration(0)
- if err = ns.Mount(rt.R().NewContext(), nhMount, nhAddr, forever); err != nil {
- vlog.Errorf("ns.Mount failed to mount neighborhood: %v", err)
- return
- }
- }
-
- if name := *mountName; len(name) > 0 {
- if err := mtServer.Publish(name); err != nil {
- vlog.Errorf("Publish(%v) failed: %v", name, err)
- return
- }
- vlog.Infof("Mount table service at: %s (%s)",
- naming.Join(name, *prefix),
- naming.JoinAddressName(mtEndpoint.String(), *prefix))
-
- } else {
- vlog.Infof("Mount table at: %s",
- naming.JoinAddressName(mtEndpoint.String(), *prefix))
}
// Wait until signal is received.
diff --git a/services/security/simpledischarged/main.go b/services/security/simpledischarged/main.go
index cb9a840..bb1db9f 100644
--- a/services/security/simpledischarged/main.go
+++ b/services/security/simpledischarged/main.go
@@ -65,22 +65,14 @@
discharger := isecurity.NewServerDischarger(&discharged{
id: r.Identity(), expiration: expiration})
- err = server.Register("discharged", ipc.SoloDispatcher(discharger, dischargeAuthorizer{}))
- if err != nil {
- log.Fatal(err)
- }
-
+ dispatcher := ipc.SoloDispatcher(discharger, dischargeAuthorizer{})
endpoint, err := server.Listen(*protocol, *address+":"+fmt.Sprint(*port))
if err != nil {
log.Fatal(err)
}
-
- if *publish != "" {
- if err := server.Publish(*publish); err != nil {
- log.Fatal(err)
- }
+ if err := server.Serve(*publish, dispatcher); err != nil {
+ log.Fatal(err)
}
-
fmt.Println(endpoint)
<-signals.ShutdownOnSignals()
}
diff --git a/services/store/stored/main.go b/services/store/stored/main.go
index 674fdf3..1d820b1 100644
--- a/services/store/stored/main.go
+++ b/services/store/stored/main.go
@@ -69,20 +69,15 @@
// Register the services.
storeDisp := server.NewStoreDispatcher(storeService, auth)
- if err := s.Register("", storeDisp); err != nil {
- log.Fatal("s.Register(storeDisp) failed: ", err)
- }
-
// Create an endpoint and start listening.
ep, err := s.Listen("tcp", *address)
if err != nil {
log.Fatal("s.Listen() failed: ", err)
}
-
// Publish the service in the mount table.
log.Printf("Mounting store on %s, endpoint /%s", mountName, ep)
- if err := s.Publish(mountName); err != nil {
- log.Fatal("s.Publish() failed: ", err)
+ if err := s.Serve(mountName, storeDisp); err != nil {
+ log.Fatal("s.Serve() failed: ", err)
}
// Wait forever.
diff --git a/services/store/testutil/store.go b/services/store/testutil/store.go
index 1350312..a53fd88 100644
--- a/services/store/testutil/store.go
+++ b/services/store/testutil/store.go
@@ -2,7 +2,6 @@
import (
"crypto/rand"
- "fmt"
"io/ioutil"
"os"
"testing"
@@ -37,12 +36,9 @@
t.Fatalf("rand.Read() failed: %v", err)
}
- name := fmt.Sprintf("test/%x", buf)
- t.Logf("Storage server at %v", name)
-
// Register the services.
storeDispatcher := istore.NewStoreDispatcher(storeService, nil)
- if err := server.Register(name, storeDispatcher); err != nil {
+ if err := server.Serve("", storeDispatcher); err != nil {
t.Fatalf("Register(%v) failed: %v", storeDispatcher, err)
}
@@ -53,8 +49,7 @@
t.Fatalf("Listen(%v, %v) failed: %v", protocol, hostname, err)
}
- name = naming.JoinAddressName(ep.String(), name)
- name = naming.MakeTerminal(name)
+ name := naming.JoinAddressName(ep.String(), "")
// Create a closure that cleans things up.
cleanup := func() {
diff --git a/services/wspr/wsprd/lib/server.go b/services/wspr/wsprd/lib/server.go
index 0497ae6..5fd89bf 100644
--- a/services/wspr/wsprd/lib/server.go
+++ b/services/wspr/wsprd/lib/server.go
@@ -6,7 +6,9 @@
"bytes"
"encoding/json"
"fmt"
+ "strings"
"sync"
+
"veyron2"
"veyron2/ipc"
"veyron2/security"
@@ -35,7 +37,9 @@
// The server that handles the ipc layer. Listen on this server is
// lazily started.
- server ipc.Server
+ server ipc.Server
+ dispatcher exactMatchDispatcher
+
// The endpoint of the server. This is empty until the server has been
// started and listen has been called on it.
endpoint string
@@ -57,6 +61,7 @@
helper: helper,
veyronProxy: veyronProxy,
outstandingServerRequests: make(map[int64]chan *serverRPCReply),
+ dispatcher: exactMatchDispatcher{dispatchers: make(map[string]ipc.Dispatcher)},
}
var err error
if server.server, err = helper.rt().NewServer(); err != nil {
@@ -141,12 +146,43 @@
}
}
+type exactMatchDispatcher struct {
+ sync.Mutex
+ dispatchers map[string]ipc.Dispatcher
+}
+
+func (em *exactMatchDispatcher) Lookup(suffix string) (ipc.Invoker, security.Authorizer, error) {
+ parts := strings.Split(suffix, "/")
+ if len(parts) == 0 || len(parts[0]) == 0 {
+ return nil, nil, fmt.Errorf("can't extract first path component from %q", suffix)
+ }
+ name := parts[0]
+ em.Lock()
+ defer em.Unlock()
+ if disp := em.dispatchers[name]; disp == nil {
+ return nil, nil, fmt.Errorf("no dispatcher registered for %q, from %q", name, suffix)
+ } else {
+ suffix = strings.TrimLeft(suffix, "/")
+ suffix = strings.TrimPrefix(suffix, name[0])
+ suffix = strings.TrimLeft(suffix, "/")
+ return disp.Lookup(suffix)
+ }
+}
+
+// register associates a dispatcher with name, where name cannot contain
+// any /s. Incoming invocations of the form <name>/... will be passed
+// on to the dispatcher with <name>/... as the parameter to its lookup
+// method.
func (s *server) register(name string, sig JSONServiceSignature) error {
serviceSig, err := sig.ServiceSignature()
if err != nil {
return err
}
+ if strings.Contains(name, "/") {
+ return fmt.Errorf("%q must not contain /", name)
+ }
+
remoteInvokeFunc := s.createRemoteInvokerFunc(name)
invoker, err := newInvoker(serviceSig, remoteInvokeFunc)
@@ -157,10 +193,9 @@
security.ACL{security.AllPrincipals: security.AllLabels},
))
- if err := s.server.Register(name, dispatcher); err != nil {
- return err
- }
-
+ s.dispatcher.Lock()
+ s.dispatcher.dispatchers[name] = dispatcher
+ s.dispatcher.Unlock()
return nil
}
@@ -175,7 +210,7 @@
}
s.endpoint = endpoint.String()
}
- if err := s.server.Publish(name); err != nil {
+ if err := s.server.Serve(name, &s.dispatcher); err != nil {
return "", err
}
s.helper.getLogger().VI(1).Infof("endpoint is %s", s.endpoint)
diff --git a/services/wspr/wsprd/lib/wspr_test.go b/services/wspr/wsprd/lib/wspr_test.go
index 4ea681a..15d4ac3 100644
--- a/services/wspr/wsprd/lib/wspr_test.go
+++ b/services/wspr/wsprd/lib/wspr_test.go
@@ -91,40 +91,26 @@
return result, nil
}
-// A function that will register an handlers on the given server
-type registerFunc func(ipc.Server) error
-
-func startServer(registerer registerFunc) (ipc.Server, naming.Endpoint, error) {
- return startAnyServer(false, registerer)
-}
-
-func startMTServer(registerer registerFunc) (ipc.Server, naming.Endpoint, error) {
- return startAnyServer(true, registerer)
-}
-
-func startAnyServer(servesMT bool, registerer registerFunc) (ipc.Server, naming.Endpoint, error) {
+func startAnyServer(servesMT bool, dispatcher ipc.Dispatcher) (ipc.Server, naming.Endpoint, error) {
// Create a new server instance.
s, err := r.NewServer(veyron2.ServesMountTableOpt(servesMT))
if err != nil {
return nil, nil, err
}
- // Register the "fortune" prefix with the fortune dispatcher.
- if err := registerer(s); err != nil {
- return nil, nil, err
- }
-
endpoint, err := s.Listen("tcp", "127.0.0.1:0")
if err != nil {
return nil, nil, err
}
+
+ if err := s.Serve("", dispatcher); err != nil {
+ return nil, nil, err
+ }
return s, endpoint, nil
}
func startAdderServer() (ipc.Server, naming.Endpoint, error) {
- return startServer(func(server ipc.Server) error {
- return server.Register("cache", ipc.SoloDispatcher(simpleAdder{}, nil))
- })
+ return startAnyServer(false, ipc.SoloDispatcher(simpleAdder{}, nil))
}
func startProxy() (*proxy.Proxy, error) {
@@ -132,18 +118,15 @@
if err != nil {
return nil, err
}
-
return proxy.New(rid, nil, "tcp", "127.0.0.1:0", "")
}
func startMountTableServer() (ipc.Server, naming.Endpoint, error) {
- return startMTServer(func(server ipc.Server) error {
- mt, err := mounttable.NewMountTable("")
- if err != nil {
- return err
- }
- return server.Register("mt", mt)
- })
+ mt, err := mounttable.NewMountTable("")
+ if err != nil {
+ return nil, nil, err
+ }
+ return startAnyServer(true, mt)
}
type testWriter struct {
@@ -251,7 +234,7 @@
wspr.setup()
wsp := websocketPipe{ctx: wspr}
wsp.setup()
- jsSig, err := wsp.getSignature("/"+endpoint.String()+"//cache", "")
+ jsSig, err := wsp.getSignature("/"+endpoint.String(), "")
if err != nil {
t.Errorf("Failed to get signature: %v", err)
}
@@ -304,7 +287,7 @@
}
request := veyronRPC{
- Name: "/" + endpoint.String() + "//cache",
+ Name: "/" + endpoint.String(),
Method: test.method,
InArgs: test.inArgs,
NumOutArgs: test.numOutArgs,
@@ -396,7 +379,7 @@
proxyEndpoint := proxyServer.Endpoint().String()
- wspr := NewWSPR(0, "/"+proxyEndpoint, veyron2.NamespaceRoots{"/" + endpoint.String() + "/mt"})
+ wspr := NewWSPR(0, "/"+proxyEndpoint, veyron2.NamespaceRoots{"/" + endpoint.String()})
wspr.setup()
wsp := websocketPipe{ctx: wspr}
writer := testWriter{
@@ -429,7 +412,8 @@
}
if len(rt.writer.stream) != 1 {
- t.Errorf("expected only on response, got %d", len(rt.writer.stream))
+ t.Errorf("expected only one response, got %d", len(rt.writer.stream))
+ return
}
resp := rt.writer.stream[0]
@@ -516,6 +500,7 @@
if len(rt.writer.stream) != 1 {
t.Errorf("expected only on response, got %d", len(rt.writer.stream))
+ return
}
resp := rt.writer.stream[0]
@@ -558,7 +543,7 @@
"args": test.inArgs,
"context": map[string]interface{}{
"name": "adder",
- "suffix": "",
+ "suffix": "adder",
},
},
},