-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
IPFS Bootstrap Command #137
Changes from all commits
25b959a
beeb4a3
0c41c57
a8a8ab7
e831138
bbcf90f
e958171
34eb326
a5b7f13
34cccde
02d6a45
085e1a5
df88566
5f7d3c9
a52b996
11f9bda
d7e7833
2566078
a0a865b
bebc87d
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 |
---|---|---|
@@ -0,0 +1,178 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag" | ||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander" | ||
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr" | ||
config "github.com/jbenet/go-ipfs/config" | ||
"strings" | ||
) | ||
|
||
var cmdIpfsBootstrap = &commander.Command{ | ||
UsageLine: "bootstrap", | ||
Short: "Show a list of bootstrapped addresses.", | ||
Long: `ipfs bootstrap - show, or manipulate bootstrap node addresses | ||
|
||
SECURITY WARNING: | ||
|
||
The bootstrap command manipulates the "bootstrap list", which contains | ||
the addresses of bootstrap nodes. These are the *trusted peers* from | ||
which to learn about other peers in the network. Only edit this list | ||
if you understand the risks of adding or removing nodes from this list. | ||
|
||
Running 'ipfs bootstrap' with no arguments will run 'ipfs bootstrap list'. | ||
|
||
Commands: | ||
|
||
list Show the boostrap list. | ||
add <address> Add a node's address to the bootstrap list. | ||
remove <address> Remove an address from the bootstrap list. | ||
|
||
`, | ||
Run: bootstrapCmd, | ||
Subcommands: []*commander.Command{ | ||
cmdIpfsBootstrapRemove, | ||
cmdIpfsBootstrapAdd, | ||
}, | ||
Flag: *flag.NewFlagSet("ipfs-bootstrap", flag.ExitOnError), | ||
} | ||
|
||
var cmdIpfsBootstrapRemove = &commander.Command{ | ||
UsageLine: "remove", | ||
Run: IpfsBootstrapRemoveCmd, | ||
Flag: *flag.NewFlagSet("ipfs-bootstrap-remove", flag.ExitOnError), | ||
} | ||
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.
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. was fixed |
||
|
||
var cmdIpfsBootstrapAdd = &commander.Command{ | ||
UsageLine: "add", | ||
Run: IpfsBootstrapAddCmd, | ||
Flag: *flag.NewFlagSet("ipfs-bootstrap-add", flag.ExitOnError), | ||
} | ||
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. This will break your config when you write back out. Please just use the functions provided in the 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. was fixed |
||
|
||
func IpfsBootstrapRemoveCmd(c *commander.Command, inp []string) error { | ||
|
||
if len(inp) == 0 { | ||
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. No no, please use 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 was a bit confused by this. I'll look into this more. |
||
fmt.Println("No peer specified.") | ||
return nil | ||
} | ||
|
||
if strings.Contains(inp[0], "/") { | ||
|
||
var pID = inp[0][len(inp[0])-46:] | ||
var ip = strings.TrimSuffix(inp[0], pID) | ||
maddr, err := ma.NewMultiaddr(strings.TrimSuffix(ip, "/")) | ||
var address, _ = maddr.String() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
peer := config.BootstrapPeer{ | ||
Address: address, | ||
PeerID: pID, | ||
} | ||
|
||
configpath, _ := config.Filename("~/.go-ipfs/config") | ||
var cfg config.Config | ||
readErr := config.ReadConfigFile(configpath, &cfg) | ||
if readErr != nil { | ||
return readErr | ||
} | ||
|
||
i := 0 | ||
for _, v := range cfg.Bootstrap { | ||
if v.PeerID == peer.PeerID && v.Address == peer.Address { | ||
continue | ||
} | ||
cfg.Bootstrap[i] = v | ||
i++ | ||
} | ||
cfg.Bootstrap = cfg.Bootstrap[:i] | ||
|
||
writeErr := config.WriteConfigFile(configpath, cfg) | ||
if writeErr != nil { | ||
return writeErr | ||
} | ||
} | ||
|
||
if !strings.Contains(inp[0], "/") { | ||
|
||
var peerID = inp[0] | ||
|
||
configpath, _ := config.Filename("~/.go-ipfs/config") | ||
var cfg config.Config | ||
readErr := config.ReadConfigFile(configpath, &cfg) | ||
if readErr != nil { | ||
return readErr | ||
} | ||
|
||
i := 0 | ||
for _, v := range cfg.Bootstrap { | ||
if v.PeerID == peerID { | ||
continue | ||
} | ||
cfg.Bootstrap[i] = v | ||
i++ | ||
} | ||
cfg.Bootstrap = cfg.Bootstrap[:i] | ||
|
||
writeErr := config.WriteConfigFile(configpath, cfg) | ||
if writeErr != nil { | ||
return writeErr | ||
} | ||
|
||
} | ||
return nil | ||
} | ||
|
||
func IpfsBootstrapAddCmd(c *commander.Command, inp []string) error { | ||
|
||
if len(inp) == 0 { | ||
fmt.Println("No peer specified.") | ||
return nil | ||
} | ||
|
||
var pID = inp[0][len(inp[0])-46:] | ||
var ip = strings.TrimSuffix(inp[0], pID) | ||
maddr, err := ma.NewMultiaddr(strings.TrimSuffix(ip, "/")) | ||
var address, _ = maddr.String() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
peer := config.BootstrapPeer{ | ||
Address: address, | ||
PeerID: pID, | ||
} | ||
|
||
configpath, _ := config.Filename("~/.go-ipfs/config") | ||
var cfg config.Config | ||
readErr := config.ReadConfigFile(configpath, &cfg) | ||
if readErr != nil { | ||
return readErr | ||
} | ||
|
||
addedPeer := append(cfg.Bootstrap, &peer) | ||
cfg.Bootstrap = addedPeer | ||
|
||
writeErr := config.WriteConfigFile(configpath, cfg) | ||
if writeErr != nil { | ||
return writeErr | ||
} | ||
return nil | ||
return nil | ||
} | ||
func bootstrapCmd(c *commander.Command, inp []string) error { | ||
|
||
configpath, _ := config.Filename("~/.go-ipfs/config") | ||
var cfg config.Config | ||
config.ReadConfigFile(configpath, &cfg) | ||
|
||
for i := range cfg.Bootstrap { | ||
s := []string{cfg.Bootstrap[i].Address, "/", cfg.Bootstrap[i].PeerID, "\n"} | ||
fmt.Printf(strings.Join(s, "")) | ||
} | ||
|
||
return nil | ||
|
||
} |
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.
How about:
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.
this was fixed