IP Basınçlı bağlantıları optimize edildi
This commit is contained in:
parent
30d96a0093
commit
603397132d
|
@ -1,5 +1,5 @@
|
||||||
const { CLIENT_SEND_MESSAGE, CLIENT_UPDATE_PROP } = require("./IPC");
|
const { CLIENT_SEND_MESSAGE, CLIENT_UPDATE_PROP } = require("../IPC");
|
||||||
const stats = require("./stats");
|
const stats = require("../stats");
|
||||||
function Client()
|
function Client()
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const { Client } = require("../Client");
|
const { Client } = require("./Client");
|
||||||
let {addService, addListener} = require("../WebSocket.js");
|
let {addService, addListener} = require("../WebSocket.js");
|
||||||
|
|
||||||
class APNumber{
|
class APNumber{
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
const {resolve} = require("node:path");
|
||||||
|
|
||||||
exports.termoutput = false;
|
exports.termoutput = false;
|
||||||
|
|
||||||
exports.HTTP_PORT = 7707;
|
exports.HTTP_PORT = 7707;
|
||||||
|
@ -7,4 +9,7 @@ exports.HTTP_AUTH = true;
|
||||||
exports.HTTP_AUTH_USERNAME = 'saqut';
|
exports.HTTP_AUTH_USERNAME = 'saqut';
|
||||||
exports.HTTP_AUTH_USERPASSWORD = 'yum81633';
|
exports.HTTP_AUTH_USERPASSWORD = 'yum81633';
|
||||||
|
|
||||||
exports.LOADBALANCE_CPU = 2; // ---> Cpu number (2,3,4...) for load balancer process or false for single thread (no load balancer and multiprocess)
|
exports.LOADBALANCE_CPU = false; // ---> Cpu number (2,3,4...) for load balancer process or false for single thread (no load balancer and multiprocess)
|
||||||
|
|
||||||
|
exports.IPALLOCATION_DB = resolve(__dirname,"../database/ipallocation.db");
|
||||||
|
exports.IPALLOCATION_STORE_TYPE = "memory" // or file
|
|
@ -6,6 +6,7 @@ require("./Services/Auth.js");
|
||||||
require("./Services/Room.js");
|
require("./Services/Room.js");
|
||||||
require("./Services/DataTransfer.js");
|
require("./Services/DataTransfer.js");
|
||||||
require("./Services/IPPressure.js");
|
require("./Services/IPPressure.js");
|
||||||
|
require("./module/IPAllocation.js");
|
||||||
|
|
||||||
process.on('unhandledRejection',()=>{
|
process.on('unhandledRejection',()=>{
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,224 @@
|
||||||
|
const knex = require("knex");
|
||||||
|
const { IPALLOCATION_DB } = require("../config");
|
||||||
|
const crypto = require("node:crypto");
|
||||||
|
const moment = require("moment");
|
||||||
|
|
||||||
|
let IPDB = knex({
|
||||||
|
client: "sqlite3",
|
||||||
|
connection: exports.IPALLOCATION_STORE_TYPE == "memory" ? ":memory:" : IPALLOCATION_DB,
|
||||||
|
useNullAsDefault: true
|
||||||
|
});
|
||||||
|
|
||||||
|
let flovitNumber = [
|
||||||
|
[
|
||||||
|
8,
|
||||||
|
12,
|
||||||
|
24,
|
||||||
|
48,
|
||||||
|
52,
|
||||||
|
56
|
||||||
|
],
|
||||||
|
[
|
||||||
|
7,
|
||||||
|
10,
|
||||||
|
13,
|
||||||
|
16,
|
||||||
|
19,
|
||||||
|
22,
|
||||||
|
25,
|
||||||
|
28,
|
||||||
|
31,
|
||||||
|
34,
|
||||||
|
37,
|
||||||
|
40,
|
||||||
|
43,
|
||||||
|
46,
|
||||||
|
49,
|
||||||
|
52,
|
||||||
|
55,
|
||||||
|
58,
|
||||||
|
61,
|
||||||
|
64,
|
||||||
|
67,
|
||||||
|
70,
|
||||||
|
73,
|
||||||
|
76,
|
||||||
|
79,
|
||||||
|
82
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
async function read(filter)
|
||||||
|
{
|
||||||
|
return await IPDB.table("iptable").where(filter).first();
|
||||||
|
}
|
||||||
|
async function has(filter)
|
||||||
|
{
|
||||||
|
return (
|
||||||
|
await IPDB.table("iptable").where(filter).count('* as key').first()
|
||||||
|
).key != 0;
|
||||||
|
}
|
||||||
|
async function flushAll()
|
||||||
|
{
|
||||||
|
await IPDB.table("iptable").delete();
|
||||||
|
}
|
||||||
|
async function write(value,filter)
|
||||||
|
{
|
||||||
|
await IPDB.table("iptable").where(filter).update(value);
|
||||||
|
}
|
||||||
|
async function create(value)
|
||||||
|
{
|
||||||
|
await IPDB.table("iptable").insert(value);
|
||||||
|
}
|
||||||
|
async function remove(...filterArgs)
|
||||||
|
{
|
||||||
|
await IPDB.table("iptable").where(...filterArgs).delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function migrate()
|
||||||
|
{
|
||||||
|
if(!await IPDB.schema.hasTable("iptable"))
|
||||||
|
{
|
||||||
|
await IPDB.schema.createTable("iptable",function(table){
|
||||||
|
table.bigInteger("ipaddress").unsigned().primary();
|
||||||
|
table.text("owner").unique();
|
||||||
|
table.string("type", 50).defaultTo("client");
|
||||||
|
table.dateTime("created").defaultTo(IPDB.fn.now());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function iptobin(a,b,c,d)
|
||||||
|
{
|
||||||
|
const bin =
|
||||||
|
((a | 0) << 24) |
|
||||||
|
((b | 0) << 16) |
|
||||||
|
((c | 0) << 8) |
|
||||||
|
(d | 0);
|
||||||
|
return bin;
|
||||||
|
}
|
||||||
|
function bintoip(bin)
|
||||||
|
{
|
||||||
|
if(typeof bin == "string")
|
||||||
|
{
|
||||||
|
bin = bin | 0;
|
||||||
|
}
|
||||||
|
const octet1 = (bin >>> 24) & 0xff;
|
||||||
|
const octet2 = (bin >>> 16) & 0xff;
|
||||||
|
const octet3 = (bin >>> 8) & 0xff;
|
||||||
|
const octet4 = bin & 0xff;
|
||||||
|
return [octet1,octet2,octet3,octet4];
|
||||||
|
}
|
||||||
|
function randomMaskINIT()
|
||||||
|
{
|
||||||
|
if(typeof bin == "string")
|
||||||
|
{
|
||||||
|
bin = bin.split('.').map(e => e | 0);
|
||||||
|
}
|
||||||
|
let globalmask = crypto.randomInt(flovitNumber[0].length);
|
||||||
|
let macromask = crypto.randomInt(flovitNumber[1].length);
|
||||||
|
|
||||||
|
return [
|
||||||
|
flovitNumber[0][globalmask],
|
||||||
|
flovitNumber[1][macromask],
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
async function init()
|
||||||
|
{
|
||||||
|
await migrate();
|
||||||
|
await flushAll();
|
||||||
|
await create({
|
||||||
|
ipaddress: 0, // globalmask & macromask
|
||||||
|
owner: randomMaskINIT().join('.'),
|
||||||
|
type: "system",
|
||||||
|
created: moment().format()
|
||||||
|
});
|
||||||
|
hook()
|
||||||
|
}
|
||||||
|
init.inited = false;
|
||||||
|
|
||||||
|
async function getip(owner, type)
|
||||||
|
{
|
||||||
|
let call = await read({
|
||||||
|
owner,
|
||||||
|
type
|
||||||
|
});
|
||||||
|
return !call ? false : {
|
||||||
|
ipaddress: call.ipaddress,
|
||||||
|
date: call.created
|
||||||
|
};
|
||||||
|
}
|
||||||
|
async function setip(owner, type, ip)
|
||||||
|
{
|
||||||
|
await getip(owner, type) ?
|
||||||
|
await write({
|
||||||
|
ipaddress: ip
|
||||||
|
},{
|
||||||
|
owner,
|
||||||
|
type
|
||||||
|
})
|
||||||
|
:
|
||||||
|
await create({
|
||||||
|
ipaddress: ip,
|
||||||
|
owner,
|
||||||
|
type
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function allocateIP(owner, type, changeOverlord)
|
||||||
|
{
|
||||||
|
let [a,b,c,d] = [ ,,, ];
|
||||||
|
if(changeOverlord)
|
||||||
|
{
|
||||||
|
[a,b,c,d] = randomMaskINIT();
|
||||||
|
}else{
|
||||||
|
let ipinfo = await read({
|
||||||
|
ipaddress: 0,
|
||||||
|
type: "system"
|
||||||
|
});
|
||||||
|
[a,b,c,d] = ipinfo.owner.split('.').map(e => e | 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
if(d != 255)
|
||||||
|
{
|
||||||
|
d++;
|
||||||
|
}else if(c != 255){
|
||||||
|
c++;
|
||||||
|
}else if(b != 255){
|
||||||
|
b++;
|
||||||
|
}else if(a != 255){
|
||||||
|
a++;
|
||||||
|
}else{
|
||||||
|
[a,b,c,d] = randomMaskINIT();
|
||||||
|
}
|
||||||
|
let query = {
|
||||||
|
ipaddress: iptobin(a,b,c,d)
|
||||||
|
};
|
||||||
|
let result = await has(query);
|
||||||
|
if(result == false)
|
||||||
|
{
|
||||||
|
await create({
|
||||||
|
ipaddress: iptobin(a,b,c,d),
|
||||||
|
owner,
|
||||||
|
type
|
||||||
|
});
|
||||||
|
await write({
|
||||||
|
owner: [a,b,c,d].join('.')
|
||||||
|
},{
|
||||||
|
type: "system",
|
||||||
|
ipaddress: 0
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}else{
|
||||||
|
console.log("Checking",[a,b,c,d].join('.'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return[a,b,c,d].join('.')
|
||||||
|
}
|
||||||
|
|
||||||
|
process.nextTick(init);
|
Binary file not shown.
|
@ -15,6 +15,7 @@
|
||||||
"fflate": "^0.8.1",
|
"fflate": "^0.8.1",
|
||||||
"joi": "^17.11.0",
|
"joi": "^17.11.0",
|
||||||
"knex": "^3.0.1",
|
"knex": "^3.0.1",
|
||||||
|
"moment": "^2.29.4",
|
||||||
"sqlite3": "^5.1.6",
|
"sqlite3": "^5.1.6",
|
||||||
"systemjs": "^6.14.2",
|
"systemjs": "^6.14.2",
|
||||||
"terminal": "^0.1.4",
|
"terminal": "^0.1.4",
|
||||||
|
@ -2619,6 +2620,14 @@
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/moment": {
|
||||||
|
"version": "2.29.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
|
||||||
|
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==",
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/ms": {
|
"node_modules/ms": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
"fflate": "^0.8.1",
|
"fflate": "^0.8.1",
|
||||||
"joi": "^17.11.0",
|
"joi": "^17.11.0",
|
||||||
"knex": "^3.0.1",
|
"knex": "^3.0.1",
|
||||||
|
"moment": "^2.29.4",
|
||||||
"sqlite3": "^5.1.6",
|
"sqlite3": "^5.1.6",
|
||||||
"systemjs": "^6.14.2",
|
"systemjs": "^6.14.2",
|
||||||
"terminal": "^0.1.4",
|
"terminal": "^0.1.4",
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
<body>
|
<body>
|
||||||
<h2><pre id="log"></pre></h2>
|
<h2><pre id="log"></pre></h2>
|
||||||
<h1 id="message"></h1>
|
<h1 id="message"></h1>
|
||||||
<script src="http://ws.saqut.com/script"></script>
|
<script src="/script"></script>
|
||||||
<script>
|
<script>
|
||||||
async function main(){
|
async function main(){
|
||||||
const wsjs = new MWSE({
|
const wsjs = new MWSE({
|
||||||
endpoint: "ws://ws.saqut.com"
|
endpoint: "ws://localhost:7707"
|
||||||
});
|
});
|
||||||
wsjs.scope(async ()=>{
|
wsjs.scope(async ()=>{
|
||||||
let me = wsjs.peer('me');
|
let me = wsjs.peer('me');
|
||||||
|
|
Loading…
Reference in New Issue