Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

dht functionality #1857

Closed
yonderblue opened this issue Jan 31, 2019 · 5 comments
Closed

dht functionality #1857

yonderblue opened this issue Jan 31, 2019 · 5 comments
Labels
exp/expert Having worked on the specific codebase is important kind/bug A bug in existing code (including security flaws) P1 High: Likely tackled by core team if no one steps up

Comments

@yonderblue
Copy link

yonderblue commented Jan 31, 2019

  • Version:
    feat/dht-part-ii branch (b0acc71)
  • Platform:
    mac/linux
  • Subsystem:
    dht

I just used browserify directly on a little example while having the feat/dhs-part-ii branch checked out.

So now my index.js looks like

'use strict'

const IPFS = require('ipfs')
const Protector = require('libp2p-pnet')

const swarmKey = Buffer.from("/key/swarm/psk/1.0.0/\n/base16/\nTHEKEY")

const node = new IPFS({
	repo: String(Math.random() + Date.now()),
	relay: {
		enabled: true,
		hop: {enabled: true}
	}, 
	preload: {enabled: false},
	libp2p2: {
		modules: {
			connProtector: new Protector(swarmKey)
		}
	},
	config: {
		Bootstrap: ["/ip4/IP_TO_A_GOLANG_NODE/tcp/9443/ws/ipfs/THE_PEER_ID"]
	}
})

node.once('ready', function() {
	console.log('IPFS node is ready')
	
	window.node = node

	node.dht.findPeer('THE_PEER_ID')
})

However I always get Error: Peer lookup failed from that last line.
Also even trying to do a node.get('THE_PEER_FILE_HASH') just hangs, even though that peers is in the node.swarm.peers() (only one since its the bootstrap).
If I take out the swarm key and connect to public network, the findPeer doesn't fail but always returns nothing, same with findProvs etc.

@yonderblue yonderblue changed the title dht experiment option dht functionality Jan 31, 2019
@alanshaw
Copy link
Member

alanshaw commented Feb 3, 2019

Is the peer you’re trying to get the file from listening on an address that your browser node can connect to?

@yonderblue
Copy link
Author

yonderblue commented Feb 4, 2019

@alanshaw I'm already connected as shown by node.swarm.peers().

@alanshaw
Copy link
Member

alanshaw commented Feb 6, 2019

@vasco-santos can we resolve this before #856 is merged?

@alanshaw alanshaw added kind/bug A bug in existing code (including security flaws) exp/expert Having worked on the specific codebase is important status/ready Ready to be worked P1 High: Likely tackled by core team if no one steps up labels Feb 6, 2019
@vasco-santos
Copy link
Member

I will have a look in this

@vasco-santos
Copy link
Member

Hello @Gaillard

I did a small test:

  const node = new IPFS({
      repo: String(Math.random() + Date.now()),
      libp2p: {
        config: {
          dht: {
            enabled: true
          }
        }
      }
    })

    node.once('ready', async () => {
      let peers
      peers = await node.swarm.peers() // empty peers (still connecting)

      setTimeout(async () => {
        peers = await node.swarm.peers() // several peers (connected now)

        if (peers.length) {
          const b58peerId = peers[0].peer._idB58String
          const peerId = await node.dht.findPeer(b58peerId)

          console.log('peerId', peerId)
        }
      }, 5000)
    })

Basically, when the node is ready, it starts connecting to the peers. That way, if you immediatly try to find the peer and you are not connected with it yet, you will not be able to find it.

In my example, just a small test with a timeout, I wait a few seconds and then try to find a peer that is connected, and it worked fine in a React app.

Let me know if this answer helped you. If not, please provide me an example failing ready to run.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
exp/expert Having worked on the specific codebase is important kind/bug A bug in existing code (including security flaws) P1 High: Likely tackled by core team if no one steps up
Projects
None yet
Development

No branches or pull requests

3 participants