veyron/runtimes/google/ipc: Move "publisher" to its own package.
In unrelated design discussions, it was determined that instead of the server
publishing the proxied-endpoint, the server should instead ask the proxy to
publish the name (only the proxy will surely know its public-network
endpoint).
Move the publisher out to a separate library so that the proxy can
re-use it for publishing the names of proxied servers.
Change-Id: Iecf5d9e56a7ead82999d581d791a7e6fdd2f97a8
diff --git a/runtimes/google/ipc/consts.go b/runtimes/google/ipc/consts.go
index 83fca57..8eee968 100644
--- a/runtimes/google/ipc/consts.go
+++ b/runtimes/google/ipc/consts.go
@@ -5,8 +5,6 @@
const (
// The publisher re-mounts on this period.
publishPeriod = time.Minute
- // The publisher adds this much slack to each TTL.
- mountTTLSlack = 20 * time.Second
// The client and server use this timeout for calls by default.
defaultCallTimeout = time.Minute
diff --git a/runtimes/google/ipc/full_test.go b/runtimes/google/ipc/full_test.go
index 4b53246..39964a6 100644
--- a/runtimes/google/ipc/full_test.go
+++ b/runtimes/google/ipc/full_test.go
@@ -17,6 +17,7 @@
imanager "veyron/runtimes/google/ipc/stream/manager"
"veyron/runtimes/google/ipc/stream/vc"
"veyron/runtimes/google/ipc/version"
+ "veyron/runtimes/google/lib/publisher"
inaming "veyron/runtimes/google/naming"
isecurity "veyron/runtimes/google/security"
"veyron/security/caveat"
@@ -670,7 +671,7 @@
defer b.cleanup(t)
// Publish some incompatible endpoints.
- publisher := InternalNewPublisher(b.mt, publishPeriod)
+ publisher := publisher.New(b.mt, publishPeriod)
defer publisher.WaitForStop()
defer publisher.Stop()
publisher.AddName("incompatible")
diff --git a/runtimes/google/ipc/server.go b/runtimes/google/ipc/server.go
index cb406cb..ffa9a11 100644
--- a/runtimes/google/ipc/server.go
+++ b/runtimes/google/ipc/server.go
@@ -8,6 +8,7 @@
"sync"
"time"
+ "veyron/runtimes/google/lib/publisher"
inaming "veyron/runtimes/google/naming"
isecurity "veyron/runtimes/google/security"
@@ -34,7 +35,7 @@
sync.Mutex
streamMgr stream.Manager // stream manager to listen for new flows.
disptrie *disptrie // dispatch trie for method dispatching.
- publisher Publisher // publisher to publish mounttable mounts.
+ publisher publisher.Publisher // publisher to publish mounttable mounts.
listenerOpts []stream.ListenerOpt // listener opts passed to Listen.
listeners []stream.Listener // listeners created by Listen.
active sync.WaitGroup // active goroutines we've spawned.
@@ -48,7 +49,7 @@
s := &server{
streamMgr: streamMgr,
disptrie: newDisptrie(),
- publisher: InternalNewPublisher(mt, publishPeriod),
+ publisher: publisher.New(mt, publishPeriod),
mt: mt,
}
for _, opt := range opts {
diff --git a/runtimes/google/ipc/publisher.go b/runtimes/google/lib/publisher/publisher.go
similarity index 95%
rename from runtimes/google/ipc/publisher.go
rename to runtimes/google/lib/publisher/publisher.go
index 18a1f81..8c99e7f 100644
--- a/runtimes/google/ipc/publisher.go
+++ b/runtimes/google/lib/publisher/publisher.go
@@ -1,4 +1,5 @@
-package ipc
+// Package publisher provides a type to publish names to a mounttable.
+package publisher
// TODO(toddw): Add unittests.
@@ -30,6 +31,9 @@
WaitForStop()
}
+// The publisher adds this much slack to each TTL.
+const mountTTLSlack = 20 * time.Second
+
// publisher maintains the name->server associations in the mounttable. It
// spawns its own goroutine that does the actual work; the publisher itself
// simply coordinates concurrent access by sending and receiving on the
@@ -53,11 +57,8 @@
type publishedCmd chan []string // published names are sent when cmd is done
-// InternalNewPublisher returns a new publisher that updates mounts on mt every
-// period.
-// As the name suggests, this method is not meant to be used outside the
-// google runtime implementation.
-func InternalNewPublisher(mt naming.MountTable, period time.Duration) Publisher {
+// New returns a new publisher that updates mounts on mt every period.
+func New(mt naming.MountTable, period time.Duration) Publisher {
p := &publisher{
cmdchan: make(chan interface{}, 10),
donechan: make(chan struct{}),