Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-autonat
Commits
4b4c43c6
Unverified
Commit
4b4c43c6
authored
Apr 08, 2020
by
Will
Committed by
GitHub
Apr 08, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #75 from libp2p/feat/unknownservice
Run Autonat Service while in unknown connectivity mode
parents
42891941
7b72774e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
7 deletions
+7
-7
autonat.go
autonat.go
+5
-5
svc_test.go
svc_test.go
+2
-2
No files found.
autonat.go
View file @
4b4c43c6
...
...
@@ -46,6 +46,7 @@ type AmbientAutoNAT struct {
emitReachabilityChanged
event
.
Emitter
}
// StaticAutoNAT is a simple AutoNAT implementation when a single NAT status is desired.
type
StaticAutoNAT
struct
{
ctx
context
.
Context
host
host
.
Host
...
...
@@ -85,15 +86,12 @@ func New(ctx context.Context, h host.Host, options ...Option) (AutoNAT, error) {
if
err
!=
nil
{
return
nil
,
err
}
service
.
Enable
()
}
if
conf
.
forceReachability
{
emitReachabilityChanged
.
Emit
(
event
.
EvtLocalReachabilityChanged
{
Reachability
:
conf
.
reachability
})
// The serice will only exist when reachability is public.
if
service
!=
nil
{
service
.
Enable
()
}
return
&
StaticAutoNAT
{
ctx
:
ctx
,
host
:
h
,
...
...
@@ -297,7 +295,7 @@ func (as *AmbientAutoNAT) recordObservation(observation autoNATResult) {
as
.
status
.
Store
(
autoNATResult
{
network
.
ReachabilityUnknown
,
nil
})
if
currentStatus
.
Reachability
!=
network
.
ReachabilityUnknown
{
if
as
.
service
!=
nil
{
as
.
service
.
Dis
able
()
as
.
service
.
En
able
()
}
as
.
emitStatus
()
}
...
...
@@ -362,10 +360,12 @@ func shufflePeers(peers []peer.AddrInfo) {
}
}
// Status returns the AutoNAT observed reachability status.
func
(
s
*
StaticAutoNAT
)
Status
()
network
.
Reachability
{
return
s
.
reachability
}
// PublicAddr returns the publicly connectable Multiaddr of this node if one is known.
func
(
s
*
StaticAutoNAT
)
PublicAddr
()
(
ma
.
Multiaddr
,
error
)
{
if
s
.
reachability
!=
network
.
ReachabilityPublic
{
return
nil
,
errors
.
New
(
"NAT status is not public"
)
...
...
svc_test.go
View file @
4b4c43c6
...
...
@@ -188,8 +188,8 @@ func TestAutoNATServiceStartup(t *testing.T) {
connect
(
t
,
h
,
hc
)
_
,
err
=
ac
.
DialBack
(
ctx
,
h
.
ID
())
if
err
=
=
nil
{
t
.
Fatal
(
"autonat s
hould not be started / advertising
."
)
if
err
!
=
nil
{
t
.
Fatal
(
"autonat s
ervice be active in unknown mode
."
)
}
sub
,
_
:=
h
.
EventBus
()
.
Subscribe
(
new
(
event
.
EvtLocalReachabilityChanged
))
...
...
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