Skip to content

Commit

Permalink
Merge branch 'v8/develop' into fix/adding-utf-encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihajlo-Pavlovic authored Jan 31, 2025
2 parents 33fa333 + 6a3ee90 commit 310c5ab
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "origintrail_node",
"version": "8.0.1",
"version": "8.0.1+hotfix.1",
"description": "OTNode V8",
"main": "index.js",
"type": "module",
Expand Down
6 changes: 3 additions & 3 deletions src/commands/protocols/get/sender/get-find-shard-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class GetFindShardCommand extends FindShardCommand {
getOperationCommandSequence(nodePartOfShard, commandData) {
const sequence = ['localGetCommand'];
sequence.push(
commandData.paranetNodesAccessPolicy === 'OPEN'
? 'networkGetCommand'
: 'curatedParanetNetworkGetCommand',
commandData.paranetNodesAccessPolicy === 'CURATED'
? 'curatedParanetNetworkGetCommand'
: 'networkGetCommand',
);
return sequence;
}
Expand Down
23 changes: 19 additions & 4 deletions src/modules/network/implementation/libp2p-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,12 @@ class Libp2pService {
return { message, valid: false, busy: false };
}

message.header = JSON.parse(stringifiedHeader);
try {
message.header = JSON.parse(stringifiedHeader);
} catch (error) {
// Return the same format as invalid request case
return { message, valid: false, busy: false };
}

// validate request / response
if (!(await isMessageValid(message.header, peerIdString))) {
Expand All @@ -481,10 +486,20 @@ class Libp2pService {

let stringifiedData = '';
// read data the data
for await (const chunk of source) {
stringifiedData += chunk;

try {
for await (const chunk of source) {

stringifiedData += chunk;

}
message.data = JSON.parse(stringifiedData);

} catch (error) {

// If data parsing fails, return invalid message response
return { message, valid: false, busy: false };
}
message.data = JSON.parse(stringifiedData);

return { message, valid: true, busy: false };
}
Expand Down
50 changes: 37 additions & 13 deletions src/modules/triple-store/implementation/ot-triple-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,23 +270,47 @@ class OtTripleStore {
return this.ask(repository, query);
}

async createKnowledgeCollectionNamedGraphs(repository, uals, assetsNQuads, visibility) {
const query = `
PREFIX schema: <${SCHEMA_CONTEXT}>
INSERT DATA {
${uals
.map(
(ual, index) => `
async createKnowledgeCollectionNamedGraphs(
repository,
uals,
assetsNQuads,
visibility,
retries = 5,
retryDelay = 10,
) {
const queries = uals.map(
(ual, index) => `
PREFIX schema: <${SCHEMA_CONTEXT}>
INSERT DATA {
GRAPH <${ual}/${visibility}> {
${assetsNQuads[index].join('\n')}
}
`,
)
.join('\n')}
}
`,
);
for (const [index, query] of queries.entries()) {
let attempts = 0;
let success = false;

while (attempts < retries && !success) {
try {
await this.queryVoid(repository, query);
success = true;
} catch (error) {
attempts += 1;
if (attempts <= retries) {
this.logger.warn(
`Insert failed for GRAPH <${uals[index]}/${visibility}>. Attempt ${attempts}/${retries}. Retrying in ${retryDelay}ms.`,
);
await setTimeout(retryDelay);
} else {
throw new Error(
`Failed to insert into GRAPH <${uals[index]}/${visibility}> after ${retries} attempts.`,
);
}
}
}
`;

await this.queryVoid(repository, query);
}
}

async deleteKnowledgeCollectionNamedGraphs(repository, uals) {
Expand Down
12 changes: 6 additions & 6 deletions src/service/sharding-table-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,19 @@ class ShardingTableService {
}

async dial(peerId) {
const { addresses } = await this.findPeerAddressAndProtocols(peerId);
if (addresses.length) {
try {
try {
const { addresses } = await this.findPeerAddressAndProtocols(peerId);
if (addresses.length) {
if (peerId !== this.networkModuleManager.getPeerId().toB58String()) {
this.logger.trace(`Dialing peer ${peerId}.`);
await this.networkModuleManager.dial(peerId);
}
await this.updatePeerRecordLastSeenAndLastDialed(peerId);
} catch (error) {
this.logger.trace(`Unable to dial peer ${peerId}. Error: ${error.message}`);
} else {
await this.updatePeerRecordLastDialed(peerId);
}
} else {
} catch (error) {
this.logger.trace(`Unable to dial peer ${peerId}. Error: ${error.message}`);
await this.updatePeerRecordLastDialed(peerId);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/service/triple-store-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TripleStoreService {
knowledgeCollectionUAL,
triples,
retries = 5,
retryDelay = 0,
retryDelay = 50,
) {
this.logger.info(
`Inserting Knowledge Collection with the UAL: ${knowledgeCollectionUAL} ` +
Expand Down

0 comments on commit 310c5ab

Please sign in to comment.