Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
851e77eb
Commit
851e77eb
authored
Mar 15, 2017
by
Hector Sanjuan
Browse files
protocol/identify: make golint happy
License: MIT Signed-off-by:
Hector Sanjuan
<
hector@protocol.ai
>
parent
d961d98f
Changes
3
Hide whitespace changes
Inline
Side-by-side
p2p/protocol/identify/id.go
View file @
851e77eb
// Package identify provides an identity service for libp2p hosts. This service
// allows to exchange information about supported protocols and observed
// addresses between hosts.
package
identify
import
(
...
...
@@ -31,6 +34,7 @@ const ID = "/ipfs/id/1.0.0"
// TODO(jbenet): fix the versioning mess.
const
LibP2PVersion
=
"ipfs/0.1.0"
// ClientVersion is similar to a UserAgent string.
var
ClientVersion
=
"go-libp2p/3.3.4"
// IDService is a structure that implements ProtocolIdentify.
...
...
@@ -55,6 +59,9 @@ type IDService struct {
observedAddrs
ObservedAddrSet
}
// NewIDService creates a new IDService by attaching
// a stream handler to the given host, making it ready to interact
// with other hosts running this service.
func
NewIDService
(
h
host
.
Host
)
*
IDService
{
s
:=
&
IDService
{
Host
:
h
,
...
...
@@ -69,6 +76,9 @@ func (ids *IDService) OwnObservedAddrs() []ma.Multiaddr {
return
ids
.
observedAddrs
.
Addrs
()
}
// IdentifyConn handles newly stablished connections, pushes and extracts
// the necessary information so they can be used: protocol, observed addresses,
// public key... The IDService's host peerstore is updated after the handshake.
func
(
ids
*
IDService
)
IdentifyConn
(
c
inet
.
Conn
)
{
ids
.
currmu
.
Lock
()
if
wait
,
found
:=
ids
.
currid
[
c
];
found
{
...
...
@@ -117,6 +127,9 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
}
}
// RequestHandler handles an identity service request
// by writing protocol version, host addresses, observed addresses
// etc. to the stream.
func
(
ids
*
IDService
)
RequestHandler
(
s
inet
.
Stream
)
{
defer
s
.
Close
()
c
:=
s
.
Conn
()
...
...
@@ -134,6 +147,9 @@ func (ids *IDService) RequestHandler(s inet.Stream) {
c
.
RemotePeer
(),
c
.
RemoteMultiaddr
())
}
// ResponseHandler handles an identity service response
// by reading the message information and updating the
// IDService's host accordingly.
func
(
ids
*
IDService
)
ResponseHandler
(
s
inet
.
Stream
)
{
defer
s
.
Close
()
c
:=
s
.
Conn
()
...
...
p2p/protocol/identify/obsaddr.go
View file @
851e77eb
...
...
@@ -28,6 +28,8 @@ type ObservedAddrSet struct {
ttl
time
.
Duration
}
// Addrs returns a slice of multiaddresses observed. The addresses
// must have not timed out and must have been seen more than once.
func
(
oas
*
ObservedAddrSet
)
Addrs
()
[]
ma
.
Multiaddr
{
oas
.
Lock
()
defer
oas
.
Unlock
()
...
...
@@ -62,6 +64,7 @@ func (oas *ObservedAddrSet) Addrs() []ma.Multiaddr {
return
addrs
}
// Add includes a new multiaddress in the observed addresses set.
func
(
oas
*
ObservedAddrSet
)
Add
(
addr
ma
.
Multiaddr
,
observer
ma
.
Multiaddr
)
{
oas
.
Lock
()
defer
oas
.
Unlock
()
...
...
@@ -103,12 +106,15 @@ func observerGroup(m ma.Multiaddr) string {
return
ma
.
Split
(
m
)[
0
]
.
String
()
}
// SetTTL sets the time to live for addresses in the ObservedAddrSet.
func
(
oas
*
ObservedAddrSet
)
SetTTL
(
ttl
time
.
Duration
)
{
oas
.
Lock
()
defer
oas
.
Unlock
()
oas
.
ttl
=
ttl
}
// TTL returns the time to live for addressed tracked by the
// ObservedAddrSet. If not set, it defaults to peerstore.OwnObservedTTL.
func
(
oas
*
ObservedAddrSet
)
TTL
()
time
.
Duration
{
oas
.
Lock
()
defer
oas
.
Unlock
()
...
...
p2p/protocol/identify/pb/identify.proto
View file @
851e77eb
...
...
@@ -6,7 +6,7 @@ message Identify {
optional
string
protocolVersion
=
5
;
// e.g. ipfs/1.0.0
// agentVersion is like a UserAgent string in browsers, or client version in bittorrent
// includes the client name and client.
// includes the client name and client
version
.
optional
string
agentVersion
=
6
;
// e.g. go-ipfs/0.1.0
// publicKey is this node's public key (which also gives its node.ID)
...
...
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