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
f47b4f17
Commit
f47b4f17
authored
10 years ago
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #255 from jbenet/id-cmd
basic ID cmd
parents
6107612f
7d2f3d81
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
5 deletions
+132
-5
core/commands2/id.go
core/commands2/id.go
+103
-0
core/commands2/root.go
core/commands2/root.go
+2
-0
core/core.go
core/core.go
+3
-0
net/handshake/handshake1.go
net/handshake/handshake1.go
+5
-5
peer/peer.go
peer/peer.go
+19
-0
No files found.
core/commands2/id.go
0 → 100644
View file @
f47b4f17
package
commands
import
(
"encoding/base64"
"encoding/json"
"errors"
"time"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
b58
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
cmds
"github.com/jbenet/go-ipfs/commands"
"github.com/jbenet/go-ipfs/peer"
kb
"github.com/jbenet/go-ipfs/routing/kbucket"
u
"github.com/jbenet/go-ipfs/util"
)
const
offlineIdErrorMessage
=
`ID command fails when run without daemon, we are working
to fix this In the meantime, please run the daemon if you want to use 'ipfs id'`
type
IdOutput
struct
{
ID
string
PublicKey
string
Addresses
[]
string
AgentVersion
string
ProtocolVersion
string
}
var
idCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Show IPFS Node ID info"
,
ShortDescription
:
`
Prints out information about the specified peer,
if no peer is specified, prints out local peers info.
`
,
},
Arguments
:
nil
,
Run
:
func
(
req
cmds
.
Request
)
(
interface
{},
error
)
{
node
,
err
:=
req
.
Context
()
.
GetNode
()
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
req
.
Arguments
())
==
0
{
return
printPeer
(
node
.
Identity
)
}
pid
,
ok
:=
req
.
Arguments
()[
0
]
.
(
string
)
if
!
ok
{
return
nil
,
errors
.
New
(
"Improperly formatted peer id"
)
}
id
:=
peer
.
ID
(
b58
.
Decode
(
pid
))
ctx
,
_
:=
context
.
WithTimeout
(
context
.
TODO
(),
time
.
Second
*
5
)
p
,
err
:=
node
.
Routing
.
FindPeer
(
ctx
,
id
)
if
err
==
kb
.
ErrLookupFailure
{
return
nil
,
errors
.
New
(
offlineIdErrorMessage
)
}
if
err
!=
nil
{
return
nil
,
err
}
return
printPeer
(
p
)
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
([]
byte
,
error
)
{
val
,
ok
:=
res
.
Output
()
.
(
*
IdOutput
)
if
!
ok
{
return
nil
,
u
.
ErrCast
()
}
return
json
.
MarshalIndent
(
val
,
""
,
"
\t
"
)
},
},
Type
:
&
IdOutput
{},
}
func
printPeer
(
p
peer
.
Peer
)
(
interface
{},
error
)
{
if
p
==
nil
{
return
nil
,
errors
.
New
(
"Attempted to print nil peer!"
)
}
info
:=
new
(
IdOutput
)
info
.
ID
=
p
.
ID
()
.
String
()
if
p
.
PubKey
()
==
nil
{
return
nil
,
errors
.
New
(
`peer publickey not populated on offline runs,
please run the daemon to use ipfs id!`
)
}
pkb
,
err
:=
p
.
PubKey
()
.
Bytes
()
if
err
!=
nil
{
return
nil
,
err
}
info
.
PublicKey
=
base64
.
StdEncoding
.
EncodeToString
(
pkb
)
for
_
,
a
:=
range
p
.
Addresses
()
{
info
.
Addresses
=
append
(
info
.
Addresses
,
a
.
String
())
}
agent
,
protocol
:=
p
.
GetVersions
()
info
.
AgentVersion
=
agent
info
.
ProtocolVersion
=
protocol
return
info
,
nil
}
This diff is collapsed.
Click to expand it.
core/commands2/root.go
View file @
f47b4f17
...
...
@@ -32,6 +32,7 @@ Tool commands:
update Download and apply go-ipfs updates
version Show ipfs version information
commands List all available commands
id Show info about ipfs peers
Advanced Commands:
...
...
@@ -77,6 +78,7 @@ var rootSubcommands = map[string]*cmds.Command{
"update"
:
UpdateCmd
,
"object"
:
objectCmd
,
"refs"
:
refsCmd
,
"id"
:
idCmd
,
}
func
init
()
{
...
...
This diff is collapsed.
Click to expand it.
core/core.go
View file @
f47b4f17
...
...
@@ -18,6 +18,7 @@ import (
merkledag
"github.com/jbenet/go-ipfs/merkledag"
namesys
"github.com/jbenet/go-ipfs/namesys"
inet
"github.com/jbenet/go-ipfs/net"
handshake
"github.com/jbenet/go-ipfs/net/handshake"
mux
"github.com/jbenet/go-ipfs/net/mux"
netservice
"github.com/jbenet/go-ipfs/net/service"
path
"github.com/jbenet/go-ipfs/path"
...
...
@@ -223,6 +224,8 @@ func initIdentity(cfg *config.Identity, peers peer.Peerstore, online bool) (peer
return
nil
,
err
}
self
.
SetVersions
(
handshake
.
ClientVersion
,
handshake
.
IpfsVersion
.
String
())
// when not online, don't need to parse private keys (yet)
if
online
{
skb
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
cfg
.
PrivKey
)
...
...
This diff is collapsed.
Click to expand it.
net/handshake/handshake1.go
View file @
f47b4f17
...
...
@@ -10,13 +10,13 @@ import (
semver
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
)
//
i
pfsVersion holds the current protocol version for a client running this code
var
i
pfsVersion
*
semver
.
Version
var
c
lientVersion
=
"go-ipfs/"
+
config
.
CurrentVersionNumber
//
I
pfsVersion holds the current protocol version for a client running this code
var
I
pfsVersion
*
semver
.
Version
var
C
lientVersion
=
"go-ipfs/"
+
config
.
CurrentVersionNumber
func
init
()
{
var
err
error
i
pfsVersion
,
err
=
semver
.
NewVersion
(
"0.0.1"
)
I
pfsVersion
,
err
=
semver
.
NewVersion
(
"0.0.1"
)
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"invalid protocol version: %v"
,
err
))
}
...
...
@@ -24,7 +24,7 @@ func init() {
// Handshake1Msg returns the current protocol version as a protobuf message
func
Handshake1Msg
()
*
pb
.
Handshake1
{
return
NewHandshake1
(
i
pfsVersion
.
String
(),
c
lientVersion
)
return
NewHandshake1
(
I
pfsVersion
.
String
(),
C
lientVersion
)
}
// ErrVersionMismatch is returned when two clients don't share a protocol version
...
...
This diff is collapsed.
Click to expand it.
peer/peer.go
View file @
f47b4f17
...
...
@@ -99,6 +99,9 @@ type Peer interface {
GetType
()
Type
SetType
(
Type
)
//Get/Set Agent and Protocol Versions
GetVersions
()
(
agent
,
protocol
string
)
SetVersions
(
agent
,
protocol
string
)
// Update with the data of another peer instance
Update
(
Peer
)
error
...
...
@@ -137,6 +140,9 @@ type peer struct {
// within that package, map from ID to latency value.
latency
time
.
Duration
protocolVersion
string
agentVersion
string
// typ can be Local, Remote, or Unspecified (default)
typ
Type
...
...
@@ -372,6 +378,19 @@ func (p *peer) Update(other Peer) error {
return
nil
}
func
(
p
*
peer
)
GetVersions
()
(
agent
,
protocol
string
)
{
p
.
RLock
()
defer
p
.
RUnlock
()
return
p
.
agentVersion
,
p
.
protocolVersion
}
func
(
p
*
peer
)
SetVersions
(
agent
,
protocol
string
)
{
p
.
Lock
()
defer
p
.
Unlock
()
p
.
agentVersion
=
agent
p
.
protocolVersion
=
protocol
}
// WithKeyPair returns a Peer object with given keys.
func
WithKeyPair
(
sk
ic
.
PrivKey
,
pk
ic
.
PubKey
)
(
Peer
,
error
)
{
if
sk
==
nil
&&
pk
==
nil
{
...
...
This diff is collapsed.
Click to expand it.
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