Skip to content

Commit

Permalink
fix datex fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
benStre committed Nov 8, 2023
1 parent 2f5d37c commit fe387da
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 3 additions & 1 deletion network/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";



Expand All @@ -38,7 +39,7 @@ export interface ComInterface {


/** common class for all client interfaces (WebSockets, TCP Sockets, GET Requests, ...)*/
export abstract class CommonInterface<Args extends unknown[] = []> implements ComInterface {
export abstract class CommonInterface<Args extends T[] = []> implements ComInterface {

// endpoint interface mapping
protected static endpoint_connection_points = new Map<Target, Set<ComInterface>>();
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion network/supranet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
17 changes: 11 additions & 6 deletions runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -1043,6 +1045,9 @@ export class Runtime {
datex = Compiler.setHeaderTTL(datex, ttl);

let [dxb_header] = <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);
}

Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions utils/blobify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit fe387da

Please sign in to comment.