ronomon / reed-solomon Goto Github PK
View Code? Open in Web Editor NEWFast, reliable Reed-Solomon erasure coding as a native addon for Node.js.
License: MIT License
Fast, reliable Reed-Solomon erasure coding as a native addon for Node.js.
License: MIT License
Hey!
Thank you a lot for your great work! Your implementation is blazingly fast! :)
I have a slightly different use case. I want to detect silent bit errors (resp. damaged shards) and don't know my sources and targets.
Do you see any possibility to add some kind of check()
method to your module that returns damaged shards?
Of course we will need at least two parity shards to achieve that. If I a correct with m=2 we can detect if 2 shards are damaged and repair if 1 shard is damaged.
Let me know what you think.
Do what needs to be done. Have a clean start
Stumbled upon this one. Reproduced using the attached mocha test (renamed as .txt for github upload)
rononmon.test.txt
Execution gives out:
$ npm test test/rononmon.test.js
> [email protected] test /home/mlubin/dev/ecstream
> mocha --use_strict --check-leaks --no-exit "test/rononmon.test.js"
✓ Test parity initialization - m=1, initValue=0
1) Test parity initialization - m=1, initValue=255
✓ Test parity initialization - m=2, initValue=0
✓ Test parity initialization - m=2, initValue=255
3 passing (13ms)
1 failing
1) Test parity initialization - m=1, initValue=255:
Uncaught AssertionError: <Buffer db db db db db db db db> === <Buffer 24 24 24 24 24 24 24 24>
+ expected - actual
[
- 219
- 219
- 219
- 219
- 219
- 219
- 219
- 219
+ 36
+ 36
+ 36
+ 36
+ 36
+ 36
+ 36
+ 36
]
at ReedSolomon.encode.err (test/rononmon.test.js:38:36)
Handling of m=1 seems very special. Looking at binding.cc code I found the special code path which directly call dot_xor and do not start with a dot_cpy first:
diff --git a/binding.cc b/binding.cc
index b61ecdd..c323b3e 100644
--- a/binding.cc
+++ b/binding.cc
@@ -705,8 +705,16 @@ void encode(
) {
// Optimization for 1 erasure (i < k + 1), encoding only targets:
uint8_t* target = shards[flags_first(targets)];
+ int copied = 0;
for (int i = 0; i < k + 1; i++) {
- if (sources & (1 << i)) dot_xor(shards[i], target, shardSize);
+ if (sources & (1 << i)) {
+ if (!copied) {
+ dot_cpy(shards[i], target, shardSize);
+ copied = 1;
+ } else {
+ dot_xor(shards[i], target, shardSize);
+ }
+ }
}
return;
}
Can be reproduced in your test by forcing random parity buffers in test.js:
diff --git a/test.js b/test.js
index ef462e9..1c1f902 100644
--- a/test.js
+++ b/test.js
@@ -317,7 +317,7 @@ queue.onData = function(args, end) {
);
var buffer = cipher.update(Buffer.alloc(bufferOffset + bufferSize));
Assert(buffer.length === bufferOffset + bufferSize);
- var parity = Buffer.alloc(parityOffset + paritySize);
+ var parity = Node.crypto.randomBytes(parityOffset + paritySize);
if (parityOffset) {
Assert(
cipher.update(Buffer.alloc(parityOffset)).copy(parity, 0) === parityOffset
The above patch fixes the issue, at least on the simple test I attached and your tests.
Cheers,
Maxime
Hi,
I am trying to find an implementation that can be used on browser. The goal is to have the erasure coding be performed on the browser and upload the multiple splits to multiple servers.
Any ideas or recommendations ?
Error: Cannot find module './binding.node'
Require stack:
I am getting Cannot find module './binding.node' error you have used
var ReedSolomon = require('./binding.node'); code in line no 5 of test.js code
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.