Commit 4557f31f authored by Hector Sanjuan's avatar Hector Sanjuan
Browse files

Make golint happy on routed host


License: MIT
Signed-off-by: default avatarHector Sanjuan <hector@protocol.ai>
parent b90873d8
Showing with 24 additions and 0 deletions
+24 -0
// Package routedhost provides a wrapper for libp2p Host and a generic Routing
// mechanism, which allow them to discover hosts which are not in their
// peerstores.
package routedhost
import (
......@@ -31,10 +34,13 @@ type RoutedHost struct {
route Routing
}
// The Routing interface allows to wrap any peer discovery implementations
type Routing interface {
FindPeer(context.Context, peer.ID) (pstore.PeerInfo, error)
}
// Wrap creates a RoutedHost by wrapping a regular Host and a Routing
// implementation.
func Wrap(h host.Host, r Routing) *RoutedHost {
return &RoutedHost{h, r}
}
......@@ -85,41 +91,59 @@ func logRoutingErrDifferentPeers(ctx context.Context, wanted, got peer.ID, err e
log.Event(ctx, "routingError", lm)
}
// ID returns the (local) peer.ID associated with this Host
func (rh *RoutedHost) ID() peer.ID {
return rh.host.ID()
}
// Peerstore returns the Host's repository of Peer Addresses and Keys.
func (rh *RoutedHost) Peerstore() pstore.Peerstore {
return rh.host.Peerstore()
}
// Addrs returns all the addresses of BasicHost at this moment in time.
func (rh *RoutedHost) Addrs() []ma.Multiaddr {
return rh.host.Addrs()
}
// Network returns the Network interface of the Host
func (rh *RoutedHost) Network() inet.Network {
return rh.host.Network()
}
// Mux returns the Mux multiplexing incoming streams to protocol handlers.
func (rh *RoutedHost) Mux() *msmux.MultistreamMuxer {
return rh.host.Mux()
}
// SetStreamHandler sets the protocol handler on the Host's Mux.
// This is equivalent to:
// host.Mux().SetHandler(proto, handler)
// (Threadsafe)
func (rh *RoutedHost) SetStreamHandler(pid protocol.ID, handler inet.StreamHandler) {
rh.host.SetStreamHandler(pid, handler)
}
// SetStreamHandlerMatch sets the protocol handler on the Host's Mux
// using a matching function to do protocol comparisons
func (rh *RoutedHost) SetStreamHandlerMatch(pid protocol.ID, m func(string) bool, handler inet.StreamHandler) {
rh.host.SetStreamHandlerMatch(pid, m, handler)
}
// RemoveStreamHandler removes the handler matching the given protocol ID.
func (rh *RoutedHost) RemoveStreamHandler(pid protocol.ID) {
rh.host.RemoveStreamHandler(pid)
}
// NewStream opens a new stream to given peer p, and writes a p2p/protocol
// header with given protocol.ID. If there is no connection to p, attempts
// to create one. If ProtocolID is "", writes no header.
// (Threadsafe)
func (rh *RoutedHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (inet.Stream, error) {
return rh.host.NewStream(ctx, p, pids...)
}
// Close shuts down the Host's services (network, etc).
func (rh *RoutedHost) Close() error {
// no need to close IpfsRouting. we dont own it.
return rh.host.Close()
......
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