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 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 = { const fetchOptions = {
method: 'POST', method: 'POST',
body: data64, body: JSON.stringify(body),
headers: { headers: {
'X-Loki-pow-nonce': nonce, 'X-Loki-EphemKey': 'not implemented yet',
'X-Loki-timestamp': timestamp.toString(),
'X-Loki-ttl': ttl.toString(),
'X-Loki-recipient': pubKey,
}, },
}; };
@ -140,7 +147,7 @@ class LokiMessageAPI {
canResolve = false; canResolve = false;
} else if (e instanceof HTTPError) { } else if (e instanceof HTTPError) {
log.error( log.error(
`POST ${e.response.url}`, `POST ${e.response.url} (store)`,
e.response.status, e.response.status,
'Error sending message' 'Error sending message'
); );
@ -208,19 +215,24 @@ class LokiMessageAPI {
}; };
const doRequest = async (nodeUrl, nodeData) => { 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 = { 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 { try {
const result = await fetch(url, { const result = await fetch(url, fetchOptions);
headers,
});
nodeComplete(nodeUrl); nodeComplete(nodeUrl);
@ -234,7 +246,7 @@ class LokiMessageAPI {
canResolve = false; canResolve = false;
} else if (e instanceof HTTPError) { } else if (e instanceof HTTPError) {
log.error( log.error(
`GET ${e.response.url}`, `POST ${e.response.url} (retrieve)`,
e.response.status, e.response.status,
`Error retrieving messages from ${nodeUrl}` `Error retrieving messages from ${nodeUrl}`
); );

Loading…
Cancel
Save