diff --git a/src/lib/SystemQuery.mjs b/src/lib/SystemQuery.mjs index db9a26e..19d44fd 100644 --- a/src/lib/SystemQuery.mjs +++ b/src/lib/SystemQuery.mjs @@ -28,6 +28,8 @@ class SystemQuery extends EventEmitter { } } + get listening() { return this.agent !== null ? this.agent.listening : false; } + // TODO: Handle duplicate connections better by both skipping counting them here, and also implementing a more robust reaper for killing duplicate connections that always kills the newest/oldest connection to avoid issues. diff --git a/src/lib/agent/Agent.mjs b/src/lib/agent/Agent.mjs index 330dab9..7577a5e 100644 --- a/src/lib/agent/Agent.mjs +++ b/src/lib/agent/Agent.mjs @@ -19,11 +19,16 @@ class Agent extends EventEmitter { get connected_peers() { return this.server.connected_peers; } get connecting_peers() { return this.server.connecting_peers; } + get listening() { return this.server !== null ? this.server.listening : false; } constructor(config) { super(); this.config = config; + + this.peer_id = null; + this.peer_name = null; + this.server = null; } async find_secret() { diff --git a/src/lib/agent/PeerServer.mjs b/src/lib/agent/PeerServer.mjs index dcb24e1..f786ae2 100644 --- a/src/lib/agent/PeerServer.mjs +++ b/src/lib/agent/PeerServer.mjs @@ -21,6 +21,10 @@ import Peer from './Peer.mjs'; * @extends EventEmitter */ class PeerServer extends EventEmitter { + get listening() { + return this.server instanceof net.Server ? this.server.listening : false; + } + constructor(our_id, secret_join) { super();