feat: Instead of delisting, push stale nodes to bottom (#161)

This commit is contained in:
Maciej Hirsz
2019-07-02 14:52:06 +02:00
committed by GitHub
parent c817a16d31
commit 983919fd87
8 changed files with 70 additions and 32 deletions
+14 -1
View File
@@ -15,6 +15,8 @@ export class Connection {
return new Connection(await Connection.socket(), update, pins);
}
private static readonly utf8decoder = new TextDecoder('utf-8');
private static readonly address = window.location.protocol === 'https:'
? `wss://${window.location.hostname}/feed/`
: `ws://${window.location.hostname}:8080`;
@@ -55,6 +57,7 @@ export class Connection {
const socket = new WebSocket(Connection.address);
socket.binaryType = "arraybuffer";
socket.addEventListener('open', onSuccess);
socket.addEventListener('error', onFailure);
socket.addEventListener('close', onFailure);
@@ -173,6 +176,14 @@ export class Connection {
break;
}
case Actions.StaleNode: {
const id = message.payload;
nodes.mutAndSort(id, (node) => node.setStale(true));
break;
}
case Actions.LocatedNode: {
const [id, lat, lon, city] = message.payload;
@@ -376,7 +387,9 @@ export class Connection {
}
private handleFeedData = (event: MessageEvent) => {
const data = event.data as FeedMessage.Data;
const data = typeof event.data === 'string'
? event.data as any as FeedMessage.Data
: Connection.utf8decoder.decode(event.data) as any as FeedMessage.Data;
this.handleMessages(FeedMessage.deserialize(data));
}