0
0
mirror of https://github.com/cjdelisle/cjdns synced 2025-10-06 00:32:50 +02:00

Remove js build related unused / unnecessary code

This commit is contained in:
Caleb James DeLisle
2024-09-11 11:14:10 +00:00
parent f5955fff9f
commit b5f6d4da85
15 changed files with 32 additions and 292 deletions

View File

@@ -21,7 +21,6 @@
#include "exception/Except.h"
#include "memory/Allocator.h"
#include "util/log/Log.h"
#include "util/UniqueName.h"
#include "util/events/EventBase.h"
#include "util/Linker.h"
Linker_require("admin/Admin.c")
@@ -76,6 +75,4 @@ struct Admin* Admin_new(AddrIface_t* ai,
struct Log* logger,
EventBase_t* eventBase,
String* password);
#else
#include "util/UniqueName.h"
#endif

View File

@@ -300,9 +300,11 @@ static Iface_DEFUN afterDecrypt(Message_t* msg, struct Iface* iface)
}
#define PRIVATEKEY_A \
Constant_stringForHex("53ff22b2eb94ce8c5f1852c0f557eb901f067e5273d541e0a21e143c20dff9da")
"\x53\xff\x22\xb2\xeb\x94\xce\x8c\x5f\x18\x52\xc0\xf5\x57\xeb\x90\x1f\x06\x7e\x52\x73\xd5\x41\xe0\xa2\x1e\x14\x3c\x20\xdf\xf9\xda"
// "53ff22b2eb94ce8c5f1852c0f557eb901f067e5273d541e0a21e143c20dff9da"
#define PRIVATEKEY_B \
Constant_stringForHex("b71c4f43e3d4b1879b5065d44a1cb43eaf07ddba96de6a72ca761c4ef4bd2988")
"\xb7\x1c\x4f\x43\xe3\xd4\xb1\x87\x9b\x50\x65\xd4\x4a\x1c\xb4\x3e\xaf\x07\xdd\xba\x96\xde\x6a\x72\xca\x76\x1c\x4e\xf4\xbd\x29\x88"
// "b71c4f43e3d4b1879b5065d44a1cb43eaf07ddba96de6a72ca761c4ef4bd2988"
void* CryptoAuthFuzz_init(struct Allocator* alloc, struct Random* rand, enum TestCa_Config cfg)
{

View File

@@ -28,15 +28,20 @@
#include "crypto/random/test/DeterminentRandomSeed.h"
#include "util/CString.h"
// console.log(x.replace(/[0-9a-f]{2}/g, (x)=>'\\x'+x))
#define PRIVATEKEY_A \
Constant_stringForHex("53ff22b2eb94ce8c5f1852c0f557eb901f067e5273d541e0a21e143c20dff9da")
"\x53\xff\x22\xb2\xeb\x94\xce\x8c\x5f\x18\x52\xc0\xf5\x57\xeb\x90\x1f\x06\x7e\x52\x73\xd5\x41\xe0\xa2\x1e\x14\x3c\x20\xdf\xf9\xda"
// "53ff22b2eb94ce8c5f1852c0f557eb901f067e5273d541e0a21e143c20dff9da"
#define PUBLICKEY_A \
Constant_stringForHex("e3ff75af6e4414494df22f200ffeaa56e7976d991d33cc87f52427e27f83235d")
"\xe3\xff\x75\xaf\x6e\x44\x14\x49\x4d\xf2\x2f\x20\x0f\xfe\xaa\x56\xe7\x97\x6d\x99\x1d\x33\xcc\x87\xf5\x24\x27\xe2\x7f\x83\x23\x5d"
// "e3ff75af6e4414494df22f200ffeaa56e7976d991d33cc87f52427e27f83235d"
#define PRIVATEKEY_B \
Constant_stringForHex("b71c4f43e3d4b1879b5065d44a1cb43eaf07ddba96de6a72ca761c4ef4bd2988")
"\xb7\x1c\x4f\x43\xe3\xd4\xb1\x87\x9b\x50\x65\xd4\x4a\x1c\xb4\x3e\xaf\x07\xdd\xba\x96\xde\x6a\x72\xca\x76\x1c\x4e\xf4\xbd\x29\x88"
// "b71c4f43e3d4b1879b5065d44a1cb43eaf07ddba96de6a72ca761c4ef4bd2988"
#define PUBLICKEY_B \
Constant_stringForHex("27c303cdc1f96e4b28d51c75130aff6cad52098f2d752615b7b6509ed6a89477")
"\x27\xc3\x03\xcd\xc1\xf9\x6e\x4b\x28\xd5\x1c\x75\x13\x0a\xff\x6c\xad\x52\x09\x8f\x2d\x75\x26\x15\xb7\xb6\x50\x9e\xd6\xa8\x94\x77"
// "27c303cdc1f96e4b28d51c75130aff6cad52098f2d752615b7b6509ed6a89477"
#define USEROBJ "This represents a user"

View File

@@ -21,6 +21,8 @@ const nThen = require('nthen');
const Crypto = require('crypto');
const Saferphore = require('saferphore');
var seed = process.env.SOURCE_DATE_EPOCH || Crypto.randomBytes(32).toString('hex');
/*::
export type Builder_File_t = {|
includes: string[],
@@ -438,6 +440,12 @@ const getExeFile = function (ctx, exe /*:Builder_CompileJob_t*/) {
return outputFile;
};
var randomHex = function (bytes, fileName) {
var material = new Crypto.Hash('sha512').update(seed).update(fileName).digest();
if (bytes > 64) { throw new Error("meh, randomHex of over 64 bytes is unimplemented"); }
return material.slice(0, bytes).toString('hex');
};
const getFlags = function (ctx, cFile, includeDirs) {
const flags = [];
if (cFile.indexOf('node_build/dependencies/libuv') > -1) {
@@ -451,6 +459,7 @@ const getFlags = function (ctx, cFile, includeDirs) {
flags.push.apply(flags, ctx.config.cflags);
}
flags.push.apply(flags, ctx.builder.fileCflags[cFile] || []);
flags.push('-DCJDNS_RAND_U64_PER_FILE=0x' + randomHex(8, cFile) + 'ull');
if (includeDirs) {
for (let i = 0; i < ctx.config.includeDirs.length; i++) {
if (flags[flags.indexOf(ctx.config.includeDirs[i])-1] === '-I') {

View File

@@ -14,7 +14,6 @@
*/
#include "switch/LabelSplicer.h"
#include "util/Endian.h"
#include "util/Constant.h"
#include "util/Assert.h"
#include <stdio.h>
@@ -27,9 +26,9 @@ static void unsplice()
static void splice()
{
uint64_t goHere = Constant_base2(000000100);
uint64_t viaHere = Constant_base2(000000100);
uint64_t expected = Constant_base2(000010000);
uint64_t goHere = 0x04; // 000000100
uint64_t viaHere = 0x04; // 000000100
uint64_t expected = 0x10; // 000010000
uint64_t out = LabelSplicer_splice(goHere, viaHere);
@@ -41,8 +40,10 @@ static void splice()
static void routesThrough()
{
uint64_t dst = Constant_base2(0000000000000000100100000000101011101010100101011100101001010101);
uint64_t mid = Constant_base2(0000000000000000000000010110010100100110001110011100011001010101);
// 0000000000000000100100000000101011101010100101011100101001010101
uint64_t dst = 0x0000900aea95ca55;
// 0000000000000000000000010110010100100110001110011100011001010101
uint64_t mid = 0x000001652639c655;
Assert_true(!LabelSplicer_routesThrough(dst, mid));
Assert_true(LabelSplicer_routesThrough(dst, 1));
}

View File

@@ -1,37 +0,0 @@
/* vim: set expandtab ts=4 sw=4: */
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef Constant_H
#define Constant_H
#include "util/Js.h"
Js({ this.Constant_JS = require("../util/Constant.js"); })
#define Constant_stringForHex(hex) Js_or({ return this.Constant_JS.stringForHex( hex ) }, "")
#define Constant_base2(num) Js_or({ return this.Constant_JS.base2( #num ); }, 0xffffffff)
#define Constant_rand64() \
Js_or({ return this.Constant_JS.rand64(this, js.currentFile); }, 0x12345678abcdefull)
#define Constant_rand32() \
Js_or({ return this.Constant_JS.rand32(this, js.currentFile); }, 0x12345678u)
#define Constant_randHexString(len) \
Js_or({ return this.Constant_JS.randHexString(#len, this, js.currentFile); }, "")
#define Constant_log2(num) Js_or({ return this.Constant_JS.log2(num); }, 0)
#endif

View File

@@ -1,113 +0,0 @@
/* vim: set expandtab ts=4 sw=4: */
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
'use strict';
var Crypto = require('crypto');
var seed = process.env.SOURCE_DATE_EPOCH || Crypto.randomBytes(32).toString('hex');
if (process.env.SOURCE_DATE_EPOCH) { console.log('\n\n\nYES\n\n\n');}
var TABLE = {
'0000': '0',
'0001': '1',
'0010': '2',
'0011': '3',
'0100': '4',
'0101': '5',
'0110': '6',
'0111': '7',
'1000': '8',
'1001': '9',
'1010': 'a',
'1011': 'b',
'1100': 'c',
'1101': 'd',
'1110': 'e',
'1111': 'f'
};
var base2ToHex = function (numStr) {
while ((numStr.length / 4) % 1) { numStr = '0' + numStr; }
var out = [];
for (var i = 0; i < numStr.length; i += 4) {
out.push(TABLE[numStr.substring(i, i+4)]);
}
return out.join('');
};
var testBase2 = function () {
for (var i = 0; i < 10000; i++) {
var num = Math.random() * 4294967296;
var b2 = num.toString(2);
var numB = Number('0x' + base2ToHex(b2));
if (num !== numB) { throw new Error(num + " --> " + b2 + " --> " + numB); }
}
};
var base2 = module.exports.base2 = function (numStr) {
var type = "uint8_t";
if (numStr.length > 8) { type = "uint16_t"; }
if (numStr.length > 16) { type = "uint32_t"; }
if (numStr.length > 32) { type = "uint64_t"; }
if (numStr.length > 64) { throw new Error("cannot have more than 64 bits"); }
return '((' + type + ') 0x' + base2ToHex(numStr) + ((type === 'uint64_t') ? 'ull' : 'ul') + ')';
};
var randomHex = function (bytes, self, fileName) {
var nonce = self.Constant_JS_nonce = (self.Constant_JS_nonce || 0) + 1;
var material = new Crypto.Hash('sha512').update(seed).update(fileName).update(String(nonce)).digest();
if (bytes > 64) { throw new Error("meh, randomHex of over 64 bytes is unimplemented"); }
return material.slice(0, bytes).toString('hex');
};
var rand64 = module.exports.rand64 = function (self, fileName) {
return '((uint64_t) 0x' + randomHex(64 / 8, self, fileName) + 'ull)';
};
var rand32 = module.exports.rand32 = function (self, fileName) {
return '((uint32_t) 0x' + randomHex(32 / 8, self, fileName) + 'ul)';
};
var randHexString = module.exports.randHexString = function (lenStr, self, fileName) {
return '"' + randomHex(lenStr / 2, self, fileName) + '"';
};
var log2 = module.exports.log2 = function (val) {
var x = 1;
for (var i = 0; i < 31; i++) {
if (x === val) {
if ((1 << i) !== val) { throw new Error(); }
return i;
}
x = x + x;
}
throw new Error("not an even power of 2");
};
var stringForHex = module.exports.stringForHex = function (hex) {
var out = [];
for (var i = 0; i < hex.length; i+=2) {
out.push(hex[i] + hex[i+1]);
}
if (out.length < 2) { throw new Error(); }
return '"\\x' + out.join('\\x') + '"';
};
if (!module.parent) {
console.log("testing " + __filename);
testBase2();
}

View File

@@ -16,16 +16,12 @@
#define Identity_H
#include "util/Assert.h"
#include "util/Constant.h"
#include "util/Js.h"
#include <stdint.h>
#if defined(Identity_CHECK)
Js({ this.Identity_hash = "0x" + Constant_randHexString(16) + "ull"; })
#define Identity_MAGIC ((uintptr_t) Js_or({ return this.Identity_hash }, 1))
#define Identity_MAGIC CJDNS_RAND_U64_PER_FILE
/** This goes in each structure which will be checked. */
#define Identity uintptr_t Identity_verifier;

View File

@@ -15,7 +15,6 @@
#ifndef Kbps_H
#define Kbps_H
#include "util/Constant.h"
#include "util/Js.h"
// Must be multiples of 2
@@ -24,8 +23,8 @@
// Must be a multiple of 1024 (1 second)
#define Kbps_TIMESPAN 1024
#define Kbps_WINDOW_SH Constant_log2(Kbps_WINDOW_SIZE)
#define Kbps_TIMESPAN_SH Constant_log2(Kbps_TIMESPAN)
#define Kbps_WINDOW_SH 3 // log2(Kbps_WINDOW_SIZE)
#define Kbps_TIMESPAN_SH 10 // log2(Kbps_TIMESPAN)
struct Kbps
{

View File

@@ -1,27 +0,0 @@
/* vim: set expandtab ts=4 sw=4: */
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef UniqueName_H
#define UniqueName_H
#include "util/Constant.h"
#include "util/Js.h"
#define UniqueName_get() Js_or({ \
return this.UniqueName_last = 'UniqueName_' + Constant_randHexString(20); \
}, UniqueName)
#define UniqueName_last() Js_or({ return this.UniqueName_last; }, UniqueName)
#endif

View File

@@ -15,9 +15,6 @@
#include "util/events/EventBase.h"
#include "rust/cjdns_sys/Rffi.h"
#include "memory/Allocator.h"
#include "util/Assert.h"
#include "util/Identity.h"
#include "util/Js.h"
EventBase_t* EventBase_new(struct Allocator* allocator)
{

View File

@@ -1,36 +0,0 @@
/* vim: set expandtab ts=4 sw=4: */
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef UvWrapper_H
#define UvWrapper_H
#include "util/Js.h"
#ifndef _GNU_SOURCE
#define _GNU_SOURCE // CHECKFILES_IGNORE libuv's fault
#endif
#ifdef win32
#define _WIN32_WINNT 0x0600 // CHECKFILES_IGNORE
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
#include <uv.h>
#ifdef win32
#pragma GCC diagnostic pop
#endif
#endif

View File

@@ -1,28 +0,0 @@
/* vim: set expandtab ts=4 sw=4: */
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "util/test/UniqueName_test.h"
#include "util/test/UniqueName_test.h"
#include "util/test/UniqueName_test.h"
#include "util/test/UniqueName_test.h"
#include "util/test/UniqueName_test.h"
#include "util/test/UniqueName_test.h"
#include "util/test/UniqueName_test.h"
#include "util/test/UniqueName_test.h"
// This will cause a compile time failure if anything.
int main()
{
return 0;
}

View File

@@ -1,24 +0,0 @@
/* vim: set expandtab ts=4 sw=4: */
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef UniqueName_test_H
#define UniqueName_test_H
#endif
#include "util/UniqueName.h"
struct UniqueName_get()
{
char x;
};

View File

@@ -13,7 +13,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "wire/Message.h"
#include "util/UniqueName.h"
Message_t* Message_new(uint32_t messageLength,
uint32_t amountOfPadding,