@matter/general
Advanced tools
Comparing version 0.11.5-alpha.0-20241109-2e3dccaa9 to 0.11.5-alpha.0-20241112-858f60251
@@ -43,2 +43,3 @@ "use strict"; | ||
module.exports = __toCommonJS(Crypto_exports); | ||
var import_Boot = require("#util/Boot.js"); | ||
var mod = __toESM(require("@noble/curves/abstract/modular"), 1); | ||
@@ -70,5 +71,3 @@ var utils = __toESM(require("@noble/curves/abstract/utils"), 1); | ||
class Crypto { | ||
static get = () => { | ||
throw new import_MatterError.NoProviderError("No provider configured"); | ||
}; | ||
static get; | ||
static encrypt = (key, data, nonce, aad) => Crypto.get().encrypt(key, data, nonce, aad); | ||
@@ -102,5 +101,10 @@ static decrypt = (key, data, nonce, aad) => Crypto.get().decrypt(key, data, nonce, aad); | ||
} | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.cryptoSetup?.(Crypto); | ||
} | ||
import_Boot.Boot.init(() => { | ||
Crypto.get = () => { | ||
throw new import_MatterError.NoProviderError("No provider configured"); | ||
}; | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.cryptoSetup?.(Crypto); | ||
} | ||
}); | ||
//# sourceMappingURL=Crypto.js.map |
@@ -24,2 +24,3 @@ "use strict"; | ||
module.exports = __toCommonJS(Environment_exports); | ||
var import_Boot = require("#util/Boot.js"); | ||
var import_DiagnosticSource = require("../log/DiagnosticSource.js"); | ||
@@ -217,3 +218,6 @@ var import_Logger = require("../log/Logger.js"); | ||
} | ||
let global = new Environment("default"); | ||
let global; | ||
import_Boot.Boot.init(() => { | ||
global = new Environment("default"); | ||
}); | ||
//# sourceMappingURL=Environment.js.map |
@@ -63,3 +63,3 @@ "use strict"; | ||
[import_Lifecycle.Lifecycle.Status.Initializing]: "\u231B", | ||
[import_Lifecycle.Lifecycle.Status.Active]: "\u2714", | ||
[import_Lifecycle.Lifecycle.Status.Active]: "\u2713", | ||
[import_Lifecycle.Lifecycle.Status.Crashed]: "\u2717", | ||
@@ -66,0 +66,0 @@ [import_Lifecycle.Lifecycle.Status.Destroying]: "\u2620\uFE0E", |
@@ -55,3 +55,3 @@ /** | ||
private readonly name; | ||
static logger: LoggerDefinition[]; | ||
static logger: Array<LoggerDefinition>; | ||
static nestingLevel: number; | ||
@@ -58,0 +58,0 @@ /** Add additional logger to the list of loggers including the default configuration. */ |
@@ -25,2 +25,3 @@ "use strict"; | ||
module.exports = __toCommonJS(Logger_exports); | ||
var import_Boot = require("#util/Boot.js"); | ||
var import_MatterError = require("../MatterError.js"); | ||
@@ -72,10 +73,4 @@ var import_Time = require("../time/Time.js"); | ||
} | ||
static logger = new Array({ | ||
logIdentifier: "default", | ||
logFormatter: import_LogFormat.LogFormat.plain, | ||
log: consoleLogger, | ||
defaultLogLevel: import_LogLevel.LogLevel.DEBUG, | ||
logLevels: {} | ||
}); | ||
static nestingLevel = 0; | ||
static logger; | ||
static nestingLevel; | ||
/** Add additional logger to the list of loggers including the default configuration. */ | ||
@@ -394,5 +389,2 @@ static addLogger(identifier, logger, options) { | ||
} | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.loggerSetup?.(Logger); | ||
} | ||
function nestingPrefix() { | ||
@@ -404,2 +396,15 @@ if (Logger.nestingLevel) { | ||
} | ||
import_Boot.Boot.init(() => { | ||
Logger.logger = new Array({ | ||
logIdentifier: "default", | ||
logFormatter: import_LogFormat.LogFormat.plain, | ||
log: consoleLogger, | ||
defaultLogLevel: import_LogLevel.LogLevel.DEBUG, | ||
logLevels: {} | ||
}); | ||
Logger.nestingLevel = 0; | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.loggerSetup?.(Logger); | ||
} | ||
}); | ||
//# sourceMappingURL=Logger.js.map |
@@ -8,13 +8,14 @@ /** | ||
import { Network, NetworkInterface, NetworkInterfaceDetails } from "../Network.js"; | ||
import { UdpChannel, UdpChannelOptions } from "../UdpChannel.js"; | ||
import { UdpChannelOptions } from "../UdpChannel.js"; | ||
import { MockUdpChannel } from "./MockUdpChannel.js"; | ||
import type { NetworkSimulator } from "./NetworkSimulator.js"; | ||
export declare class MockNetwork extends Network { | ||
private readonly mac; | ||
private readonly ipV4; | ||
private readonly ipV6; | ||
constructor(mac: string, ips: string[]); | ||
#private; | ||
constructor(simulator: NetworkSimulator, mac: string, ips: string[]); | ||
get simulator(): NetworkSimulator; | ||
getNetInterfaces(): NetworkInterface[]; | ||
getIpMac(_netInterface: string): NetworkInterfaceDetails; | ||
createUdpChannel(options: UdpChannelOptions): Promise<UdpChannel>; | ||
createUdpChannel(options: UdpChannelOptions): Promise<MockUdpChannel>; | ||
supports(type: ChannelType, _address: string): type is ChannelType.UDP; | ||
} | ||
//# sourceMappingURL=MockNetwork.d.ts.map |
@@ -28,3 +28,2 @@ "use strict"; | ||
var import_MockUdpChannel = require("./MockUdpChannel.js"); | ||
var import_NetworkSimulator = require("./NetworkSimulator.js"); | ||
/** | ||
@@ -36,18 +35,24 @@ * @license | ||
class MockNetwork extends import_Network.Network { | ||
constructor(mac, ips) { | ||
#simulator; | ||
#mac; | ||
#ipV4; | ||
#ipV6; | ||
constructor(simulator, mac, ips) { | ||
super(); | ||
this.mac = mac; | ||
this.ipV4 = ips.filter((ip) => (0, import_Ip.isIPv4)(ip)); | ||
this.ipV6 = ips.filter((ip) => !(0, import_Ip.isIPv4)(ip)); | ||
this.#simulator = simulator; | ||
this.#mac = mac; | ||
this.#ipV4 = ips.filter((ip) => (0, import_Ip.isIPv4)(ip)); | ||
this.#ipV6 = ips.filter((ip) => !(0, import_Ip.isIPv4)(ip)); | ||
} | ||
ipV4; | ||
ipV6; | ||
get simulator() { | ||
return this.#simulator; | ||
} | ||
getNetInterfaces() { | ||
return [{ name: import_NetworkSimulator.NetworkSimulator.INTERFACE_NAME }]; | ||
return [{ name: "fake0" }]; | ||
} | ||
getIpMac(_netInterface) { | ||
return { mac: this.mac, ipV4: this.ipV4, ipV6: this.ipV6 }; | ||
return { mac: this.#mac, ipV4: this.#ipV4, ipV6: this.#ipV6 }; | ||
} | ||
createUdpChannel(options) { | ||
return import_MockUdpChannel.MockUdpChannel.create(this, options); | ||
return Promise.resolve(new import_MockUdpChannel.MockUdpChannel(this, options)); | ||
} | ||
@@ -54,0 +59,0 @@ supports(type, _address) { |
@@ -11,11 +11,5 @@ /** | ||
export declare class MockUdpChannel implements UdpChannel { | ||
readonly type: "udp4" | "udp6"; | ||
private readonly localAddress; | ||
private readonly listeningAddress; | ||
static create(network: MockNetwork, { listeningAddress, listeningPort, netInterface, type }: UdpChannelOptions): Promise<MockUdpChannel>; | ||
private readonly netListeners; | ||
private readonly simulatedNetwork; | ||
private readonly listeningPort; | ||
#private; | ||
readonly maxPayloadSize: number; | ||
constructor(type: "udp4" | "udp6", localAddress: string, listeningAddress: string | undefined, listeningPort?: number); | ||
constructor(network: MockNetwork, { listeningAddress, listeningPort, netInterface, type }: UdpChannelOptions); | ||
onData(listener: (netInterface: string, peerAddress: string, peerPort: number, data: Uint8Array) => void): TransportInterface.Listener; | ||
@@ -22,0 +16,0 @@ send(host: string, port: number, data: Uint8Array): Promise<void>; |
@@ -27,3 +27,2 @@ "use strict"; | ||
var import_UdpChannel = require("../UdpChannel.js"); | ||
var import_NetworkSimulator = require("./NetworkSimulator.js"); | ||
/** | ||
@@ -35,10 +34,10 @@ * @license | ||
class MockUdpChannel { | ||
constructor(type, localAddress, listeningAddress, listeningPort) { | ||
this.type = type; | ||
this.localAddress = localAddress; | ||
this.listeningAddress = listeningAddress; | ||
this.listeningPort = listeningPort ?? 1024 + Math.floor(Math.random() * 64511); | ||
} | ||
static async create(network, { listeningAddress, listeningPort, netInterface, type }) { | ||
const { ipV4, ipV6 } = network.getIpMac(netInterface ?? import_NetworkSimulator.NetworkSimulator.INTERFACE_NAME); | ||
#netListeners = new Array(); | ||
#simulatedNetwork; | ||
#listeningAddress; | ||
#localAddress; | ||
#listeningPort; | ||
maxPayloadSize = import_UdpChannel.MAX_UDP_MESSAGE_SIZE; | ||
constructor(network, { listeningAddress, listeningPort, netInterface, type }) { | ||
const { ipV4, ipV6 } = network.getIpMac(netInterface ?? "fake0"); | ||
const localAddress = type === "udp4" ? ipV4[0] : ipV6[0] ?? ipV4[0]; | ||
@@ -48,21 +47,20 @@ if (localAddress === void 0) { | ||
} | ||
return new MockUdpChannel(type, localAddress, listeningAddress, listeningPort); | ||
this.#localAddress = localAddress; | ||
this.#simulatedNetwork = network.simulator; | ||
this.#listeningAddress = listeningAddress; | ||
this.#listeningPort = listeningPort ?? 1024 + Math.floor(Math.random() * 64511); | ||
} | ||
netListeners = new Array(); | ||
simulatedNetwork = import_NetworkSimulator.NetworkSimulator.get(); | ||
listeningPort; | ||
maxPayloadSize = import_UdpChannel.MAX_UDP_MESSAGE_SIZE; | ||
onData(listener) { | ||
const netListener = this.simulatedNetwork.onUdpData(this.listeningAddress, this.listeningPort, listener); | ||
this.netListeners.push(netListener); | ||
const netListener = this.#simulatedNetwork.onUdpData(this.#listeningAddress, this.#listeningPort, listener); | ||
this.#netListeners.push(netListener); | ||
return netListener; | ||
} | ||
async send(host, port, data) { | ||
this.simulatedNetwork.sendUdp(this.localAddress, this.listeningPort, host, port, data); | ||
this.#simulatedNetwork.sendUdp(this.#localAddress, this.#listeningPort, host, port, data); | ||
} | ||
async close() { | ||
for (const netListener of this.netListeners) { | ||
for (const netListener of this.#netListeners) { | ||
await netListener.close(); | ||
} | ||
this.netListeners.length = 0; | ||
this.#netListeners.length = 0; | ||
} | ||
@@ -73,3 +71,3 @@ async [Symbol.asyncDispose]() { | ||
get port() { | ||
return this.listeningPort; | ||
return this.#listeningPort; | ||
} | ||
@@ -76,0 +74,0 @@ supports(type, _address) { |
@@ -7,4 +7,4 @@ /** | ||
import { TransportInterface } from "../TransportInterface.js"; | ||
import { MockNetwork } from "./MockNetwork.js"; | ||
export declare class NetworkSimulator { | ||
static get: () => NetworkSimulator; | ||
private readonly listenersMap; | ||
@@ -14,7 +14,7 @@ onUdpData(host: string | undefined, port: number, listener: NetworkSimulator.Listener): TransportInterface.Listener; | ||
sendUdp(localAddress: string, localPort: number, remoteAddress: string, remotePort: number, data: Uint8Array): void; | ||
addHost(lastIdentifierByte: number): MockNetwork; | ||
} | ||
export declare namespace NetworkSimulator { | ||
type Listener = (netInterface: string, peerAddress: string, peerPort: number, data: Uint8Array) => void; | ||
const INTERFACE_NAME = "fakeInterface"; | ||
} | ||
//# sourceMappingURL=NetworkSimulator.d.ts.map |
@@ -25,3 +25,3 @@ "use strict"; | ||
var import_Logger = require("../../log/Logger.js"); | ||
var import_Singleton = require("../../util/Singleton.js"); | ||
var import_MockNetwork = require("./MockNetwork.js"); | ||
/** | ||
@@ -34,3 +34,2 @@ * @license | ||
class NetworkSimulator { | ||
static get = (0, import_Singleton.singleton)(() => new NetworkSimulator()); | ||
listenersMap = /* @__PURE__ */ new Map(); | ||
@@ -64,3 +63,3 @@ onUdpData(host, port, listener) { | ||
try { | ||
listener(NetworkSimulator.INTERFACE_NAME, localAddress, localPort, data); | ||
listener("fake0", localAddress, localPort, data); | ||
} catch (error) { | ||
@@ -72,6 +71,10 @@ logger.error(error); | ||
} | ||
addHost(lastIdentifierByte) { | ||
const byte = lastIdentifierByte.toString(16).padStart(2, "0"); | ||
return new import_MockNetwork.MockNetwork(this, `00:11:22:33:44:${byte}`, [ | ||
`1111:2222:3333:4444:5555:6666:7777:88${byte}`, | ||
`10.10.10.${lastIdentifierByte}` | ||
]); | ||
} | ||
} | ||
((NetworkSimulator2) => { | ||
NetworkSimulator2.INTERFACE_NAME = "fakeInterface"; | ||
})(NetworkSimulator || (NetworkSimulator = {})); | ||
//# sourceMappingURL=NetworkSimulator.js.map |
@@ -25,2 +25,3 @@ "use strict"; | ||
module.exports = __toCommonJS(Time_exports); | ||
var import_Boot = require("#util/Boot.js"); | ||
var import_Promises = require("#util/Promises.js"); | ||
@@ -37,3 +38,3 @@ var import_MatterError = require("../MatterError.js"); | ||
class Time { | ||
static get = () => time; | ||
static get; | ||
now() { | ||
@@ -146,5 +147,2 @@ return /* @__PURE__ */ new Date(); | ||
} | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.timeSetup?.(Time); | ||
} | ||
import_DiagnosticSource.DiagnosticSource.add({ | ||
@@ -165,2 +163,8 @@ get [import_Diagnostic.Diagnostic.value]() { | ||
}); | ||
import_Boot.Boot.init(() => { | ||
Time.get = () => time; | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks?.timeSetup?.(Time); | ||
} | ||
}); | ||
//# sourceMappingURL=Time.js.map |
@@ -7,2 +7,3 @@ /** | ||
export * from "./Array.js"; | ||
export * from "./Boot.js"; | ||
export * from "./Bytes.js"; | ||
@@ -9,0 +10,0 @@ export * from "./Cache.js"; |
@@ -19,2 +19,3 @@ "use strict"; | ||
__reExport(util_exports, require("./Array.js"), module.exports); | ||
__reExport(util_exports, require("./Boot.js"), module.exports); | ||
__reExport(util_exports, require("./Bytes.js"), module.exports); | ||
@@ -21,0 +22,0 @@ __reExport(util_exports, require("./Cache.js"), module.exports); |
@@ -6,2 +6,3 @@ /** | ||
*/ | ||
import { Boot } from "#util/Boot.js"; | ||
import * as mod from "@noble/curves/abstract/modular"; | ||
@@ -28,5 +29,3 @@ import * as utils from "@noble/curves/abstract/utils"; | ||
class Crypto { | ||
static get = () => { | ||
throw new NoProviderError("No provider configured"); | ||
}; | ||
static get; | ||
static encrypt = (key, data, nonce, aad) => Crypto.get().encrypt(key, data, nonce, aad); | ||
@@ -60,5 +59,10 @@ static decrypt = (key, data, nonce, aad) => Crypto.get().decrypt(key, data, nonce, aad); | ||
} | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.cryptoSetup?.(Crypto); | ||
} | ||
Boot.init(() => { | ||
Crypto.get = () => { | ||
throw new NoProviderError("No provider configured"); | ||
}; | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.cryptoSetup?.(Crypto); | ||
} | ||
}); | ||
export { | ||
@@ -65,0 +69,0 @@ CRYPTO_AUTH_TAG_LENGTH, |
@@ -6,2 +6,3 @@ /** | ||
*/ | ||
import { Boot } from "#util/Boot.js"; | ||
import { DiagnosticSource } from "../log/DiagnosticSource.js"; | ||
@@ -194,3 +195,6 @@ import { Logger } from "../log/Logger.js"; | ||
} | ||
let global = new Environment("default"); | ||
let global; | ||
Boot.init(() => { | ||
global = new Environment("default"); | ||
}); | ||
export { | ||
@@ -197,0 +201,0 @@ Environment |
@@ -40,3 +40,3 @@ /** | ||
[Lifecycle.Status.Initializing]: "\u231B", | ||
[Lifecycle.Status.Active]: "\u2714", | ||
[Lifecycle.Status.Active]: "\u2713", | ||
[Lifecycle.Status.Crashed]: "\u2717", | ||
@@ -43,0 +43,0 @@ [Lifecycle.Status.Destroying]: "\u2620\uFE0E", |
@@ -55,3 +55,3 @@ /** | ||
private readonly name; | ||
static logger: LoggerDefinition[]; | ||
static logger: Array<LoggerDefinition>; | ||
static nestingLevel: number; | ||
@@ -58,0 +58,0 @@ /** Add additional logger to the list of loggers including the default configuration. */ |
@@ -6,2 +6,3 @@ /** | ||
*/ | ||
import { Boot } from "#util/Boot.js"; | ||
import { ImplementationError, NotImplementedError } from "../MatterError.js"; | ||
@@ -48,10 +49,4 @@ import { Time } from "../time/Time.js"; | ||
} | ||
static logger = new Array({ | ||
logIdentifier: "default", | ||
logFormatter: LogFormat.plain, | ||
log: consoleLogger, | ||
defaultLogLevel: LogLevel.DEBUG, | ||
logLevels: {} | ||
}); | ||
static nestingLevel = 0; | ||
static logger; | ||
static nestingLevel; | ||
/** Add additional logger to the list of loggers including the default configuration. */ | ||
@@ -370,5 +365,2 @@ static addLogger(identifier, logger, options) { | ||
} | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.loggerSetup?.(Logger); | ||
} | ||
function nestingPrefix() { | ||
@@ -380,2 +372,15 @@ if (Logger.nestingLevel) { | ||
} | ||
Boot.init(() => { | ||
Logger.logger = new Array({ | ||
logIdentifier: "default", | ||
logFormatter: LogFormat.plain, | ||
log: consoleLogger, | ||
defaultLogLevel: LogLevel.DEBUG, | ||
logLevels: {} | ||
}); | ||
Logger.nestingLevel = 0; | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.loggerSetup?.(Logger); | ||
} | ||
}); | ||
export { | ||
@@ -382,0 +387,0 @@ Logger, |
@@ -8,13 +8,14 @@ /** | ||
import { Network, NetworkInterface, NetworkInterfaceDetails } from "../Network.js"; | ||
import { UdpChannel, UdpChannelOptions } from "../UdpChannel.js"; | ||
import { UdpChannelOptions } from "../UdpChannel.js"; | ||
import { MockUdpChannel } from "./MockUdpChannel.js"; | ||
import type { NetworkSimulator } from "./NetworkSimulator.js"; | ||
export declare class MockNetwork extends Network { | ||
private readonly mac; | ||
private readonly ipV4; | ||
private readonly ipV6; | ||
constructor(mac: string, ips: string[]); | ||
#private; | ||
constructor(simulator: NetworkSimulator, mac: string, ips: string[]); | ||
get simulator(): NetworkSimulator; | ||
getNetInterfaces(): NetworkInterface[]; | ||
getIpMac(_netInterface: string): NetworkInterfaceDetails; | ||
createUdpChannel(options: UdpChannelOptions): Promise<UdpChannel>; | ||
createUdpChannel(options: UdpChannelOptions): Promise<MockUdpChannel>; | ||
supports(type: ChannelType, _address: string): type is ChannelType.UDP; | ||
} | ||
//# sourceMappingURL=MockNetwork.d.ts.map |
@@ -10,20 +10,25 @@ /** | ||
import { MockUdpChannel } from "./MockUdpChannel.js"; | ||
import { NetworkSimulator } from "./NetworkSimulator.js"; | ||
class MockNetwork extends Network { | ||
constructor(mac, ips) { | ||
#simulator; | ||
#mac; | ||
#ipV4; | ||
#ipV6; | ||
constructor(simulator, mac, ips) { | ||
super(); | ||
this.mac = mac; | ||
this.ipV4 = ips.filter((ip) => isIPv4(ip)); | ||
this.ipV6 = ips.filter((ip) => !isIPv4(ip)); | ||
this.#simulator = simulator; | ||
this.#mac = mac; | ||
this.#ipV4 = ips.filter((ip) => isIPv4(ip)); | ||
this.#ipV6 = ips.filter((ip) => !isIPv4(ip)); | ||
} | ||
ipV4; | ||
ipV6; | ||
get simulator() { | ||
return this.#simulator; | ||
} | ||
getNetInterfaces() { | ||
return [{ name: NetworkSimulator.INTERFACE_NAME }]; | ||
return [{ name: "fake0" }]; | ||
} | ||
getIpMac(_netInterface) { | ||
return { mac: this.mac, ipV4: this.ipV4, ipV6: this.ipV6 }; | ||
return { mac: this.#mac, ipV4: this.#ipV4, ipV6: this.#ipV6 }; | ||
} | ||
createUdpChannel(options) { | ||
return MockUdpChannel.create(this, options); | ||
return Promise.resolve(new MockUdpChannel(this, options)); | ||
} | ||
@@ -30,0 +35,0 @@ supports(type, _address) { |
@@ -11,11 +11,5 @@ /** | ||
export declare class MockUdpChannel implements UdpChannel { | ||
readonly type: "udp4" | "udp6"; | ||
private readonly localAddress; | ||
private readonly listeningAddress; | ||
static create(network: MockNetwork, { listeningAddress, listeningPort, netInterface, type }: UdpChannelOptions): Promise<MockUdpChannel>; | ||
private readonly netListeners; | ||
private readonly simulatedNetwork; | ||
private readonly listeningPort; | ||
#private; | ||
readonly maxPayloadSize: number; | ||
constructor(type: "udp4" | "udp6", localAddress: string, listeningAddress: string | undefined, listeningPort?: number); | ||
constructor(network: MockNetwork, { listeningAddress, listeningPort, netInterface, type }: UdpChannelOptions); | ||
onData(listener: (netInterface: string, peerAddress: string, peerPort: number, data: Uint8Array) => void): TransportInterface.Listener; | ||
@@ -22,0 +16,0 @@ send(host: string, port: number, data: Uint8Array): Promise<void>; |
@@ -9,12 +9,11 @@ /** | ||
import { MAX_UDP_MESSAGE_SIZE } from "../UdpChannel.js"; | ||
import { NetworkSimulator } from "./NetworkSimulator.js"; | ||
class MockUdpChannel { | ||
constructor(type, localAddress, listeningAddress, listeningPort) { | ||
this.type = type; | ||
this.localAddress = localAddress; | ||
this.listeningAddress = listeningAddress; | ||
this.listeningPort = listeningPort ?? 1024 + Math.floor(Math.random() * 64511); | ||
} | ||
static async create(network, { listeningAddress, listeningPort, netInterface, type }) { | ||
const { ipV4, ipV6 } = network.getIpMac(netInterface ?? NetworkSimulator.INTERFACE_NAME); | ||
#netListeners = new Array(); | ||
#simulatedNetwork; | ||
#listeningAddress; | ||
#localAddress; | ||
#listeningPort; | ||
maxPayloadSize = MAX_UDP_MESSAGE_SIZE; | ||
constructor(network, { listeningAddress, listeningPort, netInterface, type }) { | ||
const { ipV4, ipV6 } = network.getIpMac(netInterface ?? "fake0"); | ||
const localAddress = type === "udp4" ? ipV4[0] : ipV6[0] ?? ipV4[0]; | ||
@@ -24,21 +23,20 @@ if (localAddress === void 0) { | ||
} | ||
return new MockUdpChannel(type, localAddress, listeningAddress, listeningPort); | ||
this.#localAddress = localAddress; | ||
this.#simulatedNetwork = network.simulator; | ||
this.#listeningAddress = listeningAddress; | ||
this.#listeningPort = listeningPort ?? 1024 + Math.floor(Math.random() * 64511); | ||
} | ||
netListeners = new Array(); | ||
simulatedNetwork = NetworkSimulator.get(); | ||
listeningPort; | ||
maxPayloadSize = MAX_UDP_MESSAGE_SIZE; | ||
onData(listener) { | ||
const netListener = this.simulatedNetwork.onUdpData(this.listeningAddress, this.listeningPort, listener); | ||
this.netListeners.push(netListener); | ||
const netListener = this.#simulatedNetwork.onUdpData(this.#listeningAddress, this.#listeningPort, listener); | ||
this.#netListeners.push(netListener); | ||
return netListener; | ||
} | ||
async send(host, port, data) { | ||
this.simulatedNetwork.sendUdp(this.localAddress, this.listeningPort, host, port, data); | ||
this.#simulatedNetwork.sendUdp(this.#localAddress, this.#listeningPort, host, port, data); | ||
} | ||
async close() { | ||
for (const netListener of this.netListeners) { | ||
for (const netListener of this.#netListeners) { | ||
await netListener.close(); | ||
} | ||
this.netListeners.length = 0; | ||
this.#netListeners.length = 0; | ||
} | ||
@@ -49,3 +47,3 @@ async [Symbol.asyncDispose]() { | ||
get port() { | ||
return this.listeningPort; | ||
return this.#listeningPort; | ||
} | ||
@@ -52,0 +50,0 @@ supports(type, _address) { |
@@ -7,4 +7,4 @@ /** | ||
import { TransportInterface } from "../TransportInterface.js"; | ||
import { MockNetwork } from "./MockNetwork.js"; | ||
export declare class NetworkSimulator { | ||
static get: () => NetworkSimulator; | ||
private readonly listenersMap; | ||
@@ -14,7 +14,7 @@ onUdpData(host: string | undefined, port: number, listener: NetworkSimulator.Listener): TransportInterface.Listener; | ||
sendUdp(localAddress: string, localPort: number, remoteAddress: string, remotePort: number, data: Uint8Array): void; | ||
addHost(lastIdentifierByte: number): MockNetwork; | ||
} | ||
export declare namespace NetworkSimulator { | ||
type Listener = (netInterface: string, peerAddress: string, peerPort: number, data: Uint8Array) => void; | ||
const INTERFACE_NAME = "fakeInterface"; | ||
} | ||
//# sourceMappingURL=NetworkSimulator.d.ts.map |
@@ -7,6 +7,5 @@ /** | ||
import { Logger } from "../../log/Logger.js"; | ||
import { singleton } from "../../util/Singleton.js"; | ||
import { MockNetwork } from "./MockNetwork.js"; | ||
const logger = Logger.get("SimulatedNetwork"); | ||
class NetworkSimulator { | ||
static get = singleton(() => new NetworkSimulator()); | ||
listenersMap = /* @__PURE__ */ new Map(); | ||
@@ -40,3 +39,3 @@ onUdpData(host, port, listener) { | ||
try { | ||
listener(NetworkSimulator.INTERFACE_NAME, localAddress, localPort, data); | ||
listener("fake0", localAddress, localPort, data); | ||
} catch (error) { | ||
@@ -48,6 +47,10 @@ logger.error(error); | ||
} | ||
addHost(lastIdentifierByte) { | ||
const byte = lastIdentifierByte.toString(16).padStart(2, "0"); | ||
return new MockNetwork(this, `00:11:22:33:44:${byte}`, [ | ||
`1111:2222:3333:4444:5555:6666:7777:88${byte}`, | ||
`10.10.10.${lastIdentifierByte}` | ||
]); | ||
} | ||
} | ||
((NetworkSimulator2) => { | ||
NetworkSimulator2.INTERFACE_NAME = "fakeInterface"; | ||
})(NetworkSimulator || (NetworkSimulator = {})); | ||
export { | ||
@@ -54,0 +57,0 @@ NetworkSimulator |
@@ -6,2 +6,3 @@ /** | ||
*/ | ||
import { Boot } from "#util/Boot.js"; | ||
import { CancelablePromise } from "#util/Promises.js"; | ||
@@ -13,3 +14,3 @@ import { ImplementationError } from "../MatterError.js"; | ||
class Time { | ||
static get = () => time; | ||
static get; | ||
now() { | ||
@@ -122,5 +123,2 @@ return /* @__PURE__ */ new Date(); | ||
} | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.timeSetup?.(Time); | ||
} | ||
DiagnosticSource.add({ | ||
@@ -141,2 +139,8 @@ get [Diagnostic.value]() { | ||
}); | ||
Boot.init(() => { | ||
Time.get = () => time; | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks?.timeSetup?.(Time); | ||
} | ||
}); | ||
export { | ||
@@ -143,0 +147,0 @@ StandardTimer, |
@@ -7,2 +7,3 @@ /** | ||
export * from "./Array.js"; | ||
export * from "./Boot.js"; | ||
export * from "./Bytes.js"; | ||
@@ -9,0 +10,0 @@ export * from "./Cache.js"; |
@@ -7,2 +7,3 @@ /** | ||
export * from "./Array.js"; | ||
export * from "./Boot.js"; | ||
export * from "./Bytes.js"; | ||
@@ -9,0 +10,0 @@ export * from "./Cache.js"; |
{ | ||
"name": "@matter/general", | ||
"version": "0.11.5-alpha.0-20241109-2e3dccaa9", | ||
"version": "0.11.5-alpha.0-20241112-858f60251", | ||
"description": "Non-Matter support for Matter.js", | ||
@@ -39,3 +39,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@matter/testing": "0.11.5-alpha.0-20241109-2e3dccaa9" | ||
"@matter/testing": "0.11.5-alpha.0-20241112-858f60251" | ||
}, | ||
@@ -42,0 +42,0 @@ "files": [ |
@@ -7,2 +7,3 @@ /** | ||
import { Boot } from "#util/Boot.js"; | ||
import * as mod from "@noble/curves/abstract/modular"; | ||
@@ -34,5 +35,3 @@ import * as utils from "@noble/curves/abstract/utils"; | ||
export abstract class Crypto { | ||
static get: () => Crypto = () => { | ||
throw new NoProviderError("No provider configured"); | ||
}; | ||
static get: () => Crypto; | ||
@@ -135,5 +134,11 @@ abstract encrypt(key: Uint8Array, data: Uint8Array, nonce: Uint8Array, aad?: Uint8Array): Uint8Array; | ||
// Hook for testing frameworks | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.cryptoSetup?.(Crypto); | ||
} | ||
Boot.init(() => { | ||
Crypto.get = () => { | ||
throw new NoProviderError("No provider configured"); | ||
}; | ||
// Hook for testing frameworks | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.cryptoSetup?.(Crypto); | ||
} | ||
}); |
@@ -7,2 +7,3 @@ /** | ||
import { Boot } from "#util/Boot.js"; | ||
import { MaybePromise } from "#util/Promises.js"; | ||
@@ -241,2 +242,6 @@ import { DiagnosticSource } from "../log/DiagnosticSource.js"; | ||
let global: Environment = new Environment("default"); | ||
let global: Environment; | ||
Boot.init(() => { | ||
global = new Environment("default"); | ||
}); |
@@ -82,3 +82,3 @@ /** | ||
[Lifecycle.Status.Initializing]: "⌛", | ||
[Lifecycle.Status.Active]: "✔", | ||
[Lifecycle.Status.Active]: "✓", | ||
[Lifecycle.Status.Crashed]: "✗", | ||
@@ -85,0 +85,0 @@ [Lifecycle.Status.Destroying]: "☠︎", |
@@ -7,2 +7,3 @@ /** | ||
import { Boot } from "#util/Boot.js"; | ||
import { ImplementationError, NotImplementedError } from "../MatterError.js"; | ||
@@ -97,10 +98,4 @@ import { Time } from "../time/Time.js"; | ||
export class Logger { | ||
static logger = new Array<LoggerDefinition>({ | ||
logIdentifier: "default", | ||
logFormatter: LogFormat.plain, | ||
log: consoleLogger, | ||
defaultLogLevel: LogLevel.DEBUG, | ||
logLevels: {}, | ||
}); | ||
static nestingLevel = 0; | ||
static logger: Array<LoggerDefinition>; | ||
static nestingLevel: number; | ||
@@ -466,7 +461,2 @@ /** Add additional logger to the list of loggers including the default configuration. */ | ||
// Hook for testing frameworks | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.loggerSetup?.(Logger); | ||
} | ||
function nestingPrefix() { | ||
@@ -478,1 +468,17 @@ if (Logger.nestingLevel) { | ||
} | ||
Boot.init(() => { | ||
Logger.logger = new Array<LoggerDefinition>({ | ||
logIdentifier: "default", | ||
logFormatter: LogFormat.plain, | ||
log: consoleLogger, | ||
defaultLogLevel: LogLevel.DEBUG, | ||
logLevels: {}, | ||
}); | ||
Logger.nestingLevel = 0; | ||
// Hook for testing frameworks | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.loggerSetup?.(Logger); | ||
} | ||
}); |
@@ -10,29 +10,34 @@ /** | ||
import { Network, NetworkInterface, NetworkInterfaceDetails } from "../Network.js"; | ||
import { UdpChannel, UdpChannelOptions } from "../UdpChannel.js"; | ||
import { UdpChannelOptions } from "../UdpChannel.js"; | ||
import { MockUdpChannel } from "./MockUdpChannel.js"; | ||
import { NetworkSimulator } from "./NetworkSimulator.js"; | ||
import type { NetworkSimulator } from "./NetworkSimulator.js"; | ||
export class MockNetwork extends Network { | ||
private readonly ipV4: string[]; | ||
private readonly ipV6: string[]; | ||
readonly #simulator: NetworkSimulator; | ||
readonly #mac: string; | ||
readonly #ipV4: string[]; | ||
readonly #ipV6: string[]; | ||
constructor( | ||
private readonly mac: string, | ||
ips: string[], | ||
) { | ||
constructor(simulator: NetworkSimulator, mac: string, ips: string[]) { | ||
super(); | ||
this.ipV4 = ips.filter(ip => isIPv4(ip)); | ||
this.ipV6 = ips.filter(ip => !isIPv4(ip)); | ||
this.#simulator = simulator; | ||
this.#mac = mac; | ||
this.#ipV4 = ips.filter(ip => isIPv4(ip)); | ||
this.#ipV6 = ips.filter(ip => !isIPv4(ip)); | ||
} | ||
get simulator() { | ||
return this.#simulator; | ||
} | ||
getNetInterfaces(): NetworkInterface[] { | ||
return [{ name: NetworkSimulator.INTERFACE_NAME }]; | ||
return [{ name: "fake0" }]; | ||
} | ||
getIpMac(_netInterface: string): NetworkInterfaceDetails { | ||
return { mac: this.mac, ipV4: this.ipV4, ipV6: this.ipV6 }; | ||
return { mac: this.#mac, ipV4: this.#ipV4, ipV6: this.#ipV6 }; | ||
} | ||
override createUdpChannel(options: UdpChannelOptions): Promise<UdpChannel> { | ||
return MockUdpChannel.create(this, options); | ||
override createUdpChannel(options: UdpChannelOptions) { | ||
return Promise.resolve(new MockUdpChannel(this, options)); | ||
} | ||
@@ -39,0 +44,0 @@ |
@@ -15,7 +15,11 @@ /** | ||
export class MockUdpChannel implements UdpChannel { | ||
static async create( | ||
network: MockNetwork, | ||
{ listeningAddress, listeningPort, netInterface, type }: UdpChannelOptions, | ||
) { | ||
const { ipV4, ipV6 } = network.getIpMac(netInterface ?? NetworkSimulator.INTERFACE_NAME); | ||
readonly #netListeners = new Array<TransportInterface.Listener>(); | ||
readonly #simulatedNetwork: NetworkSimulator; | ||
readonly #listeningAddress?: string; | ||
readonly #localAddress: string; | ||
readonly #listeningPort: number; | ||
readonly maxPayloadSize = MAX_UDP_MESSAGE_SIZE; | ||
constructor(network: MockNetwork, { listeningAddress, listeningPort, netInterface, type }: UdpChannelOptions) { | ||
const { ipV4, ipV6 } = network.getIpMac(netInterface ?? "fake0"); | ||
const localAddress = type === "udp4" ? ipV4[0] : (ipV6[0] ?? ipV4[0]); | ||
@@ -25,22 +29,11 @@ if (localAddress === undefined) { | ||
} | ||
return new MockUdpChannel(type, localAddress, listeningAddress, listeningPort); | ||
this.#localAddress = localAddress; | ||
this.#simulatedNetwork = network.simulator; | ||
this.#listeningAddress = listeningAddress; | ||
this.#listeningPort = listeningPort ?? 1024 + Math.floor(Math.random() * 64511); // Random port 1024-65535 | ||
} | ||
private readonly netListeners = new Array<TransportInterface.Listener>(); | ||
private readonly simulatedNetwork = NetworkSimulator.get(); | ||
private readonly listeningPort: number; | ||
readonly maxPayloadSize = MAX_UDP_MESSAGE_SIZE; | ||
constructor( | ||
readonly type: "udp4" | "udp6", | ||
private readonly localAddress: string, | ||
private readonly listeningAddress: string | undefined, | ||
listeningPort?: number, | ||
) { | ||
this.listeningPort = listeningPort ?? 1024 + Math.floor(Math.random() * 64511); // Random port 1024-65535 | ||
} | ||
onData(listener: (netInterface: string, peerAddress: string, peerPort: number, data: Uint8Array) => void) { | ||
const netListener = this.simulatedNetwork.onUdpData(this.listeningAddress, this.listeningPort, listener); | ||
this.netListeners.push(netListener); | ||
const netListener = this.#simulatedNetwork.onUdpData(this.#listeningAddress, this.#listeningPort, listener); | ||
this.#netListeners.push(netListener); | ||
return netListener; | ||
@@ -50,10 +43,10 @@ } | ||
async send(host: string, port: number, data: Uint8Array) { | ||
this.simulatedNetwork.sendUdp(this.localAddress, this.listeningPort, host, port, data); | ||
this.#simulatedNetwork.sendUdp(this.#localAddress, this.#listeningPort, host, port, data); | ||
} | ||
async close() { | ||
for (const netListener of this.netListeners) { | ||
for (const netListener of this.#netListeners) { | ||
await netListener.close(); | ||
} | ||
this.netListeners.length = 0; | ||
this.#netListeners.length = 0; | ||
} | ||
@@ -66,3 +59,3 @@ | ||
get port() { | ||
return this.listeningPort; | ||
return this.#listeningPort; | ||
} | ||
@@ -69,0 +62,0 @@ |
@@ -8,4 +8,4 @@ /** | ||
import { Logger } from "../../log/Logger.js"; | ||
import { singleton } from "../../util/Singleton.js"; | ||
import { TransportInterface } from "../TransportInterface.js"; | ||
import { MockNetwork } from "./MockNetwork.js"; | ||
@@ -15,4 +15,2 @@ const logger = Logger.get("SimulatedNetwork"); | ||
export class NetworkSimulator { | ||
static get = singleton(() => new NetworkSimulator()); | ||
private readonly listenersMap = new Map<string, Array<NetworkSimulator.Listener>>(); | ||
@@ -53,3 +51,3 @@ | ||
try { | ||
listener(NetworkSimulator.INTERFACE_NAME, localAddress, localPort, data); | ||
listener("fake0", localAddress, localPort, data); | ||
} catch (error) { | ||
@@ -61,2 +59,10 @@ logger.error(error); | ||
} | ||
addHost(lastIdentifierByte: number) { | ||
const byte = lastIdentifierByte.toString(16).padStart(2, "0"); | ||
return new MockNetwork(this, `00:11:22:33:44:${byte}`, [ | ||
`1111:2222:3333:4444:5555:6666:7777:88${byte}`, | ||
`10.10.10.${lastIdentifierByte}`, | ||
]); | ||
} | ||
} | ||
@@ -66,3 +72,2 @@ | ||
export type Listener = (netInterface: string, peerAddress: string, peerPort: number, data: Uint8Array) => void; | ||
export const INTERFACE_NAME = "fakeInterface"; | ||
} |
@@ -7,2 +7,3 @@ /** | ||
import { Boot } from "#util/Boot.js"; | ||
import { CancelablePromise } from "#util/Promises.js"; | ||
@@ -22,3 +23,3 @@ import { ImplementationError } from "../MatterError.js"; | ||
export class Time { | ||
static get = () => time; | ||
static get: () => Time; | ||
@@ -187,7 +188,2 @@ now() { | ||
// Hook for testing frameworks | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks.timeSetup?.(Time); | ||
} | ||
DiagnosticSource.add({ | ||
@@ -208,1 +204,10 @@ get [Diagnostic.value]() { | ||
}); | ||
Boot.init(() => { | ||
Time.get = () => time; | ||
// Hook for testing frameworks | ||
if (typeof MatterHooks !== "undefined") { | ||
MatterHooks?.timeSetup?.(Time); | ||
} | ||
}); |
@@ -8,2 +8,3 @@ /** | ||
export * from "./Array.js"; | ||
export * from "./Boot.js"; | ||
export * from "./Bytes.js"; | ||
@@ -10,0 +11,0 @@ export * from "./Cache.js"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1580691
708
32010