Skip to content

Commit

Permalink
App2app update (#10)
Browse files Browse the repository at this point in the history
* App2App: manual commit + read ahead 50

* Include test env configurations

* Log at info level (instead of trace) in app2app messages

Signed-off-by: Gabriel Indik <[email protected]>
  • Loading branch information
gabriel-indik authored Dec 30, 2020
1 parent d11dd99 commit 1ac9325
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 14 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ solidity_new/build
solidity_new/package-lock.json
core/node_modules
core/build
core/data
core/test-resources/sandbox
utils/kat-client/node_modules
68 changes: 60 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,86 @@
{
"type": "node",
"request": "launch",
"name": "Org A",
"name": "MR - Org A",
"cwd": "${workspaceFolder}/core",
"runtimeExecutable": "nodemon",
"env": {
"DATA_DIRECTORY": "/Users/gabrielindik/Kaleido/Repos/asset-trail/core/data/OrgA",
"DATA_DIRECTORY": "/Users/gabrielindik/Kaleido/Repos/asset-trail/core/data/multi-region/OrgA",
"LOG_LEVEL": "info"
},
"args": ["|", "bunyan", "-o", "short"],
"args": [
"|",
"bunyan",
"-o",
"short"
],
"outputCapture": "std",
"resolveSourceMapLocations": [
"!**/node_modules/**"
]
]
},
{
"type": "node",
"request": "launch",
"name": "Org B",
"name": "MR - Org B",
"cwd": "${workspaceFolder}/core",
"runtimeExecutable": "nodemon",
"env": {
"DATA_DIRECTORY": "/Users/gabrielindik/Kaleido/Repos/asset-trail/core/data/OrgB",
"DATA_DIRECTORY": "/Users/gabrielindik/Kaleido/Repos/asset-trail/core/data/multi-region/OrgB",
"LOG_LEVEL": "info"
},
"args": ["|", "bunyan", "-o", "short"],
"args": [
"|",
"bunyan",
"-o",
"short"
],
"outputCapture": "std",
"resolveSourceMapLocations": [
"!**/node_modules/**"
]
]
},
{
"type": "node",
"request": "launch",
"name": "SR - Org A",
"cwd": "${workspaceFolder}/core",
"runtimeExecutable": "nodemon",
"env": {
"DATA_DIRECTORY": "/Users/gabrielindik/Kaleido/Repos/asset-trail/core/data/single-region/OrgA",
"LOG_LEVEL": "info"
},
"args": [
"|",
"bunyan",
"-o",
"short"
],
"outputCapture": "std",
"resolveSourceMapLocations": [
"!**/node_modules/**"
]
},
{
"type": "node",
"request": "launch",
"name": "SR - Org B",
"cwd": "${workspaceFolder}/core",
"runtimeExecutable": "nodemon",
"env": {
"DATA_DIRECTORY": "/Users/gabrielindik/Kaleido/Repos/asset-trail/core/data/single-region/OrgB",
"LOG_LEVEL": "info"
},
"args": [
"|",
"bunyan",
"-o",
"short"
],
"outputCapture": "std",
"resolveSourceMapLocations": [
"!**/node_modules/**"
]
}
]
}
35 changes: 35 additions & 0 deletions core/data/multi-region/OrgA/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "../../../src/schemas/config.json",
"port": 4001,
"assetTrailInstanceID": "asset-trail-org-a",
"apiGateway": {
"apiEndpoint": "https://zzdk0au9rl-zznm62sm1o-connect.dev2.photic.io/instances/0x1fc8898c69211ff0140765b3fccde27878a9939f"
},
"eventStreams": {
"wsEndpoint": "wss://zzdk0au9rl-zznm62sm1o-connect.dev2-ws.photic.io/ws",
"topic": "A"
},
"ipfs": {
"apiEndpoint": "https://zzdk0au9rl-zzbj5neshi-ipfs.dev2.photic.io"
},
"app2app": {
"socketIOEndpoint": "wss://zzdk0au9rl-zzspcgumw6.dev2-ws.photic.io/api/v1",
"destinations": {
"kat": "kld://app2app/z/dev2/m/zzdza6cuf9/e/zzdk0au9rl/s/zzspcgumw6/d/kat",
"client": "kld://app2app/z/dev2/m/zzdza6cuf9/e/zzdk0au9rl/s/zzspcgumw6/d/client"
}
},
"docExchange": {
"apiEndpoint": "https://zzdk0au9rl-zzu2yrgdqw-documentstore.dev2.photic.io/api/v1",
"socketIOEndpoint": "wss://zzdk0au9rl-zzu2yrgdqw.dev2-ws.photic.io/api/v1",
"destination": "kld://documentstore/z/dev2/m/zzdza6cuf9/e/zzdk0au9rl/s/zzu2yrgdqw/d/a"
},
"appCredentials": {
"user": "zzzpyzyey1",
"password": "RVSTBdP1N9_XVPWzNbKJmTpgfM6dtKECwEdcfk3Kctw"
},
"mongodb": {
"connectionUrl": "mongodb://localhost:27017",
"databaseName": "synaptic-mr-org-a"
}
}
5 changes: 5 additions & 0 deletions core/data/multi-region/OrgA/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "../../../src/schemas/settings.json",
"clientEvents": ["asset-instance-submitted", "asset-instance-created", "payment-instance-created", "private-asset-instance-content-stored",
"asset-instance-property-submitted", "asset-instance-property-set"]
}
35 changes: 35 additions & 0 deletions core/data/multi-region/OrgB/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "../../../src/schemas/config.json",
"port": 4002,
"assetTrailInstanceID": "asset-trail-org-b",
"apiGateway": {
"apiEndpoint": "https://zzdk0au9rl-zzxtrleuk4-connect.azdev.photic.io/instances/0x1fc8898c69211ff0140765b3fccde27878a9939f"
},
"eventStreams": {
"wsEndpoint": "wss://zzdk0au9rl-zzxtrleuk4-connect.azdev-ws.photic.io/ws",
"topic": "B"
},
"ipfs": {
"apiEndpoint": "https://zzdk0au9rl-zzeab6gkxq-ipfs.azdev.photic.io"
},
"app2app": {
"socketIOEndpoint": "wss://zzdk0au9rl-zzyy8m38ff.azdev-ws.photic.io/api/v1",
"destinations": {
"kat": "kld://app2app/z/azdev/m/zzzohltm98/e/zzdk0au9rl/s/zzyy8m38ff/d/kat",
"client": "kld://app2app/z/azdev/m/zzzohltm98/e/zzdk0au9rl/s/zzyy8m38ff/d/client"
}
},
"docExchange": {
"apiEndpoint": "https://zzdk0au9rl-zzleq01yh6-documentstore.azdev.photic.io/api/v1",
"socketIOEndpoint": "wss://zzdk0au9rl-zzleq01yh6.azdev-ws.photic.io/api/v1",
"destination": "kld://documentstore/z/azdev/m/zzzohltm98/e/zzdk0au9rl/s/zzleq01yh6/d/b"
},
"appCredentials": {
"user": "zzv7dyg5d0",
"password": "2tyAt2ZaavAd76jmzP01X6fhAvp8pmh2qoLXkgBm2ps"
},
"mongodb": {
"connectionUrl": "mongodb://localhost:27017",
"databaseName": "synaptic-mr-org-b"
}
}
5 changes: 5 additions & 0 deletions core/data/multi-region/OrgB/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "../../src/schemas/settings.json",
"clientEvents": ["asset-instance-submitted", "asset-instance-created", "payment-instance-created", "private-asset-instance-content-stored",
"asset-instance-property-submitted", "asset-instance-property-set"]
}
35 changes: 35 additions & 0 deletions core/data/single-region/OrgA/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "../../src/schemas/config.json",
"port": 4001,
"assetTrailInstanceID": "asset-trail-org-a",
"apiGateway": {
"apiEndpoint": "https://zzkuwhhizm-zzhh7vdg4w-connect.dev2.photic.io/instances/0xe6719e4f7379e583046376f522a5efc30ca358f3"
},
"eventStreams": {
"wsEndpoint": "wss://zzkuwhhizm-zzhh7vdg4w-connect.dev2-ws.photic.io/ws",
"topic": "A"
},
"ipfs": {
"apiEndpoint": "https://zzkuwhhizm-zzh1ibg3o0-ipfs.dev2.photic.io"
},
"app2app": {
"socketIOEndpoint": "wss://zzkuwhhizm-zzigaja3ua.dev2-ws.photic.io/api/v1",
"destinations": {
"kat": "kld://app2app/z/dev2/m/zzxknul1nt/e/zzkuwhhizm/s/zzigaja3ua/d/a",
"client": "kld://app2app/z/dev2/m/zzxknul1nt/e/zzkuwhhizm/s/zzigaja3ua/d/external"
}
},
"docExchange": {
"apiEndpoint": "https://zzkuwhhizm-zzpp1ys1l8-documentstore.dev2.photic.io/api/v1",
"socketIOEndpoint": "wss://zzkuwhhizm-zzpp1ys1l8.dev2-ws.photic.io/api/v1",
"destination": "kld://documentstore/z/dev2/m/zzxknul1nt/e/zzkuwhhizm/s/zzpp1ys1l8/d/a"
},
"appCredentials": {
"user": "zzbvccppd3",
"password": "_WOhsqQ6ee8pW39Surq9XkZvP4Al-hjDNoFaKUQQF20"
},
"mongodb": {
"connectionUrl": "mongodb://localhost:27017",
"databaseName": "synaptic-org-a"
}
}
5 changes: 5 additions & 0 deletions core/data/single-region/OrgA/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "../../src/schemas/settings.json",
"clientEvents": ["asset-instance-submitted", "asset-instance-created", "payment-instance-created", "private-asset-instance-content-stored",
"asset-instance-property-submitted", "asset-instance-property-set"]
}
35 changes: 35 additions & 0 deletions core/data/single-region/OrgB/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "../../src/schemas/config.json",
"port": 4002,
"assetTrailInstanceID": "asset-trail-org-b",
"apiGateway": {
"apiEndpoint": "https://zzkuwhhizm-zzyi4f2hqt-connect.dev2.photic.io/instances/0xe6719e4f7379e583046376f522a5efc30ca358f3"
},
"eventStreams": {
"wsEndpoint": "wss://zzkuwhhizm-zzyi4f2hqt-connect.dev2-ws.photic.io/ws",
"topic": "B"
},
"ipfs": {
"apiEndpoint": "https://zzkuwhhizm-zzvosyrz5t-ipfs.dev2.photic.io"
},
"app2app": {
"socketIOEndpoint": "wss://zzkuwhhizm-zzcpoj78bh.dev2-ws.photic.io/api/v1",
"destinations": {
"kat": "kld://app2app/z/dev2/m/zzt1fril6n/e/zzkuwhhizm/s/zzcpoj78bh/d/b",
"client": "kld://app2app/z/dev2/m/zzt1fril6n/e/zzkuwhhizm/s/zzcpoj78bh/d/external"
}
},
"docExchange": {
"apiEndpoint": "https://zzkuwhhizm-zzwt65yyp0-documentstore.dev2.photic.io/api/v1",
"socketIOEndpoint": "wss://zzkuwhhizm-zzwt65yyp0.dev2-ws.photic.io/api/v1",
"destination": "kld://documentstore/z/dev2/m/zzt1fril6n/e/zzkuwhhizm/s/zzwt65yyp0/d/b"
},
"appCredentials": {
"user": "zzwfeybeli",
"password": "PiinAvy8PkwP3bBbXw0TrX_fzvBw4KTYtTQzS1QE4zs"
},
"mongodb": {
"connectionUrl": "mongodb://localhost:27017",
"databaseName": "synaptic-org-b"
}
}
5 changes: 5 additions & 0 deletions core/data/single-region/OrgB/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "../../src/schemas/settings.json",
"clientEvents": ["asset-instance-submitted", "asset-instance-created", "payment-instance-created", "private-asset-instance-content-stored",
"asset-instance-property-submitted", "asset-instance-property-set"]
}
5 changes: 3 additions & 2 deletions core/src/clients/app2app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function subscribeWithRetry() {

const establishSocketIOConnection = () => {
let error = false;
socket = io.connect(config.app2app.socketIOEndpoint, {
socket = io.connect(`${config.app2app.socketIOEndpoint}?auto_commit=false&read_ahead=50`, {
transportOptions: {
polling: {
extraHeaders: {
Expand Down Expand Up @@ -58,8 +58,9 @@ const establishSocketIOConnection = () => {
}
} catch (err) {
log.error(`App2App message error ${err}`);
} finally {
socket.emit('commit');
}

}) as SocketIOClient.Socket;
};

Expand Down
5 changes: 2 additions & 3 deletions core/src/handlers/asset-trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const coordinateAssetTrade = async (assetInstance: IDBAssetInstance, asse
metadata
};
const docExchangePromise = assetDefinition.contentSchema === undefined ? getDocumentExchangePromise(assetInstance.assetInstanceID) : Promise.resolve();
const app2appPromise = new Promise((resolve, reject) => {
const app2appPromise: Promise<void> = new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
app2app.removeListener(app2appListener);
reject(new Error('Asset instance author response timed out'));
Expand Down Expand Up @@ -144,7 +144,7 @@ export const coordinateAssetTrade = async (assetInstance: IDBAssetInstance, asse
await Promise.all([app2appPromise, docExchangePromise]);
};

const getDocumentExchangePromise = (assetInstanceID: string) => {
const getDocumentExchangePromise = (assetInstanceID: string): Promise<void> => {
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
docExchange.removeListener(docExchangeListener);
Expand All @@ -162,7 +162,6 @@ const getDocumentExchangePromise = (assetInstanceID: string) => {
};

const processPrivateAssetInstancePush = async (headers: IApp2AppMessageHeader, push: IAssetTradePrivateAssetInstancePush) => {

const assetInstance = await database.retrieveAssetInstanceByID(push.assetInstanceID);
if (assetInstance !== null) {
const author = await database.retrieveMemberByAddress(assetInstance.author);
Expand Down

0 comments on commit 1ac9325

Please sign in to comment.