Skip to content

Commit

Permalink
Urgent fix: create new doc issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zjkmxy committed Feb 8, 2024
1 parent 1740707 commit a581c2b
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 44 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ucla-irl/ndnts-aux",
"version": "1.0.11",
"version": "1.0.12",
"description": "NDNts Auxiliary Package for Web and Deno",
"scripts": {
"test": "deno test --no-check",
Expand All @@ -20,7 +20,7 @@
},
"dependencies": {
"eventemitter3": "^5.0.1",
"jose": "^5.2.0",
"jose": "^5.2.1",
"tslib": "^2.6.2",
"y-protocols": "^1.0.6",
"yjs": "^13.6.11"
Expand Down
103 changes: 81 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions src/namespace/base-node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Endpoint } from '@ndn/endpoint';
import type { Data, Interest } from '@ndn/packet';
import * as namePattern from './name-pattern.ts';
import * as schemaTree from './schema-tree.ts';
import { EventChain } from '../utils/event-chain.ts';

export interface BaseNodeEvents {
attach(path: namePattern.Pattern, endpoint: Endpoint): Promise<void>;
detach(): Promise<void>;
}

export class BaseNode {
public readonly onAttach = new EventChain<BaseNodeEvents['attach']>();
public readonly onDetach = new EventChain<BaseNodeEvents['detach']>();
protected endpoint: Endpoint | undefined = undefined;

public processInterest(
matched: schemaTree.MatchedObject<BaseNode>,
interest: Interest,
): Promise<Data | undefined> {
console.warn(`Silently drop unprocessable Interest ${matched.name}: ${interest.appParameters}`);
return Promise.resolve(undefined);
}

public async processAttach(path: namePattern.Pattern, endpoint: Endpoint) {
// All children's attach events are called
this.endpoint = endpoint;
await this.onAttach.emit(path, endpoint);
}

public async processDetach() {
await this.onDetach.emit();
this.endpoint = undefined;
// Then call children's detach
}
}
44 changes: 44 additions & 0 deletions src/namespace/expressing-point.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Endpoint, RetxPolicy } from '@ndn/endpoint';
import { Data, Interest, Name, Signer, type Verifier } from '@ndn/packet';
import * as namePattern from './name-pattern.ts';
import * as schemaTree from './schema-tree.ts';
import { BaseNode, BaseNodeEvents } from './base-node.ts';
import { EventChain } from '../utils/event-chain.ts';

export enum VerifyResult {
Fail = -1,
Unknown = 0,
Pass = 1,
Bypass = 2,
}

export interface ExpressingPointEvents extends BaseNodeEvents {
interest(target: schemaTree.StrictMatch<ExpressingPoint>): Promise<Data | undefined>;
verify(target: schemaTree.StrictMatch<ExpressingPoint>, pkt: Verifier.Verifiable): Promise<VerifyResult>;
searchStorage(target: schemaTree.StrictMatch<ExpressingPoint>): Promise<Data | undefined>;
saveStorage(target: schemaTree.StrictMatch<ExpressingPoint>): Promise<void>;
}

export type ExpressingPointOpts = {
lifetimeMs: number;
signer: Signer;
supressInterest?: boolean;
abortSignal?: AbortSignal;
modifyInterest?: Interest.Modify;
retx?: RetxPolicy;
};

export class ExpressingPoint extends BaseNode {
public readonly onInterest = new EventChain<ExpressingPointEvents['interest']>();
public readonly onVerify = new EventChain<ExpressingPointEvents['verify']>();
public readonly onSearchStorage = new EventChain<ExpressingPointEvents['searchStorage']>();
public readonly onSaveStorage = new EventChain<ExpressingPointEvents['saveStorage']>();

// public async need(matched: schemaTree.MatchedObject<ExpressingPoint>): Promise<Data | undefined> {}

// public override async processInterest(
// matched: schemaTree.MatchedObject<ExpressingPoint>,
// interest: Interest,
// ): Promise<Data | undefined> {
// }
}
Empty file added src/namespace/leaf-node.ts
Empty file.
2 changes: 1 addition & 1 deletion src/namespace/schema-tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Deno.test('schemaTree.call', () => {
name: name`/prefix/seq=${0}`,
resource: reflector,
};
const nodeId: string = schemaTree.call(matched, 'reflect', collector, 'request');
const nodeId = schemaTree.call(matched, 'reflect', collector, 'request');
assertEquals(collector, {
request: {
nodeId: 'node',
Expand Down
Loading

0 comments on commit a581c2b

Please sign in to comment.