Merge "veyron/services/security/revoker: revocation service"
diff --git a/examples/pipetobrowser/Makefile b/examples/pipetobrowser/Makefile
index 474caf5..e941562 100644
--- a/examples/pipetobrowser/Makefile
+++ b/examples/pipetobrowser/Makefile
@@ -20,8 +20,8 @@
all: node_modules browser/third-party browser/third-party/veyron browser/build.js browser/index.html $(VEYRON_ROOT)/veyron/go/bin
# Build p2b cli binary
-$(VEYRON_ROOT)/veyron/go/bin: cli/main.go
- $(VEYRON_BUILD_SCRIPT) install veyron/examples/pipetobrowser/...
+$(VEYRON_ROOT)/veyron/go/bin: p2b/main.go
+ $(VEYRON_BUILD_SCRIPT) install veyron/...
# Install what we need from NPM, tools such as jspm, serve, etc...
node_modules: package.json
@@ -31,9 +31,9 @@
# Build and copies Veyron from local source
browser/third-party/veyron: $(VEYRON_JS_API)
- mkdir browser/third-party -p
+ mkdir -p browser/third-party
(cd $(VEYRON_JS_API) && ./vgrunt build)
- mkdir browser/third-party/veyron -p
+ mkdir -p browser/third-party/veyron
cp -rf $(VEYRON_JS_API)/dist/*.* browser/third-party/veyron
# Install JSPM and Bower packages as listed in browser/package.json from JSPM and browser/bower.json from bower
@@ -75,10 +75,6 @@
# Deploys Veyron daemons
daemons:
- @if [[ ! -e $(VEYRON_PROXY) ]]; then \
- echo "Veyron proxy could not be found in $(VEYRON_PROXY). Please build and install veyron2 and services first"; \
- exit 1; \
- fi
identity --name=veyron_p2b_identity > $(VEYRON_IDENTITY_PATH)
export VEYRON_IDENTITY=$(VEYRON_IDENTITY_PATH) ; \
identityd --address=:$(VEYRON_IDENTITY_PORT) & \
@@ -86,7 +82,6 @@
export NAMESPACE_ROOT=/localhost:$(VEYRON_MOUNTTABLE_PORT) ; \
proxyd -address=$(VEYRON_PROXY_ADDR) & \
wsprd --v=1 -logtostderr=true -vproxy=$(VEYRON_PROXY_ADDR) --port $(VEYRON_WSPR_PORT) & \
- $(VEYRON_STORE) --address=:$(VEYRON_STORE_PORT) --name=global/$(USER)/store &
# Kills the running daemons
clean-daemons:
diff --git a/examples/pipetobrowser/browser/actions/add-pipe-viewer.js b/examples/pipetobrowser/browser/actions/add-pipe-viewer.js
index 419d70d..a284731 100644
--- a/examples/pipetobrowser/browser/actions/add-pipe-viewer.js
+++ b/examples/pipetobrowser/browser/actions/add-pipe-viewer.js
@@ -67,8 +67,11 @@
// Add a new tab and show a loading indicator for now,
// then replace the loading view with the actual viewer when ready
+ // close the stream when tab closes
var loadingView = new LoadingView();
- pipesViewInstance.addTab(tabKey, tabName, loadingView);
+ pipesViewInstance.addTab(tabKey, tabName, loadingView, () => {
+ stream.end();
+ });
// Add the redirect stream action
var icon = 'hardware:cast';
diff --git a/examples/pipetobrowser/browser/actions/navigate-help.js b/examples/pipetobrowser/browser/actions/navigate-help.js
index d2c0691..01f2117 100644
--- a/examples/pipetobrowser/browser/actions/navigate-help.js
+++ b/examples/pipetobrowser/browser/actions/navigate-help.js
@@ -12,7 +12,7 @@
import { HelpView } from 'views/help/view'
var log = new Logger('actions/navigate-help');
-const ACTION_NAME = 'help';
+var ACTION_NAME = 'help';
/*
* Registers the action
diff --git a/examples/pipetobrowser/browser/actions/redirect-pipe.js b/examples/pipetobrowser/browser/actions/redirect-pipe.js
index 28ce6d9..6bcb93b 100644
--- a/examples/pipetobrowser/browser/actions/redirect-pipe.js
+++ b/examples/pipetobrowser/browser/actions/redirect-pipe.js
@@ -61,7 +61,7 @@
getAllPublishedP2BNames().then((allNames) => {
// append current plugin name to the veyron names for better UX
dialog.existingNames = allNames.map((n) => {
- return n + (currentPluginName || '');
+ return n + '/' + currentPluginName;
});
}).catch((e) => {
log.debug('getAllPublishedP2BNames failed', e);
diff --git a/examples/pipetobrowser/browser/app.html b/examples/pipetobrowser/browser/app.html
index c592cb2..d6dfbd6 100644
--- a/examples/pipetobrowser/browser/app.html
+++ b/examples/pipetobrowser/browser/app.html
@@ -9,6 +9,14 @@
<title>Pipe To Browser - because life is too short to stare at unformatted stdout text, and is hard enough already not to have a spell-checker for stdin</title>
<script src="third-party/platform/platform.js"></script>
+ <!-- TODO(aghassemi) use CJS version of Veyron and provide an ES6 shim -->
+ <script src="third-party/veyron/veyron.js"></script>
+
+ <script src="third-party/traceur-runtime@0.0.49.js"></script>
+ <script src="third-party/system@0.6.js"></script>
+ <script src="config.js"></script>
+ <script src="build.js"></script>
+
<link rel="import" href="views/page/component.html"/>
<style type="text/css">
@@ -19,13 +27,7 @@
</style>
</head>
<body>
- <!-- TODO(aghassemi) use CJS version of Veyron and provide an ES6 shim -->
- <script src="third-party/veyron/veyron.js"></script>
- <script src="third-party/traceur-runtime@0.0.49.js"></script>
- <script src="third-party/system@0.6.js"></script>
- <script src="config.js"></script>
- <script src="build.js"></script>
<script>
window.addEventListener('polymer-ready', function(e) {
diff --git a/examples/pipetobrowser/browser/bower.json b/examples/pipetobrowser/browser/bower.json
index 6ebd373..0217621 100644
--- a/examples/pipetobrowser/browser/bower.json
+++ b/examples/pipetobrowser/browser/bower.json
@@ -2,8 +2,8 @@
"name": "pipe-to-browser",
"version": "0.0.1",
"dependencies": {
- "polymer": "Polymer/polymer#~0.3.2",
- "core-elements": "Polymer/core-elements#~0.3.2",
- "paper-elements": "Polymer/paper-elements#~0.3.2"
+ "polymer": "Polymer/polymer#~0.3.4",
+ "core-elements": "Polymer/core-elements#~0.3.4",
+ "paper-elements": "Polymer/paper-elements#~0.3.4"
}
}
diff --git a/examples/pipetobrowser/browser/config.js b/examples/pipetobrowser/browser/config.js
index 2e7b142..4206c8a 100644
--- a/examples/pipetobrowser/browser/config.js
+++ b/examples/pipetobrowser/browser/config.js
@@ -6,6 +6,8 @@
"view": "libs/mvc/view.js",
"logger": "libs/logs/logger.js",
"stream-helpers": "libs/utils/stream-helpers.js",
+ "web-component-loader": "libs/utils/web-component-loader.js",
+ "formatting": "libs/utils/formatting.js",
"npm:*": "third-party/npm/*.js",
"github:*": "third-party/github/*.js"
}
@@ -13,41 +15,43 @@
System.config({
"map": {
+ "npm:humanize": "npm:humanize@^0.0.9",
"npm:event-stream": "npm:event-stream@^3.1.5",
"nodelibs": "github:jspm/nodelibs@master",
"npm:event-stream@3.1.5": {
- "through": "npm:through@^2.3.1",
- "pause-stream": "npm:pause-stream@0.0.11",
"from": "npm:from@0",
- "stream-combiner": "npm:stream-combiner@^0.0.4",
"map-stream": "npm:map-stream@0.1",
+ "pause-stream": "npm:pause-stream@0.0.11",
"duplexer": "npm:duplexer@^0.1.1",
- "split": "npm:split@0.2"
+ "through": "npm:through@^2.3.1",
+ "split": "npm:split@0.2",
+ "stream-combiner": "npm:stream-combiner@^0.0.4"
},
+ "npm:humanize@0.0.9": {},
+ "npm:from@0.1.3": {},
"npm:stream-combiner@0.0.4": {
"duplexer": "npm:duplexer@^0.1.1"
},
+ "npm:duplexer@0.1.1": {},
+ "npm:map-stream@0.1.0": {},
"npm:pause-stream@0.0.11": {
"through": "npm:through@2.3"
},
- "npm:from@0.1.3": {},
- "npm:through@2.3.4": {},
- "npm:duplexer@0.1.1": {},
"npm:split@0.2.10": {
"through": "npm:through@2"
},
- "npm:map-stream@0.1.0": {},
+ "npm:through@2.3.4": {},
"github:jspm/nodelibs@0.0.2": {
- "base64-js": "npm:base64-js@^0.0.4",
"ieee754": "npm:ieee754@^1.1.1",
- "inherits": "npm:inherits@^2.0.1",
+ "base64-js": "npm:base64-js@^0.0.4",
"Base64": "npm:Base64@0.2",
+ "inherits": "npm:inherits@^2.0.1",
"json": "github:systemjs/plugin-json@master"
},
"npm:base64-js@0.0.4": {},
+ "npm:ieee754@1.1.3": {},
"npm:Base64@0.2.1": {},
"npm:inherits@2.0.1": {},
- "npm:ieee754@1.1.3": {},
"github:jspm/nodelibs@master": {
"Base64": "npm:Base64@0.2",
"base64-js": "npm:base64-js@^0.0.4",
@@ -60,22 +64,23 @@
System.config({
"versions": {
+ "npm:humanize": "0.0.9",
"npm:event-stream": "3.1.5",
- "npm:through": "2.3.4",
- "npm:pause-stream": "0.0.11",
"npm:from": "0.1.3",
- "npm:stream-combiner": "0.0.4",
"npm:map-stream": "0.1.0",
+ "npm:pause-stream": "0.0.11",
"npm:duplexer": "0.1.1",
+ "npm:through": "2.3.4",
"npm:split": "0.2.10",
+ "npm:stream-combiner": "0.0.4",
"github:jspm/nodelibs": [
"master",
"0.0.2"
],
- "npm:base64-js": "0.0.4",
"npm:ieee754": "1.1.3",
- "npm:inherits": "2.0.1",
+ "npm:base64-js": "0.0.4",
"npm:Base64": "0.2.1",
+ "npm:inherits": "2.0.1",
"github:systemjs/plugin-json": "master"
}
});
diff --git a/examples/pipetobrowser/browser/libs/ui-components/data-grid/grid/column/renderer.html b/examples/pipetobrowser/browser/libs/ui-components/data-grid/grid/column/renderer.html
index cb2f8c9..208ff49 100644
--- a/examples/pipetobrowser/browser/libs/ui-components/data-grid/grid/column/renderer.html
+++ b/examples/pipetobrowser/browser/libs/ui-components/data-grid/grid/column/renderer.html
@@ -38,9 +38,9 @@
}
if (this.gridState.sort.ascending) {
- return this.data.label + ' \u21A7'; // up wedge unicode character
+ return this.data.label + ' \u21A5'; // up wedge unicode character
} else {
- return this.data.label + ' \u21A5'; // down wedge unicode character
+ return this.data.label + ' \u21A7'; // down wedge unicode character
}
}
});
diff --git a/examples/pipetobrowser/browser/libs/ui-components/data-grid/grid/component.css b/examples/pipetobrowser/browser/libs/ui-components/data-grid/grid/component.css
index 87cdff3..b309a31 100644
--- a/examples/pipetobrowser/browser/libs/ui-components/data-grid/grid/component.css
+++ b/examples/pipetobrowser/browser/libs/ui-components/data-grid/grid/component.css
@@ -26,6 +26,7 @@
.more-icon {
fill: #0a7e07;
+ color: #0a7e07;
}
paper-dialog {
@@ -33,11 +34,6 @@
width: 80vw;
}
-/* hack: wrong z-index in shadow of paper-dialog disables text selection in dialog */
-paper-dialog /deep/ #shadow {
- z-index: -1;
-}
-
.more-dialog-content .heading {
font-size: 1.0em;
padding-top: 0.2em;
@@ -85,6 +81,10 @@
display: initial;
}
+.more-dialog-content [gridOnly] {
+ display:none;
+}
+
.paginator {
display: inline-block;
border: solid 1px rgba(0, 0, 0, 0.05);
@@ -97,4 +97,4 @@
.paginator paper-icon-button {
vertical-align: middle;
-}
\ No newline at end of file
+}
diff --git a/examples/pipetobrowser/browser/libs/ui-components/data-grid/grid/component.html b/examples/pipetobrowser/browser/libs/ui-components/data-grid/grid/component.html
index a67f7dd..974cc97 100644
--- a/examples/pipetobrowser/browser/libs/ui-components/data-grid/grid/component.html
+++ b/examples/pipetobrowser/browser/libs/ui-components/data-grid/grid/component.html
@@ -157,15 +157,15 @@
/*
* Number if items displayed in each page.
- * Defaults to 30
+ * Defaults to 20
* @type {integer}
*/
- pageSize: 30,
+ pageSize: 20,
showMoreInfo: function(e) {
var item = e.target.templateInstance.model.item;
this.selectedItems = [item];
- this.$.dialog.opened = true;
+ this.$.dialog.toggle();
},
ready: function() {
@@ -333,7 +333,7 @@
col.columnData.flex = col.columnData.origFlex;
}
- if (tableWidth >= minWidth) {
+ if (tableWidth === 0 || tableWidth >= minWidth) {
return;
}
diff --git a/examples/pipetobrowser/browser/libs/utils/byte-object-stream-adapter.js b/examples/pipetobrowser/browser/libs/utils/byte-object-stream-adapter.js
index d12c998..90593e1 100644
--- a/examples/pipetobrowser/browser/libs/utils/byte-object-stream-adapter.js
+++ b/examples/pipetobrowser/browser/libs/utils/byte-object-stream-adapter.js
@@ -3,9 +3,6 @@
var Transform = Stream.Transform;
var Buffer = buffer.Buffer;
-// TODO(aghassemi) doesn't look like ES6 and CommonJS modules can use the same
-// syntax to be referenced, but research more, maybe something can be done at
-// built time.
/*
* Adapts a stream of byte arrays in object mode to a regular stream of Buffer
diff --git a/examples/pipetobrowser/browser/libs/utils/formatting.js b/examples/pipetobrowser/browser/libs/utils/formatting.js
new file mode 100644
index 0000000..26f90e6
--- /dev/null
+++ b/examples/pipetobrowser/browser/libs/utils/formatting.js
@@ -0,0 +1,23 @@
+import { default as humanize } from 'npm:humanize'
+
+export function formatDate(d) {
+ if(d === undefined || d == null) { return; }
+ var naturalDay = humanize.naturalDay(d.getTime() / 1000);
+ var naturalTime = humanize.date('g:i a', d);
+ return naturalDay + ' at ' + naturalTime;
+}
+
+export function formatRelativeTime(d) {
+ if(d === undefined || d == null) { return; }
+ return humanize.relativeTime(d.getTime() / 1000);
+}
+
+export function formatInteger(n) {
+ if(n === undefined || n == null) { return; }
+ return humanize.numberFormat(n, 0);
+}
+
+export function formatBytes(b) {
+ if(b === undefined || b == null) { return; }
+ return humanize.filesize(b);
+}
\ No newline at end of file
diff --git a/examples/pipetobrowser/browser/libs/utils/stream-copy.js b/examples/pipetobrowser/browser/libs/utils/stream-copy.js
index 4b7e386..c940213 100644
--- a/examples/pipetobrowser/browser/libs/utils/stream-copy.js
+++ b/examples/pipetobrowser/browser/libs/utils/stream-copy.js
@@ -17,6 +17,13 @@
// TODO(aghassemi) make this a FIFO buffer with reasonable max-size
this.buffer = [];
this.copies = [];
+ var self = this;
+ this.on('end', () => {
+ self.ended = true;
+ for (var i=0; i < self.copies.length; i++) {
+ self.copies[i].end();
+ }
+ });
}
_transform(chunk, encoding, cb) {
@@ -42,7 +49,12 @@
copy.push(this.buffer[i]);
}
}
- this.copies.push(copy);
+ if (this.ended) {
+ copy.push(null);
+ } else {
+ this.copies.push(copy);
+ }
+
return copy;
}
}
diff --git a/examples/pipetobrowser/browser/libs/utils/time.js b/examples/pipetobrowser/browser/libs/utils/time.js
deleted file mode 100644
index be9b42d..0000000
--- a/examples/pipetobrowser/browser/libs/utils/time.js
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Given a time duration in seconds, formats it as h' hours, m' minutes, s' seconds
- * in EN-US.
- * @param {integer} durationInSeconds Time period in seconds
- * @return {string} EN-US formatted time period.
- */
-export function formatDuration(durationInSeconds) {
- var hours = Math.floor(durationInSeconds/3600);
- var minutes = Math.floor((durationInSeconds - (hours*3600))/60);
- var seconds = durationInSeconds - (hours*3600) - (minutes*60);
-
- return _pluralize('hour', hours, true) +
- _pluralize('minute', minutes, true) +
- _pluralize('second', seconds, false);
-}
-
-function _pluralize(name, value, returnEmptyIfZero) {
- if(value == 0 && returnEmptyIfZero) {
- return '';
- }
- if(value != 1) {
- name = name + 's';
- }
- return value + ' ' + name + ' ';
-}
\ No newline at end of file
diff --git a/examples/pipetobrowser/browser/libs/utils/web-component-loader.js b/examples/pipetobrowser/browser/libs/utils/web-component-loader.js
new file mode 100644
index 0000000..bb37e0c
--- /dev/null
+++ b/examples/pipetobrowser/browser/libs/utils/web-component-loader.js
@@ -0,0 +1,11 @@
+export function importComponent(path) {
+ return new Promise((resolve, reject) => {
+ var link = document.createElement('link');
+ link.setAttribute('rel', 'import');
+ link.setAttribute('href', path);
+ link.onload = function() {
+ resolve();
+ };
+ document.body.appendChild(link);
+ });
+}
\ No newline at end of file
diff --git a/examples/pipetobrowser/browser/package.json b/examples/pipetobrowser/browser/package.json
index 773f16f..93fe433 100644
--- a/examples/pipetobrowser/browser/package.json
+++ b/examples/pipetobrowser/browser/package.json
@@ -6,6 +6,7 @@
},
"dependencies": {
"npm:event-stream": "^3.1.5",
+ "npm:humanize": "^0.0.9",
"nodelibs": "master"
}
}
\ No newline at end of file
diff --git a/examples/pipetobrowser/browser/pipe-viewers/builtin/console/component.css b/examples/pipetobrowser/browser/pipe-viewers/builtin/console/component.css
index 2091d34..d1ef530 100644
--- a/examples/pipetobrowser/browser/pipe-viewers/builtin/console/component.css
+++ b/examples/pipetobrowser/browser/pipe-viewers/builtin/console/component.css
@@ -15,3 +15,12 @@
color: #ffffff;
}
+
+.auto-scroll {
+ position: fixed;
+ right: 40px;
+ bottom: 0;
+ opacity: 0.8;
+ padding: 0.8em;
+ background-color: #ffeb3b;
+}
diff --git a/examples/pipetobrowser/browser/pipe-viewers/builtin/console/component.html b/examples/pipetobrowser/browser/pipe-viewers/builtin/console/component.html
index d816aed..5505f9b 100644
--- a/examples/pipetobrowser/browser/pipe-viewers/builtin/console/component.html
+++ b/examples/pipetobrowser/browser/pipe-viewers/builtin/console/component.html
@@ -12,8 +12,11 @@
</template>
<script>
Polymer('p2b-plugin-console', {
- autoScroll: true,
- textBuffer: [],
+ ready: function() {
+ this.textBuffer = [];
+ this.autoScroll = true;
+ },
+
attached: function() {
this.renderLoop();
},
diff --git a/examples/pipetobrowser/browser/pipe-viewers/builtin/git/status/component.css b/examples/pipetobrowser/browser/pipe-viewers/builtin/git/status/component.css
index 9b266fe..99617a1 100644
--- a/examples/pipetobrowser/browser/pipe-viewers/builtin/git/status/component.css
+++ b/examples/pipetobrowser/browser/pipe-viewers/builtin/git/status/component.css
@@ -7,7 +7,8 @@
}
::shadow /deep/ .state-icon.conflicted {
- fill: #e51c23;
+ fill: #bf360c;
+ -webkit-animation: blink 0.6s infinite alternate;
}
::shadow /deep/ .state-icon.untracked {
@@ -15,7 +16,7 @@
}
::shadow /deep/ .state-icon.ignored {
- fill: #bf360c;
+ fill: #689f38;
}
::shadow /deep/ .action-icon {
diff --git a/examples/pipetobrowser/browser/pipe-viewers/builtin/git/status/plugin.js b/examples/pipetobrowser/browser/pipe-viewers/builtin/git/status/plugin.js
index 7ac8c63..11583c5 100644
--- a/examples/pipetobrowser/browser/pipe-viewers/builtin/git/status/plugin.js
+++ b/examples/pipetobrowser/browser/pipe-viewers/builtin/git/status/plugin.js
@@ -91,10 +91,10 @@
iconName = 'warning';
break;
case 'conflicted':
- iconName = 'error';
+ iconName = 'block';
break;
case 'untracked':
- iconName = 'report';
+ iconName = 'error';
break;
case 'ignored':
iconName = 'visibility-off';
@@ -122,7 +122,7 @@
iconName = 'translate';
break;
case 'renamed':
- iconName = 'sync';
+ iconName = 'swap-horiz';
break;
case 'copied':
iconName = 'content-copy';
diff --git a/examples/pipetobrowser/browser/pipe-viewers/builtin/vlog/component.html b/examples/pipetobrowser/browser/pipe-viewers/builtin/vlog/component.html
index 59f4f28..3a70a5c 100644
--- a/examples/pipetobrowser/browser/pipe-viewers/builtin/vlog/component.html
+++ b/examples/pipetobrowser/browser/pipe-viewers/builtin/vlog/component.html
@@ -12,7 +12,7 @@
<link rel="stylesheet" href="../../../libs/css/common-style.css">
<link rel="stylesheet" href="component.css">
- <p2b-grid id="grid" defaultSortKey="date" defaultSortAscending dataSource="{{ dataSource }}" summary="Data Grid displaying veyron log items in a tabular format with filters and search options.">
+ <p2b-grid id="grid" defaultSortKey="date" dataSource="{{ dataSource }}" summary="Data Grid displaying veyron log items in a tabular format with filters and search options.">
<!-- Search -->
<p2b-grid-search label="Search Logs"></p2b-grid-search>
@@ -48,8 +48,12 @@
<p2b-grid-column label="Message" key="message" primary flex="8" minFlex="5" priority="1" >
<template><div class="message-text">{{ item.message }}</div></template>
</p2b-grid-column>
- <p2b-grid-column label="Date" key="date" sortable flex="6" minFlex="3" priority="3">
- <template><span class="smaller-text">{{ item.date }}</span></template>
+ <p2b-grid-column label="Date" key="date" sortable flex="4" minFlex="3" priority="3">
+ <template>
+ <abbr gridOnly title="{{item.date}}">{{ item.formattedDate }}</abbr>
+ <span moreInfoOnly>{{item.date}}</span>
+ </template>
+
</p2b-grid-column>
<p2b-grid-column label="Threadid" key="threadid" sortable flex="0" priority="5">
<template>{{ item.threadId }}</template>
diff --git a/examples/pipetobrowser/browser/pipe-viewers/builtin/vlog/plugin.js b/examples/pipetobrowser/browser/pipe-viewers/builtin/vlog/plugin.js
index 76d52a2..db749ff 100644
--- a/examples/pipetobrowser/browser/pipe-viewers/builtin/vlog/plugin.js
+++ b/examples/pipetobrowser/browser/pipe-viewers/builtin/vlog/plugin.js
@@ -9,6 +9,7 @@
import { View } from 'view';
import { PipeViewer } from 'pipe-viewer';
import { streamUtil } from 'stream-helpers';
+import { formatDate } from 'formatting';
import { Logger } from 'logger'
import { vLogDataSource } from './data-source';
@@ -51,6 +52,7 @@
*/
function addAdditionalUIProperties(item) {
addIconProperty(item);
+ addFormattedDate(item);
}
/*
@@ -78,4 +80,12 @@
item.icon = iconName;
}
+/*
+ * Adds a human friendly date field
+ * @private
+ */
+function addFormattedDate(item) {
+ item.formattedDate = formatDate(item.date);
+}
+
export default vLogPipeViewer;
\ No newline at end of file
diff --git a/examples/pipetobrowser/browser/pipe-viewers/manager.js b/examples/pipetobrowser/browser/pipe-viewers/manager.js
index d135741..4c7dea0 100644
--- a/examples/pipetobrowser/browser/pipe-viewers/manager.js
+++ b/examples/pipetobrowser/browser/pipe-viewers/manager.js
@@ -82,7 +82,9 @@
*/
function getPath(name) {
if(isAbsoulteUrl(name)) {
- return name;
+ var encodedName = encodeURIComponent(name);
+ System.paths[encodedName] = name;
+ return encodedName;
} else {
return 'pipe-viewers/builtin/' + name + '/plugin';
}
diff --git a/examples/pipetobrowser/browser/services/pipe-to-browser-server.js b/examples/pipetobrowser/browser/services/pipe-to-browser-server.js
index cf04487..ac4e0f4 100644
--- a/examples/pipetobrowser/browser/services/pipe-to-browser-server.js
+++ b/examples/pipetobrowser/browser/services/pipe-to-browser-server.js
@@ -69,19 +69,32 @@
var stream = streamCopier.pipe(bufferStream).pipe(streamByteCounter);
stream.copier = streamCopier;
- bufferStream.on('end', () => {
+ streamByteCounter.on('end', () => {
log.debug('end of stream');
// send total number of bytes received for this call as final result
- resolve(numBytesForThisCall);
+ resolve();
});
- bufferStream.on('error', (e) => {
+ stream.on('error', (e) => {
log.debug('stream error', e);
- reject(e);
+ // TODO(aghassemi) envyor issue #50
+ // we want to reject but because of #50 we can't
+ // reject('Browser P2B threw an exception. Please see browser console for details.');
+ // reject(e);
+ resolve();
});
state.numPipes++;
- pipeRequestHandler($suffix, stream);
+ try {
+ pipeRequestHandler($suffix, stream);
+ } catch(e) {
+ // TODO(aghassemi) envyor issue #50
+ // we want to reject but because of #50 we can't
+ // reject('Browser P2B threw an exception. Please see browser console for details.');
+ log.debug('pipeRequestHandler error', e);
+ resolve();
+ }
+
});
}
};
diff --git a/examples/pipetobrowser/browser/views/help/component.css b/examples/pipetobrowser/browser/views/help/component.css
index faf1990..1e2e557 100644
--- a/examples/pipetobrowser/browser/views/help/component.css
+++ b/examples/pipetobrowser/browser/views/help/component.css
@@ -29,4 +29,5 @@
a {
color: #5677fc;
text-decoration: none;
+ cursor: pointer;
}
\ No newline at end of file
diff --git a/examples/pipetobrowser/browser/views/help/component.html b/examples/pipetobrowser/browser/views/help/component.html
index 46e1d2c..ba5112c 100644
--- a/examples/pipetobrowser/browser/views/help/component.html
+++ b/examples/pipetobrowser/browser/views/help/component.html
@@ -1,4 +1,4 @@
-<link rel="import" href="/libs/vendor/polymer/polymer/polymer.html">
+<link rel="import" href="../../third-party/polymer/polymer.html">
<polymer-element name="p2b-help">
<template>
@@ -40,10 +40,13 @@
<pre class="code">cat /dev/urandom | p2b {{publishedName}}/dev/null</pre>
<h3>Remote Viewers</h3>
- <p>In addition to built-in viewers, ad-hoc remote viewers can be hosted anywhere and used with P2B. Remote viewers are referenced by their Url without the .js extension at the end og the plug-in JavaScript file</p>
- <pre class="code">echo "Hello World" | p2b {{publishedName}}/http://googledrive.com/host/0BzmT5cnKdCAKa3hzNEVCU2tnd3c/helloworld</pre>
+ <p>In addition to built-in viewers, ad-hoc remote viewers can be hosted anywhere and used with P2B. Remote viewers are referenced by the Url of the plug-in JavaScript file</p>
+ <pre class="code">echo "Hello World" | p2b {{publishedName}}/http://googledrive.com/host/0BzmT5cnKdCAKa3hzNEVCU2tnd3c/helloworld.js</pre>
<p>Writing remote viewers is not different than writing built-in ones and basic plug-ins are pretty straight forward to write.</p>
<p>At high level, plug-ins are expected to implement a <span class="mono">PipeViewer</span> interface which has a <span class="mono">play(stream)</span> method. A <span class="mono">view</span> (which is a wrapper for a DOM element) is expected to be returned from <span class="mono">play(stream)</span>. You can look at the hello world remote plug-in <a href="http://googledrive.com/host/0BzmT5cnKdCAKa3hzNEVCU2tnd3c/helloworld.js" target="_blank">code on Google drive</a> to get started on writing new remote plug-ins</p>
+ <p>It is also possible to write the UI layer of your plug-in in HTML and CSS as a Web Component to avoid mixing logic and layout/styling in a single file.</p>
+ <p>Grumpy cat meme plug-in takes that approach. You can look at the <a href="http://googledrive.com/host/0BzmT5cnKdCAKV1p6Q0pjak5Kams/meme.js" target="_blank">JavaScript</a> and <a onClick="window.open('view-source:' + 'http://googledrive.com/host/0BzmT5cnKdCAKV1p6Q0pjak5Kams/meme.html');">HTML Web Component</a> source files.</p>
+ <pre class="code">echo "I take stuff from stdin, and send them to /dev/null" | p2b {{publishedName}}/http://googledrive.com/host/0BzmT5cnKdCAKV1p6Q0pjak5Kams/meme.js</pre>
</template>
<script>
Polymer('p2b-help', {
diff --git a/examples/pipetobrowser/browser/views/page/component.css b/examples/pipetobrowser/browser/views/page/component.css
index 787f3bb..793659b 100644
--- a/examples/pipetobrowser/browser/views/page/component.css
+++ b/examples/pipetobrowser/browser/views/page/component.css
@@ -11,12 +11,10 @@
[sidebar] {
padding: 0.5em;
- fill: #9e9e9e;
}
[sidebar] .core-selected {
color: #00bcd4;
- fill: #212121;
}
[main] {
diff --git a/examples/pipetobrowser/browser/views/page/component.html b/examples/pipetobrowser/browser/views/page/component.html
index 0993f2a..f1ab37c 100644
--- a/examples/pipetobrowser/browser/views/page/component.html
+++ b/examples/pipetobrowser/browser/views/page/component.html
@@ -15,6 +15,7 @@
<link rel="import" href="../../views/publish/component.html"/>
<link rel="import" href="../../views/status/component.html"/>
<link rel="import" href="../../views/error/component.html"/>
+<link rel="import" href="../../views/help/component.html"/>
<link rel="import" href="../../views/loading/component.html"/>
<link rel="import" href="../../views/pipes/component.html"/>
<link rel="import" href="../../views/redirect-pipe-dialog/component.html"/>
diff --git a/examples/pipetobrowser/browser/views/pipes/component.html b/examples/pipetobrowser/browser/views/pipes/component.html
index 9558d16..c877519 100644
--- a/examples/pipetobrowser/browser/views/pipes/component.html
+++ b/examples/pipetobrowser/browser/views/pipes/component.html
@@ -61,8 +61,9 @@
* @param {string} key Key of the tab to add
* @param {string} name Name of the tab to add
* @param {DOMElement} el Content of the tab
+ * @param {function} onClose Optional onClose callback.
*/
- addTab: function(key, name, el) {
+ addTab: function(key, name, el, onClose) {
var self = this;
// Create a tab thumb
@@ -75,6 +76,9 @@
tabToolbar.title = name;
tabToolbar.addEventListener('close-action', function() {
self.removeTab(key);
+ if (onClose) {
+ onClose();
+ }
});
tabToolbar.addEventListener('fullscreen-action', function() {
var tabContent = self.pipeTabs[key].tabContent;
@@ -88,7 +92,6 @@
tabContent.appendChild(el);
this.$.tabPages.appendChild(tabContent);
- this.$.tabs.appendChild(tab);
// Add the tab to our list.
this.pipeTabs[key] = {
@@ -99,6 +102,9 @@
};
this.selectedTabKey = key;
+ requestAnimationFrame(function() {
+ self.$.tabs.appendChild(tab);
+ });
},
/*
@@ -108,6 +114,9 @@
* @param onClick {function} event handler for the action
*/
addToolbarAction: function(tabKey, icon, onClick) {
+ if (!this.pipeTabs[tabKey]) {
+ return;
+ }
var toolbar = this.pipeTabs[tabKey].tabToolbar;
toolbar.add(icon, onClick);
},
@@ -117,6 +126,9 @@
* @param {string} key Key of the tab to remove
*/
removeTab: function(key) {
+ if (!this.pipeTabs[key]) {
+ return;
+ }
// Remove tab thumb and content
var tab = this.pipeTabs[key].tab;
tab.remove();
@@ -144,6 +156,9 @@
* @param {DOMElement} el New content of the tab
*/
replaceTabContent: function(key, newName, newEl) {
+ if (!this.pipeTabs[key]) {
+ return;
+ }
var tabContent = this.pipeTabs[key].tabContent;
tabContent.replaceTabContent(newEl);
if (newName) {
diff --git a/examples/pipetobrowser/browser/views/pipes/view.js b/examples/pipetobrowser/browser/views/pipes/view.js
index 8c9e2b4..78fcd20 100644
--- a/examples/pipetobrowser/browser/views/pipes/view.js
+++ b/examples/pipetobrowser/browser/views/pipes/view.js
@@ -18,9 +18,10 @@
* @param {string} name A short name for the tab that will be displayed as
* the tab title
* @param {View} view View to show inside the tab.
+ * @param {function} onClose Optional onClose callback.
*/
- addTab(key, name, view) {
- this.element.addTab(key, name, view.element);
+ addTab(key, name, view, onClose) {
+ this.element.addTab(key, name, view.element, onClose);
}
/*
diff --git a/examples/pipetobrowser/browser/views/redirect-pipe-dialog/component.css b/examples/pipetobrowser/browser/views/redirect-pipe-dialog/component.css
index a58b136..b1bdca0 100644
--- a/examples/pipetobrowser/browser/views/redirect-pipe-dialog/component.css
+++ b/examples/pipetobrowser/browser/views/redirect-pipe-dialog/component.css
@@ -11,11 +11,6 @@
width: 80vw;
}
-/* hack: wrong z-index in shadow of paper-dialog disables text selection in dialog */
-paper-dialog /deep/ #shadow {
- z-index: -1 !important;
-}
-
paper-button[affirmative] {
color: #4285f4;
}
diff --git a/examples/pipetobrowser/browser/views/status/component.html b/examples/pipetobrowser/browser/views/status/component.html
index ca511a2..8362866 100644
--- a/examples/pipetobrowser/browser/views/status/component.html
+++ b/examples/pipetobrowser/browser/views/status/component.html
@@ -1,4 +1,5 @@
<link rel="import" href="../../third-party/polymer/polymer.html">
+<link rel="import" href="../../third-party/paper-button/paper-button.html">
<polymer-element name="p2b-status" attributes="status">
@@ -6,118 +7,83 @@
<link rel="stylesheet" href="../common/common.css">
<link rel="stylesheet" href="component.css">
<h3>Status</h3>
- <p>{{ statusText }}</p>
- <div class="{{ {hidden : !serviceState.published} | tokenList}}">
+ <p>{{ serviceState | formatServiceState }}</p>
+ <div class="{{ {hidden : !serviceState.published} | tokenList }}">
<h3>Name</h3>
<p>{{ serviceState.fullServiceName }}</p>
<h3>Published on</h3>
- <p>{{ publishDate }}</p>
+ <p>{{ serviceState.date | formatDate }}</p>
- <h3>Uptime</h3>
- <p>{{ uptime }}</p>
+ <h3>Running Since</h3>
+ <p>{{ runningSince }}</p>
<h3>Number of pipe requests</h3>
- <p>{{ numPipes }}</p>
+ <p>{{ serviceState.numPipes | formatInteger }}</p>
<h3>Total bytes received</h3>
- <p>{{ numBytes }}</p>
+ <p>{{ serviceState.numBytes | formatBytes }}</p>
</div>
- <paper-button class="paper colored red" inkColor="#A9352C" on-click="{{ stopAction }}">Stop Service</paper-button>
+ <paper-button class="paper colored red" inkColor="#A9352C" on-click="{{ stopAction }}">Stop</paper-button>
</template>
<script>
- Polymer('p2b-status', {
+ System.import('libs/utils/formatting').then(function(formatter) {
+ Polymer('p2b-status', {
- /*
- * Dynamic binding for the state of publishing p2b service.
- * Any changes to this object will be reflected in the UI automatically
- */
- serviceState: null,
+ /*
+ * Dynamic binding for the state of publishing p2b service.
+ * Any changes to this object will be reflected in the UI automatically
+ */
+ serviceState: null,
- /*
- * A function that can format time duration
- * @private
- * @type {function}
- */
- formatDuration: null,
+ /*
+ * Human friendly formatting functions. Because polymer filter expressions
+ * don't accept obj.func we wrap them here
+ * @private
+ */
+ formatDate: formatter.formatDate,
+ formatInteger: formatter.formatInteger,
+ formatBytes: formatter.formatBytes,
- /*
- * Status text
- * @private
- * @type {string}
- */
- get statusText() {
- if (!this.serviceState) {
- return '';
+ /*
+ * Auto-updating Uptime text
+ * @private
+ * @type {string}
+ */
+ get runningSince() {
+ if (!this.serviceState) { return; }
+ return formatter.formatRelativeTime(this.serviceState.date);
+ },
+
+ /*
+ * Status text
+ * @private
+ * @type {string}
+ */
+ formatServiceState: function(serviceState) {
+ if (!serviceState) {
+ return '';
+ }
+ if (serviceState.published) {
+ return 'Published';
+ } else if(serviceState.publishing) {
+ return 'Publishing';
+ } else if(serviceState.stopping) {
+ return 'Stopping';
+ } else {
+ return 'Stopped';
+ }
+ },
+
+ /*
+ * Stop action. Fires when user decides to stop the p2b service.
+ * @event
+ */
+ stopAction: function() {
+ this.fire('stop');
}
- if (this.serviceState.published) {
- return 'Published';
- } else if(this.serviceState.publishing) {
- return 'Publishing';
- } else if(this.serviceState.stopping) {
- return 'Stopping';
- } else {
- return 'Stopped';
- }
- },
- /*
- * Formatted publish date
- * @private
- * @type {string}
- */
- get publishDate() {
- if (!this.serviceState || !this.serviceState.published) {
- return '';
- }
- return this.serviceState.date.toString();
- },
-
- /*
- * Formatted uptime
- * @private
- * @type {string}
- */
- get uptime() {
- if (!this.serviceState || !this.serviceState.published) {
- return '';
- }
- var elapsedSeconds = Math.floor((new Date() - this.serviceState.date) / 1000);
- return this.formatDuration(elapsedSeconds);
- },
-
- /*
- * Formatted number of pipes
- * @private
- * @type {string}
- */
- get numPipes() {
- if (!this.serviceState || !this.serviceState.published) {
- return '';
- }
- return this.serviceState.numPipes.toString();
- },
-
- /*
- * Formatted number of bytes
- * @private
- * @type {string}
- */
- get numBytes() {
- if (!this.serviceState || !this.serviceState.published) {
- return '';
- }
- return this.serviceState.numBytes.toString();
- },
-
- /*
- * Stop action. Fires when user decides to stop the p2b service.
- * @event
- */
- stopAction: function() {
- this.fire('stop');
- }
-
+ });
});
</script>
</polymer-element>
\ No newline at end of file
diff --git a/examples/pipetobrowser/browser/views/status/view.js b/examples/pipetobrowser/browser/views/status/view.js
index 0f15358..8792b8c 100644
--- a/examples/pipetobrowser/browser/views/status/view.js
+++ b/examples/pipetobrowser/browser/views/status/view.js
@@ -1,5 +1,4 @@
import { View } from 'libs/mvc/view'
-import { formatDuration } from 'libs/utils/time'
/*
* View representing the state and interaction for publishing the p2b service.
@@ -10,11 +9,6 @@
constructor(serviceState) {
var el = document.createElement('p2b-status');
el.serviceState = serviceState;
-
- // TODO(aghassemi) ES6 import syntax doesn't seem to work inside Polymer
- // script tag. Test again when compiling server-side with Traceur.
- el.formatDuration = formatDuration;
-
super(el);
}
diff --git a/examples/pipetobrowser/p2b.vdl b/examples/pipetobrowser/p2b.vdl
index eff991e..3a20904 100644
--- a/examples/pipetobrowser/p2b.vdl
+++ b/examples/pipetobrowser/p2b.vdl
@@ -3,5 +3,5 @@
// Viewer allows clients to stream data to it and to request a particular viewer to format and display the data.
type Viewer interface {
// Pipe creates a bidirectional pipe between client and viewer service, returns total number of bytes received by the service after streaming ends
- Pipe() stream<[]byte, _> (int64, error)
+ Pipe() stream<[]byte, _> (any, error)
}
\ No newline at end of file
diff --git a/examples/pipetobrowser/p2b.vdl.go b/examples/pipetobrowser/p2b.vdl.go
index 422123b..bfa0f47 100644
--- a/examples/pipetobrowser/p2b.vdl.go
+++ b/examples/pipetobrowser/p2b.vdl.go
@@ -31,7 +31,7 @@
type ViewerService interface {
// Pipe creates a bidirectional pipe between client and viewer service, returns total number of bytes received by the service after streaming ends
- Pipe(context _gen_ipc.ServerContext, stream ViewerServicePipeStream) (reply int64, err error)
+ Pipe(context _gen_ipc.ServerContext, stream ViewerServicePipeStream) (reply _gen_vdlutil.Any, err error)
}
// ViewerPipeStream is the interface for streaming responses of the method
@@ -50,7 +50,7 @@
// Finish closes the stream and returns the positional return values for
// call.
- Finish() (reply int64, err error)
+ Finish() (reply _gen_vdlutil.Any, err error)
// Cancel cancels the RPC, notifying the server to stop processing.
Cancel()
@@ -69,7 +69,7 @@
return c.clientCall.CloseSend()
}
-func (c *implViewerPipeStream) Finish() (reply int64, err error) {
+func (c *implViewerPipeStream) Finish() (reply _gen_vdlutil.Any, err error) {
if ierr := c.clientCall.Finish(&reply, &err); ierr != nil {
err = ierr
}
@@ -208,14 +208,14 @@
result.Methods["Pipe"] = _gen_ipc.MethodSignature{
InArgs: []_gen_ipc.MethodArgument{},
OutArgs: []_gen_ipc.MethodArgument{
- {Name: "", Type: 37},
{Name: "", Type: 65},
+ {Name: "", Type: 66},
},
- InStream: 67,
+ InStream: 68,
}
result.TypeDefs = []_gen_vdlutil.Any{
- _gen_wiretype.NamedPrimitiveType{Type: 0x1, Name: "error", Tags: []string(nil)}, _gen_wiretype.NamedPrimitiveType{Type: 0x32, Name: "byte", Tags: []string(nil)}, _gen_wiretype.SliceType{Elem: 0x42, Name: "", Tags: []string(nil)}}
+ _gen_wiretype.NamedPrimitiveType{Type: 0x1, Name: "anydata", Tags: []string(nil)}, _gen_wiretype.NamedPrimitiveType{Type: 0x1, Name: "error", Tags: []string(nil)}, _gen_wiretype.NamedPrimitiveType{Type: 0x32, Name: "byte", Tags: []string(nil)}, _gen_wiretype.SliceType{Elem: 0x43, Name: "", Tags: []string(nil)}}
return result, nil
}
@@ -238,7 +238,7 @@
return
}
-func (__gen_s *ServerStubViewer) Pipe(call _gen_ipc.ServerCall) (reply int64, err error) {
+func (__gen_s *ServerStubViewer) Pipe(call _gen_ipc.ServerCall) (reply _gen_vdlutil.Any, err error) {
stream := &implViewerServicePipeStream{serverCall: call}
reply, err = __gen_s.service.Pipe(call, stream)
return
diff --git a/examples/pipetobrowser/cli/main.go b/examples/pipetobrowser/p2b/main.go
similarity index 85%
rename from examples/pipetobrowser/cli/main.go
rename to examples/pipetobrowser/p2b/main.go
index 5ecef74..71c2cfb 100644
--- a/examples/pipetobrowser/cli/main.go
+++ b/examples/pipetobrowser/p2b/main.go
@@ -8,6 +8,8 @@
"io"
"os"
+ "veyron2"
+ "veyron2/ipc"
"veyron2/rt"
"veyron/examples/pipetobrowser"
@@ -73,7 +75,7 @@
return
}
- stream, err := s.Pipe(runtime.NewContext())
+ stream, err := s.Pipe(runtime.NewContext(), veyron2.CallTimeout(ipc.NoTimeout))
if err != nil {
log.Errorf("failed to pipe to '%s' please ensure p2b service is running in the browser and name is correct.\nERR:%v", name, err)
return
@@ -83,24 +85,17 @@
stream,
}
- numBytes, err := io.Copy(w, os.Stdin)
+ _, err = io.Copy(w, os.Stdin)
if err != nil {
log.Errorf("failed to copy the stdin pipe to the outgoing stream\nERR:%v", err)
return
}
- stream.CloseSend()
- result, err := stream.Finish()
+ _, err = stream.Finish()
if err != nil {
log.Errorf("error finishing stream: %v", err)
return
}
- if numBytes != result {
- log.Infof("*** number of bytes sent and received do NOT match ***")
- }
- log.Infof("%d bytes were piped to browser", numBytes)
- log.Infof("%d bytes were received by browser", result)
-
fmt.Println("Finished piping to browser! Thanks for using p2b.")
}
diff --git a/runtimes/google/rt/mgmt.go b/runtimes/google/rt/mgmt.go
index ecb62f1..e476ec0 100644
--- a/runtimes/google/rt/mgmt.go
+++ b/runtimes/google/rt/mgmt.go
@@ -7,7 +7,6 @@
"time"
"veyron/runtimes/google/appcycle"
- vflag "veyron/security/flag"
"veyron/services/mgmt/lib/exec"
"veyron2"
@@ -57,7 +56,7 @@
if ep, err = m.server.Listen("tcp", "127.0.0.1:0"); err != nil {
return err
}
- if err := m.server.Serve("", ipc.SoloDispatcher(appcycle.NewServerAppCycle(m), vflag.NewAuthorizerOrDie())); err != nil {
+ if err := m.server.Serve("", ipc.SoloDispatcher(appcycle.NewServerAppCycle(m), nil)); err != nil {
return err
}
return m.callbackToParent(parentName, naming.JoinAddressName(ep.String(), ""))
diff --git a/services/mgmt/build/constants.go b/services/mgmt/build/constants.go
deleted file mode 100644
index d150780..0000000
--- a/services/mgmt/build/constants.go
+++ /dev/null
@@ -1,64 +0,0 @@
-package build
-
-type OperatingSystem uint8
-
-const (
- LINUX OperatingSystem = iota
- DARWIN
- WINDOWS
-)
-
-func (os OperatingSystem) String() string {
- switch os {
- case LINUX:
- return "linux"
- case DARWIN:
- return "darwin"
- case WINDOWS:
- return "windows"
- default:
- return "unknown"
- }
-}
-
-type Format uint8
-
-const (
- ELF Format = iota
- MACH
- PE
-)
-
-func (format Format) String() string {
- switch format {
- case ELF:
- return "elf"
- case MACH:
- return "mach-o"
- case PE:
- return "pe"
- default:
- return "unknown"
- }
-}
-
-type Architecture uint8
-
-const (
- AMD64 Architecture = iota
- ARM
- X86
-)
-
-func (arch Architecture) String() string {
- switch arch {
- case AMD64:
- return "amd64"
- case ARM:
- return "arm"
- case X86:
- return "x86"
- default:
- return "unknown"
- }
-}
diff --git a/services/mgmt/build/impl/impl_test.go b/services/mgmt/build/impl/impl_test.go
index 31b2d71..0404e7b 100644
--- a/services/mgmt/build/impl/impl_test.go
+++ b/services/mgmt/build/impl/impl_test.go
@@ -1,6 +1,7 @@
package impl
import (
+ "io"
"os"
"path/filepath"
"strings"
@@ -49,31 +50,43 @@
}
}
-func invokeBuild(t *testing.T, client build.Build, files []build.File) ([]byte, error) {
+func invokeBuild(t *testing.T, client build.Build, files []build.File) ([]byte, []build.File, error) {
stream, err := client.Build(rt.R().NewContext())
if err != nil {
t.Errorf("Build() failed: %v", err)
- return nil, err
+ return nil, nil, err
}
for _, file := range files {
if err := stream.Send(file); err != nil {
t.Logf("Send() failed: %v", err)
stream.Cancel()
- return nil, err
+ return nil, nil, err
}
}
if err := stream.CloseSend(); err != nil {
t.Logf("CloseSend() failed: %v", err)
stream.Cancel()
- return nil, err
+ return nil, nil, err
+ }
+ bins := make([]build.File, 0)
+ for {
+ bin, err := stream.Recv()
+ if err != nil && err != io.EOF {
+ t.Logf("Recv() failed: %v", err)
+ return nil, nil, err
+ }
+ if err == io.EOF {
+ break
+ }
+ bins = append(bins, bin)
}
output, err := stream.Finish()
if err != nil {
t.Logf("Finish() failed: %v", err)
stream.Cancel()
- return nil, err
+ return nil, nil, err
}
- return output, nil
+ return output, bins, nil
}
const mainSrc = `package main
@@ -97,13 +110,16 @@
Contents: []byte(mainSrc),
},
}
- output, err := invokeBuild(t, client, files)
+ output, bins, err := invokeBuild(t, client, files)
if err != nil {
t.FailNow()
}
if got, expected := strings.TrimSpace(string(output)), "test"; got != expected {
t.Fatalf("Unexpected output: got %v, expected %v", got, expected)
}
+ if got, expected := len(bins), 1; got != expected {
+ t.Fatalf("Unexpected number of binaries: got %v, expected %v", got, expected)
+ }
}
// TestFailure checks that the build server fails to build a package
@@ -118,7 +134,7 @@
Contents: []byte(""),
},
}
- if _, err := invokeBuild(t, client, files); err == nil {
+ if _, _, err := invokeBuild(t, client, files); err == nil {
t.FailNow()
}
}
diff --git a/services/mgmt/build/impl/invoker.go b/services/mgmt/build/impl/invoker.go
index b2b9c52..2ef2585 100644
--- a/services/mgmt/build/impl/invoker.go
+++ b/services/mgmt/build/impl/invoker.go
@@ -1,6 +1,7 @@
package impl
import (
+ "bytes"
"errors"
"io"
"io/ioutil"
@@ -15,7 +16,8 @@
)
var (
- errOperationFailed = errors.New("operation failed")
+ errBuildFailed = errors.New("build failed")
+ errInternalError = errors.New("internal error")
)
// invoker holds the state of a build server invocation.
@@ -33,25 +35,28 @@
// BUILD INTERFACE IMPLEMENTATION
+// TODO(jsimsa): Add support for building for a specific profile
+// specified as a suffix the Build().
func (i *invoker) Build(_ ipc.ServerContext, stream build.BuildServiceBuildStream) ([]byte, error) {
+ vlog.VI(1).Infof("Build() called.")
dir, prefix := "", ""
dirPerm, filePerm := os.FileMode(0700), os.FileMode(0600)
root, err := ioutil.TempDir(dir, prefix)
if err != nil {
vlog.Errorf("TempDir(%v, %v) failed: %v", dir, prefix, err)
- return nil, errOperationFailed
+ return nil, errInternalError
}
defer os.RemoveAll(root)
srcDir := filepath.Join(root, "go", "src")
if err := os.MkdirAll(srcDir, dirPerm); err != nil {
vlog.Errorf("MkdirAll(%v, %v) failed: %v", srcDir, dirPerm, err)
- return nil, errOperationFailed
+ return nil, errInternalError
}
for {
srcFile, err := stream.Recv()
if err != nil && err != io.EOF {
vlog.Errorf("Recv() failed: %v", err)
- return nil, errOperationFailed
+ return nil, errInternalError
}
if err == io.EOF {
break
@@ -60,21 +65,50 @@
dir := filepath.Dir(filePath)
if err := os.MkdirAll(dir, dirPerm); err != nil {
vlog.Errorf("MkdirAll(%v, %v) failed: %v", dir, dirPerm, err)
- return nil, errOperationFailed
+ return nil, errInternalError
}
if err := ioutil.WriteFile(filePath, srcFile.Contents, filePerm); err != nil {
vlog.Errorf("WriteFile(%v, %v) failed: %v", filePath, filePerm, err)
- return nil, errOperationFailed
+ return nil, errInternalError
}
}
- cmd := exec.Command(i.gobin, "build", "-v", "...")
+ cmd := exec.Command(i.gobin, "install", "-v", "...")
cmd.Env = append(cmd.Env, "GOPATH="+filepath.Dir(srcDir))
- bytes, err := cmd.CombinedOutput()
- if err != nil {
- vlog.Errorf("CombinedOutput() failed: %v", err)
- return nil, errOperationFailed
+ var output bytes.Buffer
+ cmd.Stdout = &output
+ cmd.Stderr = &output
+ if err := cmd.Run(); err != nil {
+ vlog.Errorf("Run() failed: %v", err)
+ if output.Len() != 0 {
+ vlog.Errorf("%v", output.String())
+ }
+ return output.Bytes(), errBuildFailed
}
- return bytes, nil
+ binDir := filepath.Join(root, "go", "bin")
+ files, err := ioutil.ReadDir(binDir)
+ if err != nil {
+ vlog.Errorf("ReadDir(%v) failed: %v", binDir, err)
+ return nil, errInternalError
+ }
+ // TODO(jsimsa): Analyze the binary files for non-standard shared
+ // library dependencies.
+ for _, file := range files {
+ binPath := filepath.Join(root, "go", "bin", file.Name())
+ bytes, err := ioutil.ReadFile(binPath)
+ if err != nil {
+ vlog.Errorf("ReadFile(%v) failed: %v", binPath, err)
+ return nil, errInternalError
+ }
+ result := build.File{
+ Name: "bin/" + file.Name(),
+ Contents: bytes,
+ }
+ if err := stream.Send(result); err != nil {
+ vlog.Errorf("Send() failed: %v", err)
+ return nil, errInternalError
+ }
+ }
+ return output.Bytes(), nil
}
func (i *invoker) Describe(_ ipc.ServerContext, name string) (binary.Description, error) {
diff --git a/services/mgmt/build/impl/util.go b/services/mgmt/build/impl/util.go
new file mode 100644
index 0000000..2710ae9
--- /dev/null
+++ b/services/mgmt/build/impl/util.go
@@ -0,0 +1,59 @@
+package impl
+
+import (
+ "runtime"
+
+ "veyron2/services/mgmt/build"
+)
+
+func getArch() build.Architecture {
+ switch runtime.GOARCH {
+ case "386":
+ return build.X86
+ case "amd64":
+ return build.AMD64
+ case "arm":
+ return build.ARM
+ default:
+ return build.UnsupportedArchitecture
+ }
+}
+
+func getOS() build.OperatingSystem {
+ switch runtime.GOOS {
+ case "darwin":
+ return build.Darwin
+ case "linux":
+ return build.Linux
+ case "windows":
+ return build.Windows
+ default:
+ return build.UnsupportedOperatingSystem
+ }
+}
+
+func archString(arch build.Architecture) string {
+ switch arch {
+ case build.X86:
+ return "x86"
+ case build.AMD64:
+ return "amd64"
+ case build.ARM:
+ return "arm"
+ default:
+ return "unsupported"
+ }
+}
+
+func osString(os build.OperatingSystem) string {
+ switch os {
+ case build.Darwin:
+ return "darwin"
+ case build.Linux:
+ return "linux"
+ case build.Windows:
+ return "windows"
+ default:
+ return "unsupported"
+ }
+}
diff --git a/services/mgmt/node/impl/invoker.go b/services/mgmt/node/impl/invoker.go
index 565d6d8..ed450c6 100644
--- a/services/mgmt/node/impl/invoker.go
+++ b/services/mgmt/node/impl/invoker.go
@@ -41,8 +41,7 @@
"time"
"veyron/lib/config"
- "veyron/services/mgmt/build"
- cbinary "veyron/services/mgmt/lib/binary"
+ blib "veyron/services/mgmt/lib/binary"
vexec "veyron/services/mgmt/lib/exec"
"veyron/services/mgmt/profile"
@@ -52,6 +51,7 @@
"veyron2/rt"
"veyron2/services/mgmt/application"
"veyron2/services/mgmt/binary"
+ "veyron2/services/mgmt/build"
"veyron2/services/mgmt/node"
"veyron2/services/mgmt/repository"
"veyron2/verror"
@@ -119,30 +119,30 @@
// TODO(jsimsa): Avoid computing the host node description from
// scratch if a recent cached copy exists.
func (i *invoker) computeNodeProfile() (*profile.Specification, error) {
- result := profile.Specification{Format: profile.Format{Attributes: make(map[string]string)}}
+ result := profile.Specification{}
// Find out what the supported file format, operating system, and
// architecture is.
switch runtime.GOOS {
- case "linux":
- result.Format.Name = build.ELF.String()
- result.Format.Attributes["os"] = build.LINUX.String()
case "darwin":
- result.Format.Name = build.MACH.String()
- result.Format.Attributes["os"] = build.DARWIN.String()
+ result.Format = build.MACH
+ result.OS = build.Darwin
+ case "linux":
+ result.Format = build.ELF
+ result.OS = build.Linux
case "windows":
- result.Format.Name = build.PE.String()
- result.Format.Attributes["os"] = build.WINDOWS.String()
+ result.Format = build.PE
+ result.OS = build.Windows
default:
return nil, errors.New("Unsupported operating system: " + runtime.GOOS)
}
switch runtime.GOARCH {
case "amd64":
- result.Format.Attributes["arch"] = build.AMD64.String()
+ result.Arch = build.AMD64
case "arm":
- result.Format.Attributes["arch"] = build.AMD64.String()
+ result.Arch = build.ARM
case "x86":
- result.Format.Attributes["arch"] = build.AMD64.String()
+ result.Arch = build.X86
default:
return nil, errors.New("Unsupported hardware architecture: " + runtime.GOARCH)
}
@@ -269,13 +269,13 @@
result := node.Description{Profiles: make(map[string]struct{})}
loop:
for _, profile := range known {
- if profile.Format.Name != p.Format.Name {
+ if profile.Format != p.Format {
continue
}
- if profile.Format.Attributes["os"] != p.Format.Attributes["os"] {
+ if profile.OS != p.OS {
continue
}
- if profile.Format.Attributes["arch"] != p.Format.Attributes["arch"] {
+ if profile.Arch != p.Arch {
continue
}
for library := range profile.Libraries {
@@ -331,7 +331,7 @@
// APPLICATION INTERFACE IMPLEMENTATION
func downloadBinary(workspace, name string) error {
- data, err := cbinary.Download(name)
+ data, err := blib.Download(name)
if err != nil {
vlog.Errorf("Download(%v) failed: %v", name, err)
return errOperationFailed
diff --git a/services/mgmt/profile/impl/impl_test.go b/services/mgmt/profile/impl/impl_test.go
index bb52ef9..ca9ff10 100644
--- a/services/mgmt/profile/impl/impl_test.go
+++ b/services/mgmt/profile/impl/impl_test.go
@@ -10,15 +10,18 @@
"veyron2/naming"
"veyron2/rt"
+ "veyron2/services/mgmt/build"
)
var (
// spec is an example profile specification used throughout the test.
spec = profile.Specification{
- Format: profile.Format{Name: "elf", Attributes: map[string]string{"os": "linux", "arch": "amd64"}},
+ Arch: build.AMD64,
+ Description: "Example profile to test the profile repository implementation.",
+ Format: build.ELF,
Libraries: map[profile.Library]struct{}{profile.Library{Name: "foo", MajorVersion: "1", MinorVersion: "0"}: struct{}{}},
Label: "example",
- Description: "Example profile to test the profile repository implementation.",
+ OS: build.Linux,
}
)
diff --git a/services/mgmt/profile/profile.vdl b/services/mgmt/profile/profile.vdl
index d37c59b..0f6338b 100644
--- a/services/mgmt/profile/profile.vdl
+++ b/services/mgmt/profile/profile.vdl
@@ -2,16 +2,7 @@
// types used by the implementation of Veyron profiles.
package profile
-// Format includes a type (e.g. ELF) and each instance of the format
-// has some specific attributes. The key attributes are the target
-// operating system (e.g. for ELF this could be one of System V,
-// HP-UX, NetBSD, Linux, Solaris, AIX, IRIX, FreeBSD, and OpenBSD) and
-// the target instruction set architecture (e.g. for ELF this could be
-// one of SPARC, x86, PowerPC, ARM, IA-64, x86-64, and AArch64).
-type Format struct {
- Name string
- Attributes map[string]string
-}
+import "veyron2/services/mgmt/build"
// Library describes a shared library that applications may use.
type Library struct {
@@ -26,12 +17,17 @@
// Specification is how we represent a profile internally. It should
// provide enough information to allow matching of binaries to nodes.
type Specification struct {
- // Format is the file format of the application binary.
- Format Format
- // Libraries is a set of libraries the application binary depends on.
- Libraries set[Library]
- // A human-friendly concise label for the profile, e.g. "linux-media"
- Label string
- // A human-friendly description of the profile.
+ // Arch is the target hardware architecture of the profile.
+ Arch build.Architecture
+ // Description is a human-friendly description of the profile.
Description string
+ // Format is the file format supported by the profile.
+ Format build.Format
+ // Libraries is a set of libraries the profile requires.
+ Libraries set[Library]
+ // Label is a human-friendly concise label for the profile,
+ // e.g. "linux-media".
+ Label string
+ // OS is the target operating system of the profile.
+ OS build.OperatingSystem
}
diff --git a/services/mgmt/profile/profile.vdl.go b/services/mgmt/profile/profile.vdl.go
index c219f26..8ece520 100644
--- a/services/mgmt/profile/profile.vdl.go
+++ b/services/mgmt/profile/profile.vdl.go
@@ -5,16 +5,9 @@
// types used by the implementation of Veyron profiles.
package profile
-// Format includes a type (e.g. ELF) and each instance of the format
-// has some specific attributes. The key attributes are the target
-// operating system (e.g. for ELF this could be one of System V,
-// HP-UX, NetBSD, Linux, Solaris, AIX, IRIX, FreeBSD, and OpenBSD) and
-// the target instruction set architecture (e.g. for ELF this could be
-// one of SPARC, x86, PowerPC, ARM, IA-64, x86-64, and AArch64).
-type Format struct {
- Name string
- Attributes map[string]string
-}
+import (
+ "veyron2/services/mgmt/build"
+)
// Library describes a shared library that applications may use.
type Library struct {
@@ -29,12 +22,17 @@
// Specification is how we represent a profile internally. It should
// provide enough information to allow matching of binaries to nodes.
type Specification struct {
- // Format is the file format of the application binary.
- Format Format
- // Libraries is a set of libraries the application binary depends on.
- Libraries map[Library]struct{}
- // A human-friendly concise label for the profile, e.g. "linux-media"
- Label string
- // A human-friendly description of the profile.
+ // Arch is the target hardware architecture of the profile.
+ Arch build.Architecture
+ // Description is a human-friendly description of the profile.
Description string
+ // Format is the file format supported by the profile.
+ Format build.Format
+ // Libraries is a set of libraries the profile requires.
+ Libraries map[Library]struct{}
+ // Label is a human-friendly concise label for the profile,
+ // e.g. "linux-media".
+ Label string
+ // OS is the target operating system of the profile.
+ OS build.OperatingSystem
}
diff --git a/services/mgmt/repository/repository.vdl.go b/services/mgmt/repository/repository.vdl.go
index f6bcc37..83bc841 100644
--- a/services/mgmt/repository/repository.vdl.go
+++ b/services/mgmt/repository/repository.vdl.go
@@ -523,46 +523,42 @@
result := _gen_ipc.ServiceSignature{Methods: make(map[string]_gen_ipc.MethodSignature)}
result.Methods["Put"] = _gen_ipc.MethodSignature{
InArgs: []_gen_ipc.MethodArgument{
- {Name: "Specification", Type: 69},
+ {Name: "Specification", Type: 70},
},
OutArgs: []_gen_ipc.MethodArgument{
- {Name: "", Type: 70},
+ {Name: "", Type: 71},
},
}
result.Methods["Remove"] = _gen_ipc.MethodSignature{
InArgs: []_gen_ipc.MethodArgument{},
OutArgs: []_gen_ipc.MethodArgument{
- {Name: "", Type: 70},
+ {Name: "", Type: 71},
},
}
result.Methods["Specification"] = _gen_ipc.MethodSignature{
InArgs: []_gen_ipc.MethodArgument{},
OutArgs: []_gen_ipc.MethodArgument{
- {Name: "", Type: 69},
{Name: "", Type: 70},
+ {Name: "", Type: 71},
},
}
result.TypeDefs = []_gen_vdlutil.Any{
- _gen_wiretype.MapType{Key: 0x3, Elem: 0x3, Name: "", Tags: []string(nil)}, _gen_wiretype.StructType{
- []_gen_wiretype.FieldType{
- _gen_wiretype.FieldType{Type: 0x3, Name: "Name"},
- _gen_wiretype.FieldType{Type: 0x41, Name: "Attributes"},
- },
- "veyron/services/mgmt/profile.Format", []string(nil)},
- _gen_wiretype.StructType{
+ _gen_wiretype.NamedPrimitiveType{Type: 0x32, Name: "veyron2/services/mgmt/build.Architecture", Tags: []string(nil)}, _gen_wiretype.NamedPrimitiveType{Type: 0x32, Name: "veyron2/services/mgmt/build.Format", Tags: []string(nil)}, _gen_wiretype.StructType{
[]_gen_wiretype.FieldType{
_gen_wiretype.FieldType{Type: 0x3, Name: "Name"},
_gen_wiretype.FieldType{Type: 0x3, Name: "MajorVersion"},
_gen_wiretype.FieldType{Type: 0x3, Name: "MinorVersion"},
},
"veyron/services/mgmt/profile.Library", []string(nil)},
- _gen_wiretype.MapType{Key: 0x43, Elem: 0x2, Name: "", Tags: []string(nil)}, _gen_wiretype.StructType{
+ _gen_wiretype.MapType{Key: 0x43, Elem: 0x2, Name: "", Tags: []string(nil)}, _gen_wiretype.NamedPrimitiveType{Type: 0x32, Name: "veyron2/services/mgmt/build.OperatingSystem", Tags: []string(nil)}, _gen_wiretype.StructType{
[]_gen_wiretype.FieldType{
+ _gen_wiretype.FieldType{Type: 0x41, Name: "Arch"},
+ _gen_wiretype.FieldType{Type: 0x3, Name: "Description"},
_gen_wiretype.FieldType{Type: 0x42, Name: "Format"},
_gen_wiretype.FieldType{Type: 0x44, Name: "Libraries"},
_gen_wiretype.FieldType{Type: 0x3, Name: "Label"},
- _gen_wiretype.FieldType{Type: 0x3, Name: "Description"},
+ _gen_wiretype.FieldType{Type: 0x45, Name: "OS"},
},
"veyron/services/mgmt/profile.Specification", []string(nil)},
_gen_wiretype.NamedPrimitiveType{Type: 0x1, Name: "error", Tags: []string(nil)}}
diff --git a/services/store/memstore/blackbox/team_player_test.go b/services/store/memstore/blackbox/team_player_test.go
index fc9c3d0..61a1255 100644
--- a/services/store/memstore/blackbox/team_player_test.go
+++ b/services/store/memstore/blackbox/team_player_test.go
@@ -122,7 +122,9 @@
// Iterate over the rockets.
players := make(map[storage.ID]*Player)
name := storage.ParsePath("/teamsapp/players")
- for it := st.Snapshot().NewIterator(rootPublicID, name, nil); it.IsValid(); it.Next() {
+ for it := st.Snapshot().NewIterator(rootPublicID, name,
+ state.ListPaths, nil); it.IsValid(); it.Next() {
+
e := it.Get()
if p, ok := e.Value.(*Player); ok {
if _, ok := players[e.Stat.ID]; ok {
@@ -148,7 +150,9 @@
// Iterate over all teams, nonrecursively.
teams := make(map[storage.ID]*Team)
name = storage.ParsePath("/teamsapp/teams")
- for it := st.Snapshot().NewIterator(rootPublicID, name, state.ImmediateFilter); it.IsValid(); it.Next() {
+ for it := st.Snapshot().NewIterator(rootPublicID, name,
+ state.ListPaths, state.ImmediateFilter); it.IsValid(); it.Next() {
+
e := it.Get()
v := e.Value
if _, ok := v.(*Player); ok {
@@ -173,17 +177,19 @@
}
// Iterate over all teams, recursively.
- playerCount := 0
+ contractCount := 0
teamCount := 0
players = make(map[storage.ID]*Player)
teams = make(map[storage.ID]*Team)
name = storage.ParsePath("/teamsapp/teams")
- for it := st.Snapshot().NewIterator(rootPublicID, name, nil); it.IsValid(); it.Next() {
+ for it := st.Snapshot().NewIterator(rootPublicID, name,
+ state.ListPaths, nil); it.IsValid(); it.Next() {
+
e := it.Get()
v := e.Value
if p, ok := v.(*Player); ok {
players[e.Stat.ID] = p
- playerCount++
+ contractCount++
}
if team, ok := v.(*Team); ok {
teams[e.Stat.ID] = team
@@ -202,8 +208,8 @@
if team, ok := teams[hornetsID]; !ok || team.FullName != "Hornets" {
t.Errorf("Should have Hornets, have %v", team)
}
- if playerCount != 3 {
- t.Errorf("Should have 3 players: have %d", playerCount)
+ if contractCount != 4 {
+ t.Errorf("Should have 4 contracts: have %d", contractCount)
}
if len(players) != 3 {
t.Errorf("Should have 3 players: have %v", players)
diff --git a/services/store/memstore/query/eval.go b/services/store/memstore/query/eval.go
index cd89615..48e991a 100644
--- a/services/store/memstore/query/eval.go
+++ b/services/store/memstore/query/eval.go
@@ -357,7 +357,9 @@
path := storage.ParsePath(naming.Join(c.suffix, basepath))
vlog.VI(2).Infof("nameEvaluator suffix: %s, result.Name: %s, VName: %s",
c.suffix, result.Name, e.wildcardName.VName)
- for it := c.sn.NewIterator(c.clientID, path, state.ImmediateFilter); it.IsValid(); it.Next() {
+ for it := c.sn.NewIterator(c.clientID, path,
+ state.ListObjects, state.ImmediateFilter); it.IsValid(); it.Next() {
+
entry := it.Get()
result := &store.QueryResult{
Name: naming.Join(basepath, it.Name()),
diff --git a/services/store/memstore/query/eval_test.go b/services/store/memstore/query/eval_test.go
index 282eaa0..2985265 100644
--- a/services/store/memstore/query/eval_test.go
+++ b/services/store/memstore/query/eval_test.go
@@ -492,7 +492,7 @@
it state.Iterator
}
-func (m *mockSnapshot) NewIterator(pid security.PublicID, path storage.PathName, filter state.IterFilter) state.Iterator {
+func (m *mockSnapshot) NewIterator(pid security.PublicID, path storage.PathName, pathFilter state.PathFilter, filter state.IterFilter) state.Iterator {
return m.it
}
diff --git a/services/store/memstore/query/glob.go b/services/store/memstore/query/glob.go
index 3614af3..8b1722e 100644
--- a/services/store/memstore/query/glob.go
+++ b/services/store/memstore/query/glob.go
@@ -32,7 +32,7 @@
pathLen: len(path),
glob: parsed,
}
- g.Iterator = sn.NewIterator(clientID, path, state.IterFilter(g.filter))
+ g.Iterator = sn.NewIterator(clientID, path, state.ListPaths, state.IterFilter(g.filter))
return g, nil
}
diff --git a/services/store/memstore/query/glob_test.go b/services/store/memstore/query/glob_test.go
index 70ff580..6690d98 100644
--- a/services/store/memstore/query/glob_test.go
+++ b/services/store/memstore/query/glob_test.go
@@ -9,51 +9,64 @@
"veyron2/storage"
)
-type nameOptions []string
-
type globTest struct {
path string
pattern string
- expected []nameOptions
+ expected []string
}
var globTests = []globTest{
- {"", "mvps/...", []nameOptions{
- {"mvps"},
- {"mvps/Links/0"},
- {"mvps/Links/1"},
+ {"", "...", []string{
+ "",
+ "mvps",
+ "mvps/Links/0",
+ "mvps/Links/1",
+ "players",
+ "players/alfred",
+ "players/alice",
+ "players/betty",
+ "players/bob",
+ "teams",
+ "teams/bears",
+ "teams/cardinals",
+ "teams/sharks",
}},
- {"", "players/...", []nameOptions{
- {"players"},
- {"players/alfred"},
- {"players/alice"},
- {"players/betty"},
- {"players/bob"},
+ {"", "mvps/...", []string{
+ "mvps",
+ "mvps/Links/0",
+ "mvps/Links/1",
+ }},
+ {"", "players/...", []string{
+ "players",
+ "players/alfred",
+ "players/alice",
+ "players/betty",
+ "players/bob",
}},
// Note(mattr): This test case shows that Glob does not return
// subfield nodes.
- {"", "mvps/*", []nameOptions{}},
- {"", "mvps/Links/*", []nameOptions{
- {"mvps/Links/0"},
- {"mvps/Links/1"},
+ {"", "mvps/*", []string{}},
+ {"", "mvps/Links/*", []string{
+ "mvps/Links/0",
+ "mvps/Links/1",
}},
- {"", "players/alfred", []nameOptions{
- {"players/alfred"},
+ {"", "players/alfred", []string{
+ "players/alfred",
}},
- {"", "mvps/Links/0", []nameOptions{
- {"mvps/Links/0"},
+ {"", "mvps/Links/0", []string{
+ "mvps/Links/0",
}},
// An empty pattern returns the element referred to by the path.
- {"/mvps/Links/0", "", []nameOptions{
- {""},
+ {"/mvps/Links/0", "", []string{
+ "",
}},
- {"mvps", "Links/*", []nameOptions{
- {"Links/0"},
- {"Links/1"},
+ {"mvps", "Links/*", []string{
+ "Links/0",
+ "Links/1",
}},
- {"mvps/Links", "*", []nameOptions{
- {"0"},
- {"1"},
+ {"mvps/Links", "*", []string{
+ "0",
+ "1",
}},
}
@@ -102,16 +115,9 @@
t.Errorf("Wrong number of names for %s. got %v, wanted %v",
gt.pattern, names, gt.expected)
}
- for _, options := range gt.expected {
- found := false
- for _, name := range options {
- if names[name] {
- found = true
- break
- }
- }
- if !found {
- t.Errorf("Expected to find one of %v in %v", options, names)
+ for _, name := range gt.expected {
+ if !names[name] {
+ t.Errorf("Expected to find %v in %v", name, names)
}
}
}
diff --git a/services/store/memstore/state/iterator.go b/services/store/memstore/state/iterator.go
index 92614be..70eac5c 100644
--- a/services/store/memstore/state/iterator.go
+++ b/services/store/memstore/state/iterator.go
@@ -37,10 +37,13 @@
type iterator struct {
snapshot Snapshot
- // Set of IDs already visited.
+ // Set of IDs already visited on this path.
visited map[storage.ID]struct{}
- // Stack of IDs to visit next. Some of these may already have been visited.
+ // Stack of actions to consider next. Actions are one of:
+ // - visit a node accessible from the current path (the node may already
+ // have been visited on the current path).
+ // - unvisit a node (backtrack the current path).
next []next
// Depth of starting path.
@@ -50,6 +53,8 @@
entry *storage.Entry
path *refs.FullPath
+ pathFilter PathFilter
+
filter IterFilter
}
@@ -59,13 +64,32 @@
parent *refs.FullPath
path *refs.Path
id storage.ID
+ action action
}
+type action int
+
+const (
+ visit = action(iota)
+ unvisit
+)
+
var (
_ Iterator = (*iterator)(nil)
_ Iterator = (*errorIterator)(nil)
)
+// A PathFilter automatically limits the traversal of certain paths,
+type PathFilter int
+
+const (
+ // ListPaths permits any path that does not visit the same object twice.
+ ListPaths = PathFilter(iota)
+ // ListObjects permits any path that does not revisit any object on a
+ // previously traversed path 'Q', even if Q did not satisfy it.filter.
+ ListObjects
+)
+
// An IterFilter examines entries as they are considered by the
// iterator and allows it to give two boolean inputs to the process:
// ret: True if the iterator should return this value in its iteration.
@@ -84,11 +108,14 @@
return true, path == nil
}
-// NewIterator returns an Iterator that starts with the value at
-// <path>. If filter is given it is used to limit traversal beneath
-// certain paths. filter can be specified to limit the results of the iteration.
-// If filter is nil, all decendents of the specified path are returned.
-func (sn *snapshot) NewIterator(pid security.PublicID, path storage.PathName, filter IterFilter) Iterator {
+// NewIterator returns an Iterator that starts with the value at <path>.
+// pathFilter is used to automatically limit traversal of certain paths.
+// If filter is given, it is used to limit traversal beneath certain paths and
+// limit the results of the iteration. If filter is nil, all decendents of the
+// specified path are returned.
+func (sn *snapshot) NewIterator(pid security.PublicID, path storage.PathName,
+ pathFilter PathFilter, filter IterFilter) Iterator {
+
checker := sn.newPermChecker(pid)
cell, suffix, v := sn.resolveCell(checker, path, nil)
if cell == nil {
@@ -104,6 +131,7 @@
visited: make(map[storage.ID]struct{}),
initialDepth: len(path),
path: refs.NewFullPathFromName(path),
+ pathFilter: pathFilter,
filter: filter,
}
@@ -120,11 +148,12 @@
} else {
it.entry = cell.GetEntry()
it.visited[cell.ID] = struct{}{}
+ it.pushUnvisit(nil, cell.ID)
set = cell.refs
}
if expand {
- it.pushAll(checker, it.path, set)
+ it.pushVisitAll(checker, it.path, set)
}
if !ret {
it.Next()
@@ -133,11 +162,25 @@
return it
}
-func (it *iterator) pushAll(checker *acl.Checker, parentPath *refs.FullPath, set refs.Set) {
+func (it *iterator) pushUnvisit(path *refs.Path, id storage.ID) {
+ switch it.pathFilter {
+ case ListPaths:
+ it.next = append(it.next, next{nil, nil, path, id, unvisit})
+ case ListObjects:
+ // Do not unvisit the object, as it is on a path already seen by
+ // it.filter.
+ default:
+ panic("unknown PathFilter")
+ }
+}
+
+func (it *iterator) pushVisitAll(checker *acl.Checker,
+ parentPath *refs.FullPath, set refs.Set) {
+
set.Iter(func(x interface{}) bool {
ref := x.(*refs.Ref)
if checker.IsAllowed(ref.Label) {
- it.next = append(it.next, next{checker, parentPath, ref.Path, ref.ID})
+ it.next = append(it.next, next{checker, parentPath, ref.Path, ref.ID, visit})
}
return true
})
@@ -171,10 +214,20 @@
return
}
n, it.next = it.next[topIndex], it.next[:topIndex]
+
+ if n.action == unvisit {
+ delete(it.visited, n.id)
+ continue
+ }
+
if _, ok := it.visited[n.id]; ok {
continue
}
+ // Mark as visited.
+ it.visited[n.id] = struct{}{}
+ it.pushUnvisit(n.path, n.id)
+
// Fetch the cell.
c = it.snapshot.Find(n.id)
if c == nil {
@@ -193,7 +246,7 @@
ret, expand := it.filter(n.parent, n.path)
fullPath = n.parent.AppendPath(n.path)
if expand {
- it.pushAll(checker, fullPath, c.refs)
+ it.pushVisitAll(checker, fullPath, c.refs)
}
if ret {
// Found a value.
@@ -201,8 +254,6 @@
}
}
- // Mark as visited.
- it.visited[n.id] = struct{}{}
it.entry, it.path = c.GetEntry(), fullPath
}
diff --git a/services/store/memstore/state/iterator_test.go b/services/store/memstore/state/iterator_test.go
index 344f69b..a9f3b2b 100644
--- a/services/store/memstore/state/iterator_test.go
+++ b/services/store/memstore/state/iterator_test.go
@@ -4,16 +4,48 @@
"runtime"
"testing"
+ "veyron/services/store/memstore/refs"
"veyron/services/store/memstore/state"
"veyron2/security"
"veyron2/storage"
)
+// check that the iterator produces a set of names.
+func checkAcyclicIterator(t *testing.T, sn *state.MutableSnapshot, id security.PublicID, filter state.IterFilter, names []string) {
+ _, file, line, _ := runtime.Caller(1)
+
+ // Construct an index of names.
+ index := map[string]bool{}
+ for _, name := range names {
+ index[name] = false
+ }
+
+ // Compute the found names.
+ for it := sn.NewIterator(id, storage.ParsePath("/"), state.ListPaths, filter); it.IsValid(); it.Next() {
+ name := it.Name()
+ if found, ok := index[name]; ok {
+ if found {
+ t.Errorf("%s(%d): duplicate name %q", file, line, name)
+ }
+ index[name] = true
+ } else {
+ t.Errorf("%s(%d): unexpected name %q", file, line, name)
+ }
+ }
+
+ // Print the not found names.
+ for name, found := range index {
+ if !found {
+ t.Errorf("%s(%d): expected: %v", file, line, name)
+ }
+ }
+}
+
// check that the iterator produces a set of names. Since entries in the store
// can have multiple names, the names are provided using a set of equivalence
// classes. The requirement is that the iterator produces exactly one name from
-// each equivalence class. Order doesn't matter.
-func checkIterator(t *testing.T, sn *state.MutableSnapshot, id security.PublicID, names [][]string) {
+// each equivalence class. Order doesn't matter.
+func checkUniqueObjectsIterator(t *testing.T, sn *state.MutableSnapshot, id security.PublicID, filter state.IterFilter, names [][]string) {
_, file, line, _ := runtime.Caller(1)
// Construct an index of name to equivalence class.
@@ -26,7 +58,7 @@
// Compute the found set of equivalence classes.
found := map[int]bool{}
- for it := sn.NewIterator(id, storage.ParsePath("/"), nil); it.IsValid(); it.Next() {
+ for it := sn.NewIterator(id, storage.ParsePath("/"), state.ListObjects, filter); it.IsValid(); it.Next() {
name := it.Name()
if i, ok := index[name]; ok {
if _, ok := found[i]; ok {
@@ -46,6 +78,55 @@
}
}
+// Tests that an iterator returns all non-cyclic paths that reach an object.
+func TestDuplicatePaths(t *testing.T) {
+ st := state.New(rootPublicID)
+ sn := st.MutableSnapshot()
+
+ // Add some objects
+ put(t, sn, rootPublicID, "/", "")
+ put(t, sn, rootPublicID, "/teams", "")
+ put(t, sn, rootPublicID, "/teams/cardinals", "")
+ put(t, sn, rootPublicID, "/players", "")
+ mattID := put(t, sn, rootPublicID, "/players/matt", "")
+
+ // Add some hard links
+ put(t, sn, rootPublicID, "/teams/cardinals/mvp", mattID)
+
+ checkAcyclicIterator(t, sn, rootPublicID, nil, []string{
+ "",
+ "teams",
+ "players",
+ "teams/cardinals",
+ "players/matt",
+ "teams/cardinals/mvp",
+ })
+ checkUniqueObjectsIterator(t, sn, rootPublicID, nil, [][]string{
+ {""},
+ {"teams"},
+ {"players"},
+ {"teams/cardinals"},
+ {"players/matt", "teams/cardinals/mvp"},
+ })
+
+ // Test that the iterator does not revisit objects on previously rejected paths.
+ rejected := false
+ rejectMatt := func(fullPath *refs.FullPath, path *refs.Path) (bool, bool) {
+ name := fullPath.Append(path.Suffix(1)).Name().String()
+ if !rejected && (name == "players/matt" || name == "teams/cardinals/mvp") {
+ rejected = true
+ return false, true
+ }
+ return true, true
+ }
+ checkUniqueObjectsIterator(t, sn, rootPublicID, rejectMatt, [][]string{
+ {""},
+ {"teams"},
+ {"players"},
+ {"teams/cardinals"},
+ })
+}
+
// Test that an iterator doesn't get stuck in cycles.
func TestCyclicStructure(t *testing.T) {
st := state.New(rootPublicID)
@@ -63,7 +144,17 @@
put(t, sn, rootPublicID, "/players/matt/team", cardinalsID)
put(t, sn, rootPublicID, "/teams/cardinals/mvp", mattID)
- checkIterator(t, sn, rootPublicID, [][]string{
+ checkAcyclicIterator(t, sn, rootPublicID, nil, []string{
+ "",
+ "teams",
+ "players",
+ "players/joe",
+ "players/matt",
+ "teams/cardinals/mvp",
+ "teams/cardinals",
+ "players/matt/team",
+ })
+ checkUniqueObjectsIterator(t, sn, rootPublicID, nil, [][]string{
{""},
{"teams"},
{"players"},
@@ -108,7 +199,21 @@
put(t, sn, rootPublicID, "/Users/john/shared", sharedID)
// Root gets everything.
- checkIterator(t, sn, rootPublicID, [][]string{
+ checkAcyclicIterator(t, sn, rootPublicID, nil, []string{
+ "",
+ "Users",
+ "Users/jane",
+ "Users/jane/acls",
+ "Users/jane/acls/janeRWA",
+ "Users/jane/aaa",
+ "Users/john",
+ "Users/john/acls",
+ "Users/john/acls/johnRWA",
+ "Users/john/aaa",
+ "Users/jane/shared",
+ "Users/john/shared",
+ })
+ checkUniqueObjectsIterator(t, sn, rootPublicID, nil, [][]string{
{""},
{"Users"},
{"Users/jane"},
@@ -123,7 +228,16 @@
})
// Jane sees only her names.
- checkIterator(t, sn, janePublicID, [][]string{
+ checkAcyclicIterator(t, sn, janePublicID, nil, []string{
+ "",
+ "Users",
+ "Users/jane",
+ "Users/jane/acls",
+ "Users/jane/acls/janeRWA",
+ "Users/jane/aaa",
+ "Users/jane/shared",
+ })
+ checkUniqueObjectsIterator(t, sn, janePublicID, nil, [][]string{
{""},
{"Users"},
{"Users/jane"},
@@ -134,7 +248,16 @@
})
// John sees only his names.
- checkIterator(t, sn, johnPublicID, [][]string{
+ checkAcyclicIterator(t, sn, johnPublicID, nil, []string{
+ "",
+ "Users",
+ "Users/john",
+ "Users/john/acls",
+ "Users/john/acls/johnRWA",
+ "Users/john/aaa",
+ "Users/john/shared",
+ })
+ checkUniqueObjectsIterator(t, sn, johnPublicID, nil, [][]string{
{""},
{"Users"},
{"Users/john"},
diff --git a/services/store/memstore/state/snapshot.go b/services/store/memstore/state/snapshot.go
index fd3a032..4213a55 100644
--- a/services/store/memstore/state/snapshot.go
+++ b/services/store/memstore/state/snapshot.go
@@ -12,11 +12,12 @@
)
type Snapshot interface {
- // NewIterator returns an Iterator that starts with the value at <path>. If
- // filter is given it is used to limit traversal beneath certain paths.
- // filter can be specified to limit the results of the iteration. If filter
- // is nil, all decendents of the specified path are returned.
- NewIterator(pid security.PublicID, path storage.PathName, filter IterFilter) Iterator
+ // NewIterator returns an Iterator that starts with the value at <path>.
+ // pathFilter is used to automatically limit traversal of certain paths.
+ // If filter is given, it is used to limit traversal beneath certain paths
+ // and limit the results of the iteration. If filter is nil, all decendents
+ // of the specified path are returned.
+ NewIterator(pid security.PublicID, path storage.PathName, pathFilter PathFilter, filter IterFilter) Iterator
// PathMatch returns true iff there is a name for the store value that
// matches the pathRegex.
diff --git a/services/store/memstore/watch/glob_processor_test.go b/services/store/memstore/watch/glob_processor_test.go
index 699d5f5..02f73c7 100644
--- a/services/store/memstore/watch/glob_processor_test.go
+++ b/services/store/memstore/watch/glob_processor_test.go
@@ -19,6 +19,9 @@
id1 := put(t, st, tr, "/", "val1")
id2 := put(t, st, tr, "/a", "val2")
put(t, st, tr, "/a/b", "val3")
+ id4 := put(t, st, tr, "/a/c", "val4")
+ // Test duplicate paths to the same object.
+ put(t, st, tr, "/a/d", id4)
commit(t, tr)
// Remove /a/b.
@@ -44,20 +47,26 @@
aRecursiveProcessor := createGlobProcessor(t, storage.ParsePath("/a"), "...")
aListProcessor := createGlobProcessor(t, storage.ParsePath("/a"), "*")
- // Expect initial state that contains / and /a.
+ // Expect initial state that contains /, /a, /a/c and /a/d.
logst := readState(t, log)
- changes := processState(t, rootRecursiveProcessor, logst, 2)
+ changes := processState(t, rootRecursiveProcessor, logst, 4)
watchtesting.ExpectEntryExists(t, changes, "", id1, "val1")
watchtesting.ExpectEntryExists(t, changes, "a", id2, "val2")
+ watchtesting.ExpectEntryExists(t, changes, "a/c", id4, "val4")
+ watchtesting.ExpectEntryExists(t, changes, "a/d", id4, "val4")
changes = processState(t, rootListProcessor, logst, 1)
watchtesting.ExpectEntryExists(t, changes, "a", id2, "val2")
- changes = processState(t, aRecursiveProcessor, logst, 1)
+ changes = processState(t, aRecursiveProcessor, logst, 3)
watchtesting.ExpectEntryExists(t, changes, "a", id2, "val2")
+ watchtesting.ExpectEntryExists(t, changes, "a/c", id4, "val4")
+ watchtesting.ExpectEntryExists(t, changes, "a/d", id4, "val4")
- processState(t, aListProcessor, logst, 0)
+ processState(t, aListProcessor, logst, 2)
+ watchtesting.ExpectEntryExists(t, changes, "a/c", id4, "val4")
+ watchtesting.ExpectEntryExists(t, changes, "a/d", id4, "val4")
}
func TestGlobProcessTransactionAdd(t *testing.T) {
@@ -85,25 +94,34 @@
id1 := put(t, st, tr, "/", "val1")
id2 := put(t, st, tr, "/a", "val2")
id3 := put(t, st, tr, "/a/b", "val3")
+ id4 := put(t, st, tr, "/a/c", "val4")
+ // Test duplicate paths to the same object.
+ put(t, st, tr, "/a/d", id4)
commit(t, tr)
// Expect transaction that adds /, /a and /a/b.
mus := readTransaction(t, log)
- changes := processTransaction(t, rootRecursiveProcessor, mus, 3)
+ changes := processTransaction(t, rootRecursiveProcessor, mus, 5)
watchtesting.ExpectEntryExists(t, changes, "", id1, "val1")
watchtesting.ExpectEntryExists(t, changes, "a", id2, "val2")
watchtesting.ExpectEntryExists(t, changes, "a/b", id3, "val3")
+ watchtesting.ExpectEntryExists(t, changes, "a/c", id4, "val4")
+ watchtesting.ExpectEntryExists(t, changes, "a/d", id4, "val4")
changes = processTransaction(t, rootListProcessor, mus, 1)
watchtesting.ExpectEntryExists(t, changes, "a", id2, "val2")
- changes = processTransaction(t, aRecursiveProcessor, mus, 2)
+ changes = processTransaction(t, aRecursiveProcessor, mus, 4)
watchtesting.ExpectEntryExists(t, changes, "a", id2, "val2")
watchtesting.ExpectEntryExists(t, changes, "a/b", id3, "val3")
+ watchtesting.ExpectEntryExists(t, changes, "a/c", id4, "val4")
+ watchtesting.ExpectEntryExists(t, changes, "a/d", id4, "val4")
- changes = processTransaction(t, aListProcessor, mus, 1)
+ changes = processTransaction(t, aListProcessor, mus, 3)
watchtesting.ExpectEntryExists(t, changes, "a/b", id3, "val3")
+ watchtesting.ExpectEntryExists(t, changes, "a/c", id4, "val4")
+ watchtesting.ExpectEntryExists(t, changes, "a/d", id4, "val4")
changes = processTransaction(t, bRecursiveProcessor, mus, 1)
watchtesting.ExpectEntryExists(t, changes, "a/b", id3, "val3")
diff --git a/services/store/memstore/watch/raw_processor.go b/services/store/memstore/watch/raw_processor.go
index a783caf..5c8d76e 100644
--- a/services/store/memstore/watch/raw_processor.go
+++ b/services/store/memstore/watch/raw_processor.go
@@ -67,7 +67,9 @@
// Create a change for each id in the state. In each change, the object
// exists, has no PriorVersion, has the Version of the new cell, and
// has the Value, Tags and Dir of the new cell.
- for it := sn.NewIterator(p.pid, nil, state.RecursiveFilter); it.IsValid(); it.Next() {
+ for it := sn.NewIterator(p.pid, nil,
+ state.ListObjects, state.RecursiveFilter); it.IsValid(); it.Next() {
+
entry := it.Get()
id := entry.Stat.ID
// Retrieve Value, Tags and Dir from the corresponding cell.
diff --git a/services/store/typeregistryhack/init.go b/services/store/typeregistryhack/init.go
index 84a8f00..72b5216 100644
--- a/services/store/typeregistryhack/init.go
+++ b/services/store/typeregistryhack/init.go
@@ -5,10 +5,7 @@
package typeregistryhack
import (
- "veyron/services/mgmt/profile"
- "veyron2/services/mgmt/application"
-
- // Register boxes types
+ // Register boxes types.
"veyron/examples/boxes"
// Register mdb types.
_ "veyron/examples/storage/mdb/schema"
@@ -18,6 +15,12 @@
_ "veyron/examples/bank/schema"
// Register stfortune types.
_ "veyron/examples/stfortune/schema"
+ // Register profile types.
+ "veyron/services/mgmt/profile"
+ // Register application types.
+ "veyron2/services/mgmt/application"
+ // Register build types.
+ _ "veyron2/services/mgmt/build"
"veyron2/vom"
)
diff --git a/services/wspr/wsprd/lib/stream.go b/services/wspr/wsprd/lib/stream.go
deleted file mode 100644
index 062115b..0000000
--- a/services/wspr/wsprd/lib/stream.go
+++ /dev/null
@@ -1,81 +0,0 @@
-// The set of streaming helper objects for wspr.
-
-package lib
-
-import (
- "veyron2/ipc"
-)
-
-// An interface for an asynchronous sender.
-type sender interface {
- // Similar to ipc.Stream.Send, expect that instead of
- // returning an error, w.sendError will be called.
- Send(item interface{}, w clientWriter)
-}
-
-// A message that will be passed to the writeLoop function that will
-// eventually write the message out to the stream.
-type streamMessage struct {
- // The data to put on the stream.
- data interface{}
- // The client writer that will be used to send errors.
- w clientWriter
-}
-
-// A stream that will eventually write messages to the underlying stream.
-// It isn't initialized with a stream, but rather a chan that will eventually
-// provide a stream, so that it can accept sends before the underlying stream
-// has been set up.
-type queueingStream chan *streamMessage
-
-// Creates and returns a queueing stream that will starting writing to the
-// stream provided by the ready channel. It is expected that ready will only
-// provide a single stream.
-// TODO(bjornick): allow for ready to pass an error if the stream had any issues
-// setting up.
-func startQueueingStream(ready chan ipc.Stream) queueingStream {
- s := make(queueingStream, 100)
- go s.writeLoop(ready)
- return s
-}
-
-func (q queueingStream) Send(item interface{}, w clientWriter) {
- // TODO(bjornick): Reject the message if the queue is too long.
- message := streamMessage{data: item, w: w}
- q <- &message
-}
-
-func (q queueingStream) Close() error {
- close(q)
- return nil
-}
-
-func (q queueingStream) writeLoop(ready chan ipc.Stream) {
- stream := <-ready
- for value, ok := <-q; ok; value, ok = <-q {
- if !ok {
- break
- }
- if err := stream.Send(value.data); err != nil {
- value.w.sendError(err)
- }
- }
-
- // If the stream is on the client side, then also close the stream.
- if call, ok := stream.(ipc.Call); ok {
- call.CloseSend()
- }
-}
-
-// A simple struct that wraps a stream with the sender api. It
-// will write to the stream synchronously. Any error will still
-// be written to clientWriter.
-type senderWrapper struct {
- stream ipc.Stream
-}
-
-func (s senderWrapper) Send(item interface{}, w clientWriter) {
- if err := s.stream.Send(item); err != nil {
- w.sendError(err)
- }
-}
diff --git a/services/wsprd/ipc/client/stream.go b/services/wsprd/ipc/client/stream.go
new file mode 100644
index 0000000..4237f8f
--- /dev/null
+++ b/services/wsprd/ipc/client/stream.go
@@ -0,0 +1,62 @@
+// A client stream helper.
+
+package client
+
+import (
+ "veyron/services/wsprd/lib"
+ "veyron2/ipc"
+)
+
+// A message that will be passed to the writeLoop function that will
+// eventually write the message out to the stream.
+type streamMessage struct {
+ // The data to put on the stream.
+ data interface{}
+ // The client writer that will be used to send errors.
+ w lib.ClientWriter
+}
+
+// A stream that will eventually write messages to the underlying stream.
+// It isn't initialized with a stream, but rather a chan that will eventually
+// provide a stream, so that it can accept sends before the underlying stream
+// has been set up.
+type QueueingStream chan *streamMessage
+
+// Creates and returns a queueing stream that will starting writing to the
+// stream provided by the ready channel. It is expected that ready will only
+// provide a single stream.
+// TODO(bjornick): allow for ready to pass an error if the stream had any issues
+// setting up.
+func StartQueueingStream(ready chan ipc.Stream) QueueingStream {
+ s := make(QueueingStream, 100)
+ go s.writeLoop(ready)
+ return s
+}
+
+func (q QueueingStream) Send(item interface{}, w lib.ClientWriter) {
+ // TODO(bjornick): Reject the message if the queue is too long.
+ message := streamMessage{data: item, w: w}
+ q <- &message
+}
+
+func (q QueueingStream) Close() error {
+ close(q)
+ return nil
+}
+
+func (q QueueingStream) writeLoop(ready chan ipc.Stream) {
+ stream := <-ready
+ for value, ok := <-q; ok; value, ok = <-q {
+ if !ok {
+ break
+ }
+ if err := stream.Send(value.data); err != nil {
+ value.w.Error(err)
+ }
+ }
+
+ // If the stream is on the client side, then also close the stream.
+ if call, ok := stream.(ipc.Call); ok {
+ call.CloseSend()
+ }
+}
diff --git a/services/wspr/wsprd/lib/dispatcher.go b/services/wsprd/ipc/server/dispatcher.go
similarity index 97%
rename from services/wspr/wsprd/lib/dispatcher.go
rename to services/wsprd/ipc/server/dispatcher.go
index 97b4aab..7c73701 100644
--- a/services/wspr/wsprd/lib/dispatcher.go
+++ b/services/wsprd/ipc/server/dispatcher.go
@@ -1,4 +1,4 @@
-package lib
+package server
import (
"veyron2/ipc"
diff --git a/services/wspr/wsprd/lib/invoker.go b/services/wsprd/ipc/server/invoker.go
similarity index 96%
rename from services/wspr/wsprd/lib/invoker.go
rename to services/wsprd/ipc/server/invoker.go
index a385d4d..aabafe8 100644
--- a/services/wspr/wsprd/lib/invoker.go
+++ b/services/wsprd/ipc/server/invoker.go
@@ -1,4 +1,4 @@
-package lib
+package server
import (
"veyron2/ipc"
@@ -24,7 +24,7 @@
predefinedInvokers := make(map[string]ipc.Invoker)
// Special handling for predefined "signature" method
- predefinedInvokers[signatureMethodName] = newSignatureInvoker(sig)
+ predefinedInvokers["Signature"] = newSignatureInvoker(sig)
i := &invoker{sig, invokeFunc, predefinedInvokers}
return i, nil
diff --git a/services/wspr/wsprd/lib/server.go b/services/wsprd/ipc/server/server.go
similarity index 65%
rename from services/wspr/wsprd/lib/server.go
rename to services/wsprd/ipc/server/server.go
index 8b95ea2..8b79b15 100644
--- a/services/wspr/wsprd/lib/server.go
+++ b/services/wsprd/ipc/server/server.go
@@ -1,6 +1,6 @@
// An implementation of a server for WSPR
-package lib
+package server
import (
"bytes"
@@ -8,17 +8,19 @@
"fmt"
"sync"
+ "veyron/services/wsprd/ipc/stream"
+ "veyron/services/wsprd/lib"
+ "veyron/services/wsprd/signature"
"veyron2"
"veyron2/ipc"
"veyron2/security"
"veyron2/verror"
"veyron2/vlog"
- "veyron2/vom"
)
-type flow struct {
- id int64
- writer clientWriter
+type Flow struct {
+ ID int64
+ Writer lib.ClientWriter
}
// A request from the proxy to javascript to handle an RPC
@@ -35,17 +37,23 @@
Name string
}
-type serverHelper interface {
- createNewFlow(server *server, sender sender) *flow
-
- cleanupFlow(id int64)
-
- getLogger() vlog.Logger
-
- rt() veyron2.Runtime
+// The response from the javascript server to the proxy.
+type serverRPCReply struct {
+ Results []interface{}
+ Err *verror.Standard
}
-type server struct {
+type ServerHelper interface {
+ CreateNewFlow(server *Server, sender stream.Sender) *Flow
+
+ CleanupFlow(id int64)
+
+ GetLogger() vlog.Logger
+
+ RT() veyron2.Runtime
+}
+
+type Server struct {
sync.Mutex
// The server that handles the ipc layer. Listen on this server is
@@ -61,7 +69,7 @@
// The server id.
id uint64
- helper serverHelper
+ helper ServerHelper
// The proxy to listen through.
veyronProxy string
@@ -70,15 +78,15 @@
outstandingServerRequests map[int64]chan *serverRPCReply
}
-func newServer(id uint64, veyronProxy string, helper serverHelper) (*server, error) {
- server := &server{
+func NewServer(id uint64, veyronProxy string, helper ServerHelper) (*Server, error) {
+ server := &Server{
id: id,
helper: helper,
veyronProxy: veyronProxy,
outstandingServerRequests: make(map[int64]chan *serverRPCReply),
}
var err error
- if server.server, err = helper.rt().NewServer(); err != nil {
+ if server.server, err = helper.RT().NewServer(); err != nil {
return nil, err
}
return server, nil
@@ -88,12 +96,12 @@
// communicate the result back via a channel to the caller
type remoteInvokeFunc func(methodName string, args []interface{}, call ipc.ServerCall) <-chan *serverRPCReply
-func (s *server) createRemoteInvokerFunc() remoteInvokeFunc {
+func (s *Server) createRemoteInvokerFunc() remoteInvokeFunc {
return func(methodName string, args []interface{}, call ipc.ServerCall) <-chan *serverRPCReply {
- flow := s.helper.createNewFlow(s, senderWrapper{stream: call})
+ flow := s.helper.CreateNewFlow(s, senderWrapper{stream: call})
replyChan := make(chan *serverRPCReply, 1)
s.Lock()
- s.outstandingServerRequests[flow.id] = replyChan
+ s.outstandingServerRequests[flow.ID] = replyChan
s.Unlock()
context := serverRPCRequestContext{
Suffix: call.Suffix(),
@@ -102,13 +110,12 @@
// Send a invocation request to JavaScript
message := serverRPCRequest{
ServerId: s.id,
- Method: lowercaseFirstCharacter(methodName),
+ Method: lib.LowercaseFirstCharacter(methodName),
Args: args,
Context: context,
}
- data := response{Type: responseServerRequest, Message: message}
- if err := vom.ObjToJSON(flow.writer, vom.ValueOf(data)); err != nil {
+ if err := flow.Writer.Send(lib.ResponseServerRequest, message); err != nil {
// Error in marshaling, pass the error through the channel immediately
replyChan <- &serverRPCReply{nil,
&verror.Standard{
@@ -117,49 +124,32 @@
}
return replyChan
}
- if err := flow.writer.FinishMessage(); err != nil {
- replyChan <- &serverRPCReply{nil,
- &verror.Standard{
- ID: verror.Internal,
- Msg: fmt.Sprintf("WSPR: error finishing message: %v", err)},
- }
- return replyChan
- }
- s.helper.getLogger().VI(3).Infof("request received to call method %q on "+
+ s.helper.GetLogger().VI(3).Infof("request received to call method %q on "+
"JavaScript server with args %v, MessageId %d was assigned.",
- methodName, args, flow.id)
+ methodName, args, flow.ID)
- go proxyStream(call, flow.writer, s.helper.getLogger())
+ go proxyStream(call, flow.Writer, s.helper.GetLogger())
return replyChan
}
}
-func proxyStream(stream ipc.Stream, w clientWriter, logger vlog.Logger) {
+func proxyStream(stream ipc.Stream, w lib.ClientWriter, logger vlog.Logger) {
var item interface{}
for err := stream.Recv(&item); err == nil; err = stream.Recv(&item) {
- data := response{Type: responseStream, Message: item}
- if err := vom.ObjToJSON(w, vom.ValueOf(data)); err != nil {
- w.sendError(verror.Internalf("error marshalling stream: %v:", err))
- return
- }
- if err := w.FinishMessage(); err != nil {
- logger.Error("WSPR: error finishing message", err)
+ if err := w.Send(lib.ResponseStream, item); err != nil {
+ w.Error(verror.Internalf("error marshalling stream: %v:", err))
return
}
}
- if err := vom.ObjToJSON(w, vom.ValueOf(response{Type: responseStreamClose})); err != nil {
- w.sendError(verror.Internalf("error closing stream: %v:", err))
- return
- }
- if err := w.FinishMessage(); err != nil {
- logger.Error("WSPR: error finishing message", err)
+ if err := w.Send(lib.ResponseStreamClose, nil); err != nil {
+ w.Error(verror.Internalf("error closing stream: %v:", err))
return
}
}
-func (s *server) serve(name string, sig JSONServiceSignature) (string, error) {
+func (s *Server) Serve(name string, sig signature.JSONServiceSignature) (string, error) {
s.Lock()
defer s.Unlock()
@@ -192,17 +182,17 @@
if err := s.server.Serve(name, s.dispatcher); err != nil {
return "", err
}
- s.helper.getLogger().VI(1).Infof("endpoint is %s", s.endpoint)
+ s.helper.GetLogger().VI(1).Infof("endpoint is %s", s.endpoint)
return s.endpoint, nil
}
-func (s *server) handleServerResponse(id int64, data string) {
+func (s *Server) HandleServerResponse(id int64, data string) {
s.Lock()
ch := s.outstandingServerRequests[id]
delete(s.outstandingServerRequests, id)
s.Unlock()
if ch == nil {
- s.helper.getLogger().Errorf("unexpected result from JavaScript. No channel "+
+ s.helper.GetLogger().Errorf("unexpected result from JavaScript. No channel "+
"for MessageId: %d exists. Ignoring the results.", id)
//Ignore unknown responses that don't belong to any channel
return
@@ -218,13 +208,13 @@
serverReply = serverRPCReply{nil, &err}
}
- s.helper.getLogger().VI(3).Infof("response received from JavaScript server for "+
+ s.helper.GetLogger().VI(3).Infof("response received from JavaScript server for "+
"MessageId %d with result %v", id, serverReply)
- s.helper.cleanupFlow(id)
+ s.helper.CleanupFlow(id)
ch <- &serverReply
}
-func (s *server) Stop() {
+func (s *Server) Stop() {
result := serverRPCReply{
Results: []interface{}{nil},
Err: &verror.Standard{
diff --git a/services/wspr/wsprd/lib/signature_invoker.go b/services/wsprd/ipc/server/signature_invoker.go
similarity index 97%
rename from services/wspr/wsprd/lib/signature_invoker.go
rename to services/wsprd/ipc/server/signature_invoker.go
index 56026e2..6384510 100644
--- a/services/wspr/wsprd/lib/signature_invoker.go
+++ b/services/wsprd/ipc/server/signature_invoker.go
@@ -1,4 +1,4 @@
-package lib
+package server
import (
"veyron2/ipc"
diff --git a/services/wsprd/ipc/server/stream.go b/services/wsprd/ipc/server/stream.go
new file mode 100644
index 0000000..03b39e2
--- /dev/null
+++ b/services/wsprd/ipc/server/stream.go
@@ -0,0 +1,19 @@
+package server
+
+import (
+ "veyron/services/wsprd/lib"
+ "veyron2/ipc"
+)
+
+// A simple struct that wraps a stream with the sender api. It
+// will write to the stream synchronously. Any error will still
+// be written to clientWriter.
+type senderWrapper struct {
+ stream ipc.Stream
+}
+
+func (s senderWrapper) Send(item interface{}, w lib.ClientWriter) {
+ if err := s.stream.Send(item); err != nil {
+ w.Error(err)
+ }
+}
diff --git a/services/wsprd/ipc/stream/stream.go b/services/wsprd/ipc/stream/stream.go
new file mode 100644
index 0000000..57ef1b3
--- /dev/null
+++ b/services/wsprd/ipc/stream/stream.go
@@ -0,0 +1,14 @@
+// The set of streaming helper objects for wspr.
+
+package stream
+
+import (
+ "veyron/services/wsprd/lib"
+)
+
+// An interface for an asynchronous sender.
+type Sender interface {
+ // Similar to ipc.Stream.Send, expect that instead of
+ // returning an error, w.sendError will be called.
+ Send(item interface{}, w lib.ClientWriter)
+}
diff --git a/services/wspr/wsprd/lib/cache.go b/services/wsprd/lib/cache.go
similarity index 100%
rename from services/wspr/wsprd/lib/cache.go
rename to services/wsprd/lib/cache.go
diff --git a/services/wspr/wsprd/lib/case.go b/services/wsprd/lib/case.go
similarity index 67%
rename from services/wspr/wsprd/lib/case.go
rename to services/wsprd/lib/case.go
index b440561..e6ec0d0 100644
--- a/services/wspr/wsprd/lib/case.go
+++ b/services/wsprd/lib/case.go
@@ -2,14 +2,14 @@
import "unicode"
-func lowercaseFirstCharacter(s string) string {
+func LowercaseFirstCharacter(s string) string {
for _, r := range s {
return string(unicode.ToLower(r)) + s[1:]
}
return ""
}
-func uppercaseFirstCharacter(s string) string {
+func UppercaseFirstCharacter(s string) string {
for _, r := range s {
return string(unicode.ToUpper(r)) + s[1:]
}
diff --git a/services/wspr/wsprd/lib/remove_this.go b/services/wsprd/lib/remove_this.go
similarity index 100%
rename from services/wspr/wsprd/lib/remove_this.go
rename to services/wsprd/lib/remove_this.go
diff --git a/services/wspr/wsprd/lib/signature_manager.go b/services/wsprd/lib/signature_manager.go
similarity index 84%
rename from services/wspr/wsprd/lib/signature_manager.go
rename to services/wsprd/lib/signature_manager.go
index 642dfe8..18a76a8 100644
--- a/services/wspr/wsprd/lib/signature_manager.go
+++ b/services/wsprd/lib/signature_manager.go
@@ -8,9 +8,8 @@
"veyron2/ipc"
)
-// NewSignatureManager creates and initialized a new Signature Manager
-func newSignatureManager() *signatureManager {
- return &signatureManager{cache: make(map[string]*cacheEntry)}
+type SignatureManager interface {
+ Signature(ctx context.T, name string, client ipc.Client) (*ipc.ServiceSignature, error)
}
// signatureManager can be used to discover the signature of a remote service
@@ -24,6 +23,11 @@
cache map[string]*cacheEntry
}
+// NewSignatureManager creates and initialized a new Signature Manager
+func NewSignatureManager() SignatureManager {
+ return &signatureManager{cache: make(map[string]*cacheEntry)}
+}
+
const (
// ttl from the last-accessed time.
ttl = time.Duration(time.Hour)
@@ -41,7 +45,7 @@
// signature uses the given client to fetch the signature for the given service name.
// It locks until it fetches the service signature from the remote server, if not a cache hit.
-func (sm *signatureManager) signature(ctx context.T, name string, client ipc.Client) (*ipc.ServiceSignature, error) {
+func (sm *signatureManager) Signature(ctx context.T, name string, client ipc.Client) (*ipc.ServiceSignature, error) {
sm.Lock()
defer sm.Unlock()
@@ -51,7 +55,7 @@
}
// cache expired or not found, fetch it from the remote server
- signatureCall, err := client.StartCall(ctx, name, signatureMethodName, []interface{}{})
+ signatureCall, err := client.StartCall(ctx, name, "Signature", []interface{}{})
if err != nil {
return nil, err
}
diff --git a/services/wspr/wsprd/lib/signature_manager_test.go b/services/wsprd/lib/signature_manager_test.go
similarity index 81%
rename from services/wspr/wsprd/lib/signature_manager_test.go
rename to services/wsprd/lib/signature_manager_test.go
index ac60393..f0caf01 100644
--- a/services/wspr/wsprd/lib/signature_manager_test.go
+++ b/services/wsprd/lib/signature_manager_test.go
@@ -15,6 +15,10 @@
name = "/veyron/name"
)
+func init() {
+ rt.Init()
+}
+
func expectedSignature() ipc.ServiceSignature {
return ipc.ServiceSignature{
Methods: make(map[string]ipc.MethodSignature),
@@ -30,7 +34,7 @@
func client() *mocks_ipc.SimpleMockClient {
return mocks_ipc.NewSimpleClient(
map[string][]interface{}{
- signatureMethodName: []interface{}{expectedSignature(), nil},
+ "Signature": []interface{}{expectedSignature(), nil},
},
)
}
@@ -75,8 +79,8 @@
}
func TestFetching(t *testing.T) {
- sm := newSignatureManager()
- got, err := sm.signature(rt.R().NewContext(), name, client())
+ sm := NewSignatureManager()
+ got, err := sm.Signature(rt.R().NewContext(), name, client())
if err != nil {
t.Errorf(`Did not expect an error but got %v`, err)
return
@@ -86,8 +90,8 @@
}
func TestThatCachedAfterFetching(t *testing.T) {
- sm := newSignatureManager()
- sig, _ := sm.signature(rt.R().NewContext(), name, client())
+ sm := NewSignatureManager().(*signatureManager)
+ sig, _ := sm.Signature(rt.R().NewContext(), name, client())
cache, ok := sm.cache[name]
if !ok {
t.Errorf(`Signature manager did not cache the results`)
@@ -98,30 +102,30 @@
func TestThatCacheIsUsed(t *testing.T) {
client := client()
- sm := newSignatureManager()
+ sm := NewSignatureManager()
// call twice
- sm.signature(rt.R().NewContext(), name, client)
- sm.signature(rt.R().NewContext(), name, client)
+ sm.Signature(rt.R().NewContext(), name, client)
+ sm.Signature(rt.R().NewContext(), name, client)
// expect number of calls to Signature method of client to still be 1 since cache
// should have been used despite the second call
- if client.TimesCalled(signatureMethodName) != 1 {
+ if client.TimesCalled("Signature") != 1 {
t.Errorf("Signature cache was not used for the second call")
}
}
func TestThatLastAccessedGetUpdated(t *testing.T) {
client := client()
- sm := newSignatureManager()
- sm.signature(rt.R().NewContext(), name, client)
+ sm := NewSignatureManager().(*signatureManager)
+ sm.Signature(rt.R().NewContext(), name, client)
// make last accessed be in the past to account for the fact that
// two consecutive calls to time.Now() can return identical values.
sm.cache[name].lastAccessed = sm.cache[name].lastAccessed.Add(-ttl / 2)
prevAccess := sm.cache[name].lastAccessed
// access again
- sm.signature(rt.R().NewContext(), name, client)
+ sm.Signature(rt.R().NewContext(), name, client)
newAccess := sm.cache[name].lastAccessed
if !newAccess.After(prevAccess) {
@@ -131,17 +135,17 @@
func TestThatTTLExpires(t *testing.T) {
client := client()
- sm := newSignatureManager()
- sm.signature(rt.R().NewContext(), name, client)
+ sm := NewSignatureManager().(*signatureManager)
+ sm.Signature(rt.R().NewContext(), name, client)
// make last accessed go over the ttl
sm.cache[name].lastAccessed = sm.cache[name].lastAccessed.Add(-2 * ttl)
// make a second call
- sm.signature(rt.R().NewContext(), name, client)
+ sm.Signature(rt.R().NewContext(), name, client)
// expect number of calls to Signature method of client to be 2 since cache should have expired
- if client.TimesCalled(signatureMethodName) != 2 {
+ if client.TimesCalled("Signature") != 2 {
t.Errorf("Cache was still used but TTL had passed. It should have been fetched again")
}
}
diff --git a/services/wsprd/lib/writer.go b/services/wsprd/lib/writer.go
new file mode 100644
index 0000000..ae18996
--- /dev/null
+++ b/services/wsprd/lib/writer.go
@@ -0,0 +1,19 @@
+package lib
+
+type ResponseType int
+
+const (
+ ResponseFinal ResponseType = 0
+ ResponseStream = 1
+ ResponseError = 2
+ ResponseServerRequest = 3
+ ResponseStreamClose = 4
+)
+
+// This is basically an io.Writer interface, that allows passing error message
+// strings. This is how the proxy will talk to the javascript/java clients.
+type ClientWriter interface {
+ Send(messageType ResponseType, data interface{}) error
+
+ Error(err error)
+}
diff --git a/services/wspr/wsprd/lib/identity.go b/services/wsprd/security/identity.go
similarity index 99%
rename from services/wspr/wsprd/lib/identity.go
rename to services/wsprd/security/identity.go
index 823d4d8..f72ad24 100644
--- a/services/wspr/wsprd/lib/identity.go
+++ b/services/wsprd/security/identity.go
@@ -10,8 +10,7 @@
// information, but not the private keys for each app.
// TODO(bjornick,ataly,ashankar): Have all the accounts share the same private key which will be stored
// in a TPM, so no private key gets serialized to disk.
-
-package lib
+package security
import (
"crypto/ecdsa"
diff --git a/services/wspr/wsprd/lib/identity_test.go b/services/wsprd/security/identity_test.go
similarity index 99%
rename from services/wspr/wsprd/lib/identity_test.go
rename to services/wsprd/security/identity_test.go
index b7ccbad..9b89999 100644
--- a/services/wspr/wsprd/lib/identity_test.go
+++ b/services/wsprd/security/identity_test.go
@@ -1,4 +1,4 @@
-package lib
+package security
import (
"bytes"
diff --git a/services/wspr/wsprd/lib/signature.go b/services/wsprd/signature/signature.go
similarity index 90%
rename from services/wspr/wsprd/lib/signature.go
rename to services/wsprd/signature/signature.go
index 54dd136..0185658 100644
--- a/services/wspr/wsprd/lib/signature.go
+++ b/services/wsprd/signature/signature.go
@@ -1,16 +1,12 @@
-package lib
+package signature
import (
+ "veyron/services/wsprd/lib"
"veyron2/ipc"
"veyron2/vdl/vdlutil"
"veyron2/wiretype"
)
-const (
- // agreed-upon name of the signature method that's available on all services
- signatureMethodName = "Signature"
-)
-
var (
anydataType = wiretype.NamedPrimitiveType{
Name: "veyron2/vdlutil.AnyData",
@@ -49,7 +45,7 @@
jmethSig.InArgs[i] = inarg.Name
}
- jsig[lowercaseFirstCharacter(name)] = jmethSig
+ jsig[lib.LowercaseFirstCharacter(name)] = jmethSig
}
return jsig
@@ -88,7 +84,7 @@
ms.OutStream = anydataTypeID
}
- ss.Methods[uppercaseFirstCharacter(name)] = ms
+ ss.Methods[lib.UppercaseFirstCharacter(name)] = ms
}
ss.TypeDefs = []vdlutil.Any{anydataType, errType}
diff --git a/services/wspr/wsprd/lib/signature_test.go b/services/wsprd/signature/signature_test.go
similarity index 98%
rename from services/wspr/wsprd/lib/signature_test.go
rename to services/wsprd/signature/signature_test.go
index e8e1f4f..250acf5 100644
--- a/services/wspr/wsprd/lib/signature_test.go
+++ b/services/wsprd/signature/signature_test.go
@@ -1,4 +1,4 @@
-package lib
+package signature
import (
"reflect"
diff --git a/services/wspr/wsprd/wspr.go b/services/wsprd/wspr.go
similarity index 81%
rename from services/wspr/wsprd/wspr.go
rename to services/wsprd/wspr.go
index ef4977d..4a01ea0 100644
--- a/services/wspr/wsprd/wspr.go
+++ b/services/wsprd/wspr.go
@@ -4,7 +4,7 @@
"flag"
"veyron/lib/signals"
- "veyron/services/wspr/wsprd/lib"
+ "veyron/services/wsprd/wspr"
)
func main() {
@@ -12,7 +12,7 @@
veyronProxy := flag.String("vproxy", "", "The endpoint for the veyron proxy to publish on. This must be set")
flag.Parse()
- proxy := lib.NewWSPR(*port, *veyronProxy)
+ proxy := wspr.NewWSPR(*port, *veyronProxy)
defer proxy.Shutdown()
go func() {
proxy.Run()
diff --git a/services/wspr/wsprd/lib/writer.go b/services/wsprd/wspr/writer.go
similarity index 60%
rename from services/wspr/wsprd/lib/writer.go
rename to services/wsprd/wspr/writer.go
index 11fd44c..4c85ea0 100644
--- a/services/wspr/wsprd/lib/writer.go
+++ b/services/wsprd/wspr/writer.go
@@ -1,10 +1,13 @@
-package lib
+package wspr
import (
"bytes"
"fmt"
"path/filepath"
"runtime"
+
+ "veyron/services/wsprd/lib"
+
"veyron2/verror"
"veyron2/vlog"
"veyron2/vom"
@@ -12,30 +15,41 @@
"github.com/gorilla/websocket"
)
-// This is basically an io.Writer interface, that allows passing error message
-// strings. This is how the proxy will talk to the javascript/java clients.
-type clientWriter interface {
- Write(p []byte) (int, error)
-
- sendError(err error)
-
- FinishMessage() error
+// Wraps a response to the proxy client and adds a message type.
+type response struct {
+ Type lib.ResponseType
+ Message interface{}
}
// Implements clientWriter interface for sending messages over websockets.
type websocketWriter struct {
ws *websocket.Conn
- buf bytes.Buffer
logger vlog.Logger
id int64
}
-func (w *websocketWriter) Write(p []byte) (int, error) {
- w.buf.Write(p)
- return len(p), nil
+func (w *websocketWriter) Send(messageType lib.ResponseType, data interface{}) error {
+ var buf bytes.Buffer
+ if err := vom.ObjToJSON(&buf, vom.ValueOf(response{Type: messageType, Message: data})); err != nil {
+ w.logger.Error("Failed to marshal with", err)
+ return err
+ }
+
+ wc, err := w.ws.NextWriter(websocket.TextMessage)
+ if err != nil {
+ w.logger.Error("Failed to get a writer from the websocket", err)
+ return err
+ }
+ if err := vom.ObjToJSON(wc, vom.ValueOf(websocketMessage{Id: w.id, Data: buf.String()})); err != nil {
+ w.logger.Error("Failed to write the message", err)
+ return err
+ }
+ wc.Close()
+
+ return nil
}
-func (w *websocketWriter) sendError(err error) {
+func (w *websocketWriter) Error(err error) {
verr := verror.ToStandard(err)
// Also log the error but write internal errors at a more severe log level
@@ -56,26 +70,5 @@
Msg: verr.Error(),
}
- w.buf.Reset()
- if err := vom.ObjToJSON(&w.buf, vom.ValueOf(response{Type: responseError, Message: errMsg})); err != nil {
- w.logger.Error("Failed to marshal with", err)
- return
- }
- if err := w.FinishMessage(); err != nil {
- w.logger.Error("WSPR: error finishing message: ", err)
- return
- }
-}
-
-func (w *websocketWriter) FinishMessage() error {
- wc, err := w.ws.NextWriter(websocket.TextMessage)
- if err != nil {
- return err
- }
- if err := vom.ObjToJSON(wc, vom.ValueOf(websocketMessage{Id: w.id, Data: w.buf.String()})); err != nil {
- return err
- }
- wc.Close()
- w.buf.Reset()
- return nil
+ w.Send(lib.ResponseError, errMsg)
}
diff --git a/services/wspr/wsprd/lib/wspr.go b/services/wsprd/wspr/wspr.go
similarity index 80%
rename from services/wspr/wsprd/lib/wspr.go
rename to services/wsprd/wspr/wspr.go
index b48a310..81e31e9 100644
--- a/services/wspr/wsprd/lib/wspr.go
+++ b/services/wsprd/wspr/wspr.go
@@ -13,7 +13,7 @@
// "IsStreaming" : true/false
// }
//
-package lib
+package wspr
import (
"bytes"
@@ -31,6 +31,11 @@
"sync"
"time"
+ "veyron/services/wsprd/ipc/client"
+ "veyron/services/wsprd/ipc/server"
+ "veyron/services/wsprd/ipc/stream"
+ "veyron/services/wsprd/lib"
+ "veyron/services/wsprd/signature"
"veyron2"
"veyron2/ipc"
"veyron2/rt"
@@ -55,29 +60,13 @@
type WSPR struct {
tlsCert *tls.Certificate
- clientCache *ClientCache
+ clientCache *lib.ClientCache
rt veyron2.Runtime
logger vlog.Logger
port int
veyronProxyEP string
}
-type responseType int
-
-const (
- responseFinal responseType = 0
- responseStream = 1
- responseError = 2
- responseServerRequest = 3
- responseStreamClose = 4
-)
-
-// Wraps a response to the proxy client and adds a message type.
-type response struct {
- Type responseType
- Message interface{}
-}
-
var logger vlog.Logger
// The type of message sent by the JS client to the wspr.
@@ -139,17 +128,11 @@
type serveRequest struct {
Name string
ServerId uint64
- Service JSONServiceSignature
-}
-
-// The response from the javascript server to the proxy.
-type serverRPCReply struct {
- Results []interface{}
- Err *verror.Standard
+ Service signature.JSONServiceSignature
}
// finishCall waits for the call to finish and write out the response to w.
-func (wsp *websocketPipe) finishCall(w clientWriter, clientCall ipc.Call, msg *veyronRPC) {
+func (wsp *websocketPipe) finishCall(w lib.ClientWriter, clientCall ipc.Call, msg *veyronRPC) {
if msg.IsStreaming {
for {
var item interface{}
@@ -157,24 +140,16 @@
if err == io.EOF {
break
}
- w.sendError(err) // Send streaming error as is
+ w.Error(err) // Send streaming error as is
return
}
- data := &response{Type: responseStream, Message: item}
- if err := vom.ObjToJSON(w, vom.ValueOf(data)); err != nil {
- w.sendError(verror.Internalf("unable to marshal: %v", item))
- continue
- }
- if err := w.FinishMessage(); err != nil {
- wsp.ctx.logger.Error("WSPR: error finishing message: ", err)
+ if err := w.Send(lib.ResponseStream, item); err != nil {
+ w.Error(verror.Internalf("unable to marshal: %v", item))
}
}
- if err := vom.ObjToJSON(w, vom.ValueOf(response{Type: responseStreamClose})); err != nil {
- w.sendError(verror.Internalf("unable to marshal close stream message"))
- }
- if err := w.FinishMessage(); err != nil {
- wsp.ctx.logger.Error("WSPR: error finishing message: ", err)
+ if err := w.Send(lib.ResponseStreamClose, nil); err != nil {
+ w.Error(verror.Internalf("unable to marshal close stream message"))
}
}
@@ -186,30 +161,23 @@
}
if err := clientCall.Finish(resultptrs...); err != nil {
// return the call system error as is
- w.sendError(err)
+ w.Error(err)
return
}
// for now we assume last out argument is always error
if len(results) < 1 {
- w.sendError(verror.Internalf("client call did not return any results"))
+ w.Error(verror.Internalf("client call did not return any results"))
return
}
if err, ok := results[len(results)-1].(error); ok {
// return the call application error as is
- w.sendError(err)
+ w.Error(err)
return
}
- data := response{Type: responseFinal, Message: results[0 : len(results)-1]}
- if err := vom.ObjToJSON(w, vom.ValueOf(data)); err != nil {
- w.sendError(verror.Internalf("error marshalling results: %v", err))
- return
- }
-
- if err := w.FinishMessage(); err != nil {
- wsp.ctx.logger.Error("WSPR: error finishing message: ", err)
- return
+ if err := w.Send(lib.ResponseFinal, results[0:len(results)-1]); err != nil {
+ w.Error(verror.Internalf("error marshalling results: %v", err))
}
}
@@ -219,7 +187,7 @@
var err error
if client == nil {
// TODO(bjornick): Use the identity to create the client.
- client, err = ctx.rt.NewClient()
+ client, err = ctx.rt.NewClient(veyron2.CallTimeout(ipc.NoTimeout))
if err != nil {
return nil, fmt.Errorf("error creating client: %v", err)
}
@@ -229,16 +197,17 @@
return client, nil
}
-func (ctx WSPR) startVeyronRequest(w clientWriter, msg *veyronRPC) (ipc.Call, error) {
+func (ctx WSPR) startVeyronRequest(w lib.ClientWriter, msg *veyronRPC) (ipc.Call, error) {
// Issue request to the endpoint.
client, err := ctx.newClient(msg.PrivateId)
if err != nil {
return nil, err
}
- clientCall, err := client.StartCall(ctx.rt.TODOContext(), msg.Name, uppercaseFirstCharacter(msg.Method), msg.InArgs)
+ methodName := lib.UppercaseFirstCharacter(msg.Method)
+ clientCall, err := client.StartCall(ctx.rt.TODOContext(), msg.Name, methodName, msg.InArgs)
if err != nil {
- return nil, fmt.Errorf("error starting call (name: %v, method: %v, args: %v): %v", msg.Name, uppercaseFirstCharacter(msg.Method), msg.InArgs, err)
+ return nil, fmt.Errorf("error starting call (name: %v, method: %v, args: %v): %v", msg.Name, methodName, msg.InArgs, err)
}
return clientCall, nil
@@ -311,7 +280,7 @@
}
type outstandingStream struct {
- stream sender
+ stream stream.Sender
inType vom.Type
}
@@ -329,43 +298,43 @@
outstandingStreams map[int64]outstandingStream
// Maps flowids to the server that owns them.
- flowMap map[int64]*server
+ flowMap map[int64]*server.Server
// A manager that handles fetching and caching signature of remote services
- signatureManager *signatureManager
+ signatureManager lib.SignatureManager
// We maintain multiple Veyron server per websocket pipe for serving JavaScript
// services.
- servers map[uint64]*server
+ servers map[uint64]*server.Server
// Creates a client writer for a given flow. This is a member so that tests can override
// the default implementation.
- writerCreator func(id int64) clientWriter
+ writerCreator func(id int64) lib.ClientWriter
}
// Implements the serverHelper interface
-func (wsp *websocketPipe) createNewFlow(server *server, stream sender) *flow {
+func (wsp *websocketPipe) CreateNewFlow(s *server.Server, stream stream.Sender) *server.Flow {
wsp.Lock()
defer wsp.Unlock()
id := wsp.lastGeneratedId
wsp.lastGeneratedId += 2
- wsp.flowMap[id] = server
+ wsp.flowMap[id] = s
wsp.outstandingStreams[id] = outstandingStream{stream, vom_wiretype.Type{ID: 1}}
- return &flow{id: id, writer: wsp.writerCreator(id)}
+ return &server.Flow{ID: id, Writer: wsp.writerCreator(id)}
}
-func (wsp *websocketPipe) cleanupFlow(id int64) {
+func (wsp *websocketPipe) CleanupFlow(id int64) {
wsp.Lock()
defer wsp.Unlock()
delete(wsp.outstandingStreams, id)
delete(wsp.flowMap, id)
}
-func (wsp *websocketPipe) getLogger() vlog.Logger {
+func (wsp *websocketPipe) GetLogger() vlog.Logger {
return wsp.ctx.logger
}
-func (wsp *websocketPipe) rt() veyron2.Runtime {
+func (wsp *websocketPipe) RT() veyron2.Runtime {
return wsp.ctx.rt
}
@@ -385,13 +354,13 @@
}
func (wsp *websocketPipe) setup() {
- wsp.signatureManager = newSignatureManager()
+ wsp.signatureManager = lib.NewSignatureManager()
wsp.outstandingStreams = make(map[int64]outstandingStream)
- wsp.flowMap = make(map[int64]*server)
- wsp.servers = make(map[uint64]*server)
+ wsp.flowMap = make(map[int64]*server.Server)
+ wsp.servers = make(map[uint64]*server.Server)
if wsp.writerCreator == nil {
- wsp.writerCreator = func(id int64) clientWriter {
+ wsp.writerCreator = func(id int64) lib.ClientWriter {
return &websocketWriter{ws: wsp.ws, id: id, logger: wsp.ctx.logger}
}
}
@@ -455,12 +424,13 @@
return nil
}
-func (wsp *websocketPipe) sendParsedMessageOnStream(id int64, msg interface{}, w clientWriter) {
+func (wsp *websocketPipe) sendParsedMessageOnStream(id int64, msg interface{}, w lib.ClientWriter) {
wsp.Lock()
defer wsp.Unlock()
stream := wsp.outstandingStreams[id].stream
if stream == nil {
- w.sendError(fmt.Errorf("unknown stream"))
+ w.Error(fmt.Errorf("unknown stream"))
+ return
}
stream.Send(msg, w)
@@ -468,7 +438,7 @@
}
// sendOnStream writes data on id's stream. Returns an error if the send failed.
-func (wsp *websocketPipe) sendOnStream(id int64, data string, w clientWriter) {
+func (wsp *websocketPipe) sendOnStream(id int64, data string, w lib.ClientWriter) {
wsp.Lock()
typ := wsp.outstandingStreams[id].inType
wsp.Unlock()
@@ -484,12 +454,12 @@
wsp.sendParsedMessageOnStream(id, payload, w)
}
-func (wsp *websocketPipe) sendVeyronRequest(id int64, veyronMsg *veyronRPC, w clientWriter, signal chan ipc.Stream) {
+func (wsp *websocketPipe) sendVeyronRequest(id int64, veyronMsg *veyronRPC, w lib.ClientWriter, signal chan ipc.Stream) {
// We have to make the start call synchronous so we can make sure that we populate
// the call map before we can handle a recieve call.
call, err := wsp.ctx.startVeyronRequest(w, veyronMsg)
if err != nil {
- w.sendError(verror.Internalf("can't start Veyron Request: %v", err))
+ w.Error(verror.Internalf("can't start Veyron Request: %v", err))
return
}
@@ -509,7 +479,7 @@
func (wsp *websocketPipe) handleVeyronRequest(id int64, data string, w *websocketWriter) {
veyronMsg, inStreamType, err := wsp.parseVeyronRequest(bytes.NewBufferString(data))
if err != nil {
- w.sendError(verror.Internalf("can't parse Veyron Request: %v", err))
+ w.Error(verror.Internalf("can't parse Veyron Request: %v", err))
return
}
@@ -524,7 +494,7 @@
if veyronMsg.IsStreaming {
signal = make(chan ipc.Stream)
wsp.outstandingStreams[id] = outstandingStream{
- stream: startQueueingStream(signal),
+ stream: client.StartQueueingStream(signal),
inType: inStreamType,
}
}
@@ -540,9 +510,9 @@
return
}
- var call queueingStream
+ var call client.QueueingStream
var ok bool
- if call, ok = stream.(queueingStream); !ok {
+ if call, ok = stream.(client.QueueingStream); !ok {
wsp.ctx.logger.Errorf("can't close server stream: %v", id)
return
}
@@ -601,19 +571,19 @@
case websocketSignatureRequest:
go wsp.handleSignatureRequest(msg.Data, ww)
default:
- ww.sendError(verror.Unknownf("unknown message type: %v", msg.Type))
+ ww.Error(verror.Unknownf("unknown message type: %v", msg.Type))
}
}
wsp.cleanup()
}
-func (wsp *websocketPipe) maybeCreateServer(serverId uint64) (*server, error) {
+func (wsp *websocketPipe) maybeCreateServer(serverId uint64) (*server.Server, error) {
wsp.Lock()
defer wsp.Unlock()
if server, ok := wsp.servers[serverId]; ok {
return server, nil
}
- server, err := newServer(serverId, wsp.ctx.veyronProxyEP, wsp)
+ server, err := server.NewServer(serverId, wsp.ctx.veyronProxyEP, wsp)
if err != nil {
return nil, err
}
@@ -634,29 +604,23 @@
server.Stop()
}
-func (wsp *websocketPipe) serve(serveRequest serveRequest, w clientWriter) {
+func (wsp *websocketPipe) serve(serveRequest serveRequest, w lib.ClientWriter) {
// Create a server for the websocket pipe, if it does not exist already
server, err := wsp.maybeCreateServer(serveRequest.ServerId)
if err != nil {
- w.sendError(verror.Internalf("error creating server: %v", err))
+ w.Error(verror.Internalf("error creating server: %v", err))
}
wsp.ctx.logger.VI(2).Infof("serving under name: %q", serveRequest.Name)
- endpoint, err := server.serve(serveRequest.Name, serveRequest.Service)
+ endpoint, err := server.Serve(serveRequest.Name, serveRequest.Service)
if err != nil {
- w.sendError(verror.Internalf("error serving service: %v", err))
+ w.Error(verror.Internalf("error serving service: %v", err))
return
}
// Send the endpoint back
- endpointData := response{Type: responseFinal, Message: endpoint}
- if err := vom.ObjToJSON(w, vom.ValueOf(endpointData)); err != nil {
- w.sendError(verror.Internalf("error marshalling results: %v", err))
- return
- }
-
- if err := w.FinishMessage(); err != nil {
- wsp.ctx.logger.Error("WSPR: error finishing message: ", err)
+ if err := w.Send(lib.ResponseFinal, endpoint); err != nil {
+ w.Error(verror.Internalf("error marshalling results: %v", err))
return
}
}
@@ -668,7 +632,7 @@
var serveRequest serveRequest
decoder := json.NewDecoder(bytes.NewBufferString(data))
if err := decoder.Decode(&serveRequest); err != nil {
- w.sendError(verror.Internalf("can't unmarshal JSONMessage: %v", err))
+ w.Error(verror.Internalf("can't unmarshal JSONMessage: %v", err))
return
}
wsp.serve(serveRequest, w)
@@ -680,19 +644,17 @@
var serverId uint64
decoder := json.NewDecoder(bytes.NewBufferString(data))
if err := decoder.Decode(&serverId); err != nil {
- w.sendError(verror.Internalf("can't unmarshal JSONMessage: %v", err))
+ w.Error(verror.Internalf("can't unmarshal JSONMessage: %v", err))
return
}
wsp.removeServer(serverId)
// Send true to indicate stop has finished
- result := response{Type: responseFinal, Message: true}
- if err := vom.ObjToJSON(w, vom.ValueOf(result)); err != nil {
- w.sendError(verror.Internalf("error marshalling results: %v", err))
+ if err := w.Send(lib.ResponseFinal, true); err != nil {
+ w.Error(verror.Internalf("error marshalling results: %v", err))
return
}
- w.FinishMessage()
}
// handleServerResponse handles the completion of outstanding calls to JavaScript services
@@ -707,7 +669,7 @@
//Ignore unknown responses that don't belong to any channel
return
}
- server.handleServerResponse(id, data)
+ server.HandleServerResponse(id, data)
}
// parseVeyronRequest parses a json rpc request into a veyronRPC object.
@@ -725,12 +687,12 @@
// Fetch and adapt signature from the SignatureManager
ctx := wsp.ctx.rt.TODOContext()
- sig, err := wsp.signatureManager.signature(ctx, tempMsg.Name, client)
+ sig, err := wsp.signatureManager.Signature(ctx, tempMsg.Name, client)
if err != nil {
return nil, nil, verror.Internalf("error getting service signature for %s: %v", tempMsg.Name, err)
}
- methName := uppercaseFirstCharacter(tempMsg.Method)
+ methName := lib.UppercaseFirstCharacter(tempMsg.Method)
methSig, ok := sig.Methods[methName]
if !ok {
return nil, nil, fmt.Errorf("Method not found in signature: %v (full sig: %v)", methName, sig)
@@ -777,7 +739,7 @@
PrivateId string
}
-func (wsp *websocketPipe) getSignature(name string, privateId string) (JSONServiceSignature, error) {
+func (wsp *websocketPipe) getSignature(name string, privateId string) (signature.JSONServiceSignature, error) {
client, err := wsp.ctx.newClient(privateId)
if err != nil {
return nil, verror.Internalf("error creating client: %v", err)
@@ -785,12 +747,12 @@
// Fetch and adapt signature from the SignatureManager
ctx := wsp.ctx.rt.TODOContext()
- sig, err := wsp.signatureManager.signature(ctx, name, client)
+ sig, err := wsp.signatureManager.Signature(ctx, name, client)
if err != nil {
return nil, verror.Internalf("error getting service signature for %s: %v", name, err)
}
- return NewJSONServiceSignature(*sig), nil
+ return signature.NewJSONServiceSignature(*sig), nil
}
// handleSignatureRequest uses signature manager to get and cache signature of a remote server
@@ -799,7 +761,7 @@
var request signatureRequest
decoder := json.NewDecoder(bytes.NewBufferString(data))
if err := decoder.Decode(&request); err != nil {
- w.sendError(verror.Internalf("can't unmarshal JSONMessage: %v", err))
+ w.Error(verror.Internalf("can't unmarshal JSONMessage: %v", err))
return
}
@@ -807,25 +769,20 @@
wsp.ctx.logger.VI(2).Info("private id is", request.PrivateId)
jsSig, err := wsp.getSignature(request.Name, request.PrivateId)
if err != nil {
- w.sendError(err)
+ w.Error(err)
return
}
// Send the signature back
- signatureData := response{Type: responseFinal, Message: jsSig}
- if err := vom.ObjToJSON(w, vom.ValueOf(signatureData)); err != nil {
- w.sendError(verror.Internalf("error marshalling results: %v", err))
- return
- }
- if err := w.FinishMessage(); err != nil {
- w.logger.Error("WSPR: error finishing message: ", err)
+ if err := w.Send(lib.ResponseFinal, jsSig); err != nil {
+ w.Error(verror.Internalf("error marshalling results: %v", err))
return
}
}
func (ctx *WSPR) setup() {
// Cache up to 20 identity.PrivateID->ipc.Client mappings
- ctx.clientCache = NewClientCache(20)
+ ctx.clientCache = lib.NewClientCache(20)
}
// Starts the proxy and listens for requests. This method is blocking.
diff --git a/services/wspr/wsprd/lib/wspr_test.go b/services/wsprd/wspr/wspr_test.go
similarity index 89%
rename from services/wspr/wsprd/lib/wspr_test.go
rename to services/wsprd/wspr/wspr_test.go
index 018270d..d03d7fa 100644
--- a/services/wspr/wsprd/lib/wspr_test.go
+++ b/services/wsprd/wspr/wspr_test.go
@@ -1,4 +1,4 @@
-package lib
+package wspr
import (
"bytes"
@@ -8,6 +8,9 @@
"sync"
"testing"
"time"
+ "veyron/services/wsprd/ipc/client"
+ "veyron/services/wsprd/lib"
+ "veyron/services/wsprd/signature"
"veyron2"
"veyron2/ipc"
"veyron2/naming"
@@ -132,7 +135,6 @@
type testWriter struct {
sync.Mutex
stream []response
- buf bytes.Buffer
err error
logger vlog.Logger
// If this channel is set then a message will be sent
@@ -140,29 +142,32 @@
notifier chan bool
}
-func (w *testWriter) Write(p []byte) (int, error) {
- return w.buf.Write(p)
-
-}
-
-func (w *testWriter) sendError(err error) {
- w.err = err
-}
-
-func (w *testWriter) FinishMessage() error {
- var resp response
- p := w.buf.Bytes()
- w.buf.Reset()
- if err := json.Unmarshal(p, &resp); err != nil {
+func (w *testWriter) Send(responseType lib.ResponseType, msg interface{}) error {
+ w.Lock()
+ defer w.Unlock()
+ // We serialize and deserialize the reponse so that we can do deep equal with
+ // messages that contain non-exported structs.
+ var buf bytes.Buffer
+ if err := json.NewEncoder(&buf).Encode(response{Type: responseType, Message: msg}); err != nil {
return err
}
- w.Lock()
- w.stream = append(w.stream, resp)
+
+ var r response
+
+ if err := json.NewDecoder(&buf).Decode(&r); err != nil {
+ return err
+ }
+
+ w.stream = append(w.stream, r)
if w.notifier != nil {
w.notifier <- true
}
- w.Unlock()
return nil
+
+}
+
+func (w *testWriter) Error(err error) {
+ w.err = err
}
func (w *testWriter) streamLength() int {
@@ -204,18 +209,18 @@
}
}
-var adderServiceSignature JSONServiceSignature = JSONServiceSignature{
- "add": JSONMethodSignature{
+var adderServiceSignature signature.JSONServiceSignature = signature.JSONServiceSignature{
+ "add": signature.JSONMethodSignature{
InArgs: []string{"A", "B"},
NumOutArgs: 2,
IsStreaming: false,
},
- "divide": JSONMethodSignature{
+ "divide": signature.JSONMethodSignature{
InArgs: []string{"A", "B"},
NumOutArgs: 2,
IsStreaming: false,
},
- "streamingAdd": JSONMethodSignature{
+ "streamingAdd": signature.JSONMethodSignature{
InArgs: []string{},
NumOutArgs: 2,
IsStreaming: true,
@@ -275,7 +280,7 @@
if len(test.streamingInputs) > 0 {
signal = make(chan ipc.Stream, 1)
wsp.outstandingStreams[0] = outstandingStream{
- stream: startQueueingStream(signal),
+ stream: client.StartQueueingStream(signal),
inType: test.streamingInputType,
}
go func() {
@@ -294,6 +299,7 @@
IsStreaming: signal != nil,
}
wsp.sendVeyronRequest(0, &request, &writer, signal)
+
checkResponses(&writer, test.expectedStream, test.expectedError, t)
}
@@ -304,8 +310,8 @@
numOutArgs: 2,
expectedStream: []response{
response{
- Message: []interface{}{float64(5)},
- Type: responseFinal,
+ Message: []interface{}{5.0},
+ Type: lib.ResponseFinal,
},
},
})
@@ -330,27 +336,27 @@
expectedStream: []response{
response{
Message: 1.0,
- Type: responseStream,
+ Type: lib.ResponseStream,
},
response{
Message: 3.0,
- Type: responseStream,
+ Type: lib.ResponseStream,
},
response{
Message: 6.0,
- Type: responseStream,
+ Type: lib.ResponseStream,
},
response{
Message: 10.0,
- Type: responseStream,
+ Type: lib.ResponseStream,
},
response{
Message: nil,
- Type: responseStreamClose,
+ Type: lib.ResponseStreamClose,
},
response{
Message: []interface{}{10.0},
- Type: responseFinal,
+ Type: lib.ResponseFinal,
},
},
})
@@ -385,7 +391,7 @@
writer := testWriter{
logger: wspr.logger,
}
- wsp.writerCreator = func(int64) clientWriter {
+ wsp.writerCreator = func(int64) lib.ClientWriter {
return &writer
}
wsp.setup()
@@ -416,7 +422,7 @@
resp := rt.writer.stream[0]
- if resp.Type != responseFinal {
+ if resp.Type != lib.ResponseFinal {
t.Errorf("unknown stream message Got: %v, expected: serve response", resp)
return
}
@@ -469,14 +475,14 @@
err *verror.Standard
}
-func sendServerStream(t *testing.T, wsp *websocketPipe, test *jsServerTestCase, w clientWriter) {
+func sendServerStream(t *testing.T, wsp *websocketPipe, test *jsServerTestCase, w lib.ClientWriter) {
for _, msg := range test.serverStream {
wsp.sendParsedMessageOnStream(0, msg, w)
}
- serverReply := serverRPCReply{
- Results: []interface{}{test.finalResponse},
- Err: test.err,
+ serverReply := map[string]interface{}{
+ "Results": []interface{}{test.finalResponse},
+ "Err": test.err,
}
bytes, err := json.Marshal(serverReply)
@@ -503,7 +509,7 @@
resp := rt.writer.stream[0]
- if resp.Type != responseFinal {
+ if resp.Type != lib.ResponseFinal {
t.Errorf("unknown stream message Got: %v, expected: serve response", resp)
return
}
@@ -533,14 +539,14 @@
expectedWebsocketMessage := []response{
response{
- Type: responseServerRequest,
+ Type: lib.ResponseServerRequest,
Message: map[string]interface{}{
- "serverId": 0.0,
- "method": lowercaseFirstCharacter(test.method),
- "args": test.inArgs,
- "context": map[string]interface{}{
- "name": "adder",
- "suffix": "adder",
+ "ServerId": 0.0,
+ "Method": lib.LowercaseFirstCharacter(test.method),
+ "Args": test.inArgs,
+ "Context": map[string]interface{}{
+ "Name": "adder",
+ "Suffix": "adder",
},
},
},
@@ -551,7 +557,7 @@
t.Errorf("didn't recieve expected message: %v", err)
}
for _, msg := range test.clientStream {
- expectedWebsocketMessage = append(expectedWebsocketMessage, response{Type: responseStream, Message: msg})
+ expectedWebsocketMessage = append(expectedWebsocketMessage, response{Type: lib.ResponseStream, Message: msg})
if err := call.Send(msg); err != nil {
t.Errorf("unexpected error while sending %v: %v", msg, err)
}
@@ -562,7 +568,7 @@
t.Errorf("didn't recieve expected message: %v", err)
}
- expectedWebsocketMessage = append(expectedWebsocketMessage, response{Type: responseStreamClose})
+ expectedWebsocketMessage = append(expectedWebsocketMessage, response{Type: lib.ResponseStreamClose})
expectedStream := test.serverStream
go sendServerStream(t, rt.wsp, &test, rt.writer)
diff --git a/tools/playground/builder/vbuild.go b/tools/playground/builder/vbuild.go
index 9a3b9b9..0b8f174 100644
--- a/tools/playground/builder/vbuild.go
+++ b/tools/playground/builder/vbuild.go
@@ -6,6 +6,7 @@
import (
"bufio"
"encoding/json"
+ "flag"
"fmt"
"go/parser"
"go/token"
@@ -22,7 +23,7 @@
)
const RUN_TIMEOUT = time.Second
-const debug = false
+var debug = flag.Bool("v", false, "Verbose mode")
type CodeFile struct {
Name string
@@ -55,7 +56,7 @@
}
func Log(args ...interface{}) {
- if debug {
+ if *debug {
log.Println(args...)
}
}
@@ -108,6 +109,7 @@
}
func main() {
+ flag.Parse()
r, err := ParseRequest(os.Stdin)
if err != nil {
log.Fatal(err)
@@ -275,7 +277,7 @@
if groups := pat.FindStringSubmatch(line); groups != nil {
ch <- groups[1]
} else {
- Log(line)
+ Log("mounttabld: %s", line)
}
}
close(ch)
diff --git a/tools/profile/impl/impl.go b/tools/profile/impl/impl.go
index cef78c8..b90e8a6 100644
--- a/tools/profile/impl/impl.go
+++ b/tools/profile/impl/impl.go
@@ -8,6 +8,7 @@
"veyron/services/mgmt/repository"
"veyron2/rt"
+ "veyron2/services/mgmt/build"
)
var cmdLabel = &cmdline.Command{
@@ -105,10 +106,12 @@
// TODO(rthellend): Read an actual specification from a file.
spec := profile.Specification{
- Format: profile.Format{Name: "elf", Attributes: map[string]string{"os": "linux", "arch": "amd64"}},
+ Arch: build.AMD64,
+ Description: "Example profile to test the profile manager implementation.",
+ Format: build.ELF,
Libraries: map[profile.Library]struct{}{profile.Library{Name: "foo", MajorVersion: "1", MinorVersion: "0"}: struct{}{}},
Label: "example",
- Description: "Example profile to test the profile manager implementation.",
+ OS: build.Linux,
}
if err := p.Put(rt.R().NewContext(), spec); err != nil {
return err
diff --git a/tools/profile/impl/impl_test.go b/tools/profile/impl/impl_test.go
index 8500787..45ccf14 100644
--- a/tools/profile/impl/impl_test.go
+++ b/tools/profile/impl/impl_test.go
@@ -15,16 +15,19 @@
"veyron2/naming"
"veyron2/rt"
"veyron2/security"
+ "veyron2/services/mgmt/build"
"veyron2/vlog"
)
var (
// spec is an example profile specification used throughout the test.
spec = profile.Specification{
- Format: profile.Format{Name: "elf", Attributes: map[string]string{"os": "linux"}},
+ Arch: build.AMD64,
+ Description: "Example profile to test the profile repository implementation.",
+ Format: build.ELF,
Libraries: map[profile.Library]struct{}{profile.Library{Name: "foo", MajorVersion: "1", MinorVersion: "0"}: struct{}{}},
Label: "example",
- Description: "Example profile to test the profile repository implementation.",
+ OS: build.Linux,
}
)