summaryrefslogtreecommitdiff
path: root/threads.js
diff options
context:
space:
mode:
authorGubolin <gubolin@fantasymail.de>2015-03-08 09:52:49 +0100
committerGubolin <gubolin@fantasymail.de>2015-03-08 09:52:49 +0100
commit808076ff0f36d87a514a56de747f0c937624e75d (patch)
treee61fc54710bdaddecc2c82389ebde9088a627f91 /threads.js
parent3db303417ecb4d7200f65be05204acdf2d77aa7c (diff)
parentda6c1a37a3f760ec787299f5a7f2bbf1a149acf5 (diff)
downloadsnap-808076ff0f36d87a514a56de747f0c937624e75d.tar.gz
snap-808076ff0f36d87a514a56de747f0c937624e75d.zip
Merge branch p2p into development
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 d1c633e..2bc5142 100644
--- a/threads.js
+++ b/threads.js
@@ -1320,6 +1320,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) {