Commit 644df8e0 authored by Lars Gierth's avatar Lars Gierth Committed by GitHub
Browse files

Merge pull request #199 from enzoh/master

Publicize NAT manager struct
parents b535f3fa e9c24fdc
...@@ -56,7 +56,7 @@ type BasicHost struct { ...@@ -56,7 +56,7 @@ type BasicHost struct {
network inet.Network network inet.Network
mux *msmux.MultistreamMuxer mux *msmux.MultistreamMuxer
ids *identify.IDService ids *identify.IDService
natmgr *natManager natmgr NATManager
addrs AddrsFactory addrs AddrsFactory
negtimeout time.Duration negtimeout time.Duration
...@@ -88,11 +88,7 @@ type HostOpts struct { ...@@ -88,11 +88,7 @@ type HostOpts struct {
// NATManager takes care of setting NAT port mappings, and discovering external addresses. // NATManager takes care of setting NAT port mappings, and discovering external addresses.
// If omitted, this will simply be disabled. // If omitted, this will simply be disabled.
// NATManager NATManager
// TODO: Currently the NATManager can only be enabled by calling New,
// since the underlying struct and functions are still private.
// Once they are public, NATManager can be used through NewHost as well.
NATManager *natManager
// //
BandwidthReporter metrics.Reporter BandwidthReporter metrics.Reporter
......
...@@ -4,14 +4,32 @@ import ( ...@@ -4,14 +4,32 @@ import (
"context" "context"
"sync" "sync"
inat "github.com/libp2p/go-libp2p-nat"
goprocess "github.com/jbenet/goprocess" goprocess "github.com/jbenet/goprocess"
lgbl "github.com/libp2p/go-libp2p-loggables" inat "github.com/libp2p/go-libp2p-nat"
inet "github.com/libp2p/go-libp2p-net" inet "github.com/libp2p/go-libp2p-net"
lgbl "github.com/libp2p/go-libp2p-loggables"
ma "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr"
) )
// A simple interface to manage NAT devices.
type NATManager interface {
// Get the NAT device managed by the NAT manager.
NAT() *inat.NAT
// Receive a notification when the NAT device is ready for use.
Ready() <-chan struct{}
// Close all resources associated with a NAT manager.
Close() error
}
// Create a NAT manager.
func NewNATManager(net inet.Network) NATManager {
return newNatManager(net)
}
// natManager takes care of adding + removing port mappings to the nat. // natManager takes care of adding + removing port mappings to the nat.
// Initialized with the host if it has a NATPortMap option enabled. // Initialized with the host if it has a NATPortMap option enabled.
// natManager receives signals from the network, and check on nat mappings: // natManager receives signals from the network, and check on nat mappings:
......
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