-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
246 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.