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
No related branches found
No related tags found
No related merge requests found
import * as stream from "stream"
import {WS2PConnection} from "../../modules/ws2p/lib/WS2PConnection"
import {NewLogger} from "../logger"
const logger = NewLogger()
export class WS2PStreamer extends stream.Transform {
......@@ -8,6 +11,7 @@ export class WS2PStreamer extends stream.Transform {
}
async _write(obj:any, enc:any, done:any) {
try {
if (obj.joiners) {
await this.ws2pc.pushBlock(obj)
}
......@@ -26,6 +30,9 @@ export class WS2PStreamer extends stream.Transform {
else if (obj.endpoints) {
await this.ws2pc.pushPeer(obj)
}
} catch (e) {
logger.warn(e)
}
done && done();
}
}
......@@ -252,8 +252,9 @@ export class WS2PCluster {
}
// 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
if (data.endpoints) {
const peer = PeerDTO.fromJSONObject(data)
......@@ -286,6 +287,9 @@ export class WS2PCluster {
this.server.logger.warn(e)
}
}
})()
return data
}))
}
......@@ -296,7 +300,13 @@ export class WS2PCluster {
private async spreadNewHeads(heads:{ message:string, sig:string }[]) {
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) {
......
......@@ -159,7 +159,7 @@ export class BlockchainService extends FIFOService {
await this.blockResolution()
// Resolve the potential forks
await this.forkResolution()
const current = this.current()
const current = await this.current()
this.push({
bcEvent: OtherConstants.BC_EVENT.RESOLUTION_DONE,
block: current
......
......@@ -190,6 +190,7 @@ export class Server extends stream.Duplex implements HookableServer {
this.emit('bcEvent', e)
}
this.streamPush(e)
return e
}))
return this.conf;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment