lhartikk / naivechain

A blockchain implementation in 200 lines of code
Apache License 2.0
5.28k stars 1.15k forks source link

Confusion about peers. #11

Open jordaniac89 opened 7 years ago

jordaniac89 commented 7 years ago

In this example, I'm confused about what happens when you write a message to a peer in the broadcast function. Is there code behind the ports that handles the message? Or in this example, does the message just fall off?

lhartikk commented 7 years ago

The broadcast function send the given message to every peer the node knows about:

https://github.com/lhartikk/naivechain/blob/master/main.js#L206

The receiving peer handles the sent message using code: https://github.com/lhartikk/naivechain/blob/master/main.js#L73