Update is now Advert
This commit is contained in:
parent
ea872f6900
commit
d6c07dfb16
@ -24,7 +24,7 @@ const (
|
||||
type router struct {
|
||||
opts Options
|
||||
status Status
|
||||
advertChan chan *Update
|
||||
advertChan chan *Advert
|
||||
exit chan struct{}
|
||||
wg *sync.WaitGroup
|
||||
sync.RWMutex
|
||||
@ -43,7 +43,7 @@ func newRouter(opts ...Option) Router {
|
||||
return &router{
|
||||
opts: options,
|
||||
status: Status{Error: nil, Code: Init},
|
||||
advertChan: make(chan *Update),
|
||||
advertChan: make(chan *Advert),
|
||||
exit: make(chan struct{}),
|
||||
wg: &sync.WaitGroup{},
|
||||
}
|
||||
@ -194,7 +194,7 @@ func (r *router) watchTable(w Watcher) error {
|
||||
break
|
||||
}
|
||||
|
||||
u := &Update{
|
||||
u := &Advert{
|
||||
ID: r.ID(),
|
||||
Timestamp: time.Now(),
|
||||
Events: []*Event{event},
|
||||
@ -248,7 +248,7 @@ func (r *router) watchError(errChan <-chan error) {
|
||||
|
||||
// Advertise advertises the routes to the network.
|
||||
// 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()
|
||||
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
|
||||
if r.status.Code == Error || r.status.Code == Stopped {
|
||||
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
|
||||
@ -321,11 +321,11 @@ func (r *router) Advertise() (<-chan *Update, error) {
|
||||
}
|
||||
|
||||
// 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
|
||||
// copy update events intp new slices
|
||||
events := make([]*Event, len(u.Events))
|
||||
copy(events, u.Events)
|
||||
events := make([]*Event, len(a.Events))
|
||||
copy(events, a.Events)
|
||||
// sort events by timestamp
|
||||
sort.Slice(events, func(i, j int) bool {
|
||||
return events[i].Timestamp.Before(events[j].Timestamp)
|
||||
|
@ -23,9 +23,9 @@ type Router interface {
|
||||
// Network returns the network address of the router
|
||||
Network() string
|
||||
// Advertise starts advertising routes to the network
|
||||
Advertise() (<-chan *Update, error)
|
||||
Advertise() (<-chan *Advert, error)
|
||||
// Update updates the routing table
|
||||
Update(*Update) error
|
||||
Update(*Advert) error
|
||||
// Status returns router status
|
||||
Status() Status
|
||||
// Stop stops the router
|
||||
@ -43,8 +43,8 @@ type UpdateType int
|
||||
const (
|
||||
// Announce is advertised when the router announces itself
|
||||
Announce UpdateType = iota
|
||||
// RouteEvent advertises route events
|
||||
RouteEvent
|
||||
// Update advertises route updates
|
||||
Update
|
||||
)
|
||||
|
||||
// String returns string representation of update event
|
||||
@ -52,15 +52,15 @@ func (ut UpdateType) String() string {
|
||||
switch ut {
|
||||
case Announce:
|
||||
return "ANNOUNCE"
|
||||
case RouteEvent:
|
||||
return "ROUTE"
|
||||
case Update:
|
||||
return "UPDATE"
|
||||
default:
|
||||
return "UNKNOWN"
|
||||
}
|
||||
}
|
||||
|
||||
// Update is sent by the router to the network
|
||||
type Update struct {
|
||||
// Advert is sent by the router to the network
|
||||
type Advert struct {
|
||||
// ID is the router ID
|
||||
ID string
|
||||
// Timestamp marks the time when the update is sent
|
||||
|
Loading…
Reference in New Issue
Block a user