Commit 727b6bf9 authored by Jeromy's avatar Jeromy

udpated commands and RPC dialing to work with new configuration changes

parent 8b68776f
......@@ -45,6 +45,13 @@ Advanced Commands:
Use "ipfs help <command>" for more information about a command.
```
## Getting Started
To start using ipfs, you must first initialize ipfs's config files on your system, this is done with `ipfs init`. See `ipfs help init` for information on arguments it takes. After initialization is complete, you can use `ipfs mount`, `ipfs add` and any of the other commands to explore!
NOTE: if you have previously installed ipfs before and you are running into problems getting it to work, try deleting (or backing up somewhere else) your config directory (~/.go-ipfs/config by default) and rerunning `ipfs init`.
## Contributing
go-ipfs is MIT licensed open source software. We welcome contributions big and small! Please make sure to check the [issues](https://github.com/jbenet/go-ipfs/issues). Search the closed ones before reporting things, and help us with the open ones.
......
......@@ -2,13 +2,10 @@ package main
import (
"fmt"
"os"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
"github.com/jbenet/go-ipfs/core/commands"
"github.com/jbenet/go-ipfs/daemon"
u "github.com/jbenet/go-ipfs/util"
)
// Error indicating the max depth has been exceded.
......@@ -32,29 +29,4 @@ func init() {
cmdIpfsAdd.Flag.Bool("r", false, "add objects recursively")
}
func addCmd(c *commander.Command, inp []string) error {
if len(inp) < 1 {
u.POut(c.Long)
return nil
}
cmd := daemon.NewCommand()
cmd.Command = "add"
cmd.Args = inp
cmd.Opts["r"] = c.Flag.Lookup("r").Value.Get()
err := daemon.SendCommand(cmd, "localhost:12345")
if err != nil {
// Do locally
conf, err := getConfigDir(c.Parent)
if err != nil {
return err
}
n, err := localNode(conf, false)
if err != nil {
return err
}
return commands.Add(n, cmd.Args, cmd.Opts, os.Stdout)
}
return nil
}
var addCmd = MakeCommand("add", []string{"r"}, commands.Add)
package main
import (
"os"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
"github.com/jbenet/go-ipfs/core/commands"
"github.com/jbenet/go-ipfs/daemon"
u "github.com/jbenet/go-ipfs/util"
)
var cmdIpfsCat = &commander.Command{
......@@ -22,6 +18,9 @@ var cmdIpfsCat = &commander.Command{
Flag: *flag.NewFlagSet("ipfs-cat", flag.ExitOnError),
}
var catCmd = MakeCommand("cat", nil, commands.Cat)
/*
func catCmd(c *commander.Command, inp []string) error {
if len(inp) < 1 {
u.POut(c.Long)
......@@ -47,3 +46,4 @@ func catCmd(c *commander.Command, inp []string) error {
}
return nil
}
*/
package main
import (
"errors"
"fmt"
"os"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
"github.com/jbenet/go-ipfs/config"
"github.com/jbenet/go-ipfs/core/commands"
"github.com/jbenet/go-ipfs/daemon"
u "github.com/jbenet/go-ipfs/util"
)
type CommanderFunc func(*commander.Command, []string) error
// Wraps a commands.CmdFunc so that it may be safely run by the commander library
func MakeCommand(cmdName string, expargs []string, cmdFn commands.CmdFunc) CommanderFunc {
return func(c *commander.Command, inp []string) error {
if len(inp) < 1 {
u.POut(c.Long)
return nil
}
confdir, err := getConfigDir(c.Parent)
if err != nil {
return err
}
confapi, err := config.ReadConfigKey(confdir+"/config", "Addresses.API")
if err != nil {
return err
}
apiaddr, ok := confapi.(string)
if !ok {
return errors.New("ApiAddress in config file was not a string")
}
cmd := daemon.NewCommand()
cmd.Command = cmdName
cmd.Args = inp
for _, a := range expargs {
cmd.Opts[a] = c.Flag.Lookup(a).Value.Get()
}
err = daemon.SendCommand(cmd, apiaddr)
if err != nil {
fmt.Printf("Executing command locally: %s", err)
// Do locally
n, err := localNode(confdir, false)
if err != nil {
fmt.Println("Local node creation failed.")
return err
}
return cmdFn(n, cmd.Args, cmd.Opts, os.Stdout)
}
return nil
}
}
......@@ -93,5 +93,6 @@ func getConfigDir(c *commander.Command) (string, error) {
if !ok {
return "", errors.New("failed to retrieve config flag value.")
}
return confStr, nil
return u.TildeExpansion(confStr)
}
package main
import (
"os"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
"github.com/jbenet/go-ipfs/core/commands"
"github.com/jbenet/go-ipfs/daemon"
u "github.com/jbenet/go-ipfs/util"
)
var cmdIpfsLs = &commander.Command{
......@@ -25,28 +21,4 @@ var cmdIpfsLs = &commander.Command{
Flag: *flag.NewFlagSet("ipfs-ls", flag.ExitOnError),
}
func lsCmd(c *commander.Command, inp []string) error {
if len(inp) < 1 {
u.POut(c.Long)
return nil
}
com := daemon.NewCommand()
com.Command = "ls"
com.Args = inp
err := daemon.SendCommand(com, "localhost:12345")
if err != nil {
conf, err := getConfigDir(c.Parent)
if err != nil {
return err
}
n, err := localNode(conf, false)
if err != nil {
return err
}
return commands.Ls(n, com.Args, com.Opts, os.Stdout)
}
return nil
}
var lsCmd = MakeCommand("ls", nil, commands.Ls)
......@@ -37,10 +37,12 @@ func mountCmd(c *commander.Command, inp []string) error {
conf, err := getConfigDir(c.Parent)
if err != nil {
fmt.Println("Couldnt get config dir")
return err
}
n, err := localNode(conf, true)
if err != nil {
fmt.Println("Local node creation failed.")
return err
}
......@@ -56,6 +58,7 @@ func mountCmd(c *commander.Command, inp []string) error {
dl, err := daemon.NewDaemonListener(n, maddr)
if err != nil {
fmt.Println("Failed to create daemon listener.")
return err
}
go dl.Listen()
......@@ -63,6 +66,5 @@ func mountCmd(c *commander.Command, inp []string) error {
mp := inp[0]
fmt.Printf("Mounting at %s\n", mp)
return rofs.Mount(n, mp)
}
package main
import (
"os"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
commands "github.com/jbenet/go-ipfs/core/commands"
"github.com/jbenet/go-ipfs/daemon"
u "github.com/jbenet/go-ipfs/util"
)
var cmdIpfsRefs = &commander.Command{
......@@ -32,30 +28,4 @@ func init() {
cmdIpfsRefs.Flag.Bool("u", false, "unique: list each ref only once")
}
func refCmd(c *commander.Command, inp []string) error {
if len(inp) < 1 {
u.POut(c.Long)
return nil
}
cmd := daemon.NewCommand()
cmd.Command = "refs"
cmd.Args = inp
cmd.Opts["r"] = c.Flag.Lookup("r").Value.Get()
cmd.Opts["u"] = c.Flag.Lookup("u").Value.Get()
err := daemon.SendCommand(cmd, "localhost:12345")
if err != nil {
// Do locally
conf, err := getConfigDir(c.Parent)
if err != nil {
return err
}
n, err := localNode(conf, false)
if err != nil {
return err
}
return commands.Refs(n, cmd.Args, cmd.Opts, os.Stdout)
}
return nil
}
var refCmd = MakeCommand("refs", []string{"r", "u"}, commands.Refs)
package commands
import (
"io"
"github.com/jbenet/go-ipfs/core"
)
type CmdFunc func(*core.IpfsNode, []string, map[string]interface{}, io.Writer) error
......@@ -5,14 +5,24 @@ import (
"io"
"net"
"os"
"time"
ma "github.com/jbenet/go-multiaddr"
)
//SendCommand connects to the address on the network with a timeout and encodes the connection into JSON
func SendCommand(command *Command, server string) error {
conn, err := net.DialTimeout("tcp", server, time.Millisecond*300)
maddr, err := ma.NewMultiaddr(server)
if err != nil {
return err
}
network, host, err := maddr.DialArgs()
if err != nil {
return err
}
conn, err := net.Dial(network, host)
if err != nil {
return err
}
......
......@@ -59,7 +59,7 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key u.Key) ([]byte, error) {
routeLevel := 0
closest := dht.routingTables[routeLevel].NearestPeers(kb.ConvertKey(key), PoolSize)
if closest == nil || len(closest) == 0 {
return nil, kb.ErrLookupFailure
return nil, nil
}
// setup the Query
......@@ -101,7 +101,7 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) error {
dht.providers.AddProvider(key, dht.self)
peers := dht.routingTables[0].NearestPeers(kb.ConvertKey(key), PoolSize)
if len(peers) == 0 {
return kb.ErrLookupFailure
return nil
}
//TODO FIX: this doesn't work! it needs to be sent to the actual nearest peers.
......@@ -245,7 +245,7 @@ func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (*peer.Peer, error
routeLevel := 0
p = dht.routingTables[routeLevel].NearestPeer(kb.ConvertPeerID(id))
if p == nil {
return nil, kb.ErrLookupFailure
return nil, nil
}
if p.ID.Equal(id) {
return p, nil
......@@ -287,7 +287,7 @@ func (dht *IpfsDHT) findPeerMultiple(ctx context.Context, id peer.ID) (*peer.Pee
routeLevel := 0
peers := dht.routingTables[routeLevel].NearestPeers(kb.ConvertPeerID(id), AlphaValue)
if len(peers) == 0 {
return nil, kb.ErrLookupFailure
return nil, nil
}
// setup query function
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment