Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone committed Dec 3, 2024
1 parent ccbcd6c commit 46b633b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 78 deletions.
5 changes: 0 additions & 5 deletions js/src/Ice/Connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ declare module "ice" {
*/
get underlying(): Ice.ConnectionInfo | null;

/**
* Indicates whether the connection is incoming (`true`) or outgoing (`false`).
*/
get incoming(): boolean;

/**
* The name of the adapter associated with this connection.
*/
Expand Down
59 changes: 11 additions & 48 deletions js/src/Ice/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,26 @@
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import { defineDictionary } from "./HashMap.js";
import { StreamHelpers } from "./StreamHelpers.js";

/**
* Base class providing access to the connection details.
**/
export class ConnectionInfo {
constructor() {
if (arguments.length === 3) {
// ConnectionInfo(incoming, adapterName, connectionId)
constructor(underlying, adapterName, connectionId) {
if (underlying === null) {
this._underlying = null;
this._incoming = arguments[0];
this._adapterName = arguments[1];
this._connectionId = arguments[2];
this._adapterName = adapterName;
this._connectionId = connectionId;
} else {
// ConnectionInfo(underlying)
DEV: console.assert(arguments.length === 1);
DEV: console.assert(arguments[0] instanceof ConnectionInfo);
this._underlying = arguments[0];
this._incoming = this._underlying.incoming;
this._adapterName = this._underlying.adapterName;
this._connectionId = this._underlying.connectionId;
this._underlying = underlying;
this._adapterName = underlying.adapterName;
this._connectionId = underlying.connectionId;
}
}

get underlying() {
return this._underlying;
}

get incoming() {
return this._incoming;
}

get adapterName() {
return this._adapterName;
}
Expand All @@ -48,16 +35,8 @@ export class ConnectionInfo {
* Provides access to the connection details of an IP connection
**/
export class IPConnectionInfo extends ConnectionInfo {
constructor(
incoming,
adapterName,
connectionId,
localAddress = "",
localPort = -1,
remoteAddress = "",
remotePort = -1,
) {
super(incoming, adapterName, connectionId);
constructor(adapterName, connectionId, localAddress = "", localPort = -1, remoteAddress = "", remotePort = -1) {
super(null, adapterName, connectionId);
this._localAddress = localAddress;
this._localPort = localPort;
this._remoteAddress = remoteAddress;
Expand Down Expand Up @@ -86,7 +65,6 @@ export class IPConnectionInfo extends ConnectionInfo {
**/
export class TCPConnectionInfo extends IPConnectionInfo {
constructor(
incoming,
adapterName,
connectionId,
localAddress = "",
Expand All @@ -96,7 +74,7 @@ export class TCPConnectionInfo extends IPConnectionInfo {
rcvSize = 0,
sndSize = 0,
) {
super(incoming, adapterName, connectionId, localAddress, localPort, remoteAddress, remotePort);
super(adapterName, connectionId, localAddress, localPort, remoteAddress, remotePort);
this._rcvSize = rcvSize;
this._sndSize = sndSize;
}
Expand All @@ -110,22 +88,7 @@ export class TCPConnectionInfo extends IPConnectionInfo {
}
}

export const [HeaderDict, HeaderDictHelper] = defineDictionary(
StreamHelpers.StringHelper,
StreamHelpers.StringHelper,
false,
);

/**
* Provides access to the connection details of a WebSocket connection
**/
export class WSConnectionInfo extends ConnectionInfo {
constructor(underlying, headers) {
super(underlying);
this._headers = headers;
}

get headers() {
return this._headers;
}
}
export class WSConnectionInfo extends ConnectionInfo {}
1 change: 0 additions & 1 deletion js/src/Ice/ConnectionI.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,6 @@ export class ConnectionI {
throw this._exception;
}
return this._transceiver.getInfo(
false,
this._adapter !== null ? this._adapter.getName() : "",
this._endpoint.connectionId(),
);
Expand Down
26 changes: 10 additions & 16 deletions js/src/Ice/Endpoint.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
// Copyright (c) ZeroC, Inc.

import { InitializationException } from "./LocalExceptions.js";

/**
* Base class providing access to the endpoint details.
**/
export class EndpointInfo {
constructor() {
if (arguments.length === 2) {
constructor(underlying, timeout, compress) {
if (underlying === null) {
// EndpointInfo(timeout, compress)
this._underlying = null;
this._timeout = arguments[0];
this._compress = arguments[1];
this._timeout = timeout;
this._compress = compress;
} else {
// EndpointInfo(underlying)
DEV: console.assert(arguments.length === 1);
DEV: console.assert(arguments[0] instanceof EndpointInfo);
this._underlying = arguments[0];
this._timeout = arguments[0].timeout;
this._compress = arguments[0].compress;
this._underlying = underlying;
this._timeout = underlying.timeout;
this._compress = underlying.compress;
}
}

Expand Down Expand Up @@ -52,12 +47,11 @@ export class EndpointInfo {
* @see {@link Endpoint}
**/
export class IPEndpointInfo extends EndpointInfo {
constructor(timeout, compress, host, port, sourceAddress, type) {
super(timeout, compress);
constructor(timeout, compress, host, port, sourceAddress) {
super(null, timeout, compress);
this._host = host;
this._port = port;
this._sourceAddr = sourceAddress;
this._type = type;
}

get host() {
Expand Down Expand Up @@ -113,7 +107,7 @@ export class WSEndpointInfo extends EndpointInfo {
**/
export class OpaqueEndpointInfo extends EndpointInfo {
constructor(type, rawEncoding, rawBytes) {
super(-1, false);
super(null, -1, false);
this._type = type;
this._rawEncoding = rawEncoding;
this._rawBytes = rawBytes;
Expand Down
5 changes: 2 additions & 3 deletions js/src/Ice/TcpTransceiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,16 @@ if (typeof net.createConnection === "function") {
return "tcp";
}

getInfo(incoming, adapterName, connectionId) {
getInfo(adapterName, connectionId) {
DEV: console.assert(this._fd !== null);
return new TCPConnectionInfo(
incoming,
adapterName,
connectionId,
this._fd.localAddress,
this._fd.localPort,
this._fd.remoteAddress,
this._fd.remotePort,
-1,
0,
this._maxSendPacketSize,
);
}
Expand Down
7 changes: 3 additions & 4 deletions js/src/Ice/WSTransceiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,25 @@ if (typeof WebSocket !== "undefined") {
return this._secure ? "wss" : "ws";
}

getInfo(incoming, adapterName, connectionId) {
getInfo(adapterName, connectionId) {
DEV: console.assert(this._fd !== null);

let info = new TCPConnectionInfo(
incoming,
adapterName,
connectionId,
"",
-1,
this._addr.host,
this._addr.port,
-1,
0,
this._maxSendPacketSize,
);

if (this._secure) {
info = new SSLConnectionInfo(info);
}

return new WSConnectionInfo(info, {});
return new WSConnectionInfo(info);
}

setBufferSize(rcvSize, sndSize) {
Expand Down
1 change: 0 additions & 1 deletion js/test/Ice/info/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export class Client extends TestHelper {
const info = conn.getInfo();
let ipConnectionInfo: Ice.TCPConnectionInfo | null = getTCPConnectionInfo(info);
test(ipConnectionInfo != null);
test(!info.incoming);
test(info.adapterName.length === 0);
if (conn.type() != "ws" && conn.type() != "wss") {
test(ipConnectionInfo!.localPort > 0);
Expand Down

0 comments on commit 46b633b

Please sign in to comment.