Hash the service address before advertising it to the network.

This commit is contained in:
Milos Gajdos 2019-09-17 17:55:42 +01:00
parent e586763301
commit 38d6ffdf9a
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F

View File

@ -2,6 +2,8 @@ package network
import ( import (
"errors" "errors"
"fmt"
"hash/fnv"
"sync" "sync"
"time" "time"
@ -553,7 +555,7 @@ func (n *network) processCtrlChan(client transport.Client, listener tunnel.Liste
if pbRtrAdvert.Id == n.options.Id { if pbRtrAdvert.Id == n.options.Id {
continue continue
} }
log.Debugf("Network received advert message with %d events from: %s", len(pbRtrAdvert.Events), pbRtrAdvert.Id) log.Debugf("Network received advert message from: %s", pbRtrAdvert.Id)
// loookup advertising node in our peer topology // loookup advertising node in our peer topology
advertNode := n.node.GetPeerNode(pbRtrAdvert.Id) advertNode := n.node.GetPeerNode(pbRtrAdvert.Id)
if advertNode == nil { if advertNode == nil {
@ -642,6 +644,7 @@ func (n *network) processCtrlChan(client transport.Client, listener tunnel.Liste
// advertise advertises routes to the network // advertise advertises routes to the network
func (n *network) advertise(client transport.Client, advertChan <-chan *router.Advert) { func (n *network) advertise(client transport.Client, advertChan <-chan *router.Advert) {
hasher := fnv.New64()
for { for {
select { select {
// process local adverts and randomly fire them at other nodes // process local adverts and randomly fire them at other nodes
@ -649,10 +652,13 @@ func (n *network) advertise(client transport.Client, advertChan <-chan *router.A
// create a proto advert // create a proto advert
var events []*pbRtr.Event var events []*pbRtr.Event
for _, event := range advert.Events { for _, event := range advert.Events {
// NOTE: we override the Gateway and Link fields here // hash the service before advertising it
hasher.Reset()
hasher.Write([]byte(event.Route.Address + n.node.id))
// NOTE: we override Gateway, Link and Service here
route := &pbRtr.Route{ route := &pbRtr.Route{
Service: event.Route.Service, Service: event.Route.Service,
Address: event.Route.Address, Address: fmt.Sprintf("%d", hasher.Sum64()),
Gateway: n.node.id, Gateway: n.node.id,
Network: event.Route.Network, Network: event.Route.Network,
Router: event.Route.Router, Router: event.Route.Router,