node/dlpa/lib/dlpa.js
function Client(config) {
        RED.nodes.createNode(this, config);

        const port = String(Math.floor(Math.random() * (40000 - 30000 + 1)) + 30000);

        // Start a DLPA-Node server.
        // Options:
        //   --listen LISTEN    Listening port.
        //   --host HOST        Address of the DLPA server to be connected.
        //   --port PORT        Port number of the DLPA server to be connected.
        //   --id CLIENT_ID     Client ID
        //   --epsilon EPSILON  Epsilon used in the Laplace distribution to add noises.
        const proc = spawn("python3", [
            "-m", "dlpanode.server",
            "--listen", port,
            "--host", config.host,
            "--port", config.port,
            "--id", config.client_id,
            "--epsilon", config.epsilon
        ], {
            "cwd": __dirname,
            stdio: ["pipe", process.stdout, "pipe"]
        });
        let exited = false;
        proc.on("exit", (code, signal) => {
            this.log(`DLPA-Node server is closed: ${signal}`);
            exited = true;
        })
        const logger = readline.createInterface({
            input: proc.stderr,
        });
        logger.on("line", (line) => {
            this.log(line)
        })

        const client = new dlpanode.DLPAClient(
            `localhost:${port}`, grpc.credentials.createInsecure());

        this.on("input", (msg) => {

            // Send a message to the server.
            client.encryptNoisySum({
                values: flatten(msg.payload).map(v => Math.round((v + MAG) * MAG))
            }, (err, response) => {
                if (err) {
                    this.error(err);
                }
            });

        });

        // Stop the server.
        this.on("close", (done) => {
            if (exited) {
                done();
                return;
            }

            // Wait the server is closed.
            proc.on("exit", () => {
                done();
            });

            // Send a signal.
            this.log("DLPA-Node server is closing");
            proc.stdin.close();
            proc.stdout.close();
            logger.close();
            proc.kill();

        });

    }
function Client(config) {
        RED.nodes.createNode(this, config);

        const port = String(Math.floor(Math.random() * (40000 - 30000 + 1)) + 30000);

        // Start a DLPA-Node server.
        // Options:
        //   --listen LISTEN    Listening port.
        //   --host HOST        Address of the DLPA server to be connected.
        //   --port PORT        Port number of the DLPA server to be connected.
        //   --id CLIENT_ID     Client ID
        //   --epsilon EPSILON  Epsilon used in the Laplace distribution to add noises.
        const proc = spawn("python3", [
            "-m", "dlpanode.server",
            "--listen", port,
            "--host", config.host,
            "--port", config.port,
            "--id", config.client_id,
            "--epsilon", config.epsilon
        ], {
            "cwd": __dirname,
            stdio: ["pipe", process.stdout, "pipe"]
        });
        let exited = false;
        proc.on("exit", (code, signal) => {
            this.log(`DLPA-Node server is closed: ${signal}`);
            exited = true;
        })
        const logger = readline.createInterface({
            input: proc.stderr,
        });
        logger.on("line", (line) => {
            this.log(line)
        })

        const client = new dlpanode.DLPAClient(
            `localhost:${port}`, grpc.credentials.createInsecure());

        this.on("input", (msg) => {

            // Send a message to the server.
            client.encryptNoisySum({
                values: flatten(msg.payload).map(v => Math.round((v + MAG) * MAG))
            }, (err, response) => {
                if (err) {
                    this.error(err);
                }
            });

        });

        // Stop the server.
        this.on("close", (done) => {
            if (exited) {
                done();
                return;
            }

            // Wait the server is closed.
            proc.on("exit", () => {
                done();
            });

            // Send a signal.
            this.log("DLPA-Node server is closing");
            proc.stdin.close();
            proc.stdout.close();
            logger.close();
            proc.kill();

        });

    }
function Client ( config ) { RED . nodes . createNode ( this , config ) ; const port = String ( Math . floor ( Math . random ( ) * ( 40000 - 30000 + 1 ) ) + 30000 ) ; // Start a DLPA-Node server. // Options: //   --listen LISTEN    Listening port. //   --host HOST        Address of the DLPA server to be connected. //   --port PORT        Port number of the DLPA server to be connected. //   --id CLIENT_ID     Client ID //   --epsilon EPSILON  Epsilon used in the Laplace distribution to add noises. const proc = spawn ( "python3" , [ "-m" , "dlpanode.server" , "--listen" , port , "--host" , config . host , "--port" , config . port , "--id" , config . client_id , "--epsilon" , config . epsilon ] , { "cwd" : __dirname , stdio : [ "pipe" , process . stdout , "pipe" ] } ) ; let exited = false ; proc . on ( "exit" , ( code , signal ) => { this . log ( ` ${ signal } ` ) ; exited = true ; } ) const logger = readline . createInterface ( { input : proc . stderr , } ) ; logger . on ( "line" , ( line ) => { this . log ( line ) } ) const client = new dlpanode . DLPAClient ( ` ${ port } ` , grpc . credentials . createInsecure ( ) ) ; this . on ( "input" , ( msg ) => { // Send a message to the server. client . encryptNoisySum ( { values : flatten ( msg . payload ) . map ( v => Math . round ( ( v + MAG ) * MAG ) ) } , ( err , response ) => { if ( err ) { this . error ( err ) ; } } ) ; } ) ; // Stop the server. this . on ( "close" , ( done ) => { if ( exited ) { done ( ) ; return ; } // Wait the server is closed. proc . on ( "exit" , ( ) => { done ( ) ; } ) ; // Send a signal. this . log ( "DLPA-Node server is closing" ) ; proc . stdin . close ( ) ; proc . stdout . close ( ) ; logger . close ( ) ; proc . kill ( ) ; } ) ; }
DLPA Client Node.
DLPA Client Node .