Skip to content

Instantly share code, notes, and snippets.

@jbenet
Last active August 29, 2015 14:06
Show Gist options
  • Save jbenet/e781d8f4625c81645447 to your computer and use it in GitHub Desktop.
Save jbenet/e781d8f4625c81645447 to your computer and use it in GitHub Desktop.

setting up multiple ipfs nodes in one machine

(this will get a lot easier once we solve some of these issues)

  1. modify cmd/ipfs/config.go and set to:
# change this
const DefaultPathRoot = "~/.go-ipfs"

# to this
const DefaultPathRoot = ".go-ipfs"
  1. make two directories for your nodes
mkdir node1
mkdir node2
  1. Init both of them
cd node1 && ipfs init
cd node2 && ipfs init
  1. You'll now have files node1/.go-ipfs/config with something like this:
{
  "Identity": {
    "PeerID": "QmRSxW3e1SXVT3ovBzg6Nqe1EQwMW5PwXVByK2JKko3PH8",
    "PrivKey": "CAASrBIwggkoAgEAAoICAQDGkzuZr8xsZX7ouZdFwuGuemS...HUGE KEY...==",
    "Address": "/ip4/127.0.0.1/tcp/5001"
  },
  "Datastore": {
    "Type": "leveldb",
    "Path": "/Users/jbenet/.go-ipfs/datastore"
  },
  "RPCAddress": "/ip4/127.0.0.1/tcp/4001",
  "Peers": [
    {
      "Address": "/ip4/104.131.131.82/tcp/5001",
      "PeerID": "QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"
    }
  ]
}

You should change the following keys:

  • Identity.Address should have two different ports (say 5001, 5002)
  • RPCAddress should have two different ports (say 4001, 4002)
  • Peers should point to each other -- i.e. add:
{
  "Address": "<the Identity.Address of the other node>",
  "PeerID": "<the Identity.PeerID of the other node>"
}
  1. add some files to each node:
# in node1/
> echo "foo" > foo
> ipfs add foo
added QmdH8HtMYXGg7ZxtjG6wtDrevqFkWYDff4NVxFicfPQwXy foo

# in node2/
> echo "bar" > bar
> ipfs add bar
added QmdruGFND6oiYuszuGHApktfCUz31RfPANYARFrC2n6Dmq bar
  1. you can now launch the nodes. In two different terminals, type:
cd node1 && ipfs mount ipfs
cd node2 && ipfs mount ipfs
  1. The should connect to each other (cross fingers)

  2. You should now be able to cat one file across the other node

# in node1/
> ipfs cat QmdruGFND6oiYuszuGHApktfCUz31RfPANYARFrC2n6Dmq
foo

# in node2/ 
> cat ipfs/QmdH8HtMYXGg7ZxtjG6wtDrevqFkWYDff4NVxFicfPQwXy
bar

(both ipfs cat <hash> and cat ipfs/<hash> should work)

yay? Ping us at https://github.com/jbenet/go-ipfs or #ipfs on freenode if it doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment