IPPressure

This commit is contained in:
Abdussamed ULUTAŞ 2023-01-01 18:57:03 +03:00
parent d50f9250e8
commit e93871ed81
5 changed files with 252 additions and 2 deletions

View File

@ -19,6 +19,9 @@ exports.http = server;
app.get("/script",(request, response)=>{
response.sendFile(resolve("./script/index.js"))
});
app.get("/index.js.map",(request, response)=>{
response.sendFile(resolve("./script/index.js.map"))
});
app.get("*",(request, response)=>{
response.sendFile(resolve("./script/status.xml"))
});

View File

@ -178,6 +178,12 @@ addService(({
switch(type)
{
case "alloc/APIPAddress":{
if(client.APIPAddress) {
end({
status : "sucess",
ip : client.APIPAddress
})
};
let value = APIPAddress.lock(client);
end({
status : "sucess",
@ -186,6 +192,12 @@ addService(({
break;
}
case "alloc/APNumber":{
if(client.APNumber) {
end({
status : "sucess",
number : client.APNumber
})
};
let value = APNumber.lock(client);
end({
status : "sucess",
@ -194,6 +206,12 @@ addService(({
break;
}
case "alloc/APShortCode":{
if(client.APShortCode) {
end({
status : "sucess",
code : client.APShortCode
})
};
let value = APShortCode.lock(client);
end({
status : "sucess",
@ -202,6 +220,11 @@ addService(({
break;
}
case "realloc/APIPAddress":{
if(client.APIPAddress == 0){
return end({
status : "fail"
})
}
APIPAddress.release(client.APIPAddress);
let value = APIPAddress.lock(client);
end({
@ -211,6 +234,11 @@ addService(({
break;
}
case "realloc/APNumber":{
if(client.APNumber == 0){
return end({
status : "fail"
})
}
APNumber.release(client.APNumber);
let value = APNumber.lock(client);
end({
@ -220,6 +248,11 @@ addService(({
break;
}
case "realloc/APShortCode":{
if(client.APShortCode == 0){
return end({
status : "fail"
})
}
APShortCode.release(client.APShortCode);
let value = APShortCode.lock(client);
end({
@ -257,6 +290,10 @@ addService(({
status : "sucess",
socket : socketId
})
}else{
end({
status : "fail"
})
}
break;
}
@ -268,6 +305,10 @@ addService(({
status : "sucess",
socket : socketId
})
}else{
end({
status : "fail"
})
}
break;
}
@ -279,6 +320,10 @@ addService(({
status : "sucess",
socket : socketId
})
}else{
end({
status : "fail"
})
}
break;
}

View File

@ -4,4 +4,5 @@ require("./WebSocket.js");
require("./Services/YourID.js");
require("./Services/Auth.js");
require("./Services/Room.js");
require("./Services/DataTransfer.js");
require("./Services/DataTransfer.js");
require("./Services/IPPressure.js");

198
frontend/IPPressure.ts Normal file
View File

@ -0,0 +1,198 @@
import MWSE from "frontend";
export class IPPressure
{
public mwse : MWSE;
public APNumber? : number;
public APShortCode? : string;
public APIPAddress? : string;
constructor(mwse : MWSE){
this.mwse = mwse;
};
public async allocAPIPAddress()
{
let {status,ip} = await this.mwse.EventPooling.request({
type: 'alloc/APIPAddress'
}) as {
status:"fail"|"success",
ip?:string
};
if(status == 'success')
{
this.APIPAddress = ip;
return ip;
}else{
throw new Error("Error Allocated Access Point IP Address");
}
}
public async allocAPNumber()
{
let {status,number} = await this.mwse.EventPooling.request({
type: 'alloc/APNumber'
}) as {
status:"fail"|"success",
number?:number
};
if(status == 'success')
{
this.APNumber = number;
return number;
}else{
throw new Error("Error Allocated Access Point Number");
}
}
public async allocAPShortCode()
{
let {status,code} = await this.mwse.EventPooling.request({
type: 'alloc/APShortCode'
}) as {
status:"fail"|"success",
code?:string
};
if(status == 'success')
{
this.APShortCode = code;
return code;
}else{
throw new Error("Error Allocated Access Point Short Code");
}
}
public async reallocAPIPAddress()
{
let {status,ip} = await this.mwse.EventPooling.request({
type: 'realloc/APIPAddress'
}) as {
status:"fail"|"success",
ip?:string
};
if(status == 'success')
{
this.APIPAddress = ip;
return ip;
}else{
throw new Error("Error Reallocated Access Point IP Address");
}
}
public async reallocAPNumber()
{
let {status,number} = await this.mwse.EventPooling.request({
type: 'realloc/APNumber'
}) as {
status:"fail"|"success",
number?:number
};
if(status == 'success')
{
this.APNumber = number;
return number;
}else{
throw new Error("Error Reallocated Access Point Number");
}
}
public async reallocAPShortCode()
{
let {status,code} = await this.mwse.EventPooling.request({
type: 'realloc/APShortCode'
}) as {
status:"fail"|"success",
code?:string
};
if(status == 'success')
{
this.APShortCode = code;
return code;
}else{
throw new Error("Error Reallocated Access Point Short Code");
}
}
public async releaseAPIPAddress()
{
let {status} = await this.mwse.EventPooling.request({
type: 'release/APIPAddress'
}) as {
status:"fail"|"success",
};
if(status == 'success')
{
this.APIPAddress = undefined;
}else{
throw new Error("Error release Access Point IP Address");
}
}
public async releaseAPNumber()
{
let {status} = await this.mwse.EventPooling.request({
type: 'release/APNumber'
}) as {
status:"fail"|"success",
};
if(status == 'success')
{
this.APNumber = undefined;
}else{
throw new Error("Error release Access Point Number");
}
}
public async releaseAPShortCode()
{
let {status} = await this.mwse.EventPooling.request({
type: 'release/APShortCode'
}) as {
status:string
};
if(status == 'success')
{
this.APShortCode = undefined;
}else{
throw new Error("Error release Access Point Short Code");
}
}
public async queryAPIPAddress(ip:string)
{
let {status,socket} = await this.mwse.EventPooling.request({
type: 'alloc/APIPAddress',
whois: ip
}) as {
status:"fail"|"success",
socket?:string
};
if(status == "success")
{
return socket;
}else{
return null;
}
}
public async queryAPNumber(number:number)
{
let {status,socket} = await this.mwse.EventPooling.request({
type: 'alloc/APNumber',
whois: number
}) as {
status:"fail"|"success",
socket?:string
};
if(status == "success")
{
return socket;
}else{
return null;
}
}
public async queryAPShortCode(code:string)
{
let {status,socket} = await this.mwse.EventPooling.request({
type: 'alloc/APShortCode',
whois: code
}) as {
status:"fail"|"success",
socket?:string
};
if(status == "success")
{
return socket;
}else{
return null;
}
}
}

View File

@ -1,6 +1,7 @@
import {Connection,IConnection} from "./Connection";
import EventPool from "./EventPool";
import EventTarget from "./EventTarget";
import { IPPressure } from "./IPPressure";
import Peer from "./Peer";
import Room, { IRoomOptions } from "./Room";
import WSTSProtocol, { Message } from "./WSTSProtocol";
@ -11,13 +12,15 @@ export default class MWSE extends EventTarget {
public rooms : Map<string, Room> = new Map();
public pairs : Map<string, Peer> = new Map();
public peers : Map<string, Peer> = new Map();
public virtualPressure : IPPressure;
public me! : Peer;
constructor(options: IConnection){
super();
this.server = new Connection(options);
this.server.connect();
this.WSTSProtocol = new WSTSProtocol(this);
this.EventPooling = new EventPool(this);
this.virtualPressure = new IPPressure(this);
this.server.connect();
this.me = new Peer(this);
this.me.scope(()=>{
this.peers.set('me', this.me);