Compare commits

..

No commits in common. "40e139df0dc99b2705597830f3e129748a24f238" and "84bc6ce1cbcb8ad2099f11316419239c9f97d160" have entirely different histories.

6 changed files with 37 additions and 45 deletions

View File

@ -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, channel: any): 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;

View File

@ -94,13 +94,13 @@ class MultiSocketProxy extends proxy_js_1.default {
get sockets() { get sockets() {
return this._sockets; return this._sockets;
} }
handleNewPeerChannel(peer) { handleNewPeerChannel(peer, channel) {
this.update(peer.stream.remotePublicKey, { peer }); this.update(peer.socket.remotePublicKey, { peer });
this._registerOpenSocketMessage(peer); this._registerOpenSocketMessage(peer, channel);
this._registerWriteSocketMessage(peer); this._registerWriteSocketMessage(peer, channel);
this._registerCloseSocketMessage(peer); this._registerCloseSocketMessage(peer, channel);
this._registerTimeoutSocketMessage(peer); this._registerTimeoutSocketMessage(peer, channel);
this._registerErrorSocketMessage(peer); this._registerErrorSocketMessage(peer, channel);
} }
async handleClosePeer(peer) { async handleClosePeer(peer) {
for (const item of this._sockets) { for (const item of this._sockets) {
@ -142,9 +142,9 @@ class MultiSocketProxy extends proxy_js_1.default {
this._sockets.set(socketId, socket); this._sockets.set(socketId, socket);
return socket; return socket;
} }
_registerOpenSocketMessage(peer) { _registerOpenSocketMessage(peer, channel) {
const self = this; const self = this;
const message = peer.channel.addMessage({ const message = channel.addMessage({
encoding: { encoding: {
preencode: compact_encoding_1.json.preencode, preencode: compact_encoding_1.json.preencode,
encode: compact_encoding_1.json.encode, encode: compact_encoding_1.json.encode,
@ -176,9 +176,9 @@ class MultiSocketProxy extends proxy_js_1.default {
messages: { openSocket: message }, messages: { openSocket: message },
}); });
} }
_registerWriteSocketMessage(peer) { _registerWriteSocketMessage(peer, channel) {
const self = this; const self = this;
const message = peer.channel.addMessage({ const message = channel.addMessage({
encoding: writeSocketEncoding, encoding: writeSocketEncoding,
onmessage(m) { onmessage(m) {
self._sockets.get(m.id)?.push(m.data); self._sockets.get(m.id)?.push(m.data);
@ -188,9 +188,9 @@ class MultiSocketProxy extends proxy_js_1.default {
messages: { writeSocket: message }, messages: { writeSocket: message },
}); });
} }
_registerCloseSocketMessage(peer) { _registerCloseSocketMessage(peer, channel) {
const self = this; const self = this;
const message = peer.channel.addMessage({ const message = channel.addMessage({
encoding: socketEncoding, encoding: socketEncoding,
onmessage(m) { onmessage(m) {
self._sockets.get(m.id)?.end(); self._sockets.get(m.id)?.end();
@ -200,9 +200,9 @@ class MultiSocketProxy extends proxy_js_1.default {
messages: { closeSocket: message }, messages: { closeSocket: message },
}); });
} }
_registerTimeoutSocketMessage(peer) { _registerTimeoutSocketMessage(peer, channel) {
const self = this; const self = this;
const message = peer.channel.addMessage({ const message = channel.addMessage({
encoding: socketEncoding, encoding: socketEncoding,
onmessage(m) { onmessage(m) {
// @ts-ignore // @ts-ignore
@ -213,9 +213,9 @@ class MultiSocketProxy extends proxy_js_1.default {
messages: { timeoutSocket: message }, messages: { timeoutSocket: message },
}); });
} }
_registerErrorSocketMessage(peer) { _registerErrorSocketMessage(peer, channel) {
const self = this; const self = this;
const message = peer.channel.addMessage({ const message = channel.addMessage({
encoding: errorSocketEncoding, encoding: errorSocketEncoding,
onmessage(m) { onmessage(m) {
// @ts-ignore // @ts-ignore

View File

@ -4,7 +4,6 @@ import MultiSocketProxy from "../multiSocket.js";
export default class Peer extends BasePeer { export default class Peer extends BasePeer {
protected _proxy: MultiSocketProxy; protected _proxy: MultiSocketProxy;
protected initSocket(): Promise<void>; protected initSocket(): Promise<void>;
get stream(): any;
protected handleChannelOnClose(socket: Socket): Promise<void>; protected handleChannelOnClose(socket: Socket): Promise<void>;
protected handleChannelOnOpen(m: any): Promise<void>; protected handleChannelOnOpen(m: any): Promise<void>;
} }

View File

@ -6,14 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
const peer_js_1 = __importDefault(require("../../peer.js")); const peer_js_1 = __importDefault(require("../../peer.js"));
class Peer extends peer_js_1.default { class Peer extends peer_js_1.default {
async initSocket() { } async initSocket() { }
get stream() {
return this._muxer.stream;
}
async handleChannelOnClose(socket) { async handleChannelOnClose(socket) {
return this._proxy.handleClosePeer(this); return this._proxy.handleClosePeer(this);
} }
async handleChannelOnOpen(m) { async handleChannelOnOpen(m) {
await this._proxy.handleNewPeerChannel(this); await this._proxy.handleNewPeerChannel(this._peer, this._channel);
} }
} }
exports.default = Peer; exports.default = Peer;

View File

@ -113,14 +113,14 @@ export default class MultiSocketProxy extends Proxy {
return this._sockets; return this._sockets;
} }
handleNewPeerChannel(peer: Peer) { handleNewPeerChannel(peer: Peer, channel: any) {
this.update(peer.stream.remotePublicKey, { peer }); this.update(peer.socket.remotePublicKey, { peer });
this._registerOpenSocketMessage(peer); this._registerOpenSocketMessage(peer, channel);
this._registerWriteSocketMessage(peer); this._registerWriteSocketMessage(peer, channel);
this._registerCloseSocketMessage(peer); this._registerCloseSocketMessage(peer, channel);
this._registerTimeoutSocketMessage(peer); this._registerTimeoutSocketMessage(peer, channel);
this._registerErrorSocketMessage(peer); this._registerErrorSocketMessage(peer, channel);
} }
async handleClosePeer(peer: Peer) { async handleClosePeer(peer: Peer) {
@ -175,9 +175,9 @@ export default class MultiSocketProxy extends Proxy {
return socket; return socket;
} }
private _registerOpenSocketMessage(peer: Peer) { private _registerOpenSocketMessage(peer: Peer, channel: any) {
const self = this; const self = this;
const message = peer.channel.addMessage({ const message = channel.addMessage({
encoding: { encoding: {
preencode: json.preencode, preencode: json.preencode,
encode: json.encode, encode: json.encode,
@ -223,9 +223,9 @@ export default class MultiSocketProxy extends Proxy {
}); });
} }
private _registerWriteSocketMessage(peer: Peer) { private _registerWriteSocketMessage(peer: Peer, channel: any) {
const self = this; const self = this;
const message = peer.channel.addMessage({ const message = channel.addMessage({
encoding: writeSocketEncoding, encoding: writeSocketEncoding,
onmessage(m: WriteSocketRequest) { onmessage(m: WriteSocketRequest) {
self._sockets.get(m.id)?.push(m.data); self._sockets.get(m.id)?.push(m.data);
@ -236,9 +236,9 @@ export default class MultiSocketProxy extends Proxy {
}); });
} }
private _registerCloseSocketMessage(peer: Peer) { private _registerCloseSocketMessage(peer: Peer, channel: any) {
const self = this; const self = this;
const message = peer.channel.addMessage({ const message = channel.addMessage({
encoding: socketEncoding, encoding: socketEncoding,
onmessage(m: CloseSocketRequest) { onmessage(m: CloseSocketRequest) {
self._sockets.get(m.id)?.end(); self._sockets.get(m.id)?.end();
@ -249,9 +249,9 @@ export default class MultiSocketProxy extends Proxy {
}); });
} }
private _registerTimeoutSocketMessage(peer: Peer) { private _registerTimeoutSocketMessage(peer: Peer, channel: any) {
const self = this; const self = this;
const message = peer.channel.addMessage({ const message = channel.addMessage({
encoding: socketEncoding, encoding: socketEncoding,
onmessage(m: SocketRequest) { onmessage(m: SocketRequest) {
// @ts-ignore // @ts-ignore
@ -263,9 +263,9 @@ export default class MultiSocketProxy extends Proxy {
}); });
} }
private _registerErrorSocketMessage(peer: Peer) { private _registerErrorSocketMessage(peer: Peer, channel: any) {
const self = this; const self = this;
const message = peer.channel.addMessage({ const message = channel.addMessage({
encoding: errorSocketEncoding, encoding: errorSocketEncoding,
onmessage(m: ErrorSocketRequest) { onmessage(m: ErrorSocketRequest) {
// @ts-ignore // @ts-ignore

View File

@ -6,15 +6,11 @@ export default class Peer extends BasePeer {
protected declare _proxy: MultiSocketProxy; protected declare _proxy: MultiSocketProxy;
protected async initSocket() {} protected async initSocket() {}
get stream(): any {
return this._muxer.stream;
}
protected async handleChannelOnClose(socket: Socket): Promise<void> { protected async handleChannelOnClose(socket: Socket): Promise<void> {
return this._proxy.handleClosePeer(this); return this._proxy.handleClosePeer(this);
} }
protected async handleChannelOnOpen(m: any): Promise<void> { protected async handleChannelOnOpen(m: any): Promise<void> {
await this._proxy.handleNewPeerChannel(this); await this._proxy.handleNewPeerChannel(this._peer, this._channel);
} }
} }