- 
                Notifications
    
You must be signed in to change notification settings  - Fork 11
 
feat: add support initial peerstore support #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -13,6 +13,7 @@ message Request { | |
| CONNMANAGER = 6; | ||
| DISCONNECT = 7; | ||
| PUBSUB = 8; | ||
| PEERSTORE = 9; | ||
| } | ||
| 
     | 
||
| required Type type = 1; | ||
| 
        
          
        
         | 
    @@ -24,6 +25,7 @@ message Request { | |
| optional ConnManagerRequest connManager = 6; | ||
| optional DisconnectRequest disconnect = 7; | ||
| optional PSRequest pubsub = 8; | ||
| optional PeerstoreRequest peerStore = 9; | ||
| } | ||
| 
     | 
||
| message Response { | ||
| 
        
          
        
         | 
    @@ -39,6 +41,7 @@ message Response { | |
| optional DHTResponse dht = 5; | ||
| repeated PeerInfo peers = 6; | ||
| optional PSResponse pubsub = 7; | ||
| optional PeerstoreResponse peerStore = 8; | ||
| } | ||
| 
     | 
||
| message IdentifyResponse { | ||
| 
        
          
        
         | 
    @@ -49,11 +52,13 @@ message IdentifyResponse { | |
| message ConnectRequest { | ||
| required bytes peer = 1; | ||
| repeated bytes addrs = 2; | ||
| optional int64 timeout = 3; | ||
| } | ||
| 
     | 
||
| message StreamOpenRequest { | ||
| required bytes peer = 1; | ||
| repeated string proto = 2; | ||
| optional int64 timeout = 3; | ||
| } | ||
| 
     | 
||
| message StreamHandlerRequest { | ||
| 
          
            
          
           | 
    @@ -87,7 +92,7 @@ message DHTRequest { | |
| required Type type = 1; | ||
| optional bytes peer = 2; | ||
| optional bytes cid = 3; | ||
| optional string key = 4; | ||
| optional bytes key = 4; | ||
| optional bytes value = 5; | ||
| optional int32 count = 6; | ||
| optional int64 timeout = 7; | ||
| 
        
          
        
         | 
    @@ -112,9 +117,9 @@ message PeerInfo { | |
| 
     | 
||
| message ConnManagerRequest { | ||
| enum Type { | ||
| TAG_PEER = 0; | ||
| UNTAG_PEER = 1; | ||
| TRIM = 2; | ||
| TAG_PEER = 0; | ||
| UNTAG_PEER = 1; | ||
| TRIM = 2; | ||
| } | ||
| 
     | 
||
| required Type type = 1; | ||
| 
          
            
          
           | 
    @@ -154,4 +159,20 @@ message PSResponse { | |
| repeated string topics = 1; | ||
| repeated bytes peerIDs = 2; | ||
| } | ||
| 
     | 
||
| message PeerstoreRequest { | ||
| enum Type { | ||
| GET_PROTOCOLS = 1; | ||
| GET_PEER_INFO = 2; | ||
| } | ||
| 
     | 
||
| required Type type = 1; | ||
| optional bytes id = 2; | ||
| repeated string protos = 3; | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are also missing some properties here and in the response. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've only added the required properties for the two types that are here. The rest should be added once the spec is merged for the other types.  | 
||
| } | ||
| 
     | 
||
| message PeerstoreResponse { | ||
| optional PeerInfo peer = 1; | ||
| repeated string protos = 2; | ||
| } | ||
| `) | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| /* eslint-env mocha */ | ||
| /* eslint max-nested-callbacks: ['error', 5] */ | ||
| 'use strict' | ||
| 
     | 
||
| const chai = require('chai') | ||
| chai.use(require('dirty-chai')) | ||
| const expect = chai.expect | ||
| const os = require('os') | ||
| const path = require('path') | ||
| const ma = require('multiaddr') | ||
| const { createDaemon } = require('../../src/daemon') | ||
| const Client = require('../../src/client') | ||
| const { createLibp2p } = require('../../src/libp2p') | ||
| const { isWindows } = require('../../src/util') | ||
| const { connect } = require('../util') | ||
| const { | ||
| Request, | ||
| Response, | ||
| PeerstoreRequest | ||
| } = require('../../src/protocol') | ||
| 
     | 
||
| const daemonAddr = isWindows | ||
| ? ma('/ip4/0.0.0.0/tcp/8080') | ||
| : ma(`/unix${path.resolve(os.tmpdir(), '/tmp/p2pd.sock')}`) | ||
| 
     | 
||
| describe('peerstore features', () => { | ||
| let daemon | ||
| let libp2pPeer | ||
| let client | ||
| 
     | 
||
| before(async function () { | ||
| // this.timeout(20e3) | ||
| daemon = await createDaemon({ | ||
| quiet: false, | ||
| q: false, | ||
| bootstrap: false, | ||
| hostAddrs: '/ip4/0.0.0.0/tcp/0,/ip4/0.0.0.0/tcp/0/ws', | ||
| b: false, | ||
| dht: true, | ||
| dhtClient: false, | ||
| connMgr: false, | ||
| listen: daemonAddr.toString(), | ||
| id: '', | ||
| bootstrapPeers: '' | ||
| }) | ||
| libp2pPeer = await createLibp2p({ | ||
| dht: true, | ||
| hostAddrs: '/ip4/0.0.0.0/tcp/0' | ||
| }) | ||
| 
     | 
||
| await Promise.all([ | ||
| daemon.start(), | ||
| libp2pPeer.start() | ||
| ]) | ||
| 
     | 
||
| await connect({ | ||
| libp2pPeer, | ||
| multiaddr: daemonAddr | ||
| }) | ||
| }) | ||
| 
     | 
||
| before(async () => { | ||
| await new Promise(resolve => setTimeout(resolve, 1e3)) | ||
| }) | ||
| 
     | 
||
| after(() => { | ||
| return Promise.all([ | ||
| daemon.stop(), | ||
| libp2pPeer.stop() | ||
| ]) | ||
| }) | ||
| 
     | 
||
| afterEach(async () => { | ||
| await client && client.close() | ||
| }) | ||
| 
     | 
||
| it('should be able to get the protocols for a peer', async () => { | ||
| client = new Client(daemonAddr) | ||
| 
     | 
||
| await client.attach() | ||
| 
     | 
||
| const request = { | ||
| type: Request.Type.PEERSTORE, | ||
| peerStore: { | ||
| type: PeerstoreRequest.Type.GET_PROTOCOLS, | ||
| id: Buffer.from(libp2pPeer.peerInfo.id.toBytes()) | ||
| } | ||
| } | ||
| 
     | 
||
| const stream = client.send(request) | ||
| 
     | 
||
| const message = await stream.first() | ||
| let response = Response.decode(message) | ||
| expect(response.type).to.eql(Response.Type.OK) | ||
| expect(response.peerStore).to.eql({ | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not  
 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
  | 
||
| protos: [ | ||
| '/mplex/6.7.0', | ||
| '/ipfs/id/1.0.0', | ||
| '/ipfs/ping/1.0.0', | ||
| '/libp2p/circuit/relay/0.1.0', | ||
| '/ipfs/kad/1.0.0' | ||
| ], | ||
| peer: null | ||
| }) | ||
| stream.end() | ||
| }) | ||
| 
     | 
||
| it('NOT IMPLEMENTED get peer info', async () => { | ||
| client = new Client(daemonAddr) | ||
| 
     | 
||
| await client.attach() | ||
| 
     | 
||
| const request = { | ||
| type: Request.Type.PEERSTORE, | ||
| peerStore: { | ||
| type: PeerstoreRequest.Type.GET_PEER_INFO, | ||
| id: Buffer.from(libp2pPeer.peerInfo.id.toBytes()) | ||
| } | ||
| } | ||
| 
     | 
||
| const stream = client.send(request) | ||
| 
     | 
||
| const message = await stream.first() | ||
| let response = Response.decode(message) | ||
| expect(response.type).to.eql(Response.Type.ERROR) | ||
| expect(response.error.msg).to.eql('ERR_NOT_IMPLEMENTED') | ||
| }) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the remaining types of
PeerstoreRequest?libp2p/go-libp2p-daemon#91/files#diff-d864c93b68284fafd809efbf29a1f0ebR166
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I noticed that you have only implemented
GET_PROTOCOLShere.Can I recommend adding the other ones and then throw a
ERR_NOT_IMPLEMENTEDfor that? Moreover, can you create an issue for tracking the remaining ones?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'll create an issue for when the spec gets done. I only added these initial two, as those likely won't change, but since the spec is still being discussed it didn't make sense to me to pull in a bunch of theoretical types.
I'll add
ERR_NOT_IMPLEMENTEDfor the types that are currently in the proto file.