Skip to content
Snippets Groups Projects
Commit c980570d authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] WS2P document sharing must not close the streams

parent 8f98d936
Branches
Tags
No related merge requests found
import * as stream from "stream" import * as stream from "stream"
import {WS2PConnection} from "../../modules/ws2p/lib/WS2PConnection" import {WS2PConnection} from "../../modules/ws2p/lib/WS2PConnection"
import {NewLogger} from "../logger"
const logger = NewLogger()
export class WS2PStreamer extends stream.Transform { export class WS2PStreamer extends stream.Transform {
...@@ -8,6 +11,7 @@ export class WS2PStreamer extends stream.Transform { ...@@ -8,6 +11,7 @@ export class WS2PStreamer extends stream.Transform {
} }
async _write(obj:any, enc:any, done:any) { async _write(obj:any, enc:any, done:any) {
try {
if (obj.joiners) { if (obj.joiners) {
await this.ws2pc.pushBlock(obj) await this.ws2pc.pushBlock(obj)
} }
...@@ -26,6 +30,9 @@ export class WS2PStreamer extends stream.Transform { ...@@ -26,6 +30,9 @@ export class WS2PStreamer extends stream.Transform {
else if (obj.endpoints) { else if (obj.endpoints) {
await this.ws2pc.pushPeer(obj) await this.ws2pc.pushPeer(obj)
} }
} catch (e) {
logger.warn(e)
}
done && done(); done && done();
} }
} }
...@@ -252,8 +252,9 @@ export class WS2PCluster { ...@@ -252,8 +252,9 @@ export class WS2PCluster {
} }
// Also listen for network updates, and connect to new nodes // Also listen for network updates, and connect to new nodes
this.server.pipe(es.mapSync(async (data:any) => { this.server.pipe(es.mapSync((data:any) => {
(async () => {
// New peer // New peer
if (data.endpoints) { if (data.endpoints) {
const peer = PeerDTO.fromJSONObject(data) const peer = PeerDTO.fromJSONObject(data)
...@@ -286,6 +287,9 @@ export class WS2PCluster { ...@@ -286,6 +287,9 @@ export class WS2PCluster {
this.server.logger.warn(e) this.server.logger.warn(e)
} }
} }
})()
return data
})) }))
} }
...@@ -296,7 +300,13 @@ export class WS2PCluster { ...@@ -296,7 +300,13 @@ export class WS2PCluster {
private async spreadNewHeads(heads:{ message:string, sig:string }[]) { private async spreadNewHeads(heads:{ message:string, sig:string }[]) {
const connexions = await this.getAllConnections() const connexions = await this.getAllConnections()
return Promise.all(connexions.map(c => c.pushHeads(heads))) return Promise.all(connexions.map(async (c) => {
try {
await c.pushHeads(heads)
} catch (e) {
this.server.logger.warn('Could not spread new HEAD info to %s WS2P %s %s', c.pubkey)
}
}))
} }
private sayHeadChangedTo(number:number, hash:string) { private sayHeadChangedTo(number:number, hash:string) {
......
...@@ -159,7 +159,7 @@ export class BlockchainService extends FIFOService { ...@@ -159,7 +159,7 @@ export class BlockchainService extends FIFOService {
await this.blockResolution() await this.blockResolution()
// Resolve the potential forks // Resolve the potential forks
await this.forkResolution() await this.forkResolution()
const current = this.current() const current = await this.current()
this.push({ this.push({
bcEvent: OtherConstants.BC_EVENT.RESOLUTION_DONE, bcEvent: OtherConstants.BC_EVENT.RESOLUTION_DONE,
block: current block: current
......
...@@ -190,6 +190,7 @@ export class Server extends stream.Duplex implements HookableServer { ...@@ -190,6 +190,7 @@ export class Server extends stream.Duplex implements HookableServer {
this.emit('bcEvent', e) this.emit('bcEvent', e)
} }
this.streamPush(e) this.streamPush(e)
return e
})) }))
return this.conf; return this.conf;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment