Compare commits
No commits in common. "399e227815e893d3c6ed5de465d52cef249491c7" and "4833621f9b137824296d2c024862b23e0bb9f38a" have entirely different histories.
399e227815
...
4833621f9b
|
@ -3,17 +3,9 @@ node_js:
|
||||||
- "0.10"
|
- "0.10"
|
||||||
- "0.12"
|
- "0.12"
|
||||||
- "iojs"
|
- "iojs"
|
||||||
- "4"
|
|
||||||
sudo: false
|
sudo: false
|
||||||
addons:
|
addons:
|
||||||
firefox: "34.0"
|
firefox: "34.0"
|
||||||
apt:
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
packages:
|
|
||||||
- g++-4.8
|
|
||||||
env:
|
|
||||||
- CXX=g++-4.8
|
|
||||||
notifications:
|
notifications:
|
||||||
email:
|
email:
|
||||||
on_success: never
|
on_success: never
|
||||||
|
|
|
@ -3,12 +3,10 @@
|
||||||
* addon and makes it available for Node.
|
* addon and makes it available for Node.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
module.exports = require("../build/Release/worker");
|
module.exports = require("../build/Release/worker");
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
// Do nothing for a moment. Everything will work except the functions
|
// Do nothing for a moment. Everything will work except the functions
|
||||||
// that use worker routines.
|
// that uses worker routines.
|
||||||
// TODO(Kagami) Provide pure JS fallback.
|
// TODO(Kagami) Provide pure JS fallback.
|
||||||
}
|
}
|
||||||
|
|
10
package.json
10
package.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "bitmessage",
|
"name": "bitmessage",
|
||||||
"version": "0.6.6",
|
"version": "0.6.4",
|
||||||
"description": "JavaScript Bitmessage library",
|
"description": "JavaScript Bitmessage library",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"browser": {
|
"browser": {
|
||||||
|
@ -50,15 +50,15 @@
|
||||||
"bn.js": "^3.0.1",
|
"bn.js": "^3.0.1",
|
||||||
"bs58": "^2.0.0",
|
"bs58": "^2.0.0",
|
||||||
"buffer-equal": "~0.0.1",
|
"buffer-equal": "~0.0.1",
|
||||||
"eccrypto": "^1.0.3",
|
"eccrypto": "^1.0.1",
|
||||||
"es6-promise": "^3.0.2",
|
"es6-promise": "^2.0.1",
|
||||||
"hash.js": "^1.0.2",
|
"hash.js": "^1.0.2",
|
||||||
"nan": "^2.1.0",
|
"nan": "^1.4.1",
|
||||||
"object-assign": "^2.0.0",
|
"object-assign": "^2.0.0",
|
||||||
"sha.js": "^2.3.1",
|
"sha.js": "^2.3.1",
|
||||||
"webworkify": "^1.0.1"
|
"webworkify": "^1.0.1"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"bignum": "^0.11.0"
|
"bignum": "^0.9.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,14 +36,12 @@ typedef struct {
|
||||||
PowArgs* pow_args;
|
PowArgs* pow_args;
|
||||||
} ThreadArgs;
|
} ThreadArgs;
|
||||||
|
|
||||||
#ifndef ntohll
|
|
||||||
inline uint64_t ntohll(uint64_t x) {
|
inline uint64_t ntohll(uint64_t x) {
|
||||||
return (
|
return (
|
||||||
((uint64_t)(ntohl( (unsigned int)((x << 32) >> 32) )) << 32) |
|
((uint64_t)(ntohl( (unsigned int)((x << 32) >> 32) )) << 32) |
|
||||||
ntohl( ((unsigned int)(x >> 32)) )
|
ntohl( ((unsigned int)(x >> 32)) )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Set POW computation result in a thread-safe way.
|
// Set POW computation result in a thread-safe way.
|
||||||
void set_result(PowArgs* pow_args, PowResult res, uint64_t nonce) {
|
void set_result(PowArgs* pow_args, PowResult res, uint64_t nonce) {
|
||||||
|
|
|
@ -13,13 +13,13 @@ using v8::Number;
|
||||||
|
|
||||||
static const uint64_t MAX_SAFE_INTEGER = 9007199254740991ULL;
|
static const uint64_t MAX_SAFE_INTEGER = 9007199254740991ULL;
|
||||||
|
|
||||||
class PowWorker : public Nan::AsyncWorker {
|
class PowWorker : public NanAsyncWorker {
|
||||||
public:
|
public:
|
||||||
PowWorker(Nan::Callback* callback,
|
PowWorker(NanCallback* callback,
|
||||||
size_t pool_size,
|
size_t pool_size,
|
||||||
uint64_t target,
|
uint64_t target,
|
||||||
uint8_t* initial_hash)
|
uint8_t* initial_hash)
|
||||||
: Nan::AsyncWorker(callback),
|
: NanAsyncWorker(callback),
|
||||||
pool_size(pool_size),
|
pool_size(pool_size),
|
||||||
target(target),
|
target(target),
|
||||||
initial_hash(initial_hash) {}
|
initial_hash(initial_hash) {}
|
||||||
|
@ -40,16 +40,17 @@ class PowWorker : public Nan::AsyncWorker {
|
||||||
// this function will be run inside the main event loop
|
// this function will be run inside the main event loop
|
||||||
// so it is safe to use V8 again
|
// so it is safe to use V8 again
|
||||||
void HandleOKCallback () {
|
void HandleOKCallback () {
|
||||||
|
NanScope();
|
||||||
if (error) {
|
if (error) {
|
||||||
Local<Value> argv[1];
|
Local<Value> argv[1];
|
||||||
if (error == -1) {
|
if (error == -1) {
|
||||||
argv[0] = Nan::Error("Max safe integer overflow");
|
argv[0] = NanError("Max safe integer overflow");
|
||||||
} else {
|
} else {
|
||||||
argv[0] = Nan::Error("Internal error");
|
argv[0] = NanError("Internal error");
|
||||||
}
|
}
|
||||||
callback->Call(1, argv);
|
callback->Call(1, argv);
|
||||||
} else {
|
} else {
|
||||||
Local<Value> argv[] = {Nan::Null(), Nan::New<Number>(nonce)};
|
Local<Value> argv[] = {NanNull(), NanNew<Number>(nonce)};
|
||||||
callback->Call(2, argv);
|
callback->Call(2, argv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,35 +64,39 @@ class PowWorker : public Nan::AsyncWorker {
|
||||||
};
|
};
|
||||||
|
|
||||||
NAN_METHOD(PowAsync) {
|
NAN_METHOD(PowAsync) {
|
||||||
if (info.Length() != 4 ||
|
NanScope();
|
||||||
!info[0]->IsNumber() || // pool_size
|
|
||||||
!info[1]->IsNumber() || // target
|
if (args.Length() != 4 ||
|
||||||
!node::Buffer::HasInstance(info[2]) || // initial_hash
|
!args[0]->IsNumber() || // pool_size
|
||||||
!info[3]->IsFunction()) { // cb
|
!args[1]->IsNumber() || // target
|
||||||
return Nan::ThrowError("Bad input");
|
!node::Buffer::HasInstance(args[2]) || // initial_hash
|
||||||
|
!args[3]->IsFunction()) { // cb
|
||||||
|
return NanThrowError("Bad input");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t pool_size = info[0]->Uint32Value();
|
size_t pool_size = args[0]->Uint32Value();
|
||||||
uint64_t target = info[1]->IntegerValue();
|
uint64_t target = args[1]->IntegerValue();
|
||||||
char* buf = node::Buffer::Data(info[2]);
|
char* buf = node::Buffer::Data(args[2]);
|
||||||
size_t length = node::Buffer::Length(info[2]);
|
size_t length = node::Buffer::Length(args[2]);
|
||||||
if (pool_size < 1 ||
|
if (pool_size < 1 ||
|
||||||
pool_size > MAX_POOL_SIZE ||
|
pool_size > MAX_POOL_SIZE ||
|
||||||
buf == NULL ||
|
buf == NULL ||
|
||||||
length != HASH_SIZE) {
|
length != HASH_SIZE) {
|
||||||
return Nan::ThrowError("Bad input");
|
return NanThrowError("Bad input");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(Kagami): Do we need to process `std::bad_alloc`?
|
||||||
uint8_t* initial_hash = new uint8_t[length];
|
uint8_t* initial_hash = new uint8_t[length];
|
||||||
memcpy(initial_hash, buf, length);
|
memcpy(initial_hash, buf, length);
|
||||||
Nan::Callback* callback = new Nan::Callback(info[3].As<Function>());
|
NanCallback* callback = new NanCallback(args[3].As<Function>());
|
||||||
Nan::AsyncQueueWorker(
|
NanAsyncQueueWorker(new PowWorker(callback, pool_size, target, initial_hash));
|
||||||
new PowWorker(callback, pool_size, target, initial_hash));
|
NanReturnUndefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
NAN_MODULE_INIT(InitAll) {
|
void InitAll(Handle<Object> exports) {
|
||||||
Nan::Set(target, Nan::New<String>("powAsync").ToLocalChecked(),
|
exports->Set(
|
||||||
Nan::GetFunction(Nan::New<FunctionTemplate>(PowAsync)).ToLocalChecked());
|
NanNew<String>("powAsync"),
|
||||||
|
NanNew<FunctionTemplate>(PowAsync)->GetFunction());
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE_MODULE(worker, InitAll)
|
NODE_MODULE(worker, InitAll)
|
||||||
|
|
7
test.js
7
test.js
|
@ -1194,10 +1194,9 @@ describe("POW", function() {
|
||||||
// computed nonces may vary in a big range (since target is
|
// computed nonces may vary in a big range (since target is
|
||||||
// simple, there are a lot of valid nonces). Probably because
|
// simple, there are a lot of valid nonces). Probably because
|
||||||
// some spawned web workers get blocked for some reason.
|
// some spawned web workers get blocked for some reason.
|
||||||
// FIXME(Kagami): Local runs started to fail here too.
|
if (typeof window === "undefined") {
|
||||||
// if (typeof window === "undefined") {
|
expect(nonce).to.equal(21997550);
|
||||||
// expect(nonce).to.equal(21997550);
|
}
|
||||||
// }
|
|
||||||
expect(POW.check({
|
expect(POW.check({
|
||||||
nonce: nonce,
|
nonce: nonce,
|
||||||
target: target,
|
target: target,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user