summaryrefslogtreecommitdiff
path: root/threads.js
diff options
context:
space:
mode:
authorCode WvS <code-wvs@quantentunnel.de>2015-03-08 10:01:11 +0100
committerCode WvS <code-wvs@quantentunnel.de>2015-03-08 10:01:11 +0100
commit0b9b31b84c1070e51d4d3e257db5ccb1e63db683 (patch)
tree5d15dda7804c76f28ceacb285241163b83dba284 /threads.js
parent6769c91b58751b15ca45528ef0afbbc23a7525d2 (diff)
parentda6c1a37a3f760ec787299f5a7f2bbf1a149acf5 (diff)
downloadsnap-yow-0b9b31b84c1070e51d4d3e257db5ccb1e63db683.tar.gz
snap-yow-0b9b31b84c1070e51d4d3e257db5ccb1e63db683.zip
Merge remote branch "p2p"
Diffstat (limited to 'threads.js')
-rw-r--r--threads.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/threads.js b/threads.js
index 3bf75f1..06644f9 100644
--- a/threads.js
+++ b/threads.js
@@ -1295,6 +1295,56 @@ Process.prototype.doRemoveTemporaries = function () {
}
};
+// Peer to peer primitives
+
+Process.prototype.sendPeerMessage = function (message, peer) {
+ var myself = this;
+
+ if (peer instanceof List) {
+ peer.asArray().forEach(function (singlePeer) {
+ myself.sendPeerMessage(message, singlePeer);
+ });
+ return;
+ }
+
+ var stage = this.homeContext.receiver.parentThatIsA(StageMorph),
+ ide = this.homeContext.receiver.parentThatIsA(IDE_Morph);
+ var connection = stage.peer.connect(peer, {reliable: true});
+ connection.on('open', function () {
+ var data;
+ if (typeof message == "string") {
+ data = message;
+ } else if (typeof message == "function") {
+ data = message.toString();
+ } else {
+ data = ide.serializer.serialize(message);
+ }
+ connection.send(data);
+ });
+};
+
+Process.prototype.reportPeerList = function () {
+ var myself = this;
+
+ if (!this.context.wait) {
+ var stage = this.homeContext.receiver.parentThatIsA(StageMorph);
+ stage.peer.listAllPeers(function (peers) {
+ myself.context.result = new List(peers);
+ });
+ this.context.wait = true;
+ } else if (this.context.result) {
+ return this.context.result;
+ }
+
+ this.pushContext('doYield');
+ this.pushContext();
+};
+
+Process.prototype.reportPeerId = function () {
+ var stage = this.homeContext.receiver.parentThatIsA(StageMorph);
+ return stage.peerId;
+};
+
// Process lists primitives
Process.prototype.reportNewList = function (elements) {