@peerbit/stream 5.0.17 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/index.d.ts +76 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +390 -81
- package/dist/src/index.js.map +1 -1
- package/dist/src/routes.d.ts +31 -3
- package/dist/src/routes.d.ts.map +1 -1
- package/dist/src/routes.js.map +1 -1
- package/dist/src/rust-core.d.ts +561 -0
- package/dist/src/rust-core.d.ts.map +1 -0
- package/dist/src/rust-core.js +16 -0
- package/dist/src/rust-core.js.map +1 -0
- package/package.json +5 -5
- package/src/index.ts +539 -96
- package/src/routes.ts +43 -2
- package/src/rust-core.ts +696 -0
package/src/routes.ts
CHANGED
|
@@ -6,19 +6,60 @@ const DEFAULT_MAX_FROM_ENTRIES = 2048;
|
|
|
6
6
|
const DEFAULT_MAX_TARGETS_PER_FROM = 10_000;
|
|
7
7
|
const DEFAULT_MAX_RELAYS_PER_TARGET = 32;
|
|
8
8
|
|
|
9
|
-
type RelayInfo = {
|
|
9
|
+
export type RelayInfo = {
|
|
10
10
|
session: number;
|
|
11
11
|
hash: string;
|
|
12
12
|
updatedAt: number;
|
|
13
13
|
expireAt?: number;
|
|
14
14
|
distance: number;
|
|
15
15
|
};
|
|
16
|
-
type RouteInfo = {
|
|
16
|
+
export type RouteInfo = {
|
|
17
17
|
remoteSession: number;
|
|
18
18
|
session: number;
|
|
19
19
|
list: RelayInfo[];
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* The routing-table surface DirectStream depends on. Implemented by the TS
|
|
24
|
+
* `Routes` class below and by the native (wasm) routing table from
|
|
25
|
+
* `@peerbit/network-rust` when DirectStream runs in rust-core mode.
|
|
26
|
+
*/
|
|
27
|
+
export interface RoutesLike {
|
|
28
|
+
/** Snapshot view: FROM -> TO -> route info. */
|
|
29
|
+
routes: Map<string, Map<string, RouteInfo>>;
|
|
30
|
+
routeMaxRetentionPeriod: number;
|
|
31
|
+
clear(): void;
|
|
32
|
+
add(
|
|
33
|
+
from: string,
|
|
34
|
+
neighbour: string,
|
|
35
|
+
target: string,
|
|
36
|
+
distance: number,
|
|
37
|
+
session: number,
|
|
38
|
+
remoteSession: number,
|
|
39
|
+
): "new" | "updated" | "restart";
|
|
40
|
+
remove(target: string): string[];
|
|
41
|
+
removeNeighbour(neighbour: string): void;
|
|
42
|
+
findNeighbor(from: string, target: string): RouteInfo | undefined;
|
|
43
|
+
getRouteHints(from: string, target: string): DirectStreamAckRouteHint[];
|
|
44
|
+
getBestRouteHint(
|
|
45
|
+
from: string,
|
|
46
|
+
target: string,
|
|
47
|
+
): DirectStreamAckRouteHint | undefined;
|
|
48
|
+
isReachable(from: string, target: string, maxDistance?: number): boolean;
|
|
49
|
+
hasTarget(target: string): boolean;
|
|
50
|
+
updateSession(remote: string, session?: number): boolean;
|
|
51
|
+
getSession(remote: string): number | undefined;
|
|
52
|
+
getDependent(peer: string): string[];
|
|
53
|
+
count(from?: string): number;
|
|
54
|
+
countAll(): number;
|
|
55
|
+
getFanout(
|
|
56
|
+
from: string,
|
|
57
|
+
tos: string[],
|
|
58
|
+
redundancy: number,
|
|
59
|
+
): Map<string, Map<string, { to: string; timestamp: number }>> | undefined;
|
|
60
|
+
getPrunable(neighbours: string[]): string[];
|
|
61
|
+
}
|
|
62
|
+
|
|
22
63
|
const sortRoutes = (routes: RelayInfo[]) => {
|
|
23
64
|
// sort by distance, if same distance make the routes without expire time first
|
|
24
65
|
|