Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 6d1f23a

Browse files
committed
lint
1 parent 9b1a10f commit 6d1f23a

File tree

2 files changed

+99
-101
lines changed

2 files changed

+99
-101
lines changed
Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,65 @@
1-
const cluster = require('cluster');
2-
const ldap = require('ldapjs');
3-
const net = require('net');
4-
const os = require('os');
1+
const cluster = require('cluster')
2+
const ldap = require('ldapjs')
3+
const net = require('net')
4+
const os = require('os')
55

6-
const threads = [];
6+
const threads = []
77
threads.getNext = function () {
8-
return (Math.floor(Math.random() * this.length));
9-
};
8+
return (Math.floor(Math.random() * this.length))
9+
}
1010

1111
const serverOptions = {
12-
port: 1389
13-
};
12+
port: 1389
13+
}
1414

1515
if (cluster.isMaster) {
16-
const server = net.createServer(serverOptions, (socket) => {
17-
socket.pause();
18-
console.log('ldapjs client requesting connection');
19-
let routeTo = threads.getNext();
20-
threads[routeTo].send({ type: 'connection' }, socket);
21-
});
16+
const server = net.createServer(serverOptions, (socket) => {
17+
socket.pause()
18+
console.log('ldapjs client requesting connection')
19+
const routeTo = threads.getNext()
20+
threads[routeTo].send({ type: 'connection' }, socket)
21+
})
2222

23-
for (let i = 0; i < os.cpus().length; i++) {
24-
let thread = cluster.fork({
25-
'id': i
26-
});
27-
thread.id = i;
28-
thread.on('message', function (msg) {
23+
for (let i = 0; i < os.cpus().length; i++) {
24+
const thread = cluster.fork({
25+
id: i
26+
})
27+
thread.id = i
28+
thread.on('message', function () {
2929

30-
});
31-
threads.push(thread);
32-
}
30+
})
31+
threads.push(thread)
32+
}
3333

34-
server.listen(serverOptions.port, function () {
35-
console.log('ldapjs listening at ldap://127.0.0.1:' + serverOptions.port);
36-
});
34+
server.listen(serverOptions.port, function () {
35+
console.log('ldapjs listening at ldap://127.0.0.1:' + serverOptions.port)
36+
})
3737
} else {
38-
const server = ldap.createServer(serverOptions);
38+
const server = ldap.createServer(serverOptions)
3939

40-
let threadId = process.env.id;
40+
const threadId = process.env.id
4141

42-
process.on('message', (msg, socket) => {
43-
switch (msg.type) {
44-
case 'connection':
45-
server.newConnection(socket);
46-
socket.resume();
47-
console.log('ldapjs client connection accepted on ' + threadId.toString());
48-
}
49-
});
42+
process.on('message', (msg, socket) => {
43+
switch (msg.type) {
44+
case 'connection':
45+
server.newConnection(socket)
46+
socket.resume()
47+
console.log('ldapjs client connection accepted on ' + threadId.toString())
48+
}
49+
})
5050

51-
server.search('dc=example', function (req, res, next) {
52-
console.log('ldapjs search initiated on ' + threadId.toString());
53-
var obj = {
54-
dn: req.dn.toString(),
55-
attributes: {
56-
objectclass: ['organization', 'top'],
57-
o: 'example'
58-
}
59-
};
51+
server.search('dc=example', function (req, res) {
52+
console.log('ldapjs search initiated on ' + threadId.toString())
53+
const obj = {
54+
dn: req.dn.toString(),
55+
attributes: {
56+
objectclass: ['organization', 'top'],
57+
o: 'example'
58+
}
59+
}
6060

61-
if (req.filter.matches(obj.attributes))
62-
res.send(obj);
61+
if (req.filter.matches(obj.attributes)) { res.send(obj) }
6362

64-
res.end();
65-
});
63+
res.end()
64+
})
6665
}

examples/cluster-threading.js

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,65 @@
1-
const cluster = require('cluster');
2-
const ldap = require('ldapjs');
3-
const os = require('os');
1+
const cluster = require('cluster')
2+
const ldap = require('ldapjs')
3+
const os = require('os')
44

5-
const threads = [];
5+
const threads = []
66
threads.getNext = function () {
7-
return (Math.floor(Math.random() * this.length));
8-
};
7+
return (Math.floor(Math.random() * this.length))
8+
}
99

1010
const serverOptions = {
11-
connectionRouter: (socket) => {
12-
socket.pause();
13-
console.log('ldapjs client requesting connection');
14-
let routeTo = threads.getNext();
15-
threads[routeTo].send({ type: 'connection' }, socket);
16-
}
17-
};
11+
connectionRouter: (socket) => {
12+
socket.pause()
13+
console.log('ldapjs client requesting connection')
14+
const routeTo = threads.getNext()
15+
threads[routeTo].send({ type: 'connection' }, socket)
16+
}
17+
}
1818

19-
const server = ldap.createServer(serverOptions);
19+
const server = ldap.createServer(serverOptions)
2020

2121
if (cluster.isMaster) {
22-
for (let i = 0; i < os.cpus().length; i++) {
23-
let thread = cluster.fork({
24-
'id': i
25-
});
26-
thread.id = i;
27-
thread.on('message', function (msg) {
22+
for (let i = 0; i < os.cpus().length; i++) {
23+
const thread = cluster.fork({
24+
id: i
25+
})
26+
thread.id = i
27+
thread.on('message', function () {
2828

29-
});
30-
threads.push(thread);
31-
}
29+
})
30+
threads.push(thread)
31+
}
3232

33-
server.listen(1389, function () {
34-
console.log('ldapjs listening at ' + server.url);
35-
});
33+
server.listen(1389, function () {
34+
console.log('ldapjs listening at ' + server.url)
35+
})
3636
} else {
37-
let threadId = process.env.id;
38-
serverOptions.connectionRouter = (connection) => {
39-
console.log('should not be hit');
40-
};
37+
const threadId = process.env.id
38+
serverOptions.connectionRouter = () => {
39+
console.log('should not be hit')
40+
}
4141

42-
process.on('message', (msg, socket) => {
43-
switch (msg.type) {
44-
case 'connection':
45-
server.newConnection(socket);
46-
socket.resume();
47-
console.log('ldapjs client connection accepted on ' + threadId.toString());
48-
}
49-
});
42+
process.on('message', (msg, socket) => {
43+
switch (msg.type) {
44+
case 'connection':
45+
server.newConnection(socket)
46+
socket.resume()
47+
console.log('ldapjs client connection accepted on ' + threadId.toString())
48+
}
49+
})
5050

51-
server.search('dc=example', function (req, res, next) {
52-
console.log('ldapjs search initiated on ' + threadId.toString());
53-
var obj = {
54-
dn: req.dn.toString(),
55-
attributes: {
56-
objectclass: ['organization', 'top'],
57-
o: 'example'
58-
}
59-
};
51+
server.search('dc=example', function (req, res) {
52+
console.log('ldapjs search initiated on ' + threadId.toString())
53+
const obj = {
54+
dn: req.dn.toString(),
55+
attributes: {
56+
objectclass: ['organization', 'top'],
57+
o: 'example'
58+
}
59+
}
6060

61-
if (req.filter.matches(obj.attributes))
62-
res.send(obj);
61+
if (req.filter.matches(obj.attributes)) { res.send(obj) }
6362

64-
res.end();
65-
});
63+
res.end()
64+
})
6665
}

0 commit comments

Comments
 (0)