trac-peer 0.1.13 → 0.1.14
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 +1 -1
- package/src/check.js +7 -3
- package/src/contract.js +5 -0
- package/src/index.js +18 -7
- package/src/protocol.js +13 -1
package/package.json
CHANGED
package/src/check.js
CHANGED
|
@@ -360,7 +360,7 @@ class Check {
|
|
|
360
360
|
type : { type : "string", min : 1, max : 256 },
|
|
361
361
|
address : { type : "is_hex" },
|
|
362
362
|
deleted_by : { type : "is_hex", nullable : true },
|
|
363
|
-
reply_to : { type : "number", integer : true, min : 0, max : 2147483647, nullable : true }
|
|
363
|
+
reply_to : { type : "number", integer : true, min : 0, max : 2147483647, nullable : true }
|
|
364
364
|
}
|
|
365
365
|
}
|
|
366
366
|
};
|
|
@@ -420,8 +420,12 @@ class Check {
|
|
|
420
420
|
key: { type : "is_hex" },
|
|
421
421
|
value : {
|
|
422
422
|
$$type: "object",
|
|
423
|
-
dispatch : {
|
|
424
|
-
|
|
423
|
+
dispatch : {
|
|
424
|
+
$$type : "object",
|
|
425
|
+
type : { type : "string", min : 1, max : 256 },
|
|
426
|
+
value : { type : "any", nullable : true }
|
|
427
|
+
},
|
|
428
|
+
msbsl : { type : "number", integer : true, min : 0, max : 2147483647 },
|
|
425
429
|
ipk : { type : "is_hex" },
|
|
426
430
|
wp : { type : "is_hex" },
|
|
427
431
|
hash : { type : "is_hex" },
|
package/src/contract.js
CHANGED
|
@@ -29,6 +29,11 @@ class Contract {
|
|
|
29
29
|
key : { type : "is_hex" },
|
|
30
30
|
value : {
|
|
31
31
|
$$type: "object",
|
|
32
|
+
dispatch : {
|
|
33
|
+
$$type : "object",
|
|
34
|
+
type : { type : "string", min : 1, max : 256 },
|
|
35
|
+
value : { type : "any", nullable : true }
|
|
36
|
+
},
|
|
32
37
|
value : {
|
|
33
38
|
$$type : "object",
|
|
34
39
|
ipk : { type : "is_hex" },
|
package/src/index.js
CHANGED
|
@@ -78,6 +78,7 @@ export class Peer extends ReadyResource {
|
|
|
78
78
|
if(false === this.check.node(node)) continue;
|
|
79
79
|
const op = node.value;
|
|
80
80
|
if (op.type === 'tx') {
|
|
81
|
+
if(b4a.byteLength(jsonStringify(op)) > _this.protocol_instance.txMaxBytes()) continue;
|
|
81
82
|
if(false === this.check.tx(op)) continue;
|
|
82
83
|
while (_this.msb.base.view.core.signedLength < op.value.msbsl) {
|
|
83
84
|
await new Promise( (resolve, reject) => {
|
|
@@ -99,20 +100,28 @@ export class Peer extends ReadyResource {
|
|
|
99
100
|
_this.bootstrap, _this.msb.bootstrap,
|
|
100
101
|
post_tx.value.w, post_tx.value.i, post_tx.value.ipk,
|
|
101
102
|
post_tx.value.ch, post_tx.value.in
|
|
102
|
-
)
|
|
103
|
-
|
|
103
|
+
)) {
|
|
104
|
+
const err = _this.protocol_instance.getError(
|
|
105
|
+
await _this.contract_instance.execute(op, batch)
|
|
106
|
+
);
|
|
107
|
+
if(null !== err) {
|
|
108
|
+
op.value.dispatch['err'] = ''+err.message;
|
|
109
|
+
} else {
|
|
110
|
+
op.value.dispatch['err'] = null;
|
|
111
|
+
}
|
|
104
112
|
let len = await batch.get('txl');
|
|
105
113
|
if(null === len) {
|
|
106
114
|
len = 0;
|
|
107
115
|
} else {
|
|
108
116
|
len = len.value;
|
|
109
117
|
}
|
|
110
|
-
await batch.put('txi/'+len,
|
|
118
|
+
await batch.put('txi/'+len, op.value.dispatch);
|
|
111
119
|
await batch.put('txl', len + 1);
|
|
112
|
-
await batch.put('tx/'+post_tx.value.tx,
|
|
120
|
+
await batch.put('tx/'+post_tx.value.tx, len);
|
|
113
121
|
console.log(`${post_tx.value.tx} appended. Signed length:`, _this.base.view.core.signedLength, 'tx length', len + 1);
|
|
114
122
|
}
|
|
115
123
|
} else if(op.type === 'msg') {
|
|
124
|
+
if(b4a.byteLength(jsonStringify(op)) > _this.protocol_instance.msgMaxBytes()) continue;
|
|
116
125
|
if(false === this.check.msg(op)) continue;
|
|
117
126
|
const admin = await batch.get('admin');
|
|
118
127
|
let muted = false;
|
|
@@ -141,9 +150,10 @@ export class Peer extends ReadyResource {
|
|
|
141
150
|
null !== str_value &&
|
|
142
151
|
null !== chat_status &&
|
|
143
152
|
null === await batch.get('sh/'+op.hash) &&
|
|
144
|
-
b4a.byteLength(str_value) <= 10_2400 &&
|
|
145
153
|
chat_status.value === 'on' &&
|
|
146
|
-
null === _this.protocol_instance.getError(
|
|
154
|
+
null === _this.protocol_instance.getError(
|
|
155
|
+
await _this.contract_instance.execute(op, batch)
|
|
156
|
+
)){
|
|
147
157
|
let len = await batch.get('msgl');
|
|
148
158
|
if(null === len) {
|
|
149
159
|
len = 0;
|
|
@@ -165,6 +175,7 @@ export class Peer extends ReadyResource {
|
|
|
165
175
|
console.log(`#${len + 1} | ${nick !== null ? nick.value : op.value.dispatch.address}: ${op.value.dispatch.msg}`);
|
|
166
176
|
}
|
|
167
177
|
} else if (op.type === 'feature') {
|
|
178
|
+
if(b4a.byteLength(jsonStringify(op)) > _this.protocol_instance.featMaxBytes()) continue;
|
|
168
179
|
if(false === this.check.feature(op)) continue;
|
|
169
180
|
const str_dispatch_value = jsonStringify(op.value.dispatch.value);
|
|
170
181
|
const admin = await batch.get('admin');
|
|
@@ -449,7 +460,7 @@ export class Peer extends ReadyResource {
|
|
|
449
460
|
|
|
450
461
|
async txChannel() {
|
|
451
462
|
const _this = this;
|
|
452
|
-
this.tx_swarm = new Hyperswarm(
|
|
463
|
+
this.tx_swarm = new Hyperswarm();
|
|
453
464
|
|
|
454
465
|
this.tx_swarm.on('connection', async (connection, peerInfo) => {
|
|
455
466
|
const peerName = b4a.toString(connection.remotePublicKey, 'hex');
|
package/src/protocol.js
CHANGED
|
@@ -20,6 +20,18 @@ class Protocol{
|
|
|
20
20
|
this.sim = false;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
featMaxBytes(){
|
|
24
|
+
return 4_096;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
txMaxBytes(){
|
|
28
|
+
return 4_096;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
msgMaxBytes(){
|
|
32
|
+
return 8_192;
|
|
33
|
+
}
|
|
34
|
+
|
|
23
35
|
safeBigInt(value) {
|
|
24
36
|
try{
|
|
25
37
|
return BigInt(value);
|
|
@@ -150,7 +162,7 @@ class Protocol{
|
|
|
150
162
|
}
|
|
151
163
|
|
|
152
164
|
getError(value){
|
|
153
|
-
if (value === false || (value !== undefined && value.stack !== undefined && value.message
|
|
165
|
+
if (value === false || (value !== undefined && value.stack !== undefined && value.message !== undefined)) {
|
|
154
166
|
return value === false ? new Error('Generic Error') : value;
|
|
155
167
|
}
|
|
156
168
|
return null;
|