35
36
var queryDhtCmd = &cmds.Command{
37
Helptext: cmds.HelpText{
38
- Tagline: "Find the closest peers to a given key by querying through the DHT.",
39
- ShortDescription: ``,
38
+ Tagline: "Find the closest Peer IDs to a given Peer ID by querying the DHT.",
39
+ ShortDescription: "Outputs a list of newline-delimited Peer IDs.",
40
},
41
42
Arguments: []cmds.Argument{
43
cmds.StringArg("peerID", true, true, "The peerID to run the query against."),
44
},
45
Options: []cmds.Option{
46
- cmds.BoolOption("verbose", "v", "Write extra information."),
46
+ cmds.BoolOption("verbose", "v", "Write debug information."),
47
},
48
Run: func(req cmds.Request, res cmds.Response) {
49
n, err := req.InvocContext().GetNode()
94
return nil, u.ErrCast()
95
}
96
97
+ pfm := pfuncMap{
98
+ notif.PeerResponse: func(obj *notif.QueryEvent, out io.Writer, verbose bool) {
99
+ for _, p := range obj.Responses {
100
+ fmt.Fprintf(out, "%s\n", p.ID.Pretty())
101
+ }
102
+ },
103
+ }
104
+
105
marshal := func(v interface{}) (io.Reader, error) {
106
obj, ok := v.(*notif.QueryEvent)
107
if !ok {
111
verbose, _, _ := res.Request().Option("v").Bool()
112
113
buf := new(bytes.Buffer)
106
- printEvent(obj, buf, verbose, nil)
114
+ printEvent(obj, buf, verbose, pfm)
115
return buf, nil
116
}
117
127
128
var findProvidersDhtCmd = &cmds.Command{
129
Helptext: cmds.HelpText{
122
- Tagline: "Run a 'FindProviders' query through the DHT.",
123
- ShortDescription: `
124
-FindProviders will return a list of peers who are able to provide the value requested.
125
-`,
130
+ Tagline: "Find peers in the DHT that can provide a specific value, given a key.",
131
+ ShortDescription: "Outputs a list of newline-delimited provider Peer IDs.",
132
},
133
134
Arguments: []cmds.Argument{
135
cmds.StringArg("key", true, true, "The key to find providers for."),
136
},
137
Options: []cmds.Option{
132
- cmds.BoolOption("verbose", "v", "Write extra information."),
138
+ cmds.BoolOption("verbose", "v", "Write debug information."),
139
},
140
Run: func(req cmds.Request, res cmds.Response) {
141
n, err := req.InvocContext().GetNode()
228
229
var findPeerDhtCmd = &cmds.Command{
230
Helptext: cmds.HelpText{
225
- Tagline: "Run a 'FindPeer' query through the DHT.",
226
- ShortDescription: ``,
231
+ Tagline: "Query the DHT for all of the multiaddresses associated with a Peer ID.",
232
+ ShortDescription: "Outputs a list of newline-delimited multiaddresses.",
233
},
234
235
Arguments: []cmds.Argument{
230
- cmds.StringArg("peerID", true, true, "The peer to search for."),
236
+ cmds.StringArg("peerID", true, true, "The ID of the peer to search for."),
237
+ },
238
+ Options: []cmds.Option{
239
+ cmds.BoolOption("verbose", "v", "Write debug information."),
240
},
241
Run: func(req cmds.Request, res cmds.Response) {
242
n, err := req.InvocContext().GetNode()
294
return nil, u.ErrCast()
295
}
296
297
+ verbose, _, _ := res.Request().Option("v").Bool()
298
+
299
pfm := pfuncMap{
300
notif.FinalPeer: func(obj *notif.QueryEvent, out io.Writer, verbose bool) {
301
pi := obj.Responses[0]
291
- fmt.Fprintf(out, "%s\n", pi.ID)
302
for _, a := range pi.Addrs {
293
- fmt.Fprintf(out, "\t%s\n", a)
303
+ fmt.Fprintf(out, "%s\n", a)
304
}
305
},
306
}
311
}
312
313
buf := new(bytes.Buffer)
304
- printEvent(obj, buf, true, pfm)
314
+ printEvent(obj, buf, verbose, pfm)
315
return buf, nil
316
}
317
327
328
var getValueDhtCmd = &cmds.Command{
329
Helptext: cmds.HelpText{
320
- Tagline: "Run a 'GetValue' query through the DHT.",
330
+ Tagline: "Given a key, query the DHT for its best value.",
331
ShortDescription: `
322
-GetValue will return the value stored in the DHT at the given key.
332
+Outputs the best value for the given key.
333
+
334
+There may be several different values for a given key stored in the DHT; in this context 'best' means the record that is most desirable. There is no one metric for 'best': it depends entirely on the key type. For IPNS, 'best' is the record that is both valid and has the highest sequence number (freshest). Different key types can specify other 'best' rules.
335
`,
336
},
337
339
cmds.StringArg("key", true, true, "The key to find a value for."),
340
},
341
Options: []cmds.Option{
330
- cmds.BoolOption("verbose", "v", "Write extra information."),
342
+ cmds.BoolOption("verbose", "v", "Write debug information."),
343
},
344
Run: func(req cmds.Request, res cmds.Response) {
345
n, err := req.InvocContext().GetNode()
432
433
var putValueDhtCmd = &cmds.Command{
434
Helptext: cmds.HelpText{
423
- Tagline: "Run a 'PutValue' query through the DHT.",
435
+ Tagline: "Write a key/value pair to the DHT.",
436
ShortDescription: `
425
-PutValue will store the given key value pair in the DHT.
437
+Given a key of the form /foo/bar and a value of any form, this will write that value to the DHT with that key.
438
+
439
+Keys have two parts: a keytype (foo) and the key name (bar). IPNS uses the /ipns keytype, and expects the key name to be a Peer ID. IPNS entries are specifically formatted (protocol buffer).
440
+
441
+You may only use keytypes that are supported in your ipfs binary: currently this is only /ipns. Unless you have a relatively deep understanding of the go-ipfs DHT internals, you likely want to be using 'ipfs name publish' instead of this.
442
+
443
+Value is arbitrary text. Standard input can be used to provide value.
444
+
445
+NOTE: a value may NOT exceed 2048 bytes.
446
`,
447
},
448
451
cmds.StringArg("value", true, false, "The value to store.").EnableStdin(),
452
},
453
Options: []cmds.Option{
434
- cmds.BoolOption("verbose", "v", "Write extra information."),
454
+ cmds.BoolOption("verbose", "v", "Write debug information."),
455
},
456
Run: func(req cmds.Request, res cmds.Response) {
457
n, err := req.InvocContext().GetNode()
513
}
514
},
515
notif.Value: func(obj *notif.QueryEvent, out io.Writer, verbose bool) {
496
- fmt.Fprintf(out, "storing value at %s\n", obj.ID)
516
+ fmt.Fprintf(out, "%s\n", obj.ID.Pretty())
517
},
518
}
519
566
fmt.Fprint(out, obj.Extra)
567
}
568
case notif.PeerResponse:
549
- fmt.Fprintf(out, "* %s says use ", obj.ID)
550
- for _, p := range obj.Responses {
551
- fmt.Fprintf(out, "%s ", p.ID)
569
+ if verbose {
570
+ fmt.Fprintf(out, "* %s says use ", obj.ID)
571
+ for _, p := range obj.Responses {
572
+ fmt.Fprintf(out, "%s ", p.ID)
573
+ }
574
+ fmt.Fprintln(out)
575
}
553
- fmt.Fprintln(out)
576
case notif.QueryError:
555
- fmt.Fprintf(out, "error: %s\n", obj.Extra)
577
+ if verbose {
578
+ fmt.Fprintf(out, "error: %s\n", obj.Extra)
579
+ }
580
case notif.DialingPeer:
581
if verbose {
582
fmt.Fprintf(out, "dialing peer: %s\n", obj.ID)
585
if verbose {
586
fmt.Fprintf(out, "adding peer to query: %s\n", obj.ID)
587
}
588
+ case notif.FinalPeer:
589
default:
565
- fmt.Fprintf(out, "unrecognized event type: %d\n", obj.Type)
590
+ if verbose {
591
+ fmt.Fprintf(out, "unrecognized event type: %d\n", obj.Type)
592
+ }
593
}
594
}
595