Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
add Close method to interface, fix closing of StaticAutoNAT
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Aug 29, 2021
1 parent e6e029f commit f62691d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion autonat.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ func (as *AmbientAutoNAT) getPeerToProbe() peer.ID {

func (as *AmbientAutoNAT) Close() error {
as.ctxCancel()
as.service.Disable()
if as.service != nil {
as.service.Disable()
}
<-as.backgroundRunning
return nil
}
Expand All @@ -457,3 +459,10 @@ func (s *StaticAutoNAT) PublicAddr() (ma.Multiaddr, error) {
}
return nil, errors.New("no available address")
}

func (s *StaticAutoNAT) Close() error {
if s.service != nil {
s.service.Disable()
}
return nil
}
2 changes: 2 additions & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package autonat

import (
"context"
"io"

"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
Expand All @@ -16,6 +17,7 @@ type AutoNAT interface {
// PublicAddr returns the public dial address when NAT status is public and an
// error otherwise
PublicAddr() (ma.Multiaddr, error)
io.Closer
}

// Client is a stateless client interface to AutoNAT peers
Expand Down

0 comments on commit f62691d

Please sign in to comment.