Skip to content

Commit 9f8c7ca

Browse files
committed
got -> fetch, remove dns cache
1 parent ea4163a commit 9f8c7ca

File tree

6 files changed

+113
-82
lines changed

6 files changed

+113
-82
lines changed

README.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ Edit Settings by environment variables or by command line arguments.
8484
--uuid=<uuid> UUID for stats tracking.
8585
[env: UUID]
8686
87-
--no-dns-cache Disable DNS cache
88-
[env: NO_DNS_CACHE]
89-
9087
--anonymous Do not send platform info to the server.
9188
[env: HIDE]
9289
@@ -96,17 +93,16 @@ Edit Settings by environment variables or by command line arguments.
9693

9794
#### ENV:
9895

99-
| ENV | Default | Document |
100-
| ------------ | ------------------------ | ------------------------------------------------------------ |
101-
| URL | `wss://cluster.vtbs.moe` | Upstream URL |
102-
| INTERVAL | `1280` | Task interval in ms |
103-
| LIMIT | `Infinity` | Live room relay WebSocket connections |
104-
| UUID | `undefined` | stats tracking |
105-
| NO_DNS_CACHE | `false` * | Disable internal DNS cache |
106-
| HIDE | `false` * | hide all extra information including platform, client version, Node.js runtime version, docker status ** |
107-
| NICKNAME | `undefined` | A optional nickname to display on statistics board (in progress). |
108-
| docker | Depends | Is Docker environment? |
109-
| VERBOSE | `false` * | Verbose log |
96+
| ENV | Default | Document |
97+
| -------- | ------------------------ | ------------------------------------------------------------ |
98+
| URL | `wss://cluster.vtbs.moe` | Upstream URL |
99+
| INTERVAL | `1280` | Task interval in ms |
100+
| LIMIT | `Infinity` | Live room relay WebSocket connections |
101+
| UUID | `undefined` | stats tracking |
102+
| HIDE | `false` * | hide all extra information including platform, client version, Node.js runtime version, docker status ** |
103+
| NICKNAME | `undefined` | A optional nickname to display on statistics board (in progress). |
104+
| docker | Depends | Is Docker environment? |
105+
| VERBOSE | `false` * | Verbose log |
110106

111107
\* giving any value will make it `true`
112108

@@ -115,3 +111,16 @@ Edit Settings by environment variables or by command line arguments.
115111
## Contribution/Other information
116112

117113
The source code of backend (Cluster Manager) is available at <https://github.com/dd-center/Cluster-center>
114+
115+
116+
117+
### Note
118+
119+
120+
121+
1.11.0 use `fetch`, Node 18, remove DNS cache.
122+
123+
124+
125+
Use 1.10.0 if you need. tag `v1.10.0` commit `d0b2b7ec55fd393186c33f8deb2b1cf28cba55c7`
126+

core.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
const WebSocket = require('ws')
2-
const got = require('got')
32
const EventEmitter = require('events')
4-
const CacheableLookup = require('cacheable-lookup')
5-
const QuickLRU = require('quick-lru')
63

74
const relay = require('./relay')
85

@@ -16,7 +13,7 @@ const parse = string => {
1613
}
1714

1815
class DDAtHome extends EventEmitter {
19-
constructor(url, { PING_INTERVAL = 1000 * 30, INTERVAL = 480, start = true, wsLimit = Infinity, dnsCache = true } = {}) {
16+
constructor(url, { PING_INTERVAL = 1000 * 30, INTERVAL = 480, start = true, wsLimit = Infinity } = {}) {
2017
super()
2118
this.url = url
2219
this.PING_INTERVAL = PING_INTERVAL
@@ -25,11 +22,6 @@ class DDAtHome extends EventEmitter {
2522
this.queryTable = new Map()
2623
this.wsLimit = wsLimit
2724
this.relay = relay(this)
28-
this.dnsCache = dnsCache
29-
this.dnsLookupCache = new CacheableLookup({
30-
maxTtl: 60,
31-
cache: new QuickLRU({ maxSize: 1000 })
32-
})
3325
if (start) {
3426
this.start()
3527
}
@@ -45,10 +37,7 @@ class DDAtHome extends EventEmitter {
4537
this.emit('url', url)
4638
const time = Date.now()
4739
const opts = { headers: { Cookie: '_uuid=;rpdid=' } }
48-
if (this.dnsCache) {
49-
opts.dnsCache = this.dnsLookupCache
50-
}
51-
const { body: data } = await got(url, opts).catch(async e => ({ body: JSON.stringify({ code: e.response.statusCode }) })).catch(() => ({ body: JSON.stringify({ code: 233 }) }))
40+
const data = await fetch(url, opts).then(w => w.text()).catch(() => JSON.stringify({ code: 233 }))
5241
const result = this.secureSend(JSON.stringify({
5342
key,
5443
data

index.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ Options:
2323
--uuid=<uuid> UUID for stats tracking.
2424
[env: UUID]
2525
26-
--no-dns-cache Disable DNS cache
27-
[env: NO_DNS_CACHE]
28-
2926
--anonymous Do not send platform info to the server.
3027
[env: HIDE]
3128
@@ -44,7 +41,6 @@ start({
4441
nickname: args['--nickname'],
4542
limit: args['--ws-limit'],
4643
uuid: args['--uuid'],
47-
noDnsCache: args['--no-dns-cache'],
4844
verbose: process.env.development || args['--verbose']
4945
})
5046

@@ -55,7 +51,6 @@ function start({
5551
nickname,
5652
limit = Infinity,
5753
uuid,
58-
noDnsCache = false,
5954
verbose = false
6055
}) {
6156
console.log(welcome() + '\n')
@@ -94,12 +89,11 @@ function start({
9489
console.log({
9590
INTERVAL: interval,
9691
limit,
97-
noDnsCache,
9892
verbose
9993
})
10094
console.log(`using: ${url}\n`)
10195

102-
const ws = new DDAtHome(url, { INTERVAL: interval, wsLimit: limit, dnsCache: !noDnsCache })
96+
const ws = new DDAtHome(url, { INTERVAL: interval, wsLimit: limit })
10397

10498
if (verbose) {
10599
ws.on('log', console.log)

0 commit comments

Comments
 (0)