Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
4d78c2d7
Commit
4d78c2d7
authored
Nov 18, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmds: swarm peer
parent
faab9842
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
0 deletions
+82
-0
core/commands2/root.go
core/commands2/root.go
+1
-0
core/commands2/swarm.go
core/commands2/swarm.go
+81
-0
No files found.
core/commands2/root.go
View file @
4d78c2d7
...
...
@@ -79,6 +79,7 @@ var rootSubcommands = map[string]*cmds.Command{
"object"
:
objectCmd
,
"refs"
:
refsCmd
,
"id"
:
idCmd
,
"swarm"
:
swarmCmd
,
}
func
init
()
{
...
...
core/commands2/swarm.go
0 → 100644
View file @
4d78c2d7
package
commands
import
(
"bytes"
"fmt"
cmds
"github.com/jbenet/go-ipfs/commands"
errors
"github.com/jbenet/go-ipfs/util/debugerror"
)
type
stringList
struct
{
Strings
[]
string
}
var
swarmCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"swarm inspection tool"
,
Synopsis
:
`
ipfs swarm peers - List peers with open connections
ipfs swarm connect <address> - Open connection to a given peer
`
,
ShortDescription
:
`
ipfs swarm is a tool to manipulate the network swarm. The swarm is the
component that opens, listens for, and maintains connections to other
ipfs peers in the internet.
`
,
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"peers"
:
swarmPeersCmd
,
// "connect": swarmConnectCmd,
},
}
var
swarmPeersCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"List peers with open connections"
,
ShortDescription
:
`
ipfs swarm peers lists the set of peers this node is connected to.
`
,
},
Run
:
func
(
req
cmds
.
Request
)
(
interface
{},
error
)
{
log
.
Debug
(
"ipfs swarm peers"
)
n
,
err
:=
req
.
Context
()
.
GetNode
()
if
err
!=
nil
{
return
nil
,
err
}
if
n
.
Network
==
nil
{
return
nil
,
errNotOnline
}
conns
:=
n
.
Network
.
GetConnections
()
addrs
:=
make
([]
string
,
len
(
conns
))
for
i
,
c
:=
range
conns
{
pid
:=
c
.
RemotePeer
()
.
ID
()
addr
:=
c
.
RemoteMultiaddr
()
addrs
[
i
]
=
fmt
.
Sprintf
(
"%s/%s"
,
addr
,
pid
)
}
return
&
stringList
{
addrs
},
nil
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
stringListMarshaler
,
},
Type
:
&
stringList
{},
}
func
stringListMarshaler
(
res
cmds
.
Response
)
([]
byte
,
error
)
{
list
,
ok
:=
res
.
Output
()
.
(
*
stringList
)
if
!
ok
{
return
nil
,
errors
.
New
(
"failed to cast []string"
)
}
var
buf
bytes
.
Buffer
for
_
,
s
:=
range
list
.
Strings
{
buf
.
Write
([]
byte
(
s
))
buf
.
Write
([]
byte
(
"
\n
"
))
}
return
buf
.
Bytes
(),
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment