Update is now Advert
This commit is contained in:
parent
ea872f6900
commit
d6c07dfb16
@ -24,7 +24,7 @@ const (
|
|||||||
type router struct {
|
type router struct {
|
||||||
opts Options
|
opts Options
|
||||||
status Status
|
status Status
|
||||||
advertChan chan *Update
|
advertChan chan *Advert
|
||||||
exit chan struct{}
|
exit chan struct{}
|
||||||
wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
@ -43,7 +43,7 @@ func newRouter(opts ...Option) Router {
|
|||||||
return &router{
|
return &router{
|
||||||
opts: options,
|
opts: options,
|
||||||
status: Status{Error: nil, Code: Init},
|
status: Status{Error: nil, Code: Init},
|
||||||
advertChan: make(chan *Update),
|
advertChan: make(chan *Advert),
|
||||||
exit: make(chan struct{}),
|
exit: make(chan struct{}),
|
||||||
wg: &sync.WaitGroup{},
|
wg: &sync.WaitGroup{},
|
||||||
}
|
}
|
||||||
@ -194,7 +194,7 @@ func (r *router) watchTable(w Watcher) error {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
u := &Update{
|
u := &Advert{
|
||||||
ID: r.ID(),
|
ID: r.ID(),
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
Events: []*Event{event},
|
Events: []*Event{event},
|
||||||
@ -248,7 +248,7 @@ func (r *router) watchError(errChan <-chan error) {
|
|||||||
|
|
||||||
// Advertise advertises the routes to the network.
|
// Advertise advertises the routes to the network.
|
||||||
// It returns error if any of the launched goroutines fail with error.
|
// It returns error if any of the launched goroutines fail with error.
|
||||||
func (r *router) Advertise() (<-chan *Update, error) {
|
func (r *router) Advertise() (<-chan *Advert, error) {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
defer r.Unlock()
|
defer r.Unlock()
|
||||||
|
|
||||||
@ -275,7 +275,7 @@ func (r *router) Advertise() (<-chan *Update, error) {
|
|||||||
// NOTE: we only need to recreate the exit/advertChan if the router errored or was stopped
|
// NOTE: we only need to recreate the exit/advertChan if the router errored or was stopped
|
||||||
if r.status.Code == Error || r.status.Code == Stopped {
|
if r.status.Code == Error || r.status.Code == Stopped {
|
||||||
r.exit = make(chan struct{})
|
r.exit = make(chan struct{})
|
||||||
r.advertChan = make(chan *Update)
|
r.advertChan = make(chan *Advert)
|
||||||
}
|
}
|
||||||
|
|
||||||
// routing table watcher which watches all routes i.e. to every destination
|
// routing table watcher which watches all routes i.e. to every destination
|
||||||
@ -321,11 +321,11 @@ func (r *router) Advertise() (<-chan *Update, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update updates the routing table using the advertised values
|
// Update updates the routing table using the advertised values
|
||||||
func (r *router) Update(u *Update) error {
|
func (r *router) Update(a *Advert) error {
|
||||||
// NOTE: event sorting might not be necessary
|
// NOTE: event sorting might not be necessary
|
||||||
// copy update events intp new slices
|
// copy update events intp new slices
|
||||||
events := make([]*Event, len(u.Events))
|
events := make([]*Event, len(a.Events))
|
||||||
copy(events, u.Events)
|
copy(events, a.Events)
|
||||||
// sort events by timestamp
|
// sort events by timestamp
|
||||||
sort.Slice(events, func(i, j int) bool {
|
sort.Slice(events, func(i, j int) bool {
|
||||||
return events[i].Timestamp.Before(events[j].Timestamp)
|
return events[i].Timestamp.Before(events[j].Timestamp)
|
||||||
|
@ -23,9 +23,9 @@ type Router interface {
|
|||||||
// Network returns the network address of the router
|
// Network returns the network address of the router
|
||||||
Network() string
|
Network() string
|
||||||
// Advertise starts advertising routes to the network
|
// Advertise starts advertising routes to the network
|
||||||
Advertise() (<-chan *Update, error)
|
Advertise() (<-chan *Advert, error)
|
||||||
// Update updates the routing table
|
// Update updates the routing table
|
||||||
Update(*Update) error
|
Update(*Advert) error
|
||||||
// Status returns router status
|
// Status returns router status
|
||||||
Status() Status
|
Status() Status
|
||||||
// Stop stops the router
|
// Stop stops the router
|
||||||
@ -43,8 +43,8 @@ type UpdateType int
|
|||||||
const (
|
const (
|
||||||
// Announce is advertised when the router announces itself
|
// Announce is advertised when the router announces itself
|
||||||
Announce UpdateType = iota
|
Announce UpdateType = iota
|
||||||
// RouteEvent advertises route events
|
// Update advertises route updates
|
||||||
RouteEvent
|
Update
|
||||||
)
|
)
|
||||||
|
|
||||||
// String returns string representation of update event
|
// String returns string representation of update event
|
||||||
@ -52,15 +52,15 @@ func (ut UpdateType) String() string {
|
|||||||
switch ut {
|
switch ut {
|
||||||
case Announce:
|
case Announce:
|
||||||
return "ANNOUNCE"
|
return "ANNOUNCE"
|
||||||
case RouteEvent:
|
case Update:
|
||||||
return "ROUTE"
|
return "UPDATE"
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN"
|
return "UNKNOWN"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is sent by the router to the network
|
// Advert is sent by the router to the network
|
||||||
type Update struct {
|
type Advert struct {
|
||||||
// ID is the router ID
|
// ID is the router ID
|
||||||
ID string
|
ID string
|
||||||
// Timestamp marks the time when the update is sent
|
// Timestamp marks the time when the update is sent
|
||||||
|
Loading…
x
Reference in New Issue
Block a user