diff options
| author | Gubolin <gubolin@fantasymail.de> | 2015-03-08 09:28:56 +0100 |
|---|---|---|
| committer | Gubolin <gubolin@fantasymail.de> | 2015-03-08 09:28:56 +0100 |
| commit | 53936404d5c8ed7a6433e8e9f71c235d34b477b9 (patch) | |
| tree | 6038c09e012d436eb8b9a1cd2e5df0a0c23afee7 /threads.js | |
| parent | b83d4d83bf521b34b878662c7f145cc9286f096a (diff) | |
| download | snap-53936404d5c8ed7a6433e8e9f71c235d34b477b9.tar.gz snap-53936404d5c8ed7a6433e8e9f71c235d34b477b9.zip | |
rewrite peering flow; add peer id blocks
Diffstat (limited to 'threads.js')
| -rw-r--r-- | threads.js | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -1295,6 +1295,47 @@ Process.prototype.doRemoveTemporaries = function () { } }; +// Peer to peer primitives + +Process.prototype.sendPeerMessage = function (message, peer) { + 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) { |
