Coder Social home page Coder Social logo

bitcoin-protocol's People

Contributors

atticoos avatar fanatid avatar greenkeeperio-bot avatar mappum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bitcoin-protocol's Issues

babel & create-hash

  • For what purpose you using babel here?
  • Why you using create-hash instead crypto.createHash? create-hash is a part of crypto-browserify

Thank you!

Bad Request causes infinite loop

If a node is set up behind a proxy (or perhaps some other configuration) and does not return the expected response (a well formed p2p message), the decoder goes into an infinite loop.

Line 97 of types.js assumes there will be a 0 in the buffer array.
for (stop = 0; bvalue[stop] !== 0; ++stop);

A 400 response will not have a 0 in the array.

This could be easily fixed with (error checking may also need to be addressed)
for (stop = 0; bvalue[stop] !== 0 && stop < 12; ++stop);

A short term workaround is to not pipe the decoder through the socket.

//socket.pipe(decoder);
socket.on('data', (message) => {
        if (message.length > 132) {
          socket.end();
          console.log('Service does not appear to be a node');
          return;
        } 
        decoder.write(message);
 });

It would also be very helpful to document the available methods. I had to dig through the code for the write method.

The hex is different from the wireshark and the code console.

I have set the console log on stream.js at line 59.

      var payload = bl.slice(0, message.length)
      console.log(payload)
      console.log('----------------------')

But it look different from the wireshark and the actual console

2017-12-17 8 27 31

var net = require('net')
var bp = require('bitcoin-protocol')

var decoder = bp.createDecodeStream()
decoder.on('data', function (message) { //console.log(message) 
})

var encoder = bp.createEncodeStream()

var socket = net.connect(8333, '46.4.60.36', function () {
  socket.pipe(decoder)
  encoder.pipe(socket)

  encoder.write({
    magic: 0xd9b4bef9,
    command: 'version',
    payload: {
      version: 70012,
      services: Buffer(8).fill(0),
      timestamp: Math.round(Date.now() / 1000),
      receiverAddress: {
        services: Buffer('0100000000000000', 'hex'),
        address: '0.0.0.0',
        port: 8333
      },
      senderAddress: {
        services: Buffer(8).fill(0),
        address: '0.0.0.0',
        port: 8333
      },
      nonce: Buffer(8).fill(123),
      userAgent: 'foobar',
      startHeight: 0,
      relay: true
    }
  })
})

I also try to using the double sha256 of the message payload to get the checksum,but always different from the wireshark,can you take a look of this?Thanks.

EX:

const crypto = require('crypto');
function double_sha256(payload) {
  let sha256 = crypto.createHash('sha256').update(payload).digest();
  return crypto.createHash('sha256').update(sha256).digest().slice(0, 4);
}

console.log(double_sha256('0e06a71b67ab03e9'))

which will output <Buffer b1 ea bf f7> not <Buffer e5 a8 96 7b>

2017-12-17 8 34 27

Not working with bitcoind 0.14?

I was unable to get the example up and running, the data is sent to the node but no response data is emitted on the stream.

Running the integration tests have a similar result

$ npm run test-integration                                                                                                                   130 ↵

> [email protected] test-integration /Users/jnordberg/Development/bitcoin-protocol
> tape test/integration/*.js | faucet

✓ Integration with bitcoin core in regtest mode
⨯ spawn process
  not ok 1 should be equivalent
    ---
      operator: deepEqual
      expected: |-
        null
      actual: |-
        { [Error: Loading wallet...] code: -28 }
      at: IncomingMessage.<anonymous> (/Users/jnordberg/Development/bitcoin-protocol/node_modules/bitcoin/lib/jsonrpc.js:127:15)
    ...
✓ handshake
# send ping -> wait pong
  ok 19 correct payload

Just hangs indefinitely waiting for a response.

$ bitcoind -version
Bitcoin Core Daemon version v0.14.99.0-cf5782508
$ node --version
v7.9.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.