Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
benStre committed Feb 10, 2024
2 parents a77e2f7 + b945f57 commit 8253f16
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
4 changes: 3 additions & 1 deletion network/communication-hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ export class CommunicationHubHandler {
) :
(isDirect ? ESCAPE_SEQUENCES.UNYT_RED : DARK_RED)
const connectedState = `${color}${ESCAPE_SEQUENCES.RESET}`
return ` ${connectedState} ${directionSymbol}${isDirect?'':' (indirect)'}${isDirect&&this.defaultSocket==socket?' (default)':''} ${endpoint??'unknown endpoint'}${ESCAPE_SEQUENCES.GREY} (distance:${dynamicProperties.distance}, knownSince:${((Date.now()-dynamicProperties.knownSince)/1000).toFixed(2)}s)${ESCAPE_SEQUENCES.RESET}\n`
const knownSince = (Date.now()-dynamicProperties.knownSince)/1000;
const distance = dynamicProperties.distance
return ` ${connectedState} ${directionSymbol}${isDirect?'':' (indirect)'}${isDirect&&this.defaultSocket==socket?' (default)':''} ${endpoint??'unknown endpoint'}${ESCAPE_SEQUENCES.GREY} (distance:${distance < 0 ? 'unknown' : distance}, knownSince:${knownSince < 0 ? 'unknown' : knownSince.toFixed(2)+'s'})${ESCAPE_SEQUENCES.RESET}\n`
}

// print
Expand Down
2 changes: 1 addition & 1 deletion network/communication-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export abstract class CommunicationInterfaceSocket extends EventTarget {
static defaultLogger = new Logger("CommunicationInterfaceSocket")
public logger = CommunicationInterfaceSocket.defaultLogger;

#connectTimestamp = 0
#connectTimestamp = Date.now();

get connectTimestamp() {
return this.#connectTimestamp
Expand Down
5 changes: 4 additions & 1 deletion runtime/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ export class Crypto {

// loads keys from network or cache
static requestKeys(endpoint:Endpoint):Promise<[CryptoKey?, CryptoKey?]> {

endpoint = endpoint.main;

// already requesting/loading keys for this endpoint
if (this.#waiting_key_requests.has(endpoint)) return <Promise<[CryptoKey, CryptoKey]>>this.#waiting_key_requests.get(endpoint);

Expand Down Expand Up @@ -348,7 +351,7 @@ export class Crypto {
// convert to CryptoKeys
try {
const keys:[CryptoKey, CryptoKey] = [await this.importVerifyKey(exported_keys[0])||null, await this.importEncKey(exported_keys[1])||null];
this.public_keys.set(endpoint.main, keys);
this.public_keys.set(endpoint, keys);
this.public_keys_exported.set(endpoint, exported_keys);
logger.debug("saving keys for " + endpoint);
resolve(keys);
Expand Down
8 changes: 6 additions & 2 deletions runtime/pointers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,14 +835,18 @@ export type JSValueWith$<T> = ObjectRef<T>;

// converts Object to Record<string|symbol, unknown>

export type AnyObjectRef = {$: Record<string,unknown>, $$: Record<string,unknown>}

export type WrappedPointerValue = number|string|boolean|bigint|URL|Endpoint

// convert from any JS/DATEX value to minimal representation with reference
export type MinimalJSRef<T, _C = CollapsedValue<T>> =
_C extends symbol ? symbol : (
_C extends WrappedPointerValue ?
PointerWithPrimitive<_C>: // keep pointer reference
ObjectRef<_C> // collapsed object
_C extends AnyObjectRef ?
Pointer<_C> : // pointer wrapper to keep indirect reference intact
ObjectRef<_C> // collapsed object
)

// return Pointer<T>&T for primitives (excluding boolean) and Pointer<T> otherwise
Expand Down Expand Up @@ -2790,7 +2794,7 @@ export class Pointer<T = any> extends Ref<T> {

protected get supportsIndirectRefs() {
// only supported if indirect references are not already handled by a custom transform (e.g. for UIX elements)
return Runtime.OPTIONS.INDIRECT_REFERENCES && this.type.supportsIndirectRefs
return this.type.supportsIndirectRefs
}

protected customTransformUpdate(val: T) {
Expand Down
2 changes: 1 addition & 1 deletion threads/thread-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ addEventListener("message", async function (event) {
const endpoint = Datex.Target.get(data.endpoint as any) as DatexType.Endpoint;

// TODO: Worker type?
await communicationHub.addInterface(new WorkerInterface(self as unknown as Worker, endpoint), true);
await communicationHub.addInterface(new WorkerInterface(self as unknown as Worker, endpoint));

messageTarget.postMessage({type: "INITIALIZED", remoteModule, endpoint: Datex.Runtime.endpoint.toString()});
// trust parent endpoint
Expand Down
2 changes: 1 addition & 1 deletion types/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class Type<T = any> extends ExtensibleFunction {
*/
get supportsIndirectRefs() {
// only supported if indirect references are not already handled by a custom transform (e.g. for UIX elements)
return !this.interface_config?.handle_transform
return Runtime.OPTIONS.INDIRECT_REFERENCES && !this.interface_config?.handle_transform
}

// templated type (struct)
Expand Down

0 comments on commit 8253f16

Please sign in to comment.