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
a89e74a1
Commit
a89e74a1
authored
Oct 17, 2018
by
vyzo
Browse files
basic host: export AddrsFactory, provide method to push identify
parent
4ea04c23
Changes
1
Hide whitespace changes
Inline
Side-by-side
p2p/host/basic/basic_host.go
View file @
a89e74a1
...
@@ -59,10 +59,11 @@ type BasicHost struct {
...
@@ -59,10 +59,11 @@ type BasicHost struct {
ids
*
identify
.
IDService
ids
*
identify
.
IDService
pings
*
ping
.
PingService
pings
*
ping
.
PingService
natmgr
NATManager
natmgr
NATManager
addrs
AddrsFactory
maResolver
*
madns
.
Resolver
maResolver
*
madns
.
Resolver
cmgr
ifconnmgr
.
ConnManager
cmgr
ifconnmgr
.
ConnManager
AddrsFactory
AddrsFactory
negtimeout
time
.
Duration
negtimeout
time
.
Duration
proc
goprocess
.
Process
proc
goprocess
.
Process
...
@@ -106,11 +107,11 @@ type HostOpts struct {
...
@@ -106,11 +107,11 @@ type HostOpts struct {
// NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network.
// NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network.
func
NewHost
(
ctx
context
.
Context
,
net
inet
.
Network
,
opts
*
HostOpts
)
(
*
BasicHost
,
error
)
{
func
NewHost
(
ctx
context
.
Context
,
net
inet
.
Network
,
opts
*
HostOpts
)
(
*
BasicHost
,
error
)
{
h
:=
&
BasicHost
{
h
:=
&
BasicHost
{
network
:
net
,
network
:
net
,
mux
:
msmux
.
NewMultistreamMuxer
(),
mux
:
msmux
.
NewMultistreamMuxer
(),
negtimeout
:
DefaultNegotiationTimeout
,
negtimeout
:
DefaultNegotiationTimeout
,
a
ddrs
:
DefaultAddrsFactory
,
A
ddrs
Factory
:
DefaultAddrsFactory
,
maResolver
:
madns
.
DefaultResolver
,
maResolver
:
madns
.
DefaultResolver
,
}
}
h
.
proc
=
goprocessctx
.
WithContextAndTeardown
(
ctx
,
func
()
error
{
h
.
proc
=
goprocessctx
.
WithContextAndTeardown
(
ctx
,
func
()
error
{
...
@@ -136,7 +137,7 @@ func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost,
...
@@ -136,7 +137,7 @@ func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost,
}
}
if
opts
.
AddrsFactory
!=
nil
{
if
opts
.
AddrsFactory
!=
nil
{
h
.
a
ddrs
=
opts
.
AddrsFactory
h
.
A
ddrs
Factory
=
opts
.
AddrsFactory
}
}
if
opts
.
NATManager
!=
nil
{
if
opts
.
NATManager
!=
nil
{
...
@@ -256,6 +257,11 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) {
...
@@ -256,6 +257,11 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) {
go
handle
(
protoID
,
s
)
go
handle
(
protoID
,
s
)
}
}
// PushIdentify pushes an identify update through the identify push protocol
func
(
h
*
BasicHost
)
PushIdentify
()
{
h
.
ids
.
Push
()
}
// ID returns the (local) peer.ID associated with this Host
// ID returns the (local) peer.ID associated with this Host
func
(
h
*
BasicHost
)
ID
()
peer
.
ID
{
func
(
h
*
BasicHost
)
ID
()
peer
.
ID
{
return
h
.
Network
()
.
LocalPeer
()
return
h
.
Network
()
.
LocalPeer
()
...
@@ -474,7 +480,7 @@ func (h *BasicHost) ConnManager() ifconnmgr.ConnManager {
...
@@ -474,7 +480,7 @@ func (h *BasicHost) ConnManager() ifconnmgr.ConnManager {
// Addrs returns listening addresses that are safe to announce to the network.
// Addrs returns listening addresses that are safe to announce to the network.
// The output is the same as AllAddrs, but processed by AddrsFactory.
// The output is the same as AllAddrs, but processed by AddrsFactory.
func
(
h
*
BasicHost
)
Addrs
()
[]
ma
.
Multiaddr
{
func
(
h
*
BasicHost
)
Addrs
()
[]
ma
.
Multiaddr
{
return
h
.
a
ddrs
(
h
.
AllAddrs
())
return
h
.
A
ddrs
Factory
(
h
.
AllAddrs
())
}
}
// mergeAddrs merges input address lists, leave only unique addresses
// mergeAddrs merges input address lists, leave only unique addresses
...
...
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