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
aff1d8bd
Commit
aff1d8bd
authored
Feb 01, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ipfs swarm disconnect (opposite of connect)
parent
3cd34249
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
4 deletions
+73
-4
core/commands/swarm.go
core/commands/swarm.go
+73
-4
No files found.
core/commands/swarm.go
View file @
aff1d8bd
...
...
@@ -22,8 +22,9 @@ 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
ipfs swarm peers - List peers with open connections
ipfs swarm connect <address> - Open connection to a given address
ipfs swarm disconnect <address> - Close connection to a given address
`
,
ShortDescription
:
`
ipfs swarm is a tool to manipulate the network swarm. The swarm is the
...
...
@@ -32,8 +33,9 @@ ipfs peers in the internet.
`
,
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"peers"
:
swarmPeersCmd
,
"connect"
:
swarmConnectCmd
,
"peers"
:
swarmPeersCmd
,
"connect"
:
swarmConnectCmd
,
"disconnect"
:
swarmDisconnectCmd
,
},
}
...
...
@@ -130,6 +132,73 @@ ipfs swarm connect /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3
Type
:
stringList
{},
}
var
swarmDisconnectCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Close connection to a given address"
,
ShortDescription
:
`
'ipfs swarm disconnect' closes a connection to a peer address. The address format
is an ipfs multiaddr:
ipfs swarm disconnect /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ
`
,
},
Arguments
:
[]
cmds
.
Argument
{
cmds
.
StringArg
(
"address"
,
true
,
true
,
"address of peer to connect to"
)
.
EnableStdin
(),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
Context
()
.
GetNode
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
addrs
:=
req
.
Arguments
()
if
n
.
PeerHost
==
nil
{
res
.
SetError
(
errNotOnline
,
cmds
.
ErrClient
)
return
}
iaddrs
,
err
:=
parseAddresses
(
addrs
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
output
:=
make
([]
string
,
len
(
iaddrs
))
for
i
,
addr
:=
range
iaddrs
{
taddr
:=
addr
.
Transport
()
output
[
i
]
=
"disconnect "
+
addr
.
ID
()
.
Pretty
()
found
:=
false
conns
:=
n
.
PeerHost
.
Network
()
.
ConnsToPeer
(
addr
.
ID
())
for
_
,
conn
:=
range
conns
{
if
!
conn
.
RemoteMultiaddr
()
.
Equal
(
taddr
)
{
log
.
Error
(
"it's not"
,
conn
.
RemoteMultiaddr
(),
taddr
)
continue
}
if
err
:=
conn
.
Close
();
err
!=
nil
{
output
[
i
]
+=
" failure: "
+
err
.
Error
()
}
else
{
output
[
i
]
+=
" success"
}
found
=
true
break
}
if
!
found
{
output
[
i
]
+=
" failure: conn not found"
}
}
res
.
SetOutput
(
&
stringList
{
output
})
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
stringListMarshaler
,
},
Type
:
stringList
{},
}
func
stringListMarshaler
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
list
,
ok
:=
res
.
Output
()
.
(
*
stringList
)
if
!
ok
{
...
...
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