PeerServer, Peer: Fully support exchanging friendly names
....we should have done this a while back :P This doesn't change logging messages though
This commit is contained in:
parent
fd16ca4078
commit
7e5b0725e9
4 changed files with 21 additions and 3 deletions
|
@ -6,7 +6,6 @@ import path from 'path';
|
|||
import { EventEmitter } from 'events';
|
||||
|
||||
import log from '../io/NamespacedLog.mjs'; const l = log("agent");
|
||||
|
||||
import settings from '../../settings.mjs';
|
||||
|
||||
import PeerServer from './PeerServer.mjs';
|
||||
|
@ -61,6 +60,7 @@ class Agent extends EventEmitter {
|
|||
///
|
||||
this.server = new PeerServer(
|
||||
this.peer_id,
|
||||
this.peer_name,
|
||||
await this.find_secret()
|
||||
);
|
||||
this.server.retries = this.config.net.peer_retries;
|
||||
|
|
|
@ -22,6 +22,7 @@ class Peer extends EventEmitter {
|
|||
address: this.address,
|
||||
port: this.port,
|
||||
id: this.id,
|
||||
name: this.name,
|
||||
listening_address: this.listening_address,
|
||||
listening_port: this.listening_port
|
||||
};
|
||||
|
@ -30,7 +31,18 @@ class Peer extends EventEmitter {
|
|||
constructor(server, connection) {
|
||||
super();
|
||||
|
||||
/**
|
||||
* The ID of this peer.
|
||||
* @type {string}
|
||||
*/
|
||||
this.id = null;
|
||||
/**
|
||||
* The friendly name of this peer.
|
||||
* Unlike the ID, this *may* not be unique (though it is strongly
|
||||
* encouraged to be unique).
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = null;
|
||||
|
||||
/**
|
||||
* The parent server this Peer is part of.
|
||||
|
@ -91,6 +103,7 @@ class Peer extends EventEmitter {
|
|||
*/
|
||||
__handle_hello(msg) {
|
||||
this.id = msg.id;
|
||||
this.name = msg.name;
|
||||
this.listening_address = msg.listening_address;
|
||||
this.listening_port = msg.listening_port;
|
||||
|
||||
|
@ -115,6 +128,7 @@ class Peer extends EventEmitter {
|
|||
async __send_hello() {
|
||||
await this.send("hello", {
|
||||
id: this.server.our_id,
|
||||
name: this.server.our_name,
|
||||
listening_address: this.server.host,
|
||||
listening_port: this.server.port
|
||||
});
|
||||
|
|
|
@ -25,10 +25,11 @@ class PeerServer extends EventEmitter {
|
|||
return this.server instanceof net.Server ? this.server.listening : false;
|
||||
}
|
||||
|
||||
constructor(our_id, secret_join) {
|
||||
constructor(our_id, our_name, secret_join) {
|
||||
super();
|
||||
|
||||
this.our_id = our_id;
|
||||
this.our_name = our_name;
|
||||
this.secret_join = secret_join;
|
||||
|
||||
// The number of retries when attempting to connect to a peer
|
||||
|
|
|
@ -8,7 +8,10 @@ export default async function(sys, ctx, _next) {
|
|||
let table_name = sys.fetch_table(ctx.params.table_name.replace(/[^0-9a-zA-Z_-]/g, ""));
|
||||
for await (let next of table_name) {
|
||||
stream.write_json(`table`, {
|
||||
peer: next.peer.id,
|
||||
peer: {
|
||||
id: next.peer.id,
|
||||
name: next.peer.name
|
||||
},
|
||||
table: next.table
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue