@netifyjs/protocol 1.0.0-alpha.2 → 1.0.0-beta.1
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/package.json +2 -2
- package/src/codec/index.ts +82 -157
- package/src/dispatch/dispatcher/index.ts +116 -33
- package/src/dispatch/session/index.ts +9 -3
- package/src/index.ts +2 -4
- package/src/photon/balancing/codec/index.ts +27 -53
- package/src/photon/balancing/format/authenticate/request/index.ts +52 -6
- package/src/photon/balancing/format/friends/request/index.ts +21 -5
- package/src/photon/balancing/format/game/create/request/index.ts +45 -8
- package/src/photon/balancing/format/game/debug/request/index.ts +19 -4
- package/src/photon/balancing/format/game/join/request/index.ts +65 -13
- package/src/photon/balancing/format/game/list/request/index.ts +29 -3
- package/src/photon/balancing/format/game/random/request/index.ts +58 -10
- package/src/photon/balancing/format/groups/request/index.ts +19 -3
- package/src/photon/balancing/format/index.ts +7 -0
- package/src/photon/balancing/format/leave/request/index.ts +19 -3
- package/src/photon/balancing/format/lobby/join/request/index.ts +23 -3
- package/src/photon/balancing/format/lobby/stats/request/index.ts +19 -3
- package/src/photon/balancing/format/once/request/index.ts +31 -8
- package/src/photon/balancing/format/properties/get/request/index.ts +31 -4
- package/src/photon/balancing/format/properties/set/request/index.ts +36 -7
- package/src/photon/balancing/format/raise/request/index.ts +76 -10
- package/src/photon/balancing/format/reader/index.ts +75 -6
- package/src/photon/balancing/format/regions/request/index.ts +16 -1
- package/src/photon/balancing/format/rpc/request/index.ts +26 -3
- package/src/photon/balancing/format/settings/request/index.ts +15 -2
- package/src/photon/balancing/format/shared/credentials/index.ts +77 -33
- package/src/photon/balancing/format/shared/lobby/index.ts +41 -5
- package/src/photon/balancing/format/shared/options/index.ts +56 -24
- package/src/photon/balancing/format/table/index.ts +399 -0
- package/src/photon/balancing/index.ts +11 -1
- package/src/photon/balancing/travel/index.ts +15 -12
- package/src/photon/binary/v18/index.ts +26 -1
- package/src/photon/binary/value/index.ts +52 -3
- package/src/photon/client/connection/index.ts +6 -6
- package/src/photon/cluster/back/index.ts +32 -45
- package/src/photon/cluster/dresser/index.ts +7 -8
- package/src/photon/cluster/front/index.ts +25 -49
- package/src/photon/cluster/grid/index.ts +1 -1
- package/src/photon/cluster/mover/index.ts +12 -12
- package/src/photon/cluster/press/index.ts +2 -18
- package/src/photon/cluster/route/game/index.ts +9 -11
- package/src/photon/cluster/route/master/index.ts +15 -34
- package/src/photon/cluster/route/name/index.ts +4 -21
- package/src/photon/cluster/seat/game/index.ts +6 -26
- package/src/photon/cluster/seat/master/index.ts +1 -1
- package/src/photon/cluster/sessions/index.ts +5 -6
- package/src/photon/cluster/spread/index.ts +8 -147
- package/src/photon/enet/client/index.ts +1 -8
- package/src/photon/enet/gateway/index.ts +5 -15
- package/src/photon/enet/index.ts +1 -1
- package/src/photon/enet/link/index.ts +34 -15
- package/src/photon/enet/outbound/index.ts +279 -0
- package/src/photon/enet/peer/index.ts +59 -0
- package/src/photon/enet/transport/index.ts +8 -24
- package/src/photon/game/admission/index.ts +353 -0
- package/src/photon/game/bag/index.ts +13 -0
- package/src/photon/game/broadcast/index.ts +79 -0
- package/src/photon/game/editor/index.ts +446 -0
- package/src/photon/game/gate/index.ts +9 -8
- package/src/photon/game/handler/index.ts +30 -3
- package/src/photon/game/history/index.ts +234 -0
- package/src/photon/game/hooked/index.ts +16 -15
- package/src/photon/game/index.ts +12 -1
- package/src/photon/game/lifecycle/index.ts +193 -0
- package/src/photon/game/peer/index.ts +1 -10
- package/src/photon/game/properties/index.ts +342 -0
- package/src/photon/game/room/index.ts +435 -1793
- package/src/photon/game/rooms/index.ts +2 -1
- package/src/photon/game/seats/index.ts +237 -0
- package/src/photon/game/server/index.ts +12 -2
- package/src/photon/game/services/index.ts +41 -0
- package/src/photon/game/settings/index.ts +22 -0
- package/src/photon/game/snapshot/index.ts +133 -0
- package/src/photon/game/throttle/index.ts +60 -0
- package/src/photon/game/touch/index.ts +2 -5
- package/src/photon/game/venue/index.ts +31 -0
- package/src/photon/master/application/index.ts +7 -0
- package/src/photon/master/gate/index.ts +12 -8
- package/src/photon/master/handler/index.ts +36 -748
- package/src/photon/master/index.ts +5 -0
- package/src/photon/master/list/sql/index.ts +37 -3
- package/src/photon/master/listing/index.ts +133 -0
- package/src/photon/master/lobby/index.ts +9 -0
- package/src/photon/master/login/index.ts +424 -0
- package/src/photon/master/matchmaking/index.ts +282 -0
- package/src/photon/master/query/index.ts +45 -0
- package/src/photon/master/redirect/index.ts +8 -7
- package/src/photon/master/services/index.ts +35 -0
- package/src/photon/master/settings/index.ts +44 -0
- package/src/photon/master/sql/cost/index.ts +263 -0
- package/src/photon/master/sql/index.ts +1 -0
- package/src/photon/message/binary/index.ts +35 -1
- package/src/photon/message/client/index.ts +14 -11
- package/src/photon/message/format/index.ts +9 -0
- package/src/photon/message/handler/index.ts +48 -63
- package/src/photon/message/pipeline/index.ts +12 -12
- package/src/photon/message/server/index.ts +87 -43
- package/src/photon/message/watch/index.ts +127 -15
- package/src/photon/server/config/index.ts +5 -0
- package/src/photon/server/deferral/index.ts +57 -0
- package/src/photon/server/host/index.ts +36 -10
- package/src/photon/server/index.ts +1 -0
- package/src/photon/server/listeners/index.ts +11 -0
- package/src/photon/tcp/client/index.ts +1 -1
- package/src/photon/tcp/codec/index.ts +41 -38
- package/src/photon/tcp/framing/index.ts +24 -4
- package/src/photon/tcp/server/index.ts +4 -4
- package/src/photon/websocket/bridge/index.ts +16 -20
- package/src/photon/websocket/message/index.ts +27 -39
- package/src/photon/websocket/path/index.ts +2 -5
- package/src/scale/batch/index.ts +14 -6
- package/src/scale/fanout/index.ts +6 -6
- package/src/scale/index.ts +2 -4
- package/src/scale/outbound/index.ts +192 -0
- package/src/scale/relay/index.ts +24 -16
- package/src/scale/sink/index.ts +6 -11
- package/src/scale/transport/index.ts +27 -44
- package/src/scale/tunnel/index.ts +56 -86
- package/src/smartfox/common/bluebox/gateway/index.ts +401 -0
- package/src/smartfox/common/bluebox/index.ts +4 -0
- package/src/smartfox/{x2 → common}/bluebox/transport/index.ts +36 -23
- package/src/smartfox/common/index.ts +5 -0
- package/src/smartfox/common/strikes/index.ts +74 -0
- package/src/smartfox/pro/bluebox/index.ts +176 -4
- package/src/smartfox/pro/codec/index.ts +8 -7
- package/src/smartfox/pro/escalation/index.ts +28 -20
- package/src/smartfox/pro/flood/index.ts +2 -2
- package/src/smartfox/pro/format/extension/raw/index.ts +12 -2
- package/src/smartfox/pro/handler/chat/index.ts +11 -8
- package/src/smartfox/pro/handler/login/index.ts +2 -25
- package/src/smartfox/pro/handler/shared/index.ts +4 -3
- package/src/smartfox/pro/index.ts +11 -5
- package/src/smartfox/pro/login/gate/index.ts +166 -0
- package/src/smartfox/pro/login/index.ts +1 -0
- package/src/smartfox/pro/moderation/index.ts +220 -0
- package/src/smartfox/pro/options/index.ts +5 -5
- package/src/smartfox/pro/protocol/index.ts +62 -8
- package/src/smartfox/pro/web/index.ts +33 -26
- package/src/smartfox/pro/zone/index.ts +59 -282
- package/src/smartfox/pro/zones/index.ts +3 -3
- package/src/smartfox/x2/bluebox/index.ts +149 -4
- package/src/smartfox/x2/chat/index.ts +9 -19
- package/src/smartfox/x2/codec/index.ts +34 -40
- package/src/smartfox/x2/config/index.ts +6 -1
- package/src/smartfox/x2/data/array/index.ts +96 -60
- package/src/smartfox/x2/data/object/index.ts +144 -82
- package/src/smartfox/x2/data/serializer/index.ts +41 -23
- package/src/smartfox/x2/flood/gate/index.ts +19 -13
- package/src/smartfox/x2/format/buddy/init/response/index.ts +4 -3
- package/src/smartfox/x2/format/find/rooms/response/index.ts +4 -3
- package/src/smartfox/x2/format/find/users/response/index.ts +4 -3
- package/src/smartfox/x2/format/group/subscribe/response/index.ts +4 -3
- package/src/smartfox/x2/format/login/response/index.ts +4 -3
- package/src/smartfox/x2/format/mmo/position/response/index.ts +8 -6
- package/src/smartfox/x2/format/room/join/response/index.ts +4 -3
- package/src/smartfox/x2/games/index.ts +35 -8
- package/src/smartfox/x2/hall/index.ts +0 -6
- package/src/smartfox/x2/handler/session/index.ts +1 -1
- package/src/smartfox/x2/index.ts +8 -3
- package/src/smartfox/x2/member/index.ts +10 -3
- package/src/smartfox/x2/packet/login/response/index.ts +12 -0
- package/src/smartfox/x2/protocol/index.ts +11 -1
- package/src/smartfox/x2/rooms/index.ts +1 -2
- package/src/smartfox/x2/sessions/index.ts +6 -0
- package/src/smartfox/x2/udp/index.ts +61 -24
- package/src/smartfox/x2/web/index.ts +35 -17
- package/src/smartfox/x2/websocket/index.ts +18 -36
- package/src/smartfox/x2/zone/index.ts +77 -28
- package/src/smartfox/x2/zones/index.ts +17 -5
- package/src/photon/enet/handler/index.ts +0 -65
- package/src/scale/hosted/index.ts +0 -68
- package/src/scale/outlet/index.ts +0 -121
- package/src/smartfox/pro/bluebox/gateway/index.ts +0 -310
- package/src/smartfox/pro/bluebox/session/index.ts +0 -63
- package/src/smartfox/pro/bluebox/transport/index.ts +0 -104
- package/src/smartfox/x2/bluebox/gateway/index.ts +0 -315
- /package/src/smartfox/{x2 → common}/bluebox/session/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/memory/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/offender/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/store/index.ts +0 -0
- /package/src/smartfox/{pro → common}/sequence/index.ts +0 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ByteBuf,
|
|
3
|
+
type Outbound,
|
|
4
|
+
type OutboundEvents,
|
|
5
|
+
type OutboundFactory,
|
|
6
|
+
type OutboundLimits,
|
|
7
|
+
QueueFullError,
|
|
8
|
+
type Transport,
|
|
9
|
+
} from '@netifyjs/netify'
|
|
10
|
+
|
|
11
|
+
import { Frame } from '../../frame/index.ts'
|
|
12
|
+
import type { EnetPeer } from '../peer/index.ts'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Someone waiting for the peer to send a certain number of bytes
|
|
16
|
+
*/
|
|
17
|
+
type Waiter = {
|
|
18
|
+
/**
|
|
19
|
+
* Sent bytes that settle it
|
|
20
|
+
*/
|
|
21
|
+
readonly target: number
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The promise handed out
|
|
25
|
+
*/
|
|
26
|
+
readonly result: PromiseWithResolvers<undefined>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Hands a virtual channel's messages to its reliable UDP connection, one command each
|
|
31
|
+
* @class
|
|
32
|
+
*/
|
|
33
|
+
export class EnetOutbound implements Outbound {
|
|
34
|
+
/**
|
|
35
|
+
* Nothing is ever staged
|
|
36
|
+
*/
|
|
37
|
+
private static readonly unstaged: Uint8Array = new Uint8Array(0)
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The connection messages leave on
|
|
41
|
+
*/
|
|
42
|
+
private readonly peer: EnetPeer
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Water marks and cap
|
|
46
|
+
*/
|
|
47
|
+
private readonly limits: OutboundLimits
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Who hears about writability and failures
|
|
51
|
+
*/
|
|
52
|
+
private readonly events: OutboundEvents
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* People waiting on flushed()
|
|
56
|
+
*/
|
|
57
|
+
private readonly waiters: Waiter[]
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Whether it's below the high water mark
|
|
61
|
+
*/
|
|
62
|
+
private writable: boolean
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Error it stopped with, or null
|
|
66
|
+
*/
|
|
67
|
+
private failure: Error | null
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param peer the connection messages leave on
|
|
71
|
+
* @param limits water marks and cap
|
|
72
|
+
* @param events who hears about writability and failures
|
|
73
|
+
*/
|
|
74
|
+
private constructor(
|
|
75
|
+
peer: EnetPeer,
|
|
76
|
+
limits: OutboundLimits,
|
|
77
|
+
events: OutboundEvents,
|
|
78
|
+
) {
|
|
79
|
+
this.peer = peer
|
|
80
|
+
this.limits = limits
|
|
81
|
+
this.events = events
|
|
82
|
+
this.waiters = []
|
|
83
|
+
this.writable = true
|
|
84
|
+
this.failure = null
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Builds the outbound side for a channel on a connection
|
|
89
|
+
* @param peer the connection messages leave on
|
|
90
|
+
* @param built hears about the outbound once it exists
|
|
91
|
+
*/
|
|
92
|
+
public static factory(
|
|
93
|
+
peer: EnetPeer,
|
|
94
|
+
built: (outbound: EnetOutbound) => void,
|
|
95
|
+
): OutboundFactory {
|
|
96
|
+
return (
|
|
97
|
+
_transport: Transport,
|
|
98
|
+
limits: OutboundLimits,
|
|
99
|
+
events: OutboundEvents,
|
|
100
|
+
): EnetOutbound => {
|
|
101
|
+
const outbound = new EnetOutbound(peer, limits, events)
|
|
102
|
+
built(outbound)
|
|
103
|
+
|
|
104
|
+
return outbound
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Whether it's below the high water mark
|
|
110
|
+
*/
|
|
111
|
+
public get isWritable(): boolean {
|
|
112
|
+
return this.writable
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Payload bytes the connection still has queued
|
|
117
|
+
*/
|
|
118
|
+
public get pendingBytes(): number {
|
|
119
|
+
return this.peer.queuedBytes
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Payload bytes the connection put on the wire
|
|
124
|
+
*/
|
|
125
|
+
public get writtenBytes(): number {
|
|
126
|
+
return this.peer.sentBytes
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Always empty
|
|
131
|
+
*/
|
|
132
|
+
public get stagingBuffer(): Uint8Array {
|
|
133
|
+
return EnetOutbound.unstaged
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Queues a frame, or bytes as a reliable message on channel 0
|
|
138
|
+
* @param message a Frame, a ByteBuf or bytes
|
|
139
|
+
*/
|
|
140
|
+
public write(message: unknown): void {
|
|
141
|
+
if (message instanceof Frame) {
|
|
142
|
+
this.add(message)
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (message instanceof ByteBuf) {
|
|
147
|
+
this.add(Frame.reliable(message.toUint8Array()))
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (message instanceof Uint8Array) {
|
|
152
|
+
this.add(Frame.reliable(message))
|
|
153
|
+
return
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
throw new TypeError('Message type is not supported')
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Frames can't be written into directly
|
|
161
|
+
*/
|
|
162
|
+
public reserve(): number {
|
|
163
|
+
return -1
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Nothing is ever reserved
|
|
168
|
+
*/
|
|
169
|
+
public commit(): void {
|
|
170
|
+
return
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The connection sends on its own clock
|
|
175
|
+
*/
|
|
176
|
+
public flush(): void {
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The connection sends on its own clock
|
|
182
|
+
*/
|
|
183
|
+
public send(): void {
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The socket underneath never pushes back on a virtual channel
|
|
189
|
+
*/
|
|
190
|
+
public drain(): void {
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Settles once everything queued so far is on the wire
|
|
196
|
+
*/
|
|
197
|
+
public flushed(): Promise<void> {
|
|
198
|
+
if (this.failure !== null) return Promise.reject(this.failure)
|
|
199
|
+
if (this.peer.queuedBytes === 0) return Promise.resolve()
|
|
200
|
+
|
|
201
|
+
const target = this.peer.sentBytes + this.peer.queuedBytes
|
|
202
|
+
const last = this.waiters.at(-1)
|
|
203
|
+
if (last?.target === target) return last.result.promise
|
|
204
|
+
|
|
205
|
+
const result = Promise.withResolvers<undefined>()
|
|
206
|
+
this.waiters.push({ target, result })
|
|
207
|
+
return result.promise
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Reads don't change how frames leave
|
|
212
|
+
*/
|
|
213
|
+
public reading(): void {
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Refuses later writes, drops an overfull queue and lets go of anyone waiting
|
|
219
|
+
* @param error why it stopped
|
|
220
|
+
*/
|
|
221
|
+
public fail(error: Error): void {
|
|
222
|
+
if (this.failure !== null) return
|
|
223
|
+
|
|
224
|
+
this.failure = error
|
|
225
|
+
if (error instanceof QueueFullError) this.peer.discard()
|
|
226
|
+
for (const waiter of this.waiters.splice(0)) waiter.result.reject(error)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Notes that queued messages went on the wire
|
|
231
|
+
*/
|
|
232
|
+
public relieved(): void {
|
|
233
|
+
const sent = this.peer.sentBytes
|
|
234
|
+
let settled = 0
|
|
235
|
+
while (settled < this.waiters.length) {
|
|
236
|
+
const waiter = this.waiters[settled]
|
|
237
|
+
if (waiter === undefined || waiter.target > sent) break
|
|
238
|
+
|
|
239
|
+
waiter.result.resolve(undefined)
|
|
240
|
+
settled += 1
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (settled > 0) this.waiters.splice(0, settled)
|
|
244
|
+
this.measure()
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Hands a frame to the connection unless the queue is full
|
|
249
|
+
* @param frame what to send
|
|
250
|
+
*/
|
|
251
|
+
private add(frame: Frame): void {
|
|
252
|
+
if (this.failure !== null) return
|
|
253
|
+
if (
|
|
254
|
+
this.peer.queuedBytes + frame.payload.length >
|
|
255
|
+
this.limits.maxPendingBytes
|
|
256
|
+
) {
|
|
257
|
+
this.events.failed(new QueueFullError())
|
|
258
|
+
return
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
this.peer.send(frame)
|
|
262
|
+
this.measure()
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Tells the channel if the queue crossed a water mark
|
|
267
|
+
*/
|
|
268
|
+
private measure(): void {
|
|
269
|
+
const queued = this.peer.queuedBytes
|
|
270
|
+
|
|
271
|
+
if (this.writable && queued > this.limits.highWaterMark) {
|
|
272
|
+
this.writable = false
|
|
273
|
+
this.events.writability(false)
|
|
274
|
+
} else if (!this.writable && queued < this.limits.lowWaterMark) {
|
|
275
|
+
this.writable = true
|
|
276
|
+
this.events.writability(true)
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
@@ -33,6 +33,11 @@ export type EnetHooks = {
|
|
|
33
33
|
*/
|
|
34
34
|
established(): void
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Queued messages went on the wire
|
|
38
|
+
*/
|
|
39
|
+
relieved(): void
|
|
40
|
+
|
|
36
41
|
/**
|
|
37
42
|
* The connection is over
|
|
38
43
|
*/
|
|
@@ -235,6 +240,16 @@ export class EnetPeer {
|
|
|
235
240
|
*/
|
|
236
241
|
private queued: number
|
|
237
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Payload bytes waiting in the queues
|
|
245
|
+
*/
|
|
246
|
+
private waiting: number
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Payload bytes that left the queues so far
|
|
250
|
+
*/
|
|
251
|
+
private departed: number
|
|
252
|
+
|
|
238
253
|
/**
|
|
239
254
|
* Unacked reliable bytes on the wire
|
|
240
255
|
*/
|
|
@@ -389,6 +404,8 @@ export class EnetPeer {
|
|
|
389
404
|
this.batch = []
|
|
390
405
|
this.filled = 0
|
|
391
406
|
this.queued = 0
|
|
407
|
+
this.waiting = 0
|
|
408
|
+
this.departed = 0
|
|
392
409
|
this.transit = 0
|
|
393
410
|
this.buffered = 0
|
|
394
411
|
this.group = 0
|
|
@@ -468,6 +485,20 @@ export class EnetPeer {
|
|
|
468
485
|
return this.count
|
|
469
486
|
}
|
|
470
487
|
|
|
488
|
+
/**
|
|
489
|
+
* Payload bytes waiting to go on the wire
|
|
490
|
+
*/
|
|
491
|
+
public get queuedBytes(): number {
|
|
492
|
+
return this.waiting
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Payload bytes put on the wire so far
|
|
497
|
+
*/
|
|
498
|
+
public get sentBytes(): number {
|
|
499
|
+
return this.departed
|
|
500
|
+
}
|
|
501
|
+
|
|
471
502
|
/**
|
|
472
503
|
* Whether messages can be sent
|
|
473
504
|
*/
|
|
@@ -753,6 +784,19 @@ export class EnetPeer {
|
|
|
753
784
|
this.finish(this.ending)
|
|
754
785
|
}
|
|
755
786
|
|
|
787
|
+
/**
|
|
788
|
+
* Forgets every message still waiting to go on the wire
|
|
789
|
+
*/
|
|
790
|
+
public discard(): void {
|
|
791
|
+
for (const lane of this.order) {
|
|
792
|
+
this.queued -= lane.reliables.length + lane.unreliables.length
|
|
793
|
+
lane.reliables.length = 0
|
|
794
|
+
lane.unreliables.length = 0
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
this.waiting = 0
|
|
798
|
+
}
|
|
799
|
+
|
|
756
800
|
/**
|
|
757
801
|
* Hangs up at once
|
|
758
802
|
* @param reason reserved byte the other end is shown
|
|
@@ -932,6 +976,7 @@ export class EnetPeer {
|
|
|
932
976
|
else lane.unreliables.push(command)
|
|
933
977
|
|
|
934
978
|
this.queued += 1
|
|
979
|
+
this.waiting += command.payload.length
|
|
935
980
|
}
|
|
936
981
|
|
|
937
982
|
/**
|
|
@@ -1269,10 +1314,12 @@ export class EnetPeer {
|
|
|
1269
1314
|
return
|
|
1270
1315
|
}
|
|
1271
1316
|
|
|
1317
|
+
const before = this.departed
|
|
1272
1318
|
this.idle(now)
|
|
1273
1319
|
this.fill(now, late)
|
|
1274
1320
|
this.emit(now)
|
|
1275
1321
|
this.wake(this.next())
|
|
1322
|
+
if (this.departed !== before) this.hooks.relieved()
|
|
1276
1323
|
}
|
|
1277
1324
|
|
|
1278
1325
|
/**
|
|
@@ -1375,11 +1422,13 @@ export class EnetPeer {
|
|
|
1375
1422
|
this.flights.set(flight.key, flight)
|
|
1376
1423
|
this.transit += command.size
|
|
1377
1424
|
this.queued -= 1
|
|
1425
|
+
this.leave(command)
|
|
1378
1426
|
lane.flying += 1
|
|
1379
1427
|
this.load(command, now)
|
|
1380
1428
|
}
|
|
1381
1429
|
|
|
1382
1430
|
for (const command of lane.unreliables) {
|
|
1431
|
+
this.leave(command)
|
|
1383
1432
|
this.load(command, now)
|
|
1384
1433
|
}
|
|
1385
1434
|
|
|
@@ -1387,6 +1436,15 @@ export class EnetPeer {
|
|
|
1387
1436
|
lane.unreliables.length = 0
|
|
1388
1437
|
}
|
|
1389
1438
|
|
|
1439
|
+
/**
|
|
1440
|
+
* Counts a command's payload as gone from the queues
|
|
1441
|
+
* @param command what left
|
|
1442
|
+
*/
|
|
1443
|
+
private leave(command: Command): void {
|
|
1444
|
+
this.waiting -= command.payload.length
|
|
1445
|
+
this.departed += command.payload.length
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1390
1448
|
/**
|
|
1391
1449
|
* Whether the wire has room for another reliable command of a channel
|
|
1392
1450
|
* @param lane the channel
|
|
@@ -1520,6 +1578,7 @@ export class EnetPeer {
|
|
|
1520
1578
|
this.acks = []
|
|
1521
1579
|
this.batch = []
|
|
1522
1580
|
this.order = []
|
|
1581
|
+
this.waiting = 0
|
|
1523
1582
|
this.lanes.clear()
|
|
1524
1583
|
this.flights.clear()
|
|
1525
1584
|
this.hooks.closed()
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Transport } from '@netifyjs/netify'
|
|
2
2
|
|
|
3
|
-
import { Frame } from '../../frame/index.ts'
|
|
4
3
|
import type { EnetPeer } from '../peer/index.ts'
|
|
5
4
|
|
|
6
5
|
/**
|
|
@@ -8,11 +7,6 @@ import type { EnetPeer } from '../peer/index.ts'
|
|
|
8
7
|
* @class
|
|
9
8
|
*/
|
|
10
9
|
export class EnetTransport implements Transport {
|
|
11
|
-
/**
|
|
12
|
-
* Every write is a message of its own
|
|
13
|
-
*/
|
|
14
|
-
public readonly datagram: boolean = true
|
|
15
|
-
|
|
16
10
|
/**
|
|
17
11
|
* Where the other end's datagrams come from
|
|
18
12
|
*/
|
|
@@ -23,11 +17,6 @@ export class EnetTransport implements Transport {
|
|
|
23
17
|
*/
|
|
24
18
|
public readonly remotePort: number
|
|
25
19
|
|
|
26
|
-
/**
|
|
27
|
-
* Whether the channel asked for reads to stop
|
|
28
|
-
*/
|
|
29
|
-
public paused: boolean
|
|
30
|
-
|
|
31
20
|
/**
|
|
32
21
|
* The connection underneath
|
|
33
22
|
*/
|
|
@@ -45,19 +34,14 @@ export class EnetTransport implements Transport {
|
|
|
45
34
|
) {
|
|
46
35
|
this.remoteAddress = remoteAddress
|
|
47
36
|
this.remotePort = remotePort
|
|
48
|
-
this.paused = false
|
|
49
37
|
this.peer = peer
|
|
50
38
|
}
|
|
51
39
|
|
|
52
40
|
/**
|
|
53
|
-
*
|
|
54
|
-
* @param bytes a whole message
|
|
41
|
+
* Never called
|
|
55
42
|
*/
|
|
56
|
-
public write(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.peer.send(Frame.reliable(bytes))
|
|
60
|
-
return bytes.length
|
|
43
|
+
public write(): number {
|
|
44
|
+
return -1
|
|
61
45
|
}
|
|
62
46
|
|
|
63
47
|
/**
|
|
@@ -68,16 +52,16 @@ export class EnetTransport implements Transport {
|
|
|
68
52
|
}
|
|
69
53
|
|
|
70
54
|
/**
|
|
71
|
-
*
|
|
55
|
+
* Says reads on a shared socket can't be held back
|
|
72
56
|
*/
|
|
73
|
-
public pause():
|
|
74
|
-
|
|
57
|
+
public pause(): boolean {
|
|
58
|
+
return false
|
|
75
59
|
}
|
|
76
60
|
|
|
77
61
|
/**
|
|
78
|
-
*
|
|
62
|
+
* Nothing to start again
|
|
79
63
|
*/
|
|
80
64
|
public resume(): void {
|
|
81
|
-
|
|
65
|
+
return
|
|
82
66
|
}
|
|
83
67
|
}
|