*Update dist
This commit is contained in:
parent
96dd1ad46e
commit
c3c8e6fb3b
|
@ -21,7 +21,7 @@ export default class MultiSocketProxy extends Proxy {
|
||||||
get socketMap(): Map<number, number>;
|
get socketMap(): Map<number, number>;
|
||||||
private _sockets;
|
private _sockets;
|
||||||
get sockets(): Map<number, any>;
|
get sockets(): Map<number, any>;
|
||||||
handleNewPeerChannel(peer: Peer): void;
|
handleNewPeerChannel(peer: Peer): Promise<void>;
|
||||||
handleClosePeer(peer: Peer): Promise<void>;
|
handleClosePeer(peer: Peer): Promise<void>;
|
||||||
get(pubkey: Uint8Array): PeerEntity | undefined;
|
get(pubkey: Uint8Array): PeerEntity | undefined;
|
||||||
update(pubkey: Uint8Array, data: Partial<PeerEntity>): void;
|
update(pubkey: Uint8Array, data: Partial<PeerEntity>): void;
|
||||||
|
@ -32,4 +32,5 @@ export default class MultiSocketProxy extends Proxy {
|
||||||
private _registerTimeoutSocketMessage;
|
private _registerTimeoutSocketMessage;
|
||||||
private _registerErrorSocketMessage;
|
private _registerErrorSocketMessage;
|
||||||
private _toString;
|
private _toString;
|
||||||
|
private _getPublicKey;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,13 +96,15 @@ class MultiSocketProxy extends proxy_js_1.default {
|
||||||
get sockets() {
|
get sockets() {
|
||||||
return this._sockets;
|
return this._sockets;
|
||||||
}
|
}
|
||||||
handleNewPeerChannel(peer) {
|
async handleNewPeerChannel(peer) {
|
||||||
this.update(peer.stream.remotePublicKey, { peer });
|
this.update(await this._getPublicKey(peer), {
|
||||||
this._registerOpenSocketMessage(peer);
|
peer,
|
||||||
this._registerWriteSocketMessage(peer);
|
});
|
||||||
this._registerCloseSocketMessage(peer);
|
await this._registerOpenSocketMessage(peer);
|
||||||
this._registerTimeoutSocketMessage(peer);
|
await this._registerWriteSocketMessage(peer);
|
||||||
this._registerErrorSocketMessage(peer);
|
await this._registerCloseSocketMessage(peer);
|
||||||
|
await this._registerTimeoutSocketMessage(peer);
|
||||||
|
await this._registerErrorSocketMessage(peer);
|
||||||
}
|
}
|
||||||
async handleClosePeer(peer) {
|
async handleClosePeer(peer) {
|
||||||
for (const item of this._sockets) {
|
for (const item of this._sockets) {
|
||||||
|
@ -110,7 +112,7 @@ class MultiSocketProxy extends proxy_js_1.default {
|
||||||
item[1].end();
|
item[1].end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const pubkey = this._toString(peer.stream.remotePublicKey);
|
const pubkey = this._toString(await this._getPublicKey(peer));
|
||||||
if (this._peers.has(pubkey)) {
|
if (this._peers.has(pubkey)) {
|
||||||
this._peers.delete(pubkey);
|
this._peers.delete(pubkey);
|
||||||
}
|
}
|
||||||
|
@ -144,7 +146,7 @@ class MultiSocketProxy extends proxy_js_1.default {
|
||||||
this._sockets.set(socketId, socket);
|
this._sockets.set(socketId, socket);
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
_registerOpenSocketMessage(peer) {
|
async _registerOpenSocketMessage(peer) {
|
||||||
const self = this;
|
const self = this;
|
||||||
const message = peer.channel.addMessage({
|
const message = peer.channel.addMessage({
|
||||||
encoding: {
|
encoding: {
|
||||||
|
@ -155,7 +157,7 @@ class MultiSocketProxy extends proxy_js_1.default {
|
||||||
async onmessage(m) {
|
async onmessage(m) {
|
||||||
if (self._allowedPorts.length &&
|
if (self._allowedPorts.length &&
|
||||||
!self._allowedPorts.includes(m.port)) {
|
!self._allowedPorts.includes(m.port)) {
|
||||||
self.get(peer.stream.remotePublicKey).messages.errorSocket.send({
|
self.get(await this._getPublicKey(peer)).messages.errorSocket.send({
|
||||||
id: m.id,
|
id: m.id,
|
||||||
err: new Error(`port ${m.port} not allowed`),
|
err: new Error(`port ${m.port} not allowed`),
|
||||||
});
|
});
|
||||||
|
@ -163,7 +165,7 @@ class MultiSocketProxy extends proxy_js_1.default {
|
||||||
}
|
}
|
||||||
m = m;
|
m = m;
|
||||||
if (self._server) {
|
if (self._server) {
|
||||||
new self.socketClass(nextSocketId(), m, self, self.get(peer.stream.remotePublicKey), m).connect();
|
new self.socketClass(nextSocketId(), m, self, self.get(await this._getPublicKey(peer)), m).connect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const socket = self._sockets.get(m.id);
|
const socket = self._sockets.get(m.id);
|
||||||
|
@ -174,11 +176,11 @@ class MultiSocketProxy extends proxy_js_1.default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.update(peer.stream.remotePublicKey, {
|
this.update(await this._getPublicKey(peer), {
|
||||||
messages: { openSocket: message },
|
messages: { openSocket: message },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_registerWriteSocketMessage(peer) {
|
async _registerWriteSocketMessage(peer) {
|
||||||
const self = this;
|
const self = this;
|
||||||
const message = peer.channel.addMessage({
|
const message = peer.channel.addMessage({
|
||||||
encoding: writeSocketEncoding,
|
encoding: writeSocketEncoding,
|
||||||
|
@ -186,11 +188,11 @@ class MultiSocketProxy extends proxy_js_1.default {
|
||||||
self._sockets.get(m.id)?.push(m.data);
|
self._sockets.get(m.id)?.push(m.data);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.update(peer.stream.remotePublicKey, {
|
this.update(await this._getPublicKey(peer), {
|
||||||
messages: { writeSocket: message },
|
messages: { writeSocket: message },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_registerCloseSocketMessage(peer) {
|
async _registerCloseSocketMessage(peer) {
|
||||||
const self = this;
|
const self = this;
|
||||||
const message = peer.channel.addMessage({
|
const message = peer.channel.addMessage({
|
||||||
encoding: socketEncoding,
|
encoding: socketEncoding,
|
||||||
|
@ -198,11 +200,11 @@ class MultiSocketProxy extends proxy_js_1.default {
|
||||||
self._sockets.get(m.id)?.end();
|
self._sockets.get(m.id)?.end();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.update(peer.stream.remotePublicKey, {
|
this.update(await this._getPublicKey(peer), {
|
||||||
messages: { closeSocket: message },
|
messages: { closeSocket: message },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_registerTimeoutSocketMessage(peer) {
|
async _registerTimeoutSocketMessage(peer) {
|
||||||
const self = this;
|
const self = this;
|
||||||
const message = peer.channel.addMessage({
|
const message = peer.channel.addMessage({
|
||||||
encoding: socketEncoding,
|
encoding: socketEncoding,
|
||||||
|
@ -211,11 +213,11 @@ class MultiSocketProxy extends proxy_js_1.default {
|
||||||
self._sockets.get(m.id)?.emit("timeout");
|
self._sockets.get(m.id)?.emit("timeout");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.update(peer.stream.remotePublicKey, {
|
this.update(await this._getPublicKey(peer), {
|
||||||
messages: { timeoutSocket: message },
|
messages: { timeoutSocket: message },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_registerErrorSocketMessage(peer) {
|
async _registerErrorSocketMessage(peer) {
|
||||||
const self = this;
|
const self = this;
|
||||||
const message = peer.channel.addMessage({
|
const message = peer.channel.addMessage({
|
||||||
encoding: errorSocketEncoding,
|
encoding: errorSocketEncoding,
|
||||||
|
@ -224,12 +226,15 @@ class MultiSocketProxy extends proxy_js_1.default {
|
||||||
self._sockets.get(m.id)?.emit("error", m.err);
|
self._sockets.get(m.id)?.emit("error", m.err);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.update(peer.stream.remotePublicKey, {
|
this.update(await this._getPublicKey(peer), {
|
||||||
messages: { errorSocket: message },
|
messages: { errorSocket: message },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_toString(pubkey) {
|
_toString(pubkey) {
|
||||||
return b4a_1.default.from(pubkey).toString("hex");
|
return b4a_1.default.from(pubkey).toString("hex");
|
||||||
}
|
}
|
||||||
|
async _getPublicKey(peer) {
|
||||||
|
return (0, util_js_1.maybeGetAsyncProperty)(peer.stream.remotePublicKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.default = MultiSocketProxy;
|
exports.default = MultiSocketProxy;
|
||||||
|
|
Loading…
Reference in New Issue