-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:MTKruto/server
- Loading branch information
Showing
17 changed files
with
483 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* MTKruto Server | ||
* Copyright (C) 2024 Roj <https://roj.im/> | ||
* | ||
* This file is part of MTKruto Server. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { functions } from "mtkruto/mod.ts"; | ||
import { ALLOWED_METHODS } from "../allowed_methods.ts"; | ||
import { isFunctionDisallowed } from "../disallowed_functions.ts"; | ||
|
||
Deno.bench("isFunctionDisallowed(ping)", () => { | ||
isFunctionDisallowed(new functions.ping({ ping_id: 0n })); | ||
}); | ||
|
||
Deno.bench("isFunctionDisallowed(Allowed Method)", () => { | ||
isFunctionDisallowed(ALLOWED_METHODS[0]); | ||
}); | ||
|
||
Deno.bench("isFunctionDisallowed(MTProto Function)", () => { | ||
isFunctionDisallowed( | ||
new functions.req_DH_params({ | ||
nonce: 0n, | ||
encrypted_data: new Uint8Array(), | ||
p: new Uint8Array(), | ||
q: new Uint8Array(), | ||
public_key_fingerprint: 0n, | ||
server_nonce: 0n, | ||
}), | ||
); | ||
}); | ||
|
||
Deno.bench("isFunctionDisallowed(ALLOWED_METHODS)", () => { | ||
ALLOWED_METHODS.map(isFunctionDisallowed); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* MTKruto Server | ||
* Copyright (C) 2024 Roj <https://roj.im/> | ||
* | ||
* This file is part of MTKruto Server. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { parseFormDataParams, parseGetParams } from "../params.ts"; | ||
|
||
const formData = new FormData(); | ||
const params = new URLSearchParams(); | ||
|
||
const args = [ | ||
JSON.stringify(1), | ||
"MTKruto", | ||
false, | ||
null, | ||
[1, 2, 3, 4, 5, "", null, false], | ||
{ _: [1, 2, 3, 4, 5, "", null, false] }, | ||
]; | ||
const kwargs = [ | ||
["a", "b"], | ||
["c", "d"], | ||
]; | ||
for (let i = 0; i < 2; ++i) { | ||
for (const arg of args.map((v) => JSON.stringify(v))) { | ||
params.set(arg, ""); | ||
formData.append("_", arg); | ||
} | ||
for (const [k, v] of kwargs) { | ||
params.set(k, JSON.stringify(v)); | ||
} | ||
} | ||
formData.append("_", new Blob([new Uint8Array(1024)])); | ||
formData.append("_", JSON.stringify(Object.fromEntries(kwargs))); | ||
|
||
Deno.bench("parseFormDataParams", () => { | ||
parseFormDataParams(formData); | ||
}); | ||
|
||
Deno.bench("parseGetParams", () => { | ||
parseGetParams(params); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* MTKruto Server | ||
* Copyright (C) 2024 Roj <https://roj.im/> | ||
* | ||
* This file is part of MTKruto Server. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { assertArgCount } from "../responses.ts"; | ||
|
||
Deno.bench("assertArgCount(2, 2)", () => { | ||
assertArgCount(2, 2); | ||
}); | ||
|
||
Deno.bench("assertArgCount(1, 2)", () => { | ||
try { | ||
assertArgCount(1, 2); | ||
} catch { | ||
// | ||
} | ||
}); | ||
|
||
Deno.bench("assertArgCount(0, 1)", () => { | ||
try { | ||
assertArgCount(0, 1); | ||
} catch { | ||
// | ||
} | ||
}); | ||
|
||
Deno.bench("assertArgCount(1, 0)", () => { | ||
try { | ||
assertArgCount(1, 0); | ||
} catch { | ||
// | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* MTKruto Server | ||
* Copyright (C) 2024 Roj <https://roj.im/> | ||
* | ||
* This file is part of MTKruto Server. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { transform } from "../transform.ts"; | ||
|
||
const date = new Date(); | ||
const object = { _: { _: { _: date, a: [date, date] } } }; | ||
|
||
Deno.bench("transform", () => { | ||
transform(object); | ||
}); | ||
|
||
Deno.bench("JSON.stringify(transform)", () => { | ||
JSON.stringify(transform(object)); | ||
}); | ||
|
||
Deno.bench("JSON.parse(JSON.stringify(transform))", () => { | ||
JSON.parse(JSON.stringify(transform(object))); | ||
}); | ||
|
||
Deno.bench("transform(JSON.parse(JSON.stringify(transform)))", () => { | ||
transform(JSON.parse(JSON.stringify(transform(object)))); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.