@matter/protocol 0.18.0 → 0.18.1-alpha.0-20261111-b84c5d1bc
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/cjs/action/Val.d.ts +8 -0
- package/dist/cjs/action/Val.d.ts.map +1 -1
- package/dist/cjs/action/client/ClientInteraction.d.ts.map +1 -1
- package/dist/cjs/action/client/ClientInteraction.js +45 -32
- package/dist/cjs/action/client/ClientInteraction.js.map +1 -1
- package/dist/cjs/action/client/ClientRequest.d.ts +14 -0
- package/dist/cjs/action/client/ClientRequest.d.ts.map +1 -1
- package/dist/cjs/action/client/InputChunk.js +39 -2
- package/dist/cjs/action/client/InputChunk.js.map +1 -1
- package/dist/cjs/action/client/subscription/ClientSubscription.d.ts +2 -0
- package/dist/cjs/action/client/subscription/ClientSubscription.d.ts.map +1 -1
- package/dist/cjs/action/client/subscription/ClientSubscription.js +4 -0
- package/dist/cjs/action/client/subscription/ClientSubscription.js.map +1 -1
- package/dist/cjs/action/client/subscription/ClientSubscriptionHandler.d.ts.map +1 -1
- package/dist/cjs/action/client/subscription/ClientSubscriptionHandler.js +14 -0
- package/dist/cjs/action/client/subscription/ClientSubscriptionHandler.js.map +1 -1
- package/dist/cjs/action/client/subscription/PeerSubscription.d.ts +32 -0
- package/dist/cjs/action/client/subscription/PeerSubscription.d.ts.map +1 -1
- package/dist/cjs/action/client/subscription/PeerSubscription.js +61 -0
- package/dist/cjs/action/client/subscription/PeerSubscription.js.map +1 -1
- package/dist/cjs/action/errors.d.ts +3 -1
- package/dist/cjs/action/errors.d.ts.map +1 -1
- package/dist/cjs/action/errors.js +7 -2
- package/dist/cjs/action/errors.js.map +1 -1
- package/dist/cjs/action/protocols.d.ts +6 -1
- package/dist/cjs/action/protocols.d.ts.map +1 -1
- package/dist/cjs/action/request/Invoke.d.ts +24 -1
- package/dist/cjs/action/request/Invoke.d.ts.map +1 -1
- package/dist/cjs/action/request/Invoke.js +40 -12
- package/dist/cjs/action/request/Invoke.js.map +1 -1
- package/dist/cjs/action/request/Write.d.ts.map +1 -1
- package/dist/cjs/action/request/Write.js +6 -5
- package/dist/cjs/action/request/Write.js.map +1 -1
- package/dist/cjs/action/response/InvokeResult.d.ts +8 -2
- package/dist/cjs/action/response/InvokeResult.d.ts.map +1 -1
- package/dist/cjs/action/response/InvokeResult.js +28 -0
- package/dist/cjs/action/response/InvokeResult.js.map +2 -2
- package/dist/cjs/action/response/ReadResult.d.ts +14 -5
- package/dist/cjs/action/response/ReadResult.d.ts.map +1 -1
- package/dist/cjs/action/server/AttributeReadResponse.d.ts.map +1 -1
- package/dist/cjs/action/server/AttributeReadResponse.js +1 -1
- package/dist/cjs/action/server/AttributeReadResponse.js.map +1 -1
- package/dist/cjs/action/server/AttributeWriteResponse.d.ts.map +1 -1
- package/dist/cjs/action/server/AttributeWriteResponse.js +4 -2
- package/dist/cjs/action/server/AttributeWriteResponse.js.map +1 -1
- package/dist/cjs/action/server/EventReadResponse.d.ts.map +1 -1
- package/dist/cjs/action/server/EventReadResponse.js +1 -0
- package/dist/cjs/action/server/EventReadResponse.js.map +1 -1
- package/dist/cjs/advertisement/mdns/MdnsAdvertisement.d.ts +1 -1
- package/dist/cjs/advertisement/mdns/MdnsAdvertisement.d.ts.map +1 -1
- package/dist/cjs/advertisement/mdns/MdnsAdvertisement.js +7 -7
- package/dist/cjs/advertisement/mdns/MdnsAdvertisement.js.map +1 -1
- package/dist/cjs/ble/Ble.d.ts +2 -0
- package/dist/cjs/ble/Ble.d.ts.map +1 -1
- package/dist/cjs/ble/Ble.js +4 -0
- package/dist/cjs/ble/Ble.js.map +1 -1
- package/dist/cjs/certificate/CdSigners.d.ts +52 -0
- package/dist/cjs/certificate/CdSigners.d.ts.map +1 -0
- package/dist/cjs/certificate/CdSigners.js +111 -0
- package/dist/cjs/certificate/CdSigners.js.map +6 -0
- package/dist/cjs/certificate/CertificateAuthority.d.ts +1 -1
- package/dist/cjs/certificate/CertificateAuthority.d.ts.map +1 -1
- package/dist/cjs/certificate/DeviceAttestationValidator.d.ts +59 -7
- package/dist/cjs/certificate/DeviceAttestationValidator.d.ts.map +1 -1
- package/dist/cjs/certificate/DeviceAttestationValidator.js +122 -42
- package/dist/cjs/certificate/DeviceAttestationValidator.js.map +1 -1
- package/dist/cjs/certificate/DeviceCertification.d.ts.map +1 -1
- package/dist/cjs/certificate/DeviceCertification.js +5 -2
- package/dist/cjs/certificate/DeviceCertification.js.map +1 -1
- package/dist/cjs/certificate/NocsrValidator.d.ts +57 -0
- package/dist/cjs/certificate/NocsrValidator.d.ts.map +1 -0
- package/dist/cjs/certificate/NocsrValidator.js +109 -0
- package/dist/cjs/certificate/NocsrValidator.js.map +6 -0
- package/dist/cjs/certificate/PeerData.d.ts +12 -0
- package/dist/cjs/certificate/PeerData.d.ts.map +1 -0
- package/dist/cjs/certificate/PeerData.js +33 -0
- package/dist/cjs/certificate/PeerData.js.map +6 -0
- package/dist/cjs/certificate/index.d.ts +2 -0
- package/dist/cjs/certificate/index.d.ts.map +1 -1
- package/dist/cjs/certificate/index.js +2 -0
- package/dist/cjs/certificate/index.js.map +1 -1
- package/dist/cjs/certificate/kinds/AttestationCertificates.d.ts +42 -6
- package/dist/cjs/certificate/kinds/AttestationCertificates.d.ts.map +1 -1
- package/dist/cjs/certificate/kinds/AttestationCertificates.js +110 -13
- package/dist/cjs/certificate/kinds/AttestationCertificates.js.map +1 -1
- package/dist/cjs/certificate/kinds/Certificate.d.ts +13 -7
- package/dist/cjs/certificate/kinds/Certificate.d.ts.map +1 -1
- package/dist/cjs/certificate/kinds/Certificate.js +146 -240
- package/dist/cjs/certificate/kinds/Certificate.js.map +2 -2
- package/dist/cjs/certificate/kinds/CertificationDeclaration.d.ts +21 -3
- package/dist/cjs/certificate/kinds/CertificationDeclaration.d.ts.map +1 -1
- package/dist/cjs/certificate/kinds/CertificationDeclaration.js +76 -20
- package/dist/cjs/certificate/kinds/CertificationDeclaration.js.map +1 -1
- package/dist/cjs/certificate/kinds/DistinguishedName.d.ts +190 -0
- package/dist/cjs/certificate/kinds/DistinguishedName.d.ts.map +1 -0
- package/dist/cjs/certificate/kinds/DistinguishedName.js +417 -0
- package/dist/cjs/certificate/kinds/DistinguishedName.js.map +6 -0
- package/dist/cjs/certificate/kinds/Icac.d.ts.map +1 -1
- package/dist/cjs/certificate/kinds/Icac.js +5 -10
- package/dist/cjs/certificate/kinds/Icac.js.map +1 -1
- package/dist/cjs/certificate/kinds/Noc.d.ts.map +1 -1
- package/dist/cjs/certificate/kinds/Noc.js +5 -4
- package/dist/cjs/certificate/kinds/Noc.js.map +1 -1
- package/dist/cjs/certificate/kinds/OperationalBase.d.ts.map +1 -1
- package/dist/cjs/certificate/kinds/OperationalBase.js +4 -2
- package/dist/cjs/certificate/kinds/OperationalBase.js.map +1 -1
- package/dist/cjs/certificate/kinds/Rcac.d.ts.map +1 -1
- package/dist/cjs/certificate/kinds/Rcac.js +5 -10
- package/dist/cjs/certificate/kinds/Rcac.js.map +1 -1
- package/dist/cjs/certificate/kinds/Vvsc.d.ts +3 -3
- package/dist/cjs/certificate/kinds/Vvsc.d.ts.map +1 -1
- package/dist/cjs/certificate/kinds/Vvsc.js +19 -14
- package/dist/cjs/certificate/kinds/Vvsc.js.map +1 -1
- package/dist/cjs/certificate/kinds/definitions/asn.d.ts +1 -1
- package/dist/cjs/certificate/kinds/definitions/asn.d.ts.map +1 -1
- package/dist/cjs/certificate/kinds/definitions/asn.js.map +1 -1
- package/dist/cjs/certificate/kinds/definitions/attestation.d.ts +15 -15
- package/dist/cjs/certificate/kinds/definitions/attestation.d.ts.map +1 -1
- package/dist/cjs/certificate/kinds/definitions/base.d.ts +33 -0
- package/dist/cjs/certificate/kinds/definitions/base.d.ts.map +1 -1
- package/dist/cjs/certificate/kinds/definitions/base.js +8 -1
- package/dist/cjs/certificate/kinds/definitions/base.js.map +1 -1
- package/dist/cjs/certificate/kinds/definitions/operational.d.ts +24 -20
- package/dist/cjs/certificate/kinds/definitions/operational.d.ts.map +1 -1
- package/dist/cjs/certificate/kinds/definitions/operational.js +5 -3
- package/dist/cjs/certificate/kinds/definitions/operational.js.map +1 -1
- package/dist/cjs/codec/MessageCodec.d.ts +27 -2
- package/dist/cjs/codec/MessageCodec.d.ts.map +1 -1
- package/dist/cjs/codec/MessageCodec.js +81 -74
- package/dist/cjs/codec/MessageCodec.js.map +1 -1
- package/dist/cjs/common/OperationalCredentialsTypes.d.ts +6 -0
- package/dist/cjs/common/OperationalCredentialsTypes.d.ts.map +1 -1
- package/dist/cjs/common/OperationalCredentialsTypes.js +2 -0
- package/dist/cjs/common/OperationalCredentialsTypes.js.map +1 -1
- package/dist/cjs/dcl/DclCertificateService.d.ts +28 -7
- package/dist/cjs/dcl/DclCertificateService.d.ts.map +1 -1
- package/dist/cjs/dcl/DclCertificateService.js +103 -30
- package/dist/cjs/dcl/DclCertificateService.js.map +1 -1
- package/dist/cjs/fabric/Fabric.d.ts +10 -5
- package/dist/cjs/fabric/Fabric.d.ts.map +1 -1
- package/dist/cjs/fabric/Fabric.js +12 -5
- package/dist/cjs/fabric/Fabric.js.map +1 -1
- package/dist/cjs/fabric/FabricManager.d.ts +2 -2
- package/dist/cjs/fabric/FabricManager.js +2 -2
- package/dist/cjs/groups/FabricGroups.d.ts +2 -0
- package/dist/cjs/groups/FabricGroups.d.ts.map +1 -1
- package/dist/cjs/groups/FabricGroups.js +4 -0
- package/dist/cjs/groups/FabricGroups.js.map +1 -1
- package/dist/cjs/groups/Groups.d.ts +7 -0
- package/dist/cjs/groups/Groups.d.ts.map +1 -1
- package/dist/cjs/groups/Groups.js +11 -2
- package/dist/cjs/groups/Groups.js.map +1 -1
- package/dist/cjs/groups/KeySets.d.ts +3 -3
- package/dist/cjs/groups/KeySets.js +3 -3
- package/dist/cjs/interaction/InteractionMessenger.d.ts +18 -1
- package/dist/cjs/interaction/InteractionMessenger.d.ts.map +1 -1
- package/dist/cjs/interaction/InteractionMessenger.js +49 -19
- package/dist/cjs/interaction/InteractionMessenger.js.map +1 -1
- package/dist/cjs/mdns/InterfaceResponder.d.ts +137 -0
- package/dist/cjs/mdns/InterfaceResponder.d.ts.map +1 -0
- package/dist/cjs/mdns/InterfaceResponder.js +799 -0
- package/dist/cjs/mdns/InterfaceResponder.js.map +6 -0
- package/dist/cjs/mdns/MdnsServer.d.ts +82 -9
- package/dist/cjs/mdns/MdnsServer.d.ts.map +1 -1
- package/dist/cjs/mdns/MdnsServer.js +337 -267
- package/dist/cjs/mdns/MdnsServer.js.map +2 -2
- package/dist/cjs/mdns/MdnsService.d.ts.map +1 -1
- package/dist/cjs/mdns/MdnsService.js +3 -1
- package/dist/cjs/mdns/MdnsService.js.map +1 -1
- package/dist/cjs/peer/AdministratorCommands.d.ts +26 -0
- package/dist/cjs/peer/AdministratorCommands.d.ts.map +1 -0
- package/dist/cjs/peer/AdministratorCommands.js +40 -0
- package/dist/cjs/peer/AdministratorCommands.js.map +6 -0
- package/dist/cjs/peer/CommissioningConnection.d.ts.map +1 -1
- package/dist/cjs/peer/CommissioningConnection.js +4 -2
- package/dist/cjs/peer/CommissioningConnection.js.map +1 -1
- package/dist/cjs/peer/ControllerCommissioner.d.ts +9 -0
- package/dist/cjs/peer/ControllerCommissioner.d.ts.map +1 -1
- package/dist/cjs/peer/ControllerCommissioner.js +59 -13
- package/dist/cjs/peer/ControllerCommissioner.js.map +1 -1
- package/dist/cjs/peer/ControllerCommissioningFlow.d.ts +7 -7
- package/dist/cjs/peer/ControllerCommissioningFlow.d.ts.map +1 -1
- package/dist/cjs/peer/ControllerCommissioningFlow.js +124 -67
- package/dist/cjs/peer/ControllerCommissioningFlow.js.map +1 -1
- package/dist/cjs/peer/OperationalCertificateUpdate.d.ts +181 -0
- package/dist/cjs/peer/OperationalCertificateUpdate.d.ts.map +1 -0
- package/dist/cjs/peer/OperationalCertificateUpdate.js +553 -0
- package/dist/cjs/peer/OperationalCertificateUpdate.js.map +6 -0
- package/dist/cjs/peer/Peer.d.ts +5 -0
- package/dist/cjs/peer/Peer.d.ts.map +1 -1
- package/dist/cjs/peer/Peer.js +29 -1
- package/dist/cjs/peer/Peer.js.map +1 -1
- package/dist/cjs/peer/PeerAddressStore.d.ts +37 -0
- package/dist/cjs/peer/PeerAddressStore.d.ts.map +1 -0
- package/dist/cjs/peer/PeerAddressStore.js +114 -0
- package/dist/cjs/peer/PeerAddressStore.js.map +6 -0
- package/dist/cjs/peer/PeerConnection.d.ts.map +1 -1
- package/dist/cjs/peer/PeerConnection.js +0 -1
- package/dist/cjs/peer/PeerConnection.js.map +1 -1
- package/dist/cjs/peer/PeerDescriptor.d.ts +3 -4
- package/dist/cjs/peer/PeerDescriptor.d.ts.map +1 -1
- package/dist/cjs/peer/PeerDescriptor.js.map +1 -1
- package/dist/cjs/peer/PeerExchangeProvider.d.ts.map +1 -1
- package/dist/cjs/peer/PeerExchangeProvider.js +2 -1
- package/dist/cjs/peer/PeerExchangeProvider.js.map +1 -1
- package/dist/cjs/peer/PeerLossContext.d.ts +10 -2
- package/dist/cjs/peer/PeerLossContext.d.ts.map +1 -1
- package/dist/cjs/peer/PhysicalDeviceProperties.d.ts +13 -0
- package/dist/cjs/peer/PhysicalDeviceProperties.d.ts.map +1 -1
- package/dist/cjs/peer/PhysicalDeviceProperties.js +3 -2
- package/dist/cjs/peer/PhysicalDeviceProperties.js.map +1 -1
- package/dist/cjs/peer/RebootResubscribeArmer.d.ts +3 -3
- package/dist/cjs/peer/RebootResubscribeArmer.d.ts.map +1 -1
- package/dist/cjs/peer/RebootResubscribeArmer.js +21 -9
- package/dist/cjs/peer/RebootResubscribeArmer.js.map +1 -1
- package/dist/cjs/peer/index.d.ts +2 -0
- package/dist/cjs/peer/index.d.ts.map +1 -1
- package/dist/cjs/peer/index.js +2 -0
- package/dist/cjs/peer/index.js.map +1 -1
- package/dist/cjs/protocol/DeviceAdvertiser.d.ts.map +1 -1
- package/dist/cjs/protocol/DeviceAdvertiser.js +1 -1
- package/dist/cjs/protocol/DeviceAdvertiser.js.map +1 -1
- package/dist/cjs/protocol/ExchangeManager.d.ts +0 -1
- package/dist/cjs/protocol/ExchangeManager.d.ts.map +1 -1
- package/dist/cjs/protocol/ExchangeManager.js +136 -64
- package/dist/cjs/protocol/ExchangeManager.js.map +1 -1
- package/dist/cjs/protocol/ExchangeProvider.d.ts +3 -2
- package/dist/cjs/protocol/ExchangeProvider.d.ts.map +1 -1
- package/dist/cjs/protocol/ExchangeProvider.js.map +1 -1
- package/dist/cjs/protocol/MessageExchange.d.ts +13 -0
- package/dist/cjs/protocol/MessageExchange.d.ts.map +1 -1
- package/dist/cjs/protocol/MessageExchange.js +23 -7
- package/dist/cjs/protocol/MessageExchange.js.map +1 -1
- package/dist/cjs/protocol/MessageReceptionState.d.ts +1 -1
- package/dist/cjs/protocol/errors.d.ts +7 -1
- package/dist/cjs/protocol/errors.d.ts.map +1 -1
- package/dist/cjs/protocol/errors.js +3 -0
- package/dist/cjs/protocol/errors.js.map +1 -1
- package/dist/cjs/securechannel/SecureChannelMessenger.d.ts +6 -1
- package/dist/cjs/securechannel/SecureChannelMessenger.d.ts.map +1 -1
- package/dist/cjs/securechannel/SecureChannelMessenger.js +27 -12
- package/dist/cjs/securechannel/SecureChannelMessenger.js.map +1 -1
- package/dist/cjs/session/GroupSession.d.ts +58 -15
- package/dist/cjs/session/GroupSession.d.ts.map +1 -1
- package/dist/cjs/session/GroupSession.js +97 -102
- package/dist/cjs/session/GroupSession.js.map +2 -2
- package/dist/cjs/session/NodeSession.d.ts +50 -1
- package/dist/cjs/session/NodeSession.d.ts.map +1 -1
- package/dist/cjs/session/NodeSession.js +80 -4
- package/dist/cjs/session/NodeSession.js.map +1 -1
- package/dist/cjs/session/SecureSession.d.ts +9 -0
- package/dist/cjs/session/SecureSession.d.ts.map +1 -1
- package/dist/cjs/session/SecureSession.js +12 -0
- package/dist/cjs/session/SecureSession.js.map +1 -1
- package/dist/cjs/session/Session.d.ts +2 -2
- package/dist/cjs/session/Session.d.ts.map +1 -1
- package/dist/cjs/session/Session.js +1 -1
- package/dist/cjs/session/SessionManager.d.ts +76 -28
- package/dist/cjs/session/SessionManager.d.ts.map +1 -1
- package/dist/cjs/session/SessionManager.js +316 -153
- package/dist/cjs/session/SessionManager.js.map +2 -2
- package/dist/cjs/session/UnsecuredSession.d.ts +0 -1
- package/dist/cjs/session/UnsecuredSession.d.ts.map +1 -1
- package/dist/cjs/session/UnsecuredSession.js +2 -4
- package/dist/cjs/session/UnsecuredSession.js.map +1 -1
- package/dist/cjs/session/case/CaseClient.d.ts +5 -0
- package/dist/cjs/session/case/CaseClient.d.ts.map +1 -1
- package/dist/cjs/session/case/CaseClient.js +12 -11
- package/dist/cjs/session/case/CaseClient.js.map +2 -2
- package/dist/cjs/session/case/CaseServer.d.ts.map +1 -1
- package/dist/cjs/session/case/CaseServer.js +31 -11
- package/dist/cjs/session/case/CaseServer.js.map +1 -1
- package/dist/esm/action/Val.d.ts +8 -0
- package/dist/esm/action/Val.d.ts.map +1 -1
- package/dist/esm/action/client/ClientInteraction.d.ts.map +1 -1
- package/dist/esm/action/client/ClientInteraction.js +45 -32
- package/dist/esm/action/client/ClientInteraction.js.map +1 -1
- package/dist/esm/action/client/ClientRequest.d.ts +14 -0
- package/dist/esm/action/client/ClientRequest.d.ts.map +1 -1
- package/dist/esm/action/client/InputChunk.js +39 -2
- package/dist/esm/action/client/InputChunk.js.map +1 -1
- package/dist/esm/action/client/subscription/ClientSubscription.d.ts +2 -0
- package/dist/esm/action/client/subscription/ClientSubscription.d.ts.map +1 -1
- package/dist/esm/action/client/subscription/ClientSubscription.js +4 -0
- package/dist/esm/action/client/subscription/ClientSubscription.js.map +1 -1
- package/dist/esm/action/client/subscription/ClientSubscriptionHandler.d.ts.map +1 -1
- package/dist/esm/action/client/subscription/ClientSubscriptionHandler.js +14 -0
- package/dist/esm/action/client/subscription/ClientSubscriptionHandler.js.map +1 -1
- package/dist/esm/action/client/subscription/PeerSubscription.d.ts +32 -0
- package/dist/esm/action/client/subscription/PeerSubscription.d.ts.map +1 -1
- package/dist/esm/action/client/subscription/PeerSubscription.js +61 -0
- package/dist/esm/action/client/subscription/PeerSubscription.js.map +1 -1
- package/dist/esm/action/errors.d.ts +3 -1
- package/dist/esm/action/errors.d.ts.map +1 -1
- package/dist/esm/action/errors.js +7 -2
- package/dist/esm/action/errors.js.map +1 -1
- package/dist/esm/action/protocols.d.ts +6 -1
- package/dist/esm/action/protocols.d.ts.map +1 -1
- package/dist/esm/action/request/Invoke.d.ts +24 -1
- package/dist/esm/action/request/Invoke.d.ts.map +1 -1
- package/dist/esm/action/request/Invoke.js +41 -13
- package/dist/esm/action/request/Invoke.js.map +1 -1
- package/dist/esm/action/request/Write.d.ts.map +1 -1
- package/dist/esm/action/request/Write.js +7 -6
- package/dist/esm/action/request/Write.js.map +1 -1
- package/dist/esm/action/response/InvokeResult.d.ts +8 -2
- package/dist/esm/action/response/InvokeResult.d.ts.map +1 -1
- package/dist/esm/action/response/InvokeResult.js +26 -0
- package/dist/esm/action/response/InvokeResult.js.map +2 -2
- package/dist/esm/action/response/ReadResult.d.ts +14 -5
- package/dist/esm/action/response/ReadResult.d.ts.map +1 -1
- package/dist/esm/action/server/AttributeReadResponse.d.ts.map +1 -1
- package/dist/esm/action/server/AttributeReadResponse.js +2 -2
- package/dist/esm/action/server/AttributeReadResponse.js.map +1 -1
- package/dist/esm/action/server/AttributeWriteResponse.d.ts.map +1 -1
- package/dist/esm/action/server/AttributeWriteResponse.js +11 -3
- package/dist/esm/action/server/AttributeWriteResponse.js.map +1 -1
- package/dist/esm/action/server/EventReadResponse.d.ts.map +1 -1
- package/dist/esm/action/server/EventReadResponse.js +1 -0
- package/dist/esm/action/server/EventReadResponse.js.map +1 -1
- package/dist/esm/advertisement/mdns/MdnsAdvertisement.d.ts +1 -1
- package/dist/esm/advertisement/mdns/MdnsAdvertisement.d.ts.map +1 -1
- package/dist/esm/advertisement/mdns/MdnsAdvertisement.js +7 -7
- package/dist/esm/advertisement/mdns/MdnsAdvertisement.js.map +1 -1
- package/dist/esm/ble/Ble.d.ts +2 -0
- package/dist/esm/ble/Ble.d.ts.map +1 -1
- package/dist/esm/ble/Ble.js +4 -0
- package/dist/esm/ble/Ble.js.map +1 -1
- package/dist/esm/certificate/CdSigners.d.ts +52 -0
- package/dist/esm/certificate/CdSigners.d.ts.map +1 -0
- package/dist/esm/certificate/CdSigners.js +91 -0
- package/dist/esm/certificate/CdSigners.js.map +6 -0
- package/dist/esm/certificate/CertificateAuthority.d.ts +1 -1
- package/dist/esm/certificate/CertificateAuthority.d.ts.map +1 -1
- package/dist/esm/certificate/DeviceAttestationValidator.d.ts +59 -7
- package/dist/esm/certificate/DeviceAttestationValidator.d.ts.map +1 -1
- package/dist/esm/certificate/DeviceAttestationValidator.js +124 -45
- package/dist/esm/certificate/DeviceAttestationValidator.js.map +1 -1
- package/dist/esm/certificate/DeviceCertification.d.ts.map +1 -1
- package/dist/esm/certificate/DeviceCertification.js +5 -2
- package/dist/esm/certificate/DeviceCertification.js.map +1 -1
- package/dist/esm/certificate/NocsrValidator.d.ts +57 -0
- package/dist/esm/certificate/NocsrValidator.d.ts.map +1 -0
- package/dist/esm/certificate/NocsrValidator.js +89 -0
- package/dist/esm/certificate/NocsrValidator.js.map +6 -0
- package/dist/esm/certificate/PeerData.d.ts +12 -0
- package/dist/esm/certificate/PeerData.d.ts.map +1 -0
- package/dist/esm/certificate/PeerData.js +13 -0
- package/dist/esm/certificate/PeerData.js.map +6 -0
- package/dist/esm/certificate/index.d.ts +2 -0
- package/dist/esm/certificate/index.d.ts.map +1 -1
- package/dist/esm/certificate/index.js +2 -0
- package/dist/esm/certificate/index.js.map +1 -1
- package/dist/esm/certificate/kinds/AttestationCertificates.d.ts +42 -6
- package/dist/esm/certificate/kinds/AttestationCertificates.d.ts.map +1 -1
- package/dist/esm/certificate/kinds/AttestationCertificates.js +112 -15
- package/dist/esm/certificate/kinds/AttestationCertificates.js.map +1 -1
- package/dist/esm/certificate/kinds/Certificate.d.ts +13 -7
- package/dist/esm/certificate/kinds/Certificate.d.ts.map +1 -1
- package/dist/esm/certificate/kinds/Certificate.js +153 -256
- package/dist/esm/certificate/kinds/Certificate.js.map +2 -2
- package/dist/esm/certificate/kinds/CertificationDeclaration.d.ts +21 -3
- package/dist/esm/certificate/kinds/CertificationDeclaration.d.ts.map +1 -1
- package/dist/esm/certificate/kinds/CertificationDeclaration.js +79 -20
- package/dist/esm/certificate/kinds/CertificationDeclaration.js.map +1 -1
- package/dist/esm/certificate/kinds/DistinguishedName.d.ts +190 -0
- package/dist/esm/certificate/kinds/DistinguishedName.d.ts.map +1 -0
- package/dist/esm/certificate/kinds/DistinguishedName.js +422 -0
- package/dist/esm/certificate/kinds/DistinguishedName.js.map +6 -0
- package/dist/esm/certificate/kinds/Icac.d.ts.map +1 -1
- package/dist/esm/certificate/kinds/Icac.js +6 -11
- package/dist/esm/certificate/kinds/Icac.js.map +1 -1
- package/dist/esm/certificate/kinds/Noc.d.ts.map +1 -1
- package/dist/esm/certificate/kinds/Noc.js +5 -4
- package/dist/esm/certificate/kinds/Noc.js.map +1 -1
- package/dist/esm/certificate/kinds/OperationalBase.d.ts.map +1 -1
- package/dist/esm/certificate/kinds/OperationalBase.js +4 -2
- package/dist/esm/certificate/kinds/OperationalBase.js.map +1 -1
- package/dist/esm/certificate/kinds/Rcac.d.ts.map +1 -1
- package/dist/esm/certificate/kinds/Rcac.js +6 -11
- package/dist/esm/certificate/kinds/Rcac.js.map +1 -1
- package/dist/esm/certificate/kinds/Vvsc.d.ts +3 -3
- package/dist/esm/certificate/kinds/Vvsc.d.ts.map +1 -1
- package/dist/esm/certificate/kinds/Vvsc.js +20 -15
- package/dist/esm/certificate/kinds/Vvsc.js.map +1 -1
- package/dist/esm/certificate/kinds/definitions/asn.d.ts +1 -1
- package/dist/esm/certificate/kinds/definitions/asn.d.ts.map +1 -1
- package/dist/esm/certificate/kinds/definitions/asn.js.map +1 -1
- package/dist/esm/certificate/kinds/definitions/attestation.d.ts +15 -15
- package/dist/esm/certificate/kinds/definitions/attestation.d.ts.map +1 -1
- package/dist/esm/certificate/kinds/definitions/base.d.ts +33 -0
- package/dist/esm/certificate/kinds/definitions/base.d.ts.map +1 -1
- package/dist/esm/certificate/kinds/definitions/base.js +9 -2
- package/dist/esm/certificate/kinds/definitions/base.js.map +1 -1
- package/dist/esm/certificate/kinds/definitions/operational.d.ts +24 -20
- package/dist/esm/certificate/kinds/definitions/operational.d.ts.map +1 -1
- package/dist/esm/certificate/kinds/definitions/operational.js +5 -3
- package/dist/esm/certificate/kinds/definitions/operational.js.map +1 -1
- package/dist/esm/codec/MessageCodec.d.ts +27 -2
- package/dist/esm/codec/MessageCodec.d.ts.map +1 -1
- package/dist/esm/codec/MessageCodec.js +82 -75
- package/dist/esm/codec/MessageCodec.js.map +1 -1
- package/dist/esm/common/OperationalCredentialsTypes.d.ts +6 -0
- package/dist/esm/common/OperationalCredentialsTypes.d.ts.map +1 -1
- package/dist/esm/common/OperationalCredentialsTypes.js +2 -0
- package/dist/esm/common/OperationalCredentialsTypes.js.map +1 -1
- package/dist/esm/dcl/DclCertificateService.d.ts +28 -7
- package/dist/esm/dcl/DclCertificateService.d.ts.map +1 -1
- package/dist/esm/dcl/DclCertificateService.js +108 -31
- package/dist/esm/dcl/DclCertificateService.js.map +1 -1
- package/dist/esm/fabric/Fabric.d.ts +10 -5
- package/dist/esm/fabric/Fabric.d.ts.map +1 -1
- package/dist/esm/fabric/Fabric.js +12 -5
- package/dist/esm/fabric/Fabric.js.map +1 -1
- package/dist/esm/fabric/FabricManager.d.ts +2 -2
- package/dist/esm/fabric/FabricManager.js +2 -2
- package/dist/esm/groups/FabricGroups.d.ts +2 -0
- package/dist/esm/groups/FabricGroups.d.ts.map +1 -1
- package/dist/esm/groups/FabricGroups.js +4 -0
- package/dist/esm/groups/FabricGroups.js.map +1 -1
- package/dist/esm/groups/Groups.d.ts +7 -0
- package/dist/esm/groups/Groups.d.ts.map +1 -1
- package/dist/esm/groups/Groups.js +11 -2
- package/dist/esm/groups/Groups.js.map +1 -1
- package/dist/esm/groups/KeySets.d.ts +3 -3
- package/dist/esm/groups/KeySets.js +3 -3
- package/dist/esm/interaction/InteractionMessenger.d.ts +18 -1
- package/dist/esm/interaction/InteractionMessenger.d.ts.map +1 -1
- package/dist/esm/interaction/InteractionMessenger.js +50 -20
- package/dist/esm/interaction/InteractionMessenger.js.map +1 -1
- package/dist/esm/mdns/InterfaceResponder.d.ts +137 -0
- package/dist/esm/mdns/InterfaceResponder.d.ts.map +1 -0
- package/dist/esm/mdns/InterfaceResponder.js +794 -0
- package/dist/esm/mdns/InterfaceResponder.js.map +6 -0
- package/dist/esm/mdns/MdnsServer.d.ts +82 -9
- package/dist/esm/mdns/MdnsServer.d.ts.map +1 -1
- package/dist/esm/mdns/MdnsServer.js +341 -273
- package/dist/esm/mdns/MdnsServer.js.map +2 -2
- package/dist/esm/mdns/MdnsService.d.ts.map +1 -1
- package/dist/esm/mdns/MdnsService.js +3 -1
- package/dist/esm/mdns/MdnsService.js.map +1 -1
- package/dist/esm/peer/AdministratorCommands.d.ts +26 -0
- package/dist/esm/peer/AdministratorCommands.d.ts.map +1 -0
- package/dist/esm/peer/AdministratorCommands.js +20 -0
- package/dist/esm/peer/AdministratorCommands.js.map +6 -0
- package/dist/esm/peer/CommissioningConnection.d.ts.map +1 -1
- package/dist/esm/peer/CommissioningConnection.js +4 -2
- package/dist/esm/peer/CommissioningConnection.js.map +1 -1
- package/dist/esm/peer/ControllerCommissioner.d.ts +9 -0
- package/dist/esm/peer/ControllerCommissioner.d.ts.map +1 -1
- package/dist/esm/peer/ControllerCommissioner.js +59 -13
- package/dist/esm/peer/ControllerCommissioner.js.map +1 -1
- package/dist/esm/peer/ControllerCommissioningFlow.d.ts +7 -7
- package/dist/esm/peer/ControllerCommissioningFlow.d.ts.map +1 -1
- package/dist/esm/peer/ControllerCommissioningFlow.js +125 -70
- package/dist/esm/peer/ControllerCommissioningFlow.js.map +1 -1
- package/dist/esm/peer/OperationalCertificateUpdate.d.ts +181 -0
- package/dist/esm/peer/OperationalCertificateUpdate.d.ts.map +1 -0
- package/dist/esm/peer/OperationalCertificateUpdate.js +553 -0
- package/dist/esm/peer/OperationalCertificateUpdate.js.map +6 -0
- package/dist/esm/peer/Peer.d.ts +5 -0
- package/dist/esm/peer/Peer.d.ts.map +1 -1
- package/dist/esm/peer/Peer.js +29 -1
- package/dist/esm/peer/Peer.js.map +1 -1
- package/dist/esm/peer/PeerAddressStore.d.ts +37 -0
- package/dist/esm/peer/PeerAddressStore.d.ts.map +1 -0
- package/dist/esm/peer/PeerAddressStore.js +94 -0
- package/dist/esm/peer/PeerAddressStore.js.map +6 -0
- package/dist/esm/peer/PeerConnection.d.ts.map +1 -1
- package/dist/esm/peer/PeerConnection.js +0 -1
- package/dist/esm/peer/PeerConnection.js.map +1 -1
- package/dist/esm/peer/PeerDescriptor.d.ts +3 -4
- package/dist/esm/peer/PeerDescriptor.d.ts.map +1 -1
- package/dist/esm/peer/PeerDescriptor.js.map +1 -1
- package/dist/esm/peer/PeerExchangeProvider.d.ts.map +1 -1
- package/dist/esm/peer/PeerExchangeProvider.js +3 -2
- package/dist/esm/peer/PeerExchangeProvider.js.map +1 -1
- package/dist/esm/peer/PeerLossContext.d.ts +10 -2
- package/dist/esm/peer/PeerLossContext.d.ts.map +1 -1
- package/dist/esm/peer/PhysicalDeviceProperties.d.ts +13 -0
- package/dist/esm/peer/PhysicalDeviceProperties.d.ts.map +1 -1
- package/dist/esm/peer/PhysicalDeviceProperties.js +3 -2
- package/dist/esm/peer/PhysicalDeviceProperties.js.map +1 -1
- package/dist/esm/peer/RebootResubscribeArmer.d.ts +3 -3
- package/dist/esm/peer/RebootResubscribeArmer.d.ts.map +1 -1
- package/dist/esm/peer/RebootResubscribeArmer.js +21 -9
- package/dist/esm/peer/RebootResubscribeArmer.js.map +1 -1
- package/dist/esm/peer/index.d.ts +2 -0
- package/dist/esm/peer/index.d.ts.map +1 -1
- package/dist/esm/peer/index.js +2 -0
- package/dist/esm/peer/index.js.map +1 -1
- package/dist/esm/protocol/DeviceAdvertiser.d.ts.map +1 -1
- package/dist/esm/protocol/DeviceAdvertiser.js +1 -1
- package/dist/esm/protocol/DeviceAdvertiser.js.map +1 -1
- package/dist/esm/protocol/ExchangeManager.d.ts +0 -1
- package/dist/esm/protocol/ExchangeManager.d.ts.map +1 -1
- package/dist/esm/protocol/ExchangeManager.js +145 -67
- package/dist/esm/protocol/ExchangeManager.js.map +1 -1
- package/dist/esm/protocol/ExchangeProvider.d.ts +3 -2
- package/dist/esm/protocol/ExchangeProvider.d.ts.map +1 -1
- package/dist/esm/protocol/ExchangeProvider.js.map +1 -1
- package/dist/esm/protocol/MessageExchange.d.ts +13 -0
- package/dist/esm/protocol/MessageExchange.d.ts.map +1 -1
- package/dist/esm/protocol/MessageExchange.js +23 -7
- package/dist/esm/protocol/MessageExchange.js.map +1 -1
- package/dist/esm/protocol/MessageReceptionState.d.ts +1 -1
- package/dist/esm/protocol/errors.d.ts +7 -1
- package/dist/esm/protocol/errors.d.ts.map +1 -1
- package/dist/esm/protocol/errors.js +4 -1
- package/dist/esm/protocol/errors.js.map +1 -1
- package/dist/esm/securechannel/SecureChannelMessenger.d.ts +6 -1
- package/dist/esm/securechannel/SecureChannelMessenger.d.ts.map +1 -1
- package/dist/esm/securechannel/SecureChannelMessenger.js +27 -12
- package/dist/esm/securechannel/SecureChannelMessenger.js.map +1 -1
- package/dist/esm/session/GroupSession.d.ts +58 -15
- package/dist/esm/session/GroupSession.d.ts.map +1 -1
- package/dist/esm/session/GroupSession.js +97 -102
- package/dist/esm/session/GroupSession.js.map +2 -2
- package/dist/esm/session/NodeSession.d.ts +50 -1
- package/dist/esm/session/NodeSession.d.ts.map +1 -1
- package/dist/esm/session/NodeSession.js +83 -5
- package/dist/esm/session/NodeSession.js.map +1 -1
- package/dist/esm/session/SecureSession.d.ts +9 -0
- package/dist/esm/session/SecureSession.d.ts.map +1 -1
- package/dist/esm/session/SecureSession.js +18 -1
- package/dist/esm/session/SecureSession.js.map +1 -1
- package/dist/esm/session/Session.d.ts +2 -2
- package/dist/esm/session/Session.d.ts.map +1 -1
- package/dist/esm/session/Session.js +1 -1
- package/dist/esm/session/SessionManager.d.ts +76 -28
- package/dist/esm/session/SessionManager.d.ts.map +1 -1
- package/dist/esm/session/SessionManager.js +319 -156
- package/dist/esm/session/SessionManager.js.map +2 -2
- package/dist/esm/session/UnsecuredSession.d.ts +0 -1
- package/dist/esm/session/UnsecuredSession.d.ts.map +1 -1
- package/dist/esm/session/UnsecuredSession.js +5 -3
- package/dist/esm/session/UnsecuredSession.js.map +1 -1
- package/dist/esm/session/case/CaseClient.d.ts +5 -0
- package/dist/esm/session/case/CaseClient.d.ts.map +1 -1
- package/dist/esm/session/case/CaseClient.js +12 -11
- package/dist/esm/session/case/CaseClient.js.map +2 -2
- package/dist/esm/session/case/CaseServer.d.ts.map +1 -1
- package/dist/esm/session/case/CaseServer.js +31 -11
- package/dist/esm/session/case/CaseServer.js.map +1 -1
- package/package.json +5 -5
- package/src/action/Val.ts +8 -0
- package/src/action/client/ClientInteraction.ts +57 -33
- package/src/action/client/ClientRequest.ts +15 -0
- package/src/action/client/InputChunk.ts +57 -2
- package/src/action/client/subscription/ClientSubscription.ts +5 -0
- package/src/action/client/subscription/ClientSubscriptionHandler.ts +15 -0
- package/src/action/client/subscription/PeerSubscription.ts +73 -0
- package/src/action/errors.ts +10 -3
- package/src/action/protocols.ts +7 -1
- package/src/action/request/Invoke.ts +60 -15
- package/src/action/request/Write.ts +7 -6
- package/src/action/response/InvokeResult.ts +32 -2
- package/src/action/response/ReadResult.ts +15 -5
- package/src/action/server/AttributeReadResponse.ts +3 -2
- package/src/action/server/AttributeWriteResponse.ts +14 -3
- package/src/action/server/EventReadResponse.ts +1 -0
- package/src/advertisement/mdns/MdnsAdvertisement.ts +9 -9
- package/src/ble/Ble.ts +5 -0
- package/src/certificate/CdSigners.ts +137 -0
- package/src/certificate/CertificateAuthority.ts +1 -1
- package/src/certificate/DeviceAttestationValidator.ts +213 -56
- package/src/certificate/DeviceCertification.ts +6 -2
- package/src/certificate/NocsrValidator.ts +140 -0
- package/src/certificate/PeerData.ts +15 -0
- package/src/certificate/index.ts +2 -0
- package/src/certificate/kinds/AttestationCertificates.ts +183 -15
- package/src/certificate/kinds/Certificate.ts +203 -308
- package/src/certificate/kinds/CertificationDeclaration.ts +100 -46
- package/src/certificate/kinds/DistinguishedName.ts +677 -0
- package/src/certificate/kinds/Icac.ts +7 -12
- package/src/certificate/kinds/Noc.ts +12 -8
- package/src/certificate/kinds/OperationalBase.ts +5 -2
- package/src/certificate/kinds/Rcac.ts +7 -12
- package/src/certificate/kinds/Vvsc.ts +24 -15
- package/src/certificate/kinds/definitions/asn.ts +1 -1
- package/src/certificate/kinds/definitions/attestation.ts +15 -15
- package/src/certificate/kinds/definitions/base.ts +43 -1
- package/src/certificate/kinds/definitions/operational.ts +4 -3
- package/src/codec/MessageCodec.ts +92 -81
- package/src/common/OperationalCredentialsTypes.ts +7 -0
- package/src/dcl/DclCertificateService.ts +135 -36
- package/src/fabric/Fabric.ts +13 -6
- package/src/fabric/FabricManager.ts +2 -2
- package/src/groups/FabricGroups.ts +5 -0
- package/src/groups/Groups.ts +12 -3
- package/src/groups/KeySets.ts +3 -3
- package/src/interaction/InteractionMessenger.ts +58 -20
- package/src/mdns/InterfaceResponder.ts +1031 -0
- package/src/mdns/MdnsServer.ts +400 -360
- package/src/mdns/MdnsService.ts +2 -0
- package/src/peer/AdministratorCommands.ts +37 -0
- package/src/peer/CommissioningConnection.ts +5 -1
- package/src/peer/ControllerCommissioner.ts +69 -19
- package/src/peer/ControllerCommissioningFlow.ts +149 -99
- package/src/peer/OperationalCertificateUpdate.ts +922 -0
- package/src/peer/Peer.ts +31 -16
- package/src/peer/PeerAddressStore.ts +119 -0
- package/src/peer/PeerConnection.ts +0 -1
- package/src/peer/PeerDescriptor.ts +3 -4
- package/src/peer/PeerExchangeProvider.ts +4 -6
- package/src/peer/PeerLossContext.ts +11 -2
- package/src/peer/PhysicalDeviceProperties.ts +25 -12
- package/src/peer/RebootResubscribeArmer.ts +37 -16
- package/src/peer/index.ts +2 -0
- package/src/protocol/DeviceAdvertiser.ts +5 -1
- package/src/protocol/ExchangeManager.ts +162 -88
- package/src/protocol/ExchangeProvider.ts +3 -2
- package/src/protocol/MessageExchange.ts +29 -7
- package/src/protocol/MessageReceptionState.ts +2 -2
- package/src/protocol/errors.ts +7 -1
- package/src/securechannel/SecureChannelMessenger.ts +26 -13
- package/src/session/GroupSession.ts +147 -111
- package/src/session/NodeSession.ts +89 -4
- package/src/session/SecureSession.ts +27 -1
- package/src/session/Session.ts +2 -2
- package/src/session/SessionManager.ts +429 -189
- package/src/session/UnsecuredSession.ts +9 -3
- package/src/session/case/CaseClient.ts +15 -10
- package/src/session/case/CaseServer.ts +41 -17
|
@@ -0,0 +1,1031 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022-2026 Matter.js Authors
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
Bytes,
|
|
9
|
+
ClosedError,
|
|
10
|
+
DnsCodec,
|
|
11
|
+
DnsMessage,
|
|
12
|
+
DnsMessageType,
|
|
13
|
+
DnsRecord,
|
|
14
|
+
DnsRecordType,
|
|
15
|
+
Instant,
|
|
16
|
+
isDeepEqual,
|
|
17
|
+
Logger,
|
|
18
|
+
MaybePromise,
|
|
19
|
+
MdnsSocket,
|
|
20
|
+
Millis,
|
|
21
|
+
Minutes,
|
|
22
|
+
Mutex,
|
|
23
|
+
NetworkInterfaceDetails,
|
|
24
|
+
Seconds,
|
|
25
|
+
SrvRecordValue,
|
|
26
|
+
Time,
|
|
27
|
+
Timer,
|
|
28
|
+
} from "@matter/general";
|
|
29
|
+
import type { MdnsServer } from "./MdnsServer.js";
|
|
30
|
+
|
|
31
|
+
// Same facility as MdnsServer: operators see one mDNS responder component
|
|
32
|
+
const logger = Logger.get("MdnsServer");
|
|
33
|
+
|
|
34
|
+
/** RFC 6762 §6 allows one multicast of a record per second and interface */
|
|
35
|
+
const MULTICAST_INTERVAL = Seconds(1);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* How long interface details stay in use before they are read again, and how long an interface whose peers cache
|
|
39
|
+
* nothing stays unused before its state is dropped. Matches the maximum commissioning window.
|
|
40
|
+
*/
|
|
41
|
+
const INTERFACE_LIFETIME = Minutes(15);
|
|
42
|
+
|
|
43
|
+
/** How long after a failed or empty read of the interface details they are read again */
|
|
44
|
+
const DETAILS_RETRY_INTERVAL = Seconds(10);
|
|
45
|
+
|
|
46
|
+
/** The longest wait between two attempts to send a goodbye that did not leave; the first attempt waits a second */
|
|
47
|
+
const GOODBYE_RETRY_MAXIMUM_INTERVAL = Minutes(1);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The mDNS responder state of one network interface, and the only path by which {@link MdnsServer} sends on it.
|
|
51
|
+
*
|
|
52
|
+
* The state is a record of what peer caches on this interface may hold: each record sent here, with the time its
|
|
53
|
+
* TTL ends and the time of its last multicast answer or goodbye. Every decision reads it, and every send writes
|
|
54
|
+
* it as far as the message reached, see {@link #transmit}:
|
|
55
|
+
*
|
|
56
|
+
* | Decision | Reads |
|
|
57
|
+
* |--------------------------------|-------------------------------------------------------------------------------|
|
|
58
|
+
* | goodbye content | cached records that the current records of the registrations no longer hold |
|
|
59
|
+
* | RFC 6762 §6 one-second rule | last multicast answer of each record; a held record is deferred, not dropped |
|
|
60
|
+
* | RFC 6762 §5.4 quarter-TTL rule | last multicast answer of each record that peers still cache |
|
|
61
|
+
* | end of the interface state | nothing cached or deferred, no goodbye retry waits, unused for 15 minutes |
|
|
62
|
+
*
|
|
63
|
+
* The last multicast of a record is the last multicast that answered a query with it, or its goodbye. As in CHIP,
|
|
64
|
+
* announcements and additional records do not count, and announcements are never held: a querier that clears its
|
|
65
|
+
* cache before it asks, as python-zeroconf does, gets its answer at once after an announcement. RFC 6762 §5.4 and
|
|
66
|
+
* §6 count every multicast; this deviation follows CHIP. Unlike CHIP, a goodbye counts, and an announcement does
|
|
67
|
+
* not end the hold of an earlier answer. Answers and additional records are held by the one-second rule; a goodbye
|
|
68
|
+
* is never held. A record the rule holds back is
|
|
69
|
+
* deferred to the moment its second has passed; all records due then go out in one deferred message under the same
|
|
70
|
+
* rule, so a record held again is deferred again. The address records of one name are held together (RFC 6762
|
|
71
|
+
* §6.2). A held record is not sent when the querier already has it: a multicast answer that carried the record
|
|
72
|
+
* left at or after the query arrived or the record was deferred. A known answer of the querier is not sent either,
|
|
73
|
+
* and a deferred record that its service no longer publishes is dropped. RFC 6762 §6 would also accept
|
|
74
|
+
* dropping a held record, because "a querier that did not receive and cache the previous transmission will retry its
|
|
75
|
+
* request"; deferring costs one more message and spares the querier that retry.
|
|
76
|
+
*
|
|
77
|
+
* Each packet is composed inside a task of one {@link Mutex}: the task decides the content and calls
|
|
78
|
+
* {@link MdnsSocket.send} with no await in between, and the next task starts only after that send settled. So a
|
|
79
|
+
* packet never carries a decision that changed while it waited, and no chunk of an earlier packet follows a later
|
|
80
|
+
* packet. The delays between the packets of one answer happen outside the mutex. Records returned by the
|
|
81
|
+
* generators are never changed. Times come from {@link Time.nowUs}, which is monotonic where the platform provides
|
|
82
|
+
* `performance`.
|
|
83
|
+
*/
|
|
84
|
+
export class InterfaceResponder {
|
|
85
|
+
readonly name: string;
|
|
86
|
+
readonly #owner: InterfaceResponder.Owner;
|
|
87
|
+
readonly #gate: Mutex;
|
|
88
|
+
#details?: NetworkInterfaceDetails;
|
|
89
|
+
#detailsVersion = 0;
|
|
90
|
+
#detailsExpireAt = 0;
|
|
91
|
+
#retryReadAt = 0;
|
|
92
|
+
#reading?: Promise<void>;
|
|
93
|
+
#view?: View;
|
|
94
|
+
/** What peer caches on this interface may hold, keyed by {@link recordKeyOf} */
|
|
95
|
+
readonly #peerCache = new Map<string, PeerCacheEntry>();
|
|
96
|
+
/** Records the RFC 6762 §6 rule held back, keyed by {@link recordKeyOf} */
|
|
97
|
+
readonly #deferred = new Map<string, Deferral>();
|
|
98
|
+
#deferredTimer?: Timer;
|
|
99
|
+
#goodbyeRetry?: { timer: Timer; interval: number };
|
|
100
|
+
#usedAt: number;
|
|
101
|
+
#isListed = true;
|
|
102
|
+
#isClosing = false;
|
|
103
|
+
/** Whether a read failed while no details were known; valid details are never forgotten, so this ends nothing */
|
|
104
|
+
#isDetailsFailing = false;
|
|
105
|
+
/** Set by a multicast that failed or missed an address family; cleared by one that reached every family */
|
|
106
|
+
#isMulticastOutage = false;
|
|
107
|
+
|
|
108
|
+
constructor(name: string, owner: InterfaceResponder.Owner) {
|
|
109
|
+
this.name = name;
|
|
110
|
+
this.#owner = owner;
|
|
111
|
+
this.#gate = new Mutex(this);
|
|
112
|
+
this.#usedAt = Time.nowUs;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
toString() {
|
|
116
|
+
return `mDNS responder on ${this.name}`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The last valid details read, if any. */
|
|
120
|
+
get details() {
|
|
121
|
+
return this.#details;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Whether the details should be read before the next answer or announcement: never read, read longer than
|
|
126
|
+
* {@link INTERFACE_LIFETIME} ago, and no failed read waiting for its retry.
|
|
127
|
+
*/
|
|
128
|
+
get needsDetailsRead() {
|
|
129
|
+
const now = Time.nowUs;
|
|
130
|
+
return this.#detailsExpireAt <= now && this.#retryReadAt <= now;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Whether the last interface listing included this interface. */
|
|
134
|
+
get isListed() {
|
|
135
|
+
return this.#isListed;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
set isListed(isListed: boolean) {
|
|
139
|
+
this.#isListed = isListed;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Forget records whose TTL ended and whose last multicast is more than a second ago. Returns whether this state
|
|
144
|
+
* can go: peers cache nothing sent here, nothing is deferred, no goodbye retry waits, and neither {@link answer}
|
|
145
|
+
* nor {@link publish} ran for {@link INTERFACE_LIFETIME}.
|
|
146
|
+
*/
|
|
147
|
+
prune() {
|
|
148
|
+
const now = Time.nowUs;
|
|
149
|
+
for (const [key, { cachedUntil, lastMulticastAt }] of this.#peerCache) {
|
|
150
|
+
if (cachedUntil <= now && now - (lastMulticastAt ?? -Infinity) >= MULTICAST_INTERVAL) {
|
|
151
|
+
this.#peerCache.delete(key);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return (
|
|
155
|
+
this.#peerCache.size === 0 &&
|
|
156
|
+
this.#deferred.size === 0 &&
|
|
157
|
+
!this.#goodbyeRetry?.timer.isRunning &&
|
|
158
|
+
now - this.#usedAt > INTERFACE_LIFETIME
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Read the details again at the next {@link readDetails}, also within {@link INTERFACE_LIFETIME} or a retry wait,
|
|
164
|
+
* because the network reported that they changed.
|
|
165
|
+
*/
|
|
166
|
+
detailsChanged() {
|
|
167
|
+
this.#detailsExpireAt = 0;
|
|
168
|
+
this.#retryReadAt = 0;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Read the addresses and MAC of this interface; synchronous if the network reports them synchronously.
|
|
173
|
+
* Concurrent reads share one lookup.
|
|
174
|
+
*
|
|
175
|
+
* A read that fails or reports no details never replaces valid details read before: those stay in use, and no
|
|
176
|
+
* read happens again before {@link DETAILS_RETRY_INTERVAL} passed; until then this returns at once. Without
|
|
177
|
+
* earlier details, a failed read throws what the network throws, after logging it: a notice for the first failure,
|
|
178
|
+
* debug for later ones.
|
|
179
|
+
*/
|
|
180
|
+
readDetails(): MaybePromise<void> {
|
|
181
|
+
if (this.#reading !== undefined) {
|
|
182
|
+
return this.#reading;
|
|
183
|
+
}
|
|
184
|
+
if (this.#retryReadAt > Time.nowUs) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
let details;
|
|
188
|
+
try {
|
|
189
|
+
details = this.#owner.socket.network.getIpMac(this.name);
|
|
190
|
+
} catch (error) {
|
|
191
|
+
this.#readFailed(error);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (!MaybePromise.is(details)) {
|
|
195
|
+
this.#setDetails(details);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
return (this.#reading = Promise.resolve(details)
|
|
199
|
+
.then(
|
|
200
|
+
details => this.#setDetails(details),
|
|
201
|
+
error => this.#readFailed(error),
|
|
202
|
+
)
|
|
203
|
+
.finally(() => (this.#reading = undefined)));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
#setDetails(details: NetworkInterfaceDetails | undefined) {
|
|
207
|
+
const now = Time.nowUs;
|
|
208
|
+
if (details === undefined) {
|
|
209
|
+
if (this.#details !== undefined) {
|
|
210
|
+
logger.debug(`Keeping the last details of interface ${this.name}, which reports none now`);
|
|
211
|
+
}
|
|
212
|
+
this.#retryReadAt = now + DETAILS_RETRY_INTERVAL;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (!isDeepEqual(details, this.#details)) {
|
|
216
|
+
this.#details = details;
|
|
217
|
+
this.#detailsVersion++;
|
|
218
|
+
}
|
|
219
|
+
this.#detailsExpireAt = now + INTERFACE_LIFETIME;
|
|
220
|
+
this.#retryReadAt = 0;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Without earlier details, the first failure logs a notice and later ones log at debug level; the error is
|
|
225
|
+
* rethrown, so the caller does not log it again. With earlier details, those stay in use.
|
|
226
|
+
*/
|
|
227
|
+
#readFailed(error: unknown) {
|
|
228
|
+
this.#retryReadAt = Time.nowUs + DETAILS_RETRY_INTERVAL;
|
|
229
|
+
if (this.#details !== undefined) {
|
|
230
|
+
logger.debug(`Keeping the last details of interface ${this.name}, which cannot be read`, error);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (this.#isDetailsFailing) {
|
|
234
|
+
logger.debug(`Details of interface ${this.name} cannot be read`, error);
|
|
235
|
+
} else {
|
|
236
|
+
this.#isDetailsFailing = true;
|
|
237
|
+
logger.notice(`Details of interface ${this.name} cannot be read`, error);
|
|
238
|
+
}
|
|
239
|
+
throw error;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** The names of the records of the current registrations; empty without valid details. */
|
|
243
|
+
names(): ReadonlySet<string> {
|
|
244
|
+
return this.#currentView(false)?.ownedNames ?? new Set();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Answer a query: one packet per service with answers, 20–120 ms apart. Settles once these packets are sent.
|
|
249
|
+
* A failed send is logged and does not stop the next packet. Records the one-second rule holds back are
|
|
250
|
+
* deferred, see the class description.
|
|
251
|
+
*
|
|
252
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc6762#section-6} RFC 6762 §6
|
|
253
|
+
*/
|
|
254
|
+
async answer(message: MdnsSocket.Message) {
|
|
255
|
+
const receivedAt = (this.#usedAt = Time.nowUs);
|
|
256
|
+
const view = this.#currentView();
|
|
257
|
+
if (view === undefined || !message.queries.some(({ name }) => view.ownedNames.has(name.toLowerCase()))) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const visited = new Set<string>();
|
|
262
|
+
let more: boolean | undefined = false;
|
|
263
|
+
do {
|
|
264
|
+
if (more) {
|
|
265
|
+
await Time.sleep("MDNS delay", packetDelay());
|
|
266
|
+
}
|
|
267
|
+
more = await this.#produce(() => this.#sendAnswer(message, visited, receivedAt));
|
|
268
|
+
} while (more);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* In one message, say goodbye to the records that peers may cache here but that the current records of the
|
|
273
|
+
* registrations no longer hold, and announce the named services, or all registered services for "all". A service
|
|
274
|
+
* is announced as well when one of its records replaces a record that gets a goodbye: a unique record (SRV, TXT,
|
|
275
|
+
* A, AAAA) of the same name, type and class, as after a change of the host name, a TXT value or an address. This
|
|
276
|
+
* holds for every publication, a goodbye retry included, while the interface is listed; an interface no longer
|
|
277
|
+
* listed gets only goodbyes. While such a goodbye does not reach every address family, each publication on the
|
|
278
|
+
* interface carries the replacing services again, until peers dropped the old record at the end of its TTL; we
|
|
279
|
+
* accept these repeats because a peer on the failed family would otherwise keep no record of the service.
|
|
280
|
+
*
|
|
281
|
+
* The goodbye goes out only while the current records are known: without valid interface details nothing is
|
|
282
|
+
* sent. Every record that left gets a goodbye with TTL 0. It carries the cache-flush bit only when its type is
|
|
283
|
+
* unique (SRV, TXT, A, AAAA) and the current records hold nothing of its name, type and class (RFC 6762 §10.2);
|
|
284
|
+
* otherwise it carries no bit, so it removes only the old record.
|
|
285
|
+
*
|
|
286
|
+
* Goodbyes and announcements are never held by the one-second rule, as in CHIP and matter.js 0.18; RFC 6762 §6
|
|
287
|
+
* has no such exception. Settles once sent. A failed
|
|
288
|
+
* send is logged like a failed answer; the goodbyes, with the services that replace them, are tried again, see
|
|
289
|
+
* {@link #retryGoodbyes}. Once
|
|
290
|
+
* {@link close} started, rejects with {@link ClosedError}.
|
|
291
|
+
*
|
|
292
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc6762#section-8.3} RFC 6762 §8.3
|
|
293
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc6762#section-10.1} RFC 6762 §10.1
|
|
294
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc6762#section-10.2} RFC 6762 §10.2
|
|
295
|
+
*/
|
|
296
|
+
async publish(services: string[] | "all") {
|
|
297
|
+
if (this.#isClosing) {
|
|
298
|
+
throw new ClosedError(`Cannot publish: ${this} is closed`);
|
|
299
|
+
}
|
|
300
|
+
this.#usedAt = Time.nowUs;
|
|
301
|
+
await this.#gate.produce(() => this.#sendPublication(services));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Stop sending. Deferred records are dropped, and so are answers that wait for the mutex; publications that
|
|
306
|
+
* wait still send their goodbyes. Settles once the last send settled, so it waits for the UDP send in flight.
|
|
307
|
+
*/
|
|
308
|
+
async close() {
|
|
309
|
+
this.#isClosing = true;
|
|
310
|
+
this.#deferredTimer?.stop();
|
|
311
|
+
this.#deferred.clear();
|
|
312
|
+
this.#goodbyeRetry?.timer.stop();
|
|
313
|
+
this.#goodbyeRetry = undefined;
|
|
314
|
+
await this.#gate.close();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** Run {@link task} in the mutex unless closing; resolves to undefined if it did not run. */
|
|
318
|
+
#produce<T>(task: () => PromiseLike<T | undefined>) {
|
|
319
|
+
if (this.#isClosing) {
|
|
320
|
+
return Promise.resolve(undefined);
|
|
321
|
+
}
|
|
322
|
+
return this.#gate.produce(() => (this.#isClosing ? Promise.resolve(undefined) : task()));
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Send the packet for the first service in registration order that has not been visited yet and that has
|
|
327
|
+
* answers. Resolves to whether services remain.
|
|
328
|
+
*/
|
|
329
|
+
#sendAnswer(message: MdnsSocket.Message, visited: Set<string>, receivedAt: number) {
|
|
330
|
+
const view = this.#currentView();
|
|
331
|
+
if (view === undefined) {
|
|
332
|
+
return Promise.resolve(false);
|
|
333
|
+
}
|
|
334
|
+
const { sourceIp, transactionId, queries, answers: knownAnswers } = message;
|
|
335
|
+
const knownKeys = knownAnswers.map(record => ({ key: recordKeyOf(record), ttl: record.ttl }));
|
|
336
|
+
const isKnown = (record: DnsRecord) =>
|
|
337
|
+
knownKeys.some(({ key, ttl }) => ttl > record.ttl / 2 && key === recordKeyOf(record));
|
|
338
|
+
|
|
339
|
+
for (const [service, portRecords] of view.byService) {
|
|
340
|
+
if (visited.has(service)) continue;
|
|
341
|
+
visited.add(service);
|
|
342
|
+
|
|
343
|
+
const answers = uniqueRecords(queries.flatMap(query => queryRecords(query, portRecords))).filter(
|
|
344
|
+
record => !isKnown(record),
|
|
345
|
+
);
|
|
346
|
+
if (answers.length === 0) continue;
|
|
347
|
+
const additionalRecords = additionalRecordsFor(queries, portRecords, answers).filter(
|
|
348
|
+
record => !isKnown(record),
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
const now = Time.nowUs;
|
|
352
|
+
const isUnicast =
|
|
353
|
+
queries.every(query => query.uniCastResponse) &&
|
|
354
|
+
answers.every(answer => this.#sinceCachedMulticast(answer, now) <= answer.ttl / 4);
|
|
355
|
+
let sentAnswers = answers;
|
|
356
|
+
let sentAdditional = additionalRecords;
|
|
357
|
+
if (!isUnicast) {
|
|
358
|
+
const packet = [...answers, ...additionalRecords];
|
|
359
|
+
sentAnswers = this.#holdBack(
|
|
360
|
+
answers,
|
|
361
|
+
now,
|
|
362
|
+
() => receivedAt,
|
|
363
|
+
"answer",
|
|
364
|
+
() => additionalRecords,
|
|
365
|
+
packet,
|
|
366
|
+
);
|
|
367
|
+
sentAdditional = this.#holdBack(
|
|
368
|
+
additionalRecords,
|
|
369
|
+
now,
|
|
370
|
+
() => receivedAt,
|
|
371
|
+
"additional",
|
|
372
|
+
noRecords,
|
|
373
|
+
packet,
|
|
374
|
+
);
|
|
375
|
+
if (sentAnswers.length === 0) continue;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const more = [...view.byService.keys()].some(other => !visited.has(other));
|
|
379
|
+
return this.#transmit(
|
|
380
|
+
{
|
|
381
|
+
messageType: DnsMessageType.Response,
|
|
382
|
+
transactionId,
|
|
383
|
+
answers: sendable(sentAnswers, portRecords, isUnicast),
|
|
384
|
+
additionalRecords: sendable(sentAdditional, portRecords, isUnicast),
|
|
385
|
+
},
|
|
386
|
+
isUnicast ? sourceIp : undefined,
|
|
387
|
+
sentAnswers,
|
|
388
|
+
).then(
|
|
389
|
+
() => more,
|
|
390
|
+
error => {
|
|
391
|
+
this.#sendFailed(error, isUnicast ? sourceIp : undefined);
|
|
392
|
+
return more;
|
|
393
|
+
},
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
return Promise.resolve(false);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* {@link records} without those the one-second rule holds back. The address records of one name form one set
|
|
402
|
+
* (RFC 6762 §6.2) across {@link packet}, the records that may go in the same packet in either section: when one of
|
|
403
|
+
* them is held, all of them wait for the latest one's second. A held record is
|
|
404
|
+
* deferred unless a multicast answer that carried it left at or after its {@link sinceOf} time. A deferred answer
|
|
405
|
+
* remembers its {@link additionalOf} records, so the deferred packet carries what this packet would have carried.
|
|
406
|
+
*/
|
|
407
|
+
#holdBack(
|
|
408
|
+
records: DnsRecord[],
|
|
409
|
+
now: number,
|
|
410
|
+
sinceOf: (record: DnsRecord) => number,
|
|
411
|
+
section: Deferral["section"],
|
|
412
|
+
additionalOf: (record: DnsRecord) => DnsRecord[],
|
|
413
|
+
packet: DnsRecord[],
|
|
414
|
+
) {
|
|
415
|
+
const heldUntil = new Map<DnsRecord, number>();
|
|
416
|
+
for (const record of records) {
|
|
417
|
+
const until = this.#heldUntil(record);
|
|
418
|
+
if (now < until) {
|
|
419
|
+
heldUntil.set(record, until);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
for (const addressSet of addressSetsOf(packet)) {
|
|
423
|
+
const until = Math.max(...addressSet.map(record => this.#heldUntil(record)));
|
|
424
|
+
if (now < until) {
|
|
425
|
+
for (const record of addressSet) {
|
|
426
|
+
if (records.includes(record)) {
|
|
427
|
+
heldUntil.set(record, until);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return records.filter(record => {
|
|
433
|
+
const until = heldUntil.get(record);
|
|
434
|
+
if (until === undefined) {
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
const since = sinceOf(record);
|
|
438
|
+
if (!this.#isDeliveredSince(record, since)) {
|
|
439
|
+
this.#defer(record, section, since, additionalOf(record), until);
|
|
440
|
+
}
|
|
441
|
+
return false;
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
#sendPublication(services: string[] | "all") {
|
|
446
|
+
const view = this.#currentView();
|
|
447
|
+
if (view === undefined) {
|
|
448
|
+
return Promise.resolve();
|
|
449
|
+
}
|
|
450
|
+
const now = Time.nowUs;
|
|
451
|
+
const goodbye = this.#goodbyesFor(view, now);
|
|
452
|
+
|
|
453
|
+
const replaced = new Set(
|
|
454
|
+
this.#isListed
|
|
455
|
+
? goodbye
|
|
456
|
+
.filter(record => DnsRecordType.isUnique(record.recordType) && view.setKeys.has(setKeyOf(record)))
|
|
457
|
+
.map(setKeyOf)
|
|
458
|
+
: [],
|
|
459
|
+
);
|
|
460
|
+
const complete = new Array<DnsRecord>();
|
|
461
|
+
if (!this.#isClosing) {
|
|
462
|
+
for (const [service, records] of view.byService) {
|
|
463
|
+
if (
|
|
464
|
+
services === "all" ||
|
|
465
|
+
services.includes(service) ||
|
|
466
|
+
records.some(record => replaced.has(setKeyOf(record)))
|
|
467
|
+
) {
|
|
468
|
+
complete.push(...records);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
const announced = uniqueRecords(complete);
|
|
473
|
+
|
|
474
|
+
if (!goodbye.length && !announced.length) {
|
|
475
|
+
this.#stopGoodbyeRetry();
|
|
476
|
+
return Promise.resolve();
|
|
477
|
+
}
|
|
478
|
+
// RFC 6762 §8.3: announcements carry all records in the answer section. Goodbyes first: CHIP's resolver
|
|
479
|
+
// applies every TXT record of a packet in order, TTL 0 included, so the new TXT record must come last
|
|
480
|
+
return this.#transmit({
|
|
481
|
+
messageType: DnsMessageType.Response,
|
|
482
|
+
answers: [...goodbye, ...sendable(announced, complete, false)],
|
|
483
|
+
}).then(
|
|
484
|
+
() => this.#settleGoodbyes(),
|
|
485
|
+
error => {
|
|
486
|
+
this.#sendFailed(error);
|
|
487
|
+
this.#settleGoodbyes();
|
|
488
|
+
},
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* The goodbyes for the records peers may cache here that {@link view} no longer holds, see {@link publish}.
|
|
494
|
+
*
|
|
495
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc6762#section-10.2} RFC 6762 §10.2
|
|
496
|
+
*/
|
|
497
|
+
#goodbyesFor(view: View, now: number) {
|
|
498
|
+
const goodbye = new Array<DnsRecord>();
|
|
499
|
+
for (const [key, { record, cachedUntil }] of this.#peerCache) {
|
|
500
|
+
if (cachedUntil <= now || view.byKey.has(key)) {
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
goodbye.push({
|
|
504
|
+
...record,
|
|
505
|
+
ttl: Instant,
|
|
506
|
+
flushCache: DnsRecordType.isUnique(record.recordType) && !view.setKeys.has(setKeyOf(record)),
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
return goodbye;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Send the goodbyes again that peers may still need here, with the services that replace them, see
|
|
514
|
+
* {@link publish}, and with no other publication needed: first a second later,
|
|
515
|
+
* then at twice the interval up to {@link GOODBYE_RETRY_MAXIMUM_INTERVAL}. A retry that waits keeps its schedule.
|
|
516
|
+
* {@link #settleGoodbyes} ends the retry, and the next one starts at a second again, once no goodbye is needed.
|
|
517
|
+
* Stops on {@link close}.
|
|
518
|
+
*/
|
|
519
|
+
#retryGoodbyes() {
|
|
520
|
+
if (this.#isClosing || this.#goodbyeRetry?.timer.isRunning) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
const interval = Math.min(
|
|
524
|
+
(this.#goodbyeRetry?.interval ?? MULTICAST_INTERVAL / 2) * 2,
|
|
525
|
+
GOODBYE_RETRY_MAXIMUM_INTERVAL,
|
|
526
|
+
);
|
|
527
|
+
const timer = Time.getTimer("MDNS goodbye retry", Millis(interval), () =>
|
|
528
|
+
this.#gate.run(() => this.#sendPublication([])),
|
|
529
|
+
);
|
|
530
|
+
this.#goodbyeRetry = { timer, interval };
|
|
531
|
+
timer.start();
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** Try the goodbyes again that peers may still need here, or end the retry when none remain. */
|
|
535
|
+
#settleGoodbyes() {
|
|
536
|
+
const view = this.#currentView();
|
|
537
|
+
if (view !== undefined && this.#goodbyesFor(view, Time.nowUs).length) {
|
|
538
|
+
this.#retryGoodbyes();
|
|
539
|
+
} else {
|
|
540
|
+
this.#stopGoodbyeRetry();
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
#stopGoodbyeRetry() {
|
|
545
|
+
this.#goodbyeRetry?.timer.stop();
|
|
546
|
+
this.#goodbyeRetry = undefined;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Send the deferred records whose second has passed, as one packet, under the same {@link #holdBack} decision as
|
|
551
|
+
* the packet that deferred them: a record held again is deferred again, and a record a multicast answer carried at
|
|
552
|
+
* or after its deferral's {@link Deferral.since} time is not sent. A record its service no longer publishes is
|
|
553
|
+
* dropped. A deferred answer brings the additional records its query would have carried.
|
|
554
|
+
*/
|
|
555
|
+
#sendDeferred() {
|
|
556
|
+
const now = Time.nowUs;
|
|
557
|
+
const published = this.#currentView()?.byKey ?? new Map<string, DnsRecord>();
|
|
558
|
+
const deferrals = [...this.#deferred];
|
|
559
|
+
this.#deferred.clear();
|
|
560
|
+
|
|
561
|
+
const answers = new Array<DnsRecord>();
|
|
562
|
+
const additionalRecords = new Array<DnsRecord>();
|
|
563
|
+
const sinceOf = new Map<DnsRecord, number>();
|
|
564
|
+
const additionalOf = new Map<DnsRecord, DnsRecord[]>();
|
|
565
|
+
for (const [key, { section, since, additionalKeys }] of deferrals) {
|
|
566
|
+
const record = published.get(key);
|
|
567
|
+
if (record === undefined) continue;
|
|
568
|
+
sinceOf.set(record, since);
|
|
569
|
+
if (section === "additional") {
|
|
570
|
+
additionalRecords.push(record);
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
answers.push(record);
|
|
574
|
+
const additional = new Array<DnsRecord>();
|
|
575
|
+
for (const additionalKey of additionalKeys) {
|
|
576
|
+
const additionalRecord = published.get(additionalKey);
|
|
577
|
+
if (additionalRecord !== undefined) {
|
|
578
|
+
additional.push(additionalRecord);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
additionalOf.set(record, additional);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const timeOf = (record: DnsRecord) => sinceOf.get(record) ?? now;
|
|
585
|
+
const packet = uniqueRecords([...answers, ...additionalRecords, ...[...additionalOf.values()].flat()]);
|
|
586
|
+
const sentAnswers = this.#holdBack(
|
|
587
|
+
answers,
|
|
588
|
+
now,
|
|
589
|
+
timeOf,
|
|
590
|
+
"answer",
|
|
591
|
+
record => additionalOf.get(record) ?? [],
|
|
592
|
+
packet,
|
|
593
|
+
);
|
|
594
|
+
const answerKeys = new Set(sentAnswers.map(record => recordKeyOf(record)));
|
|
595
|
+
for (const answer of sentAnswers) {
|
|
596
|
+
for (const additional of additionalOf.get(answer) ?? []) {
|
|
597
|
+
if (!sinceOf.has(additional)) {
|
|
598
|
+
sinceOf.set(additional, timeOf(answer));
|
|
599
|
+
}
|
|
600
|
+
additionalRecords.push(additional);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
const sentAdditional = this.#holdBack(
|
|
604
|
+
uniqueRecords(additionalRecords).filter(record => !answerKeys.has(recordKeyOf(record))),
|
|
605
|
+
now,
|
|
606
|
+
timeOf,
|
|
607
|
+
"additional",
|
|
608
|
+
noRecords,
|
|
609
|
+
uniqueRecords([...sentAnswers, ...additionalRecords]),
|
|
610
|
+
);
|
|
611
|
+
this.#scheduleDeferred();
|
|
612
|
+
|
|
613
|
+
if (!sentAnswers.length && !sentAdditional.length) {
|
|
614
|
+
return Promise.resolve();
|
|
615
|
+
}
|
|
616
|
+
const complete = [...published.values()];
|
|
617
|
+
const answerSection = sentAnswers.length ? sentAnswers : sentAdditional;
|
|
618
|
+
return this.#transmit(
|
|
619
|
+
{
|
|
620
|
+
messageType: DnsMessageType.Response,
|
|
621
|
+
answers: sendable(answerSection, complete, false),
|
|
622
|
+
additionalRecords: sentAnswers.length ? sendable(sentAdditional, complete, false) : [],
|
|
623
|
+
},
|
|
624
|
+
undefined,
|
|
625
|
+
answerSection,
|
|
626
|
+
).catch(error => this.#sendFailed(error));
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/** When the RFC 6762 §6 rule stops holding {@link record} back; a goodbye counts as a multicast. */
|
|
630
|
+
#heldUntil(record: DnsRecord) {
|
|
631
|
+
return (this.#peerCache.get(recordKeyOf(record))?.lastMulticastAt ?? -Infinity) + MULTICAST_INTERVAL;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/** Whether a multicast answer that carried {@link record}, not its goodbye, left at or after {@link since}. */
|
|
635
|
+
#isDeliveredSince(record: DnsRecord, since: number) {
|
|
636
|
+
const entry = this.#peerCache.get(recordKeyOf(record));
|
|
637
|
+
return entry !== undefined && !entry.lastMulticastIsGoodbye && (entry.lastMulticastAt ?? -Infinity) >= since;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/** Time since the last multicast answer that carried {@link record}, or infinity when peers may not cache it. */
|
|
641
|
+
#sinceCachedMulticast(record: DnsRecord, now: number) {
|
|
642
|
+
const entry = this.#peerCache.get(recordKeyOf(record));
|
|
643
|
+
if (
|
|
644
|
+
entry === undefined ||
|
|
645
|
+
entry.lastMulticastAt === undefined ||
|
|
646
|
+
entry.lastMulticastIsGoodbye ||
|
|
647
|
+
entry.cachedUntil <= now
|
|
648
|
+
) {
|
|
649
|
+
return Infinity;
|
|
650
|
+
}
|
|
651
|
+
return now - entry.lastMulticastAt;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
#defer(
|
|
655
|
+
record: DnsRecord,
|
|
656
|
+
section: Deferral["section"],
|
|
657
|
+
since: number,
|
|
658
|
+
additionalRecords: DnsRecord[],
|
|
659
|
+
dueAt: number,
|
|
660
|
+
) {
|
|
661
|
+
const key = recordKeyOf(record);
|
|
662
|
+
const deferral = this.#deferred.get(key);
|
|
663
|
+
if (deferral === undefined) {
|
|
664
|
+
this.#deferred.set(key, {
|
|
665
|
+
section,
|
|
666
|
+
dueAt,
|
|
667
|
+
since,
|
|
668
|
+
additionalKeys: new Set(additionalRecords.map(additional => recordKeyOf(additional))),
|
|
669
|
+
});
|
|
670
|
+
} else {
|
|
671
|
+
if (section === "answer") {
|
|
672
|
+
deferral.section = "answer";
|
|
673
|
+
}
|
|
674
|
+
deferral.dueAt = Math.max(deferral.dueAt, dueAt);
|
|
675
|
+
deferral.since = Math.min(deferral.since, since);
|
|
676
|
+
for (const additional of additionalRecords) {
|
|
677
|
+
deferral.additionalKeys.add(recordKeyOf(additional));
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
this.#scheduleDeferred();
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
#scheduleDeferred() {
|
|
684
|
+
this.#deferredTimer?.stop();
|
|
685
|
+
this.#deferredTimer = undefined;
|
|
686
|
+
if (!this.#deferred.size) {
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
const dueAt = Math.min(...[...this.#deferred.values()].map(({ dueAt }) => dueAt));
|
|
690
|
+
this.#deferredTimer = Time.getTimer("MDNS deferred answer", Millis(Math.max(0, dueAt - Time.nowUs)), () =>
|
|
691
|
+
this.#gate.run(() => this.#sendDeferred()),
|
|
692
|
+
).start();
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Logs a failed send, see {@link #multicastMissed}: peers trigger answers and goodbyes are sent again, so only the
|
|
697
|
+
* first failure of an outage logs a notice. A failed unicast answer logs at debug level and does not start an
|
|
698
|
+
* outage.
|
|
699
|
+
*/
|
|
700
|
+
#sendFailed(error: unknown, unicastTarget?: string) {
|
|
701
|
+
if (unicastTarget !== undefined) {
|
|
702
|
+
logger.debug(`Failed to send mDNS response to ${unicastTarget}`, error);
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
this.#multicastMissed(`mDNS messages on interface ${this.name} cannot be sent`, error);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Logs a multicast that failed or reached only some address families. Both count as one outage, which only a
|
|
710
|
+
* multicast that reached every family ends, see {@link #transmit}. The first multicast of an outage logs a
|
|
711
|
+
* notice, so a peer that makes the reach change between "some" and failed cannot repeat it. Later ones log at
|
|
712
|
+
* debug level, and so does every one while closing or after the interface left the listing.
|
|
713
|
+
*/
|
|
714
|
+
#multicastMissed(text: string, error: unknown) {
|
|
715
|
+
if (this.#isMulticastOutage || this.#isClosing || !this.#isListed) {
|
|
716
|
+
logger.debug(text, error);
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
this.#isMulticastOutage = true;
|
|
720
|
+
logger.notice(text, error);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Send records, always on this interface: without an interface the socket lists interfaces first, an await
|
|
725
|
+
* before the send. Resolves to how far the message reached, see {@link MdnsSocket.send}.
|
|
726
|
+
*
|
|
727
|
+
* | Reach | Records with TTL | Goodbyes |
|
|
728
|
+
* |------------------------------|----------------------|-------------------------------------------------|
|
|
729
|
+
* | every address family | peers may cache them | end the record at once |
|
|
730
|
+
* | some address families | peers may cache them | count as its last multicast, the record stays |
|
|
731
|
+
* | none (no usable family) | change nothing | change nothing |
|
|
732
|
+
* | rejected (error, no address) | change nothing | change nothing |
|
|
733
|
+
*
|
|
734
|
+
* A message that reached some families counts as reaching each of its records, also those in a datagram that
|
|
735
|
+
* failed on every family: a peer may have got any of them. A deferred answer that missed a peer then waits for
|
|
736
|
+
* the querier's retry, which RFC 6762 §6 accepts. A record that stays here gets its goodbye again, see
|
|
737
|
+
* {@link #settleGoodbyes}.
|
|
738
|
+
*
|
|
739
|
+
* A record peers may cache is cached until its TTL after the time the send was called, which is earlier than the
|
|
740
|
+
* wire time by the send latency. Of a multicast, only goodbyes and the records in {@link answered}, the answers to
|
|
741
|
+
* a query, count as the last multicast of their record, see the class description.
|
|
742
|
+
*/
|
|
743
|
+
#transmit(
|
|
744
|
+
message: Partial<DnsMessage> & { messageType: DnsMessageType },
|
|
745
|
+
unicastTarget?: string,
|
|
746
|
+
answered: DnsRecord[] = [],
|
|
747
|
+
) {
|
|
748
|
+
const sentAt = Time.nowUs;
|
|
749
|
+
const isMulticast = unicastTarget === undefined;
|
|
750
|
+
const answeredKeys = new Set(answered.map(record => recordKeyOf(record)));
|
|
751
|
+
return this.#owner.socket.send(message, this.name, unicastTarget).then(reach => {
|
|
752
|
+
if (reach === undefined || reach.kind === "none") {
|
|
753
|
+
return reach;
|
|
754
|
+
}
|
|
755
|
+
for (const record of [...(message.answers ?? []), ...(message.additionalRecords ?? [])]) {
|
|
756
|
+
const key = recordKeyOf(record);
|
|
757
|
+
const entry = this.#peerCache.get(key);
|
|
758
|
+
if (record.ttl === 0 && reach.kind === "some") {
|
|
759
|
+
if (entry !== undefined) {
|
|
760
|
+
entry.lastMulticastAt = sentAt;
|
|
761
|
+
entry.lastMulticastIsGoodbye = true;
|
|
762
|
+
}
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
const isCounted = isMulticast && (record.ttl === 0 || answeredKeys.has(key));
|
|
766
|
+
this.#peerCache.set(key, {
|
|
767
|
+
record,
|
|
768
|
+
cachedUntil: sentAt + record.ttl,
|
|
769
|
+
lastMulticastAt: isCounted ? sentAt : entry?.lastMulticastAt,
|
|
770
|
+
lastMulticastIsGoodbye: isCounted ? record.ttl === 0 : entry?.lastMulticastIsGoodbye,
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
if (!isMulticast) {
|
|
774
|
+
if (reach.kind === "some") {
|
|
775
|
+
logger.debug(`Failed to send part of mDNS response to ${unicastTarget}`, reach.failure);
|
|
776
|
+
}
|
|
777
|
+
return reach;
|
|
778
|
+
}
|
|
779
|
+
if (reach.kind === "all") {
|
|
780
|
+
this.#isMulticastOutage = false;
|
|
781
|
+
} else {
|
|
782
|
+
this.#multicastMissed(
|
|
783
|
+
`mDNS messages on interface ${this.name} reach only some address families`,
|
|
784
|
+
reach.failure,
|
|
785
|
+
);
|
|
786
|
+
}
|
|
787
|
+
return reach;
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* The records of the current registrations, also keyed by {@link recordKeyOf}; rebuilt when the registrations,
|
|
793
|
+
* details or host name change. A rebuild tells the owner, whose socket names depend on the view, unless
|
|
794
|
+
* {@link notify} is false.
|
|
795
|
+
*/
|
|
796
|
+
#currentView(notify = true): View | undefined {
|
|
797
|
+
const details = this.#details;
|
|
798
|
+
if (details === undefined) {
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
const { generation, registrations } = this.#owner;
|
|
802
|
+
const hostname = this.#owner.hostnameFor(details);
|
|
803
|
+
const view = this.#view;
|
|
804
|
+
if (
|
|
805
|
+
view?.generation === generation &&
|
|
806
|
+
view.detailsVersion === this.#detailsVersion &&
|
|
807
|
+
view.hostname === hostname
|
|
808
|
+
) {
|
|
809
|
+
return view;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
const byService = new Map<string, DnsRecord[]>();
|
|
813
|
+
const byKey = new Map<string, DnsRecord>();
|
|
814
|
+
const setKeys = new Set<string>();
|
|
815
|
+
const ownedNames = new Set<string>();
|
|
816
|
+
for (const [service, { generator }] of registrations) {
|
|
817
|
+
const records = generator(this.name, details, hostname);
|
|
818
|
+
byService.set(service, records);
|
|
819
|
+
for (const record of records) {
|
|
820
|
+
byKey.set(recordKeyOf(record), record);
|
|
821
|
+
setKeys.add(setKeyOf(record));
|
|
822
|
+
ownedNames.add(record.name.toLowerCase());
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
this.#view = {
|
|
826
|
+
generation,
|
|
827
|
+
detailsVersion: this.#detailsVersion,
|
|
828
|
+
hostname,
|
|
829
|
+
byService,
|
|
830
|
+
byKey,
|
|
831
|
+
setKeys,
|
|
832
|
+
ownedNames,
|
|
833
|
+
};
|
|
834
|
+
if (notify) {
|
|
835
|
+
this.#owner.viewChanged();
|
|
836
|
+
}
|
|
837
|
+
return this.#view;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
export namespace InterfaceResponder {
|
|
842
|
+
/** What an {@link InterfaceResponder} reads from the {@link MdnsServer} that owns it. */
|
|
843
|
+
export interface Owner {
|
|
844
|
+
readonly socket: MdnsSocket;
|
|
845
|
+
|
|
846
|
+
/** The registered services in registration order. */
|
|
847
|
+
readonly registrations: ReadonlyMap<string, { readonly generator: MdnsServer.RecordGenerator }>;
|
|
848
|
+
|
|
849
|
+
/** Changes with every change of {@link registrations} and every refresh of a registration. */
|
|
850
|
+
readonly generation: number;
|
|
851
|
+
|
|
852
|
+
/** The host name to publish on an interface with {@link details}. */
|
|
853
|
+
hostnameFor(details: NetworkInterfaceDetails): string;
|
|
854
|
+
|
|
855
|
+
/** Called after the records of an interface were generated again, so their names may differ. */
|
|
856
|
+
viewChanged(): void;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
interface PeerCacheEntry {
|
|
861
|
+
record: DnsRecord;
|
|
862
|
+
cachedUntil: number;
|
|
863
|
+
lastMulticastAt?: number;
|
|
864
|
+
|
|
865
|
+
/** Whether the last multicast was the record's goodbye, also one that left on only some address families */
|
|
866
|
+
lastMulticastIsGoodbye?: boolean;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
interface Deferral {
|
|
870
|
+
section: "answer" | "additional";
|
|
871
|
+
dueAt: number;
|
|
872
|
+
|
|
873
|
+
/** A multicast that carried the record at or after this time reached the peers; the record is not sent then */
|
|
874
|
+
since: number;
|
|
875
|
+
|
|
876
|
+
/** The additional records the packet that deferred an answer would have carried */
|
|
877
|
+
additionalKeys: Set<string>;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
interface View {
|
|
881
|
+
generation: number;
|
|
882
|
+
detailsVersion: number;
|
|
883
|
+
hostname: string;
|
|
884
|
+
byService: Map<string, DnsRecord[]>;
|
|
885
|
+
byKey: Map<string, DnsRecord>;
|
|
886
|
+
|
|
887
|
+
/** The {@link setKeyOf} of each record */
|
|
888
|
+
setKeys: Set<string>;
|
|
889
|
+
|
|
890
|
+
/** Lower-cased names of records we own on this interface - used to fast-reject unrelated LAN queries. */
|
|
891
|
+
ownedNames: Set<string>;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
function noRecords() {
|
|
895
|
+
return new Array<DnsRecord>();
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
/** The address records among {@link records}, grouped by name: the unit of the RFC 6762 §6 hold (§6.2). */
|
|
899
|
+
function addressSetsOf(records: DnsRecord[]) {
|
|
900
|
+
const sets = new Map<string, DnsRecord[]>();
|
|
901
|
+
for (const record of records) {
|
|
902
|
+
if (record.recordType === DnsRecordType.A || record.recordType === DnsRecordType.AAAA) {
|
|
903
|
+
const name = record.name.toLowerCase();
|
|
904
|
+
sets.set(name, [...(sets.get(name) ?? []), record]);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
return [...sets.values()];
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
/** The additional records for {@link answers}: none for an address query, else the other non-PTR records. */
|
|
911
|
+
function additionalRecordsFor(queries: Question[], records: DnsRecord[], answers: DnsRecord[]) {
|
|
912
|
+
if (queries.every(({ recordType }) => recordType === DnsRecordType.A || recordType === DnsRecordType.AAAA)) {
|
|
913
|
+
return [];
|
|
914
|
+
}
|
|
915
|
+
return records.filter(record => !answers.includes(record) && record.recordType !== DnsRecordType.PTR);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
type Question = { name: string; recordType: DnsRecordType };
|
|
919
|
+
|
|
920
|
+
function packetDelay() {
|
|
921
|
+
return Millis(20 + Math.floor(Math.random() * 100));
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
function queryRecords({ name, recordType }: Question, records: DnsRecord[]) {
|
|
925
|
+
// DNS names are case-insensitive per RFC 6762 §16 / RFC 1035 §2.3.3.
|
|
926
|
+
const queryName = name.toLowerCase();
|
|
927
|
+
if (recordType === DnsRecordType.ANY) {
|
|
928
|
+
return records.filter(record => record.name.toLowerCase() === queryName);
|
|
929
|
+
} else {
|
|
930
|
+
return records.filter(record => record.name.toLowerCase() === queryName && record.recordType === recordType);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Prepares records for the wire, clearing the cache-flush bit wherever we cannot honor what it claims.
|
|
936
|
+
*
|
|
937
|
+
* The bit says the receiver may drop everything else it holds for the name and type, which is only true if this
|
|
938
|
+
* response carries that whole set — suppression and rate limiting both remove records before we get here. A legacy
|
|
939
|
+
* resolver, which we cannot distinguish because the source port does not reach us, must never see the bit at all, so
|
|
940
|
+
* a unicast response omits it.
|
|
941
|
+
*
|
|
942
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc6762#section-10.2} RFC 6762 §10.2
|
|
943
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc6762#section-6.7} RFC 6762 §6.7
|
|
944
|
+
*/
|
|
945
|
+
function sendable(sent: DnsRecord[], complete: DnsRecord[], isUnicast: boolean) {
|
|
946
|
+
if (isUnicast) {
|
|
947
|
+
return sent.map(record => (record.flushCache ? { ...record, flushCache: false } : record));
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
if (!sent.some(record => record.flushCache)) {
|
|
951
|
+
return sent;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
const sentSizes = setSizes(sent);
|
|
955
|
+
const completeSizes = setSizes(uniqueRecords(complete));
|
|
956
|
+
|
|
957
|
+
return sent.map(record =>
|
|
958
|
+
record.flushCache && (sentSizes.get(setKeyOf(record)) ?? 0) < (completeSizes.get(setKeyOf(record)) ?? 0)
|
|
959
|
+
? { ...record, flushCache: false }
|
|
960
|
+
: record,
|
|
961
|
+
);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
/** Identifies the record set a record belongs to: RFC 6762 scopes the cache-flush bit to one name, type and class. */
|
|
965
|
+
function setKeyOf(record: DnsRecord) {
|
|
966
|
+
return `${record.recordType}-${record.recordClass}-${record.name.toLowerCase()}`;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
function setSizes(records: DnsRecord[]) {
|
|
970
|
+
const sizes = new Map<string, number>();
|
|
971
|
+
for (const record of records) {
|
|
972
|
+
const key = setKeyOf(record);
|
|
973
|
+
sizes.set(key, (sizes.get(key) ?? 0) + 1);
|
|
974
|
+
}
|
|
975
|
+
return sizes;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
/** {@link records} with each resource record once, in first-seen order. */
|
|
979
|
+
function uniqueRecords(records: DnsRecord[]) {
|
|
980
|
+
const seen = new Set<string>();
|
|
981
|
+
return records.filter(record => {
|
|
982
|
+
const key = recordKeyOf(record);
|
|
983
|
+
if (seen.has(key)) {
|
|
984
|
+
return false;
|
|
985
|
+
}
|
|
986
|
+
seen.add(key);
|
|
987
|
+
return true;
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
const recordKeys = new WeakMap<DnsRecord, string>();
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* Identifies a resource record by its name, rrtype, rrclass and rdata, the fields RFC 6762 §10.1 names for a goodbye.
|
|
995
|
+
* Names, in the record and inside PTR and SRV rdata, compare without case (§16); the rdata otherwise compares as
|
|
996
|
+
* encoded on the wire, so TTL and the cache-flush bit do not count. The one identity for the peer cache, the goodbye
|
|
997
|
+
* and known-answer suppression.
|
|
998
|
+
*
|
|
999
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc6762#section-10.1} RFC 6762 §10.1
|
|
1000
|
+
*/
|
|
1001
|
+
function recordKeyOf(record: DnsRecord) {
|
|
1002
|
+
let key = recordKeys.get(record);
|
|
1003
|
+
if (key === undefined) {
|
|
1004
|
+
key = Bytes.toHex(
|
|
1005
|
+
DnsCodec.encodeRecord({
|
|
1006
|
+
...record,
|
|
1007
|
+
name: record.name.toLowerCase(),
|
|
1008
|
+
value: canonicalValueOf(record),
|
|
1009
|
+
ttl: Instant,
|
|
1010
|
+
flushCache: false,
|
|
1011
|
+
}),
|
|
1012
|
+
);
|
|
1013
|
+
recordKeys.set(record, key);
|
|
1014
|
+
}
|
|
1015
|
+
return key;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
function canonicalValueOf({ recordType, value }: DnsRecord) {
|
|
1019
|
+
switch (recordType) {
|
|
1020
|
+
case DnsRecordType.PTR:
|
|
1021
|
+
return typeof value === "string" ? value.toLowerCase() : value;
|
|
1022
|
+
case DnsRecordType.SRV:
|
|
1023
|
+
return isSrvValue(value) ? { ...value, target: value.target.toLowerCase() } : value;
|
|
1024
|
+
default:
|
|
1025
|
+
return value;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
function isSrvValue(value: unknown): value is SrvRecordValue {
|
|
1030
|
+
return typeof value === "object" && value !== null && "target" in value && typeof value.target === "string";
|
|
1031
|
+
}
|