bitpay / bitcore-p2p

Interface to the bitcoin P2P network for bitcore
MIT License
81 stars 275 forks source link

Questions about bitcore-p2p #99

Open afterburn opened 6 years ago

afterburn commented 6 years ago

I'm trying to find a P2P library that allows me to easily do peer discovery without having to worry about things like NAT traversal. I've recently started developing an interest for blockchain technology so I need this P2P network to test my own blockchain implementation on. I'm relatively new to networking so things like NAT traversal are mechanisms I'd prefer not to put a lot of effort into, so I was hoping bitcore-p2p could provide the functionality I need.

Basically I need functionality like this:

// Create a node on the users' local machine.
const socket = new Peer("127.0.0.1", 3000);

// Listen for events.

// emitted when peer connects to this node.
socket.on('peer_connected', (peer) => {
    // send data to this peer.
    peer.write('some data');

    //relay the peer_connected events to other peers.
    socket.peers.emit('peer_connected', peer);
});

// emitted when peer disconnects from this node.
socket.on('peer_disconnected', (peer) => {
    //relay the peer_disconnected events to other peers.
    socket.peers.emit('peer_disconnected', peer);
});

// emitted when data is received from another peer.
socket.on('data', (data, peer) => {

});

I was wondering if bitcore-p2p is solely usable for the bitcoin network or is it possible to create my own network as well?