add libp2p UX examples

This commit is contained in:
David Dias
2015-11-26 21:31:05 +00:00
parent e770001ce7
commit c286bb93ea

View File

@@ -5,9 +5,7 @@
## 6.1 libp2p
libp2p, the top module that interfaces all the other modules that make a libp2p instance, must offer an interface for dialing to a peer and plugging in all of the modules (e.g. which transports) we want to support.
libp2p, the top module that interfaces all the other modules that make a libp2p instance, must offer an interface for dialing to a peer and plugging in all of the modules (e.g. which transports) we want to support. We present libp2p interface and UX on setion 6.6, after presenting every other module interface.
## 6.2 Peer Routing
@@ -49,4 +47,53 @@ https://github.com/diasdavid/abstract-record-store
## 6.5 Peer Discovery
A Peer Discovery system interface should return PeerInfo objects, as it finds new peers to be considered to our Peer Routing schemes
## 6.6 libp2p interface and UX
libp2p implementations should enable for it to be instantiated programatically, or to use a previous compiled lib some of the protocol decisions already made, so that the user can reuse or expand.
### Constructing libp2p instance programatically
Example made with JavaScript, should be mapped to other languages
```JavaScript
var Libp2p = require('libp2p')
var node = new Libp2p()
// add a swarm instance
node.addSwarm(swarmInstance)
// add one or more Peer Routing mechanisms
node.addPeerRouting(peerRoutingInstance)
// add a Distributed Record Store
node.addDistributedRecordStore(distributedRecordStoreInstance)
```
Configuring libp2p is quite straight forward since most of the configuration comes from instantiating the several modules, one at each time.
### Dialing and Listening for connections to/from a peer
Ideally, libp2p uses its own mechanisms (PeerRouting and Record Store) to find a way to dial to a given peer
```JavaScript
node.dial(PeerInfo)
```
To receive an incoming connection, specify one or more protocols to handle
```JavaScript
node.handleProtocol('<multicodec>', function (duplexStream) {
})
```
### Finding a peer
Finding a peer functionality is done through Peer Routing, so the interface is the same.
### Storing and Retrieving Records
Like Finding a Peer, Storing and Retrieving records is done through Record Store, so the interface is the same.