Commit 851e77eb authored by Hector Sanjuan's avatar Hector Sanjuan
Browse files

protocol/identify: make golint happy



License: MIT
Signed-off-by: default avatarHector Sanjuan <hector@protocol.ai>
parent d961d98f
// 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()
......
......@@ -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()
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment