From 05e62a2b954fd4cb06c11ff2f2fe6dfd9a7808f2 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 18 Sep 2019 18:56:02 +0100 Subject: [PATCH] allow setting advertise address --- network/default.go | 10 ++++++++-- network/options.go | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/network/default.go b/network/default.go index af5badc7..7685dcd4 100644 --- a/network/default.go +++ b/network/default.go @@ -86,11 +86,17 @@ func newNetwork(opts ...Option) Network { 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 := server.NewServer( server.Id(options.Id), server.Address(options.Id), - server.Advertise(options.Address), + server.Advertise(address), server.Name(options.Name), server.Transport(tunTransport), ) @@ -108,7 +114,7 @@ func newNetwork(opts ...Option) Network { network := &network{ node: &node{ id: options.Id, - address: options.Address, + address: address, peers: make(map[string]*node), }, options: options, diff --git a/network/options.go b/network/options.go index e670cf4c..eb3aa61c 100644 --- a/network/options.go +++ b/network/options.go @@ -20,6 +20,8 @@ type Options struct { Name string // Address to bind to Address string + // Advertise sets the address to advertise + Advertise string // Nodes is a list of seed nodes Nodes []string // 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 // with resolved node func Nodes(n ...string) Option {