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
4557f31f
Commit
4557f31f
authored
8 years ago
by
Hector Sanjuan
Browse files
Options
Download
Email Patches
Plain Diff
Make golint happy on routed host
License: MIT Signed-off-by:
Hector Sanjuan
<
hector@protocol.ai
>
parent
b90873d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
p2p/host/routed/routed.go
+24
-0
p2p/host/routed/routed.go
with
24 additions
and
0 deletions
+24
-0
p2p/host/routed/routed.go
View file @
4557f31f
// 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
()
...
...
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