Mise à jour de GitLab prévue ce dimanche 25 octobre 2020 à partir de 9h00 CEST | GitLab upgrade planned this Sunday 25th of October 2020 from 9:00 AM CEST

Commit bed5964a authored by Cédric Moreau's avatar Cédric Moreau

[fix] #1037 Migrate module "router"

parent 04285439
......@@ -14,5 +14,6 @@ app/service/*.js
app/lib/rules/local_rules.js
app/lib/rules/global_rules.js
app/modules/wizard.js
app/modules/router.js
test/*.js
test/**/*.js
\ No newline at end of file
......@@ -51,4 +51,6 @@ app/lib/rules/local_rules*.js*
app/lib/rules/global_rules*.js*
app/lib/logger*js*
app/service/*.js*
app/lib/wot.js*
\ No newline at end of file
app/lib/wot.js*
app/modules/router*.js*
app/modules/wizard.js*
\ No newline at end of file
"use strict";
const co = require('co');
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const stream = require("stream");
const constants = require('../lib/constants');
const util = require('util');
const stream = require('stream');
const router = require('../lib/streams/router');
const multicaster = require('../lib/streams/multicaster');
module.exports = {
duniter: {
service: {
output: (server, conf, logger) => new Router(server, conf, logger)
},
methods: {
routeToNetwork: (server) => {
const theRouter = new Router(server);
theRouter.startService();
server.pipe(theRouter);
}
duniter: {
service: {
output: (server, conf, logger) => new Router(server)
},
methods: {
routeToNetwork: (server) => {
const theRouter = new Router(server);
theRouter.startService();
server.pipe(theRouter);
}
}
}
}
}
};
/**
* Service which triggers the server's peering generation (actualization of the Peer document).
* @constructor
*/
function Router(server) {
const that = this;
let theRouter, theMulticaster = multicaster();
stream.Transform.call(this, { objectMode: true });
this._write = function (obj, enc, done) {
// Never close the stream
if (obj) {
that.push(obj);
class Router extends stream.Transform {
constructor(server) {
super({ objectMode: true });
this.server = server;
this.theMulticaster = multicaster();
}
_write(obj, enc, done) {
// Never close the stream
if (obj) {
this.push(obj);
}
done && done();
}
;
startService() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.theRouter) {
this.theRouter = router(this.server.PeeringService, this.server.dal);
}
this.theRouter.setActive(true);
this.theRouter.setConfDAL(this.server.dal);
/**
* Enable routing features:
* - The server will try to send documents to the network
* - The server will eventually be notified of network failures
*/
// The router asks for multicasting of documents
this
.pipe(this.theRouter)
.pipe(this.theMulticaster)
.pipe(this.theRouter);
});
}
done && done();
};
this.startService = () => co(function*() {
if (!theRouter) {
theRouter = router(server.PeeringService, server.dal);
stopService() {
return __awaiter(this, void 0, void 0, function* () {
this.unpipe();
this.theRouter && this.theRouter.unpipe();
this.theMulticaster && this.theMulticaster.unpipe();
});
}
theRouter.setActive(true);
theRouter.setConfDAL(server.dal);
/**
* Enable routing features:
* - The server will try to send documents to the network
* - The server will eventually be notified of network failures
*/
// The router asks for multicasting of documents
that
.pipe(theRouter)
// The documents get sent to peers
.pipe(theMulticaster)
// The multicaster may answer 'unreachable peer'
.pipe(theRouter);
});
this.stopService = () => co(function*() {
that.unpipe();
theRouter && theRouter.unpipe();
theMulticaster && theMulticaster.unpipe();
});
}
util.inherits(Router, stream.Transform);
//# sourceMappingURL=router.js.map
\ No newline at end of file
"use strict";
import {ConfDTO} from "../lib/dto/ConfDTO"
import * as stream from "stream"
const constants = require('../lib/constants');
const router = require('../lib/streams/router');
const multicaster = require('../lib/streams/multicaster');
module.exports = {
duniter: {
service: {
output: (server:any, conf:ConfDTO, logger:any) => new Router(server)
},
methods: {
routeToNetwork: (server:any) => {
const theRouter = new Router(server);
theRouter.startService();
server.pipe(theRouter);
}
}
}
}
/**
* Service which triggers the server's peering generation (actualization of the Peer document).
* @constructor
*/
class Router extends stream.Transform {
theRouter:any
theMulticaster:any = multicaster()
constructor(private server:any) {
super({ objectMode: true })
}
_write(obj:any, enc:string, done:any) {
// Never close the stream
if (obj) {
this.push(obj);
}
done && done();
};
async startService() {
if (!this.theRouter) {
this.theRouter = router(this.server.PeeringService, this.server.dal);
}
this.theRouter.setActive(true);
this.theRouter.setConfDAL(this.server.dal);
/**
* Enable routing features:
* - The server will try to send documents to the network
* - The server will eventually be notified of network failures
*/
// The router asks for multicasting of documents
this
.pipe(this.theRouter)
// The documents get sent to peers
.pipe(this.theMulticaster)
// The multicaster may answer 'unreachable peer'
.pipe(this.theRouter);
}
async stopService() {
this.unpipe();
this.theRouter && this.theRouter.unpipe();
this.theMulticaster && this.theMulticaster.unpipe();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment