visual cleanup of router code

This commit is contained in:
Asim Aslam
2019-07-10 07:45:27 +01:00
parent 34967e8e33
commit 0a1b657221
5 changed files with 69 additions and 104 deletions

View File

@@ -31,6 +31,8 @@ const (
// router provides default router implementation
type router struct {
// embed the table
table.Table
opts Options
status Status
exit chan struct{}
@@ -52,6 +54,7 @@ func newRouter(opts ...Option) Router {
}
return &router{
Table: options.Table,
opts: options,
status: Status{Error: nil, Code: Stopped},
exit: make(chan struct{}),
@@ -75,26 +78,6 @@ func (r *router) Options() Options {
return r.opts
}
// ID returns router ID
func (r *router) ID() string {
return r.opts.ID
}
// Table returns routing table
func (r *router) Table() table.Table {
return r.opts.Table
}
// Address returns router's bind address
func (r *router) Address() string {
return r.opts.Address
}
// Network returns the address router advertises to the network
func (r *router) Network() string {
return r.opts.Network
}
// manageServiceRoutes manages routes for a given service.
// It returns error of the routing table action fails.
func (r *router) manageServiceRoutes(service *registry.Service, action string) error {
@@ -224,7 +207,7 @@ func (r *router) advertEvents(advType AdvertType, events []*table.Event) {
defer r.advertWg.Done()
a := &Advert{
ID: r.ID(),
Id: r.opts.Id,
Type: advType,
Timestamp: time.Now(),
Events: events,
@@ -490,8 +473,8 @@ func (r *router) Advertise() (<-chan *Advert, error) {
return r.advertChan, nil
}
// Update updates the routing table using the advertised values
func (r *router) Update(a *Advert) error {
// Process updates the routing table using the advertised values
func (r *router) Process(a *Advert) error {
// NOTE: event sorting might not be necessary
// copy update events intp new slices
events := make([]*table.Event, len(a.Events))
@@ -546,6 +529,6 @@ func (r *router) Stop() error {
}
// String prints debugging information about router
func (r router) String() string {
func (r *router) String() string {
return "router"
}