Skip to content

Commit

Permalink
📦 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaubee committed Dec 18, 2024
1 parent 64328ec commit 65b991a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@
dist/
node_modules/
pnpm-lock.yaml
dns-packet
ip-codec
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dweb/cloud",
"version": "0.3.3",
"version": "0.4.0",
"tasks": {
"gateway": "npx tsx ./src/gateway.demo.mts",
"mdns": "npx tsx ./src/mdns.demo.mts"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"dependencies": {
"@bfmeta/sign-util": "^1.1.1",
"@gaubee/util": "npm:@jsr/gaubee__util@^0.19.0",
"@types/dns-packet": "^5.6.5",
"dns-packet": "^5.6.1",
"import-meta-ponyfill": "^3.2.1",
"zod": "^3.23.8"
},
"devDependencies": {
"@std/cli": "npm:@jsr/std__cli@^1.0.6",
"@types/dns-packet": "^5.6.5"
"@std/cli": "npm:@jsr/std__cli@^1.0.6"
}
}
9 changes: 7 additions & 2 deletions src/mdns/server.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { pureEvent } from "@gaubee/util";
import type { Question, SrvAnswer, TxtAnswer } from "dns-packet";
import { multicastDNS, type mDNS } from "../multicast-dns/index.mts";
import {
multicastDNS,
type mDNS,
type Question,
type SrvAnswer,
type TxtAnswer,
} from "../multicast-dns/index.mts";
import { Buffer } from "node:buffer";
import { HealthChecker } from "./health.mts";
import { getWlanIpv4List } from "./network.mts";
Expand Down
6 changes: 3 additions & 3 deletions src/mdns/types.mts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export interface ServiceHealth {
}

// 从multicast-dns导入类型
import type { ResponsePacket, QueryPacket } from "multicast-dns";
import type { mDNS } from "../multicast-dns/index.mts";

// 远程信息接口
export interface RemoteInfo {
Expand All @@ -86,8 +86,8 @@ export interface RemoteInfo {

// 事件类型定义
export interface MdnsEvents {
'response': (response: ResponsePacket) => void; // 收到响应时触发
'query': (query: QueryPacket, rinfo: RemoteInfo) => void; // 收到查询时触发
'response': (response: mDNS.ResponsePacket) => void; // 收到响应时触发
'query': (query: mDNS.QueryPacket, rinfo: RemoteInfo) => void; // 收到查询时触发
'error': (error: Error) => void; // 发生错误时触发
'ready': () => void; // 服务就绪时触发
'service-discovery': (service: ServiceDiscovery) => void; // 发现新服务时触发
Expand Down
13 changes: 8 additions & 5 deletions src/multicast-dns/index.mts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { func_remember } from "@gaubee/util";
import packet, { type Question, type RecordType } from "dns-packet";
import packet from "dns-packet";
import dgram from "node:dgram";
import events from "node:events";
import cluster from "node:cluster";
import os from "node:os";
import type { mDNS } from "./types.mts";
export * from "./types.mts";
import type { mDNS } from "./mdns.d.mts";
import type { Question, RecordType, DecodedPacket } from "dns-packet";
import type { Buffer } from "node:buffer";
export * from "./mdns.d.mts";
export * from "dns-packet";

const noop = () => {};

Expand Down Expand Up @@ -41,7 +44,7 @@ export function multicastDNS(opts: mDNS.Options = {}) {
});

socket.on("message", function (message, rinfo) {
let packet_msg: packet.DecodedPacket;
let packet_msg: DecodedPacket;
try {
packet_msg = packet.decode(message);
} catch (err) {
Expand Down Expand Up @@ -103,7 +106,7 @@ export function multicastDNS(opts: mDNS.Options = {}) {
function onbind(err: Error | null) {
if (destroyed) return cb(null);
if (err) return cb(err);
const message = packet.encode(value);
const message: Buffer = packet.encode(value);
socket.send(
message,
0,
Expand Down
File renamed without changes.

0 comments on commit 65b991a

Please sign in to comment.