@yz-social/civildefense.io 4.4.4 → 4.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -3
- package/public/javascripts/agent.js +2 -2
- package/public/javascripts/alert.js +557 -0
- package/public/javascripts/conversation.js +99 -0
- package/public/javascripts/hashtags.js +10 -9
- package/public/javascripts/main.js +4 -5
- package/public/javascripts/map.js +9 -573
- package/public/javascripts/p2pWebNetwork.js +17 -14
- package/public/javascripts/service-manager.js +1 -1
- package/public/javascripts/versions.js +1 -1
- package/public/service-worker.js +7 -4
- package/server/app.js +8 -7
- package/server/getLocation.js +1 -1
- package/server/location.json +2 -2
- package/spec/axonSpec.js +5 -11
- package/spec/conversationSpec.js +116 -0
- package/movie/camera.jpg +0 -0
- package/movie/movie.js +0 -151
- package/movie/script.js +0 -272
- package/movie/test.js +0 -2
- package/nginx/nginx.conf +0 -83
- package/nginx/yz.social +0 -81
- package/public/about/In case of Nazis, use CivilDefense.io.png +0 -0
- package/server/bridge.js +0 -397
- package/server/identity.js +0 -111
- package/spec/axonSpec.gratuitousNameChangeForSignal +0 -246
- package/spec/axonSpec.jsRemoveThePartAfterJS +0 -252
- package/spec/civildefenseSpec.js +0 -61
- package/spec/pubsubSpec.js +0 -128
package/spec/pubsubSpec.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
TODO:
|
|
3
|
-
- subscribe and publish to a series of owned/since:'latest' topic that includes a kill, but Bob's history ends with that kill.
|
|
4
|
-
- chunking
|
|
5
|
-
- Put agents in different regions.
|
|
6
|
-
- Throttled flood of 1000 alerts
|
|
7
|
-
*/
|
|
8
|
-
const { describe, it, expect, beforeAll, afterAll } = globalThis;
|
|
9
|
-
import { P2PWebNetwork as Node } from '../index.js';
|
|
10
|
-
|
|
11
|
-
describe("CivilDefense", function () {
|
|
12
|
-
// These two are not acceptance criteria for how long the operation should take, but are instead
|
|
13
|
-
// how long we are willing to wait in in the test before assuming it is never going to happen.
|
|
14
|
-
const connectAllowanceMS = 20e3;
|
|
15
|
-
const deliveryAllowanceMS = 10e3;
|
|
16
|
-
const location = {lat: 37.468640806567656, lng:-122.25797749532343};
|
|
17
|
-
Node.setSessionRegion(location); //fixme
|
|
18
|
-
|
|
19
|
-
let alice, bob, carol, david, emma;
|
|
20
|
-
let aliceKillTag, currentOperation;
|
|
21
|
-
|
|
22
|
-
const version = Date.now(); // Each run gets a new topic.
|
|
23
|
-
const eventName = `civilDefense.io:${version}:pubsub-test`;
|
|
24
|
-
const regionCode = Node.regionCode(location.lat, location.lng);
|
|
25
|
-
class TestNode extends Node { // Version of Node specific to these tests.
|
|
26
|
-
async publish({message, killTag, ...rest}) { // Log publish, and default eventName/region for these tests.
|
|
27
|
-
const published = await super.publish({eventName, region:regionCode, message, killTag, ...rest});
|
|
28
|
-
this.log(killTag ? 'kill' : 'publish', currentOperation, message || killTag);
|
|
29
|
-
return published;
|
|
30
|
-
}
|
|
31
|
-
resetExpectedPromise(expectedCount) {
|
|
32
|
-
// Sets a current internal handler, without updating subscription, which records handled messages in this.events[currentOperation].
|
|
33
|
-
// Returns a ready promise that resolves when the expectedCount has been received.
|
|
34
|
-
return this.ready = new Promise(resolve => {
|
|
35
|
-
const handlerTime = Date.now();
|
|
36
|
-
this.handler = ({message, receiver, ts:pubTime}) => { // Ensure that the receiver's events[currentOperation] is a list, and push message on to it.
|
|
37
|
-
// FIXME: ts is undefined for a kill, which is weird:
|
|
38
|
-
// 1. I would think that Axona needs the time in order to dedupe and order properly?
|
|
39
|
-
// 2. The app may need the time, especially since we are not reliably getting events in ts order. (See "wrong order" comment, below.)
|
|
40
|
-
pubTime ||= 0;
|
|
41
|
-
const start = Math.max(pubTime, handlerTime);
|
|
42
|
-
const elapsed = Date.now() - start;
|
|
43
|
-
const data = receiver.events[currentOperation] ||= [];
|
|
44
|
-
receiver.log(`received ${currentOperation} ${data.length} ${message} after ${elapsed.toLocaleString()} ms.`);
|
|
45
|
-
data.push(message || null);
|
|
46
|
-
if (data.length < expectedCount) return;
|
|
47
|
-
resolve();
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
async subscribe({expectedCount = 0, handler = (...rest) => this.handler?.(...rest), ...rest} = {}) {
|
|
52
|
-
const ready = this.resetExpectedPromise(expectedCount);
|
|
53
|
-
const subscribed = await super.subscribe({eventName, region:regionCode, handler});
|
|
54
|
-
this.log('subscribed, expecting', expectedCount);
|
|
55
|
-
return subscribed;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const inOrder = ['alice pub', ' bob pub'];
|
|
59
|
-
|
|
60
|
-
beforeAll(async function () {
|
|
61
|
-
[alice, bob] = await Promise.all([
|
|
62
|
-
TestNode.create({location, events: {}, label: 'alice', authorIdentity: '{"kind":"author","pubkey":"b08988518013fabc5949353281d263cb7916f273f3f8badf0b16443a67d0b05c","privkey":"MC4CAQAwBQYDK2VwBCIEIC7ZrU8C2WSBdoBQW/JoE0ZYRkp/kFcCGf7H25DVqM17","createdAt":1782508727637}'}),
|
|
63
|
-
TestNode.create({location, events: {}, label: ' bob', authorIdentity: '{"kind":"author","pubkey":"6447bae1e8f1d5c99243251b43b4d354fb4928c10b69076563617c06fff46ca3","privkey":"MC4CAQAwBQYDK2VwBCIEIGGHVqedJBPtzSDR3P03HHpWTPlyXteHJAPtABmdwujM","createdAt":1782508849433}'})
|
|
64
|
-
]);
|
|
65
|
-
await Promise.all([alice.subscribe({expectedCount: 2}), bob.subscribe({expectedCount: 2})]);
|
|
66
|
-
// Now carol joins and subscribes.
|
|
67
|
-
carol = await TestNode.create({location, events: {}, label: 'carol', authorIdentity: '{"kind":"author","pubkey":"9fac71086211be29c685fc8aeab7725f4e78a0476482b817b9160273a40812e8","privkey":"MC4CAQAwBQYDK2VwBCIEILSc0paO923M0X8d8ux6JkjEFz65gk2BVBPlTtlZD6Q3","createdAt":1782508860832}'});
|
|
68
|
-
await carol.subscribe({expectedCount: 2});
|
|
69
|
-
|
|
70
|
-
currentOperation = 'initial';
|
|
71
|
-
// 'alice pub' starts and completes before 'bob pub' starts.
|
|
72
|
-
aliceKillTag = await alice.publish({message: 'alice pub'});
|
|
73
|
-
await TestNode.delay(500); // FIXME: without this delay, subscription handlers are called in the wrong order.
|
|
74
|
-
await bob.publish({message: ' bob pub'});
|
|
75
|
-
await Promise.all([alice.ready, bob.ready, carol.ready]);
|
|
76
|
-
}, 2 * connectAllowanceMS + deliveryAllowanceMS);
|
|
77
|
-
describe("initial", function () {
|
|
78
|
-
it("alice receives all pubs from herself and bob", function () { expect(alice.events.initial).toEqual(inOrder); });
|
|
79
|
-
it(" bob receives all pubs from himself and bob", function () { expect( bob.events.initial).toEqual(inOrder); });
|
|
80
|
-
it("carol receives all pubs from alice and bob", function () { expect(carol.events.initial).toEqual(inOrder); });
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe("restart", function () {
|
|
84
|
-
beforeAll(async function () {
|
|
85
|
-
await bob.disconnect();
|
|
86
|
-
carol.handler = null; // We're not going to disconnect this instance of carol, but let's not get confused by subscription callbacks.
|
|
87
|
-
[bob, carol, david] = await Promise.all([
|
|
88
|
-
TestNode.create({location, events: bob.events, label: ' bob', authorIdentity: bob.authorIdentity}),
|
|
89
|
-
TestNode.create({location, events: carol.events, label: 'carol', authorIdentity: carol.authorIdentity}),
|
|
90
|
-
TestNode.create({location, events: {}, label: 'david', authorIdentity: '{"kind":"author","pubkey":"4071c632d8aedfeee7293c23a539b368211cf903722d12d521eeda226047e1ed","privkey":"MC4CAQAwBQYDK2VwBCIEIN/rAuWAlhP2blF3neaoXxLM727hQ1ZzR0hsg9yYS6hd","createdAt":1782508870567}'})
|
|
91
|
-
]);
|
|
92
|
-
currentOperation = 'restart';
|
|
93
|
-
await Promise.all([bob.subscribe({expectedCount: 2}), carol.subscribe({expectedCount: 2}), david.subscribe({expectedCount: 2})]);
|
|
94
|
-
await Promise.all([bob.ready, carol.ready, david.ready]);
|
|
95
|
-
}, 1 * connectAllowanceMS + deliveryAllowanceMS);
|
|
96
|
-
it(" bob receives all pubs from himself and bob", function () { expect( bob.events.restart).toEqual(inOrder); });
|
|
97
|
-
it("carol receives all pubs from alice and bob", function () { expect(carol.events.restart).toEqual(inOrder); });
|
|
98
|
-
it("david receives all pubs from alice and bob", function () { expect(david.events.restart).toEqual(inOrder); });
|
|
99
|
-
|
|
100
|
-
describe("after kill", function () {
|
|
101
|
-
beforeAll(async function () {
|
|
102
|
-
currentOperation = 'kill';
|
|
103
|
-
alice.resetExpectedPromise(1);
|
|
104
|
-
bob.resetExpectedPromise(1);
|
|
105
|
-
carol.resetExpectedPromise(1);
|
|
106
|
-
david.resetExpectedPromise(1);
|
|
107
|
-
await alice.publish({killTag: aliceKillTag});
|
|
108
|
-
await TestNode.delay(500); // FIXME: without this delay, someone already subscribed (like Bob) sometimes (rarely) doesn't get the kill callback.
|
|
109
|
-
emma = await TestNode.create({location, events: {}, label: ' emma', authorIdentity: '{"kind":"author","pubkey":"ddd028fe0436ce4d1eaf697b3be3971ff009fabcd4949028adf8305d5291e1f7","privkey":"MC4CAQAwBQYDK2VwBCIEIO0eoNtBvNuA84mFckAIR0ozuwFbMwJhR+FbMOq+ZALf","createdAt":1782509271005}'});
|
|
110
|
-
emma.subscribe({expectedCount: 1});
|
|
111
|
-
await Promise.all([alice.ready, bob.ready, carol.ready, david.ready, emma.ready]);
|
|
112
|
-
}, connectAllowanceMS + deliveryAllowanceMS);
|
|
113
|
-
it("alice receives kill", function () { expect(alice.events.kill).toEqual([null]); });
|
|
114
|
-
it(" bob receives kill", function () { expect( bob.events.kill).toEqual([null]); });
|
|
115
|
-
it("carol receives kill", function () { expect(carol.events.kill).toEqual([null]); });
|
|
116
|
-
it("david receives kill", function () { expect(david.events.kill).toEqual([null]); });
|
|
117
|
-
it(" emma only receives unkilled pub from bob", function () { expect( emma.events.kill).toEqual(inOrder.slice(1)); });
|
|
118
|
-
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
afterAll(async function () {
|
|
122
|
-
await alice.disconnect();
|
|
123
|
-
await bob.disconnect();
|
|
124
|
-
await carol?.disconnect();
|
|
125
|
-
await david?.disconnect();
|
|
126
|
-
await emma?.disconnect();
|
|
127
|
-
});
|
|
128
|
-
});
|