From fe387daadf03b761238a888385a8418dc3536e50 Mon Sep 17 00:00:00 2001 From: benStre Date: Wed, 8 Nov 2023 02:41:02 +0100 Subject: [PATCH] fix datex fetch --- network/client.ts | 4 +++- network/supranet.ts | 2 +- runtime/runtime.ts | 17 +++++++++++------ utils/blobify.ts | 1 + 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/network/client.ts b/network/client.ts index 54c64ecd..f36b621d 100644 --- a/network/client.ts +++ b/network/client.ts @@ -19,6 +19,7 @@ import type { dxb_header } from "../utils/global_types.ts"; import { client_type } from "../utils/constants.ts"; import { Disjunction } from "../types/logic.ts"; import { Pointer } from "../runtime/pointers.ts"; +import { logger } from "../utils/global_values.ts"; @@ -38,7 +39,7 @@ export interface ComInterface { /** common class for all client interfaces (WebSockets, TCP Sockets, GET Requests, ...)*/ -export abstract class CommonInterface implements ComInterface { +export abstract class CommonInterface implements ComInterface { // endpoint interface mapping protected static endpoint_connection_points = new Map>(); @@ -759,6 +760,7 @@ export class InterfaceManager { } // send else { + logger.debug("sending to " + to + " (interface " + comInterface.type + " / " + comInterface.endpoint + ")"); return await comInterface.send(addressed_datex, to); // send to first available interface (todo) } diff --git a/network/supranet.ts b/network/supranet.ts index 3b07e065..7b8bcd43 100644 --- a/network/supranet.ts +++ b/network/supranet.ts @@ -276,7 +276,7 @@ export class Supranet { public static sayHello(node:Endpoint = Runtime.main_node){ // TODO REPLACE, only temporary as placeholder to inform router about own public keys const keys = Crypto.getOwnPublicKeysExported(); - Runtime.datexOut(['?', [keys], {type:ProtocolDataType.HELLO, sign:false, flood:true, __routing_ttl:1}], undefined, undefined, false, false) + Runtime.datexOut(['?', [keys], {type:ProtocolDataType.HELLO, sign:false, flood:true, __routing_ttl:10}], undefined, undefined, false, false) // send with plain endpoint id as sender // if (Runtime.endpoint.id_endpoint !== Runtime.endpoint) Runtime.datexOut(['?', [keys], {type:ProtocolDataType.HELLO, sign:false, flood:true, force_id:true, __routing_ttl:1}], undefined, undefined, false, false) } diff --git a/runtime/runtime.ts b/runtime/runtime.ts index 4f5a0d3a..78c45c2f 100644 --- a/runtime/runtime.ts +++ b/runtime/runtime.ts @@ -581,7 +581,7 @@ export class Runtime { let doFetch = true; // possible js module import: fetch headers first and check content type: - if (url_string.endsWith("js") || url_string.endsWith("ts") || url_string.endsWith("tsx") || url_string.endsWith("jsx") || url_string.endsWith("dx") || url_string.endsWith("dxb")) { + if (!raw && (url_string.endsWith("js") || url_string.endsWith("ts") || url_string.endsWith("tsx") || url_string.endsWith("jsx") || url_string.endsWith("dx") || url_string.endsWith("dxb"))) { try { response = await fetch(url, {method: 'HEAD'}); const type = response.headers.get('content-type'); @@ -963,7 +963,8 @@ export class Runtime { // flood exclude flood_exclude receiver if (flood) { - this.datex_out(dxb, flood_exclude, true, source)?.catch(e=>reject(e)); + this.datex_out(dxb, flood_exclude, true, source) + .catch(e=>reject(e)); } // send to receivers else if (to) { @@ -973,7 +974,8 @@ export class Runtime { // check offline status (async), immediately reject if offline this._handleEndpointOffline(to_endpoint, reject) // send dxb - this.datex_out(dxb, to_endpoint, undefined, source)?.catch(e=>reject(e)); + this.datex_out(dxb, to_endpoint, undefined, source) + .catch(e=>reject(e)); } } @@ -1027,7 +1029,7 @@ export class Runtime { datex = Compiler.setHeaderTTL(datex, header.routing.ttl-1); - logger.debug("redirect " + header.sid + " > " + Runtime.valueToDatexString(header.routing.receivers)); + logger.debug("redirect " + (ProtocolDataType[header.type]) + " " + header.sid + " > " + Runtime.valueToDatexString(header.routing.receivers) + ", ttl="+ (header.routing.ttl-1)); let res = await this.datexOut(datex, header.routing.receivers, header.sid, wait_for_result, undefined, undefined, undefined, undefined, undefined, source); return res; @@ -1043,6 +1045,9 @@ export class Runtime { datex = Compiler.setHeaderTTL(datex, ttl); let [dxb_header] = this.parseHeaderSynchronousPart(datex); + + logger.debug("flood " + (ProtocolDataType[dxb_header.type]) + " " + dxb_header.sid + ", ttl="+ (dxb_header.routing?.ttl)); + this.datexOut(datex, null, dxb_header.sid, false, false, null, true, exclude); } @@ -1853,13 +1858,13 @@ export class Runtime { let keys_updated = await Crypto.bindKeys(header.sender, ...<[ArrayBuffer,ArrayBuffer]>return_value); if (header.routing?.ttl) header.routing.ttl--; - logger.debug("HELLO ("+header.sid+"/" + header.inc+ "/" + header.return_index + ") from " + header.sender + ", keys "+(keys_updated?"":"not ")+"updated", header.routing?.ttl ?? 0); + logger.debug("HELLO ("+header.sid+"/" + header.inc+ "/" + header.return_index + ") from " + header.sender + ", keys "+(keys_updated?"":"not ")+"updated, ttl = " + header.routing?.ttl); } catch (e) { logger.error("Invalid HELLO keys"); } } - else logger.debug("HELLO from " + header.sender + ", no keys"); + else logger.debug("HELLO from " + header.sender + ", no keys, ttl = " + header.routing?.ttl); } else if (header.type == ProtocolDataType.DEBUGGER) { diff --git a/utils/blobify.ts b/utils/blobify.ts index af57c628..d0366bec 100644 --- a/utils/blobify.ts +++ b/utils/blobify.ts @@ -8,6 +8,7 @@ import { client_type } from "./constants.ts"; */ export async function blobifyFile(path: string|URL) { const [script] = await Datex.Runtime.getURLContent(path.toString(), true, true) as [string, string]; + console.log("script", script) return blobifyScript(script); }