Commit 5915f4b12de689ba1985efe90c4181b4e774977c
moved more to port manager
wanderer committed on 7/5/2017, 3:57:33 AMParent: 1aa22ba2b0c933edd5df2a76889d2cd6751baca0
Files changed
kernel.js | changed |
portManager.js | changed |
kernel.js | ||
---|---|---|
@@ -79,9 +79,9 @@ | ||
79 | 79 | |
80 | 80 | const responsePort = message.responsePort |
81 | 81 | delete message.responsePort |
82 | 82 | |
83 | - message.ports.forEach(port => this.ports._unboundPorts.add(port)) | |
83 | + this.ports.addReceivedPorts(message) | |
84 | 84 | message._hops++ |
85 | 85 | |
86 | 86 | if (message.constructor === DeleteMessage) { |
87 | 87 | this.ports._delete(message.fromName) |
@@ -133,13 +133,9 @@ | ||
133 | 133 | * @param {*} data |
134 | 134 | */ |
135 | 135 | createMessage (opts) { |
136 | 136 | const message = new Message(opts) |
137 | - for (const port of message.ports) { | |
138 | - if (this.ports.isBound(port)) { | |
139 | - throw new Error('message must not contain bound ports') | |
140 | - } | |
141 | - } | |
137 | + this.ports.checkSendingPorts(message) | |
142 | 138 | return message |
143 | 139 | } |
144 | 140 | |
145 | 141 | /** |
portManager.js | ||
---|---|---|
@@ -249,5 +249,17 @@ | ||
249 | 249 | |
250 | 250 | removeSentPorts (message) { |
251 | 251 | message.ports.forEach(port => this._unboundPorts.delete(port)) |
252 | 252 | } |
253 | + | |
254 | + addReceivedPorts (message) { | |
255 | + message.ports.forEach(port => this._unboundPorts.add(port)) | |
256 | + } | |
257 | + | |
258 | + checkSendingPorts(message) { | |
259 | + for (const port of message.ports) { | |
260 | + if (this.isBound(port)) { | |
261 | + throw new Error('message must not contain bound ports') | |
262 | + } | |
263 | + } | |
264 | + } | |
253 | 265 | } |
Built with git-ssb-web