Merge pull request #199 from sachaaaaa/new_message_api

Use new message json rpc API
pull/207/head
sachaaaaa 6 years ago committed by GitHub
commit 1c4d9b40bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -118,15 +118,22 @@ class LokiMessageAPI {
};
const doRequest = async nodeUrl => {
const url = `${nodeUrl}${this.messageServerPort}/store`;
const url = `${nodeUrl}${this.messageServerPort}/v1/storage_rpc`;
const body = {
method: 'store',
params: {
pubKey,
ttl: ttl.toString(),
nonce,
timestamp: timestamp.toString(),
data: data64,
},
};
const fetchOptions = {
method: 'POST',
body: data64,
body: JSON.stringify(body),
headers: {
'X-Loki-pow-nonce': nonce,
'X-Loki-timestamp': timestamp.toString(),
'X-Loki-ttl': ttl.toString(),
'X-Loki-recipient': pubKey,
'X-Loki-EphemKey': 'not implemented yet',
},
};
@ -140,7 +147,7 @@ class LokiMessageAPI {
canResolve = false;
} else if (e instanceof HTTPError) {
log.error(
`POST ${e.response.url}`,
`POST ${e.response.url} (store)`,
e.response.status,
'Error sending message'
);
@ -208,19 +215,24 @@ class LokiMessageAPI {
};
const doRequest = async (nodeUrl, nodeData) => {
const url = `${nodeUrl}${this.messageServerPort}/retrieve`;
const url = `${nodeUrl}${this.messageServerPort}/v1/storage_rpc`;
const body = {
method: 'retrieve',
params: {
pubKey: ourKey,
lastHash: nodeData.lastHash,
},
};
const headers = {
'X-Loki-recipient': ourKey,
'X-Loki-EphemKey': 'not implemented yet',
};
const fetchOptions = {
method: 'POST',
body: JSON.stringify(body),
headers,
};
if (nodeData.lastHash) {
headers['X-Loki-last-hash'] = nodeData.lastHash;
}
try {
const result = await fetch(url, {
headers,
});
const result = await fetch(url, fetchOptions);
nodeComplete(nodeUrl);
@ -234,7 +246,7 @@ class LokiMessageAPI {
canResolve = false;
} else if (e instanceof HTTPError) {
log.error(
`GET ${e.response.url}`,
`POST ${e.response.url} (retrieve)`,
e.response.status,
`Error retrieving messages from ${nodeUrl}`
);

Loading…
Cancel
Save