Hash the network address

This commit is contained in:
Asim Aslam 2019-10-02 15:22:44 +01:00
parent 5d77ce9e9b
commit 308424488b

View File

@ -86,17 +86,25 @@ func newNetwork(opts ...Option) Network {
tun.WithTunnel(options.Tunnel), tun.WithTunnel(options.Tunnel),
) )
// set the address to a hashed address
hasher := fnv.New64()
hasher.Write([]byte(options.Address + options.Id))
address := fmt.Sprintf("%d", hasher.Sum64())
// set the address to advertise // set the address to advertise
address := options.Address var advertise string
if len(options.Advertise) > 0 { if len(options.Advertise) > 0 {
address = options.Advertise advertise = options.Advertise
} else {
advertise = options.Address
} }
// 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(address),
server.Advertise(address), server.Advertise(advertise),
server.Name(options.Name), server.Name(options.Name),
server.Transport(tunTransport), server.Transport(tunTransport),
) )
@ -728,7 +736,6 @@ func (n *network) Connect() error {
// set our internal node address // set our internal node address
// if advertise address is not set // if advertise address is not set
if len(n.options.Advertise) == 0 { if len(n.options.Advertise) == 0 {
n.node.address = n.tunnel.Address()
n.server.Init(server.Advertise(n.tunnel.Address())) n.server.Init(server.Advertise(n.tunnel.Address()))
} }