Merge pull request #769 from micro/advertise
allow setting advertise address
This commit is contained in:
commit
ee74e26582
@ -86,11 +86,17 @@ func newNetwork(opts ...Option) Network {
|
|||||||
tun.WithTunnel(options.Tunnel),
|
tun.WithTunnel(options.Tunnel),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// set the address to advertise
|
||||||
|
address := options.Address
|
||||||
|
if len(options.Advertise) > 0 {
|
||||||
|
address = options.Advertise
|
||||||
|
}
|
||||||
|
|
||||||
// server is network server
|
// server is network server
|
||||||
server := server.NewServer(
|
server := server.NewServer(
|
||||||
server.Id(options.Id),
|
server.Id(options.Id),
|
||||||
server.Address(options.Id),
|
server.Address(options.Id),
|
||||||
server.Advertise(options.Address),
|
server.Advertise(address),
|
||||||
server.Name(options.Name),
|
server.Name(options.Name),
|
||||||
server.Transport(tunTransport),
|
server.Transport(tunTransport),
|
||||||
)
|
)
|
||||||
@ -108,7 +114,7 @@ func newNetwork(opts ...Option) Network {
|
|||||||
network := &network{
|
network := &network{
|
||||||
node: &node{
|
node: &node{
|
||||||
id: options.Id,
|
id: options.Id,
|
||||||
address: options.Address,
|
address: address,
|
||||||
peers: make(map[string]*node),
|
peers: make(map[string]*node),
|
||||||
},
|
},
|
||||||
options: options,
|
options: options,
|
||||||
@ -710,7 +716,11 @@ func (n *network) Connect() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set our internal node address
|
// set our internal node address
|
||||||
|
// if advertise address is not set
|
||||||
|
if len(n.options.Advertise) == 0 {
|
||||||
n.node.address = n.Tunnel.Address()
|
n.node.address = n.Tunnel.Address()
|
||||||
|
n.server.Init(server.Advertise(n.Tunnel.Address()))
|
||||||
|
}
|
||||||
|
|
||||||
// initialize the tunnel to resolved nodes
|
// initialize the tunnel to resolved nodes
|
||||||
n.Tunnel.Init(
|
n.Tunnel.Init(
|
||||||
|
@ -20,6 +20,8 @@ type Options struct {
|
|||||||
Name string
|
Name string
|
||||||
// Address to bind to
|
// Address to bind to
|
||||||
Address string
|
Address string
|
||||||
|
// Advertise sets the address to advertise
|
||||||
|
Advertise string
|
||||||
// Nodes is a list of seed nodes
|
// Nodes is a list of seed nodes
|
||||||
Nodes []string
|
Nodes []string
|
||||||
// Tunnel is network tunnel
|
// Tunnel is network tunnel
|
||||||
@ -53,6 +55,13 @@ func Address(a string) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Advertise sets the address to advertise
|
||||||
|
func Advertise(a string) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Advertise = a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Nodes is a list of seed nodes used along
|
// Nodes is a list of seed nodes used along
|
||||||
// with resolved node
|
// with resolved node
|
||||||
func Nodes(n ...string) Option {
|
func Nodes(n ...string) Option {
|
||||||
|
Loading…
Reference in New Issue
Block a user