Skip to content

Commit

Permalink
Add 'active' boolean to a domain to denote if the domain is heartbeating
Browse files Browse the repository at this point in the history
Include 'active', 'protocol', and 'version' is domain information in Place returned info
Update number of domain reported users to be sum of logged in and anonymous avatars
Reorder Place return tests so /api/v1/places does not return Places with no domains
Update documentation on return of added fields for Places
  • Loading branch information
Misterblue committed Mar 24, 2021
1 parent b6799ed commit 1f58e15
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 14 deletions.
3 changes: 3 additions & 0 deletions docs/API-Places.md
Expand Up @@ -105,6 +105,9 @@ This request return JSON formatted as:
"sponsorAccountId": string,
"network_address": string,
"ice_server_address": string,
'version': string, // version of domain-server
'protocol_version': string, // protocol version for domain-server
'active': boolean, // true if domain is heartbeating
"time_of_last_heartbeat": ISOStringDate,
"num_users": integer
},
Expand Down
2 changes: 1 addition & 1 deletion docs/API-Users.md
Expand Up @@ -51,7 +51,7 @@ The response body is an "applicaton/json" structure that contains an array of us
"node_id": stringSessionId,
"root": {
"domain": {
"id":
"id": string
"network_address": stringHostname,
"network_port": intPortNum,
"ice_server_address": stringHostname,
Expand Down
3 changes: 2 additions & 1 deletion src/Entities/DomainEntity.ts
Expand Up @@ -51,7 +51,8 @@ export class DomainEntity implements Entity {

// admin stuff
public iPAddrOfFirstContact: string; // IP address that registered this domain
public whenCreated: Date; // What the variable name says
public whenCreated: Date; // What the variable name says
public active: boolean; // domain is heartbeating
public timeOfLastHeartbeat: Date; // time of last heartbeat
public lastSenderKey: string; // a key identifying the sender

Expand Down
9 changes: 9 additions & 0 deletions src/Entities/DomainFields.ts
Expand Up @@ -319,6 +319,15 @@ export const DomainFields: { [key: string]: FieldDefn } = {
setter: noSetter,
getter: dateStringGetter
},
'active': {
entity_field: 'active',
request_field_name: 'active',
get_permissions: [ Perm.ALL ],
set_permissions: [ Perm.NONE ],
validate: isBooleanValidator,
setter: noSetter,
getter: simpleGetter
},
'time_of_last_heartbeat': {
entity_field: 'timeOfLastHeartbeat',
request_field_name: 'time_of_last_heartbeat',
Expand Down
1 change: 1 addition & 0 deletions src/Entities/Domains.ts
Expand Up @@ -52,6 +52,7 @@ export function initDomains(): void {
Logger.info(`Domains: domain ${aDomain.name} not heartbeating. Zeroing users.`);
aDomain.numUsers = 0;
aDomain.anonUsers = 0;
aDomain.active = false;
const updates: VKeyedCollection = {
'numUsers': 0,
'anonUsers': 0
Expand Down
16 changes: 8 additions & 8 deletions src/Entities/Places.ts
Expand Up @@ -174,19 +174,19 @@ export const Places = {
// The address is of the form "optional-domain/x,y,z/x,y,z,w".
// If the domain is missing, the domain-server's network address is added
let addr = pPlace.path ?? '/0,0,0/0,0,0,1';

// If no domain/address specified in path, build addr using reported domain IP/port
const pieces = addr.split('/');
// kludge as there were a bunch of "undefined" domain/address names
if (pieces.length > 0 && pieces[0].length === 9 && pieces[0] === 'undefined') {
pieces[0] = '';
};
if (pieces[0].length === 0) {
const aDomain = await Domains.getDomainWithId(pPlace.domainId);
if (IsNotNullOrEmpty(aDomain)) {
let domainAddr = aDomain.networkAddr;
if (IsNotNullOrEmpty(aDomain.networkPort)) {
domainAddr = aDomain.networkAddr + ":" + aDomain.networkPort;
if (IsNotNullOrEmpty(aDomain.networkAddr)) {
let domainAddr = aDomain.networkAddr;
if (IsNotNullOrEmpty(aDomain.networkPort)) {
domainAddr = aDomain.networkAddr + ":" + aDomain.networkPort;
};
addr = domainAddr + addr;
};
addr = domainAddr + addr;
};
};
return addr;
Expand Down
5 changes: 4 additions & 1 deletion src/route-tools/Util.ts
Expand Up @@ -134,8 +134,11 @@ export async function buildDomainInfo(pDomain: DomainEntity): Promise<any> {
'network_address': pDomain.networkAddr,
'network_port': pDomain.networkPort,
'ice_server_address': pDomain.iceServerAddr,
'version': pDomain.version,
'protocol_version': pDomain.protocol,
'active': pDomain.active ?? false,
'time_of_last_heartbeat': pDomain.timeOfLastHeartbeat ? pDomain.timeOfLastHeartbeat.toISOString() : undefined,
'num_users': pDomain.numUsers
'num_users': pDomain.numUsers + pDomain.anonUsers
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/routes/api/v1/domains/domainId.ts
Expand Up @@ -31,6 +31,7 @@ import { VKeyedCollection } from '@Tools/vTypes';
import { Logger } from '@Tools/Logging';
import Config from '@Base/config';
import { IsNullOrEmpty } from '@Tools/Misc';
import { updateObjectFields } from '@Tools/Db';

// GET /api/v1/domains/:domainId
// Return a small snippet if domain data for the domainId specified in the request
Expand Down Expand Up @@ -90,7 +91,7 @@ const procPutDomains: RequestHandler = async (req: Request, resp: Response, next
};
};

/* FOLLOWING CODE DOES NOT WORK: the socker.remoteAddress is the IP addr
/* FOLLOWING CODE DOES NOT WORK: the socket.remoteAddress is the IP addr
of the front end proxy server. Need to use 'x-forwarded-for:' header
or whatever is the right source.
Could also have the domain-server send the information more often.
Expand All @@ -109,6 +110,7 @@ const procPutDomains: RequestHandler = async (req: Request, resp: Response, next

// This 'POST" is used as the domain heartbeat. Remember it's alive.
updated.timeOfLastHeartbeat = new Date();
updated.active = true;
Logger.debug('procPutDomains. updating=' + JSON.stringify(updated));
Domains.updateEntityFields(req.vDomain, updated);
}
Expand Down
4 changes: 2 additions & 2 deletions src/routes/api/v1/places.ts
Expand Up @@ -52,8 +52,8 @@ const procGetPlaces: RequestHandler = async (req: Request, resp: Response, next:
const places: any[] = [];
for await (const place of Places.enumerateAsync(placer, pager)) {
const aDomain = await Domains.getDomainWithId(place.domainId);
if (await visibilitier.criteriaTestAsync(place, aDomain)) {
if (aDomain && IsNotNullOrEmpty(aDomain.networkAddr)) {
if (aDomain && IsNotNullOrEmpty(aDomain.networkAddr)) {
if (await visibilitier.criteriaTestAsync(place, aDomain)) {
places.push(await buildPlaceInfo(place, aDomain));
};
};
Expand Down

0 comments on commit 1f58e15

Please sign in to comment.