2019-07-25 23:19:05 +01:00
|
|
|
package router
|
2019-06-09 23:09:38 +01:00
|
|
|
|
2019-06-18 18:33:05 +01:00
|
|
|
import (
|
2019-07-05 19:15:32 +01:00
|
|
|
"hash/fnv"
|
2020-11-18 16:50:41 +03:00
|
|
|
|
|
|
|
"github.com/unistack-org/micro/v3/metadata"
|
2019-06-18 18:33:05 +01:00
|
|
|
)
|
2019-06-12 22:30:42 +01:00
|
|
|
|
2019-06-13 15:12:07 +01:00
|
|
|
var (
|
2019-07-09 15:45:42 +01:00
|
|
|
// DefaultLink is default network link
|
|
|
|
DefaultLink = "local"
|
2019-08-27 23:08:35 +01:00
|
|
|
// DefaultLocalMetric is default route cost for a local route
|
2019-10-23 12:53:36 +01:00
|
|
|
DefaultLocalMetric int64 = 1
|
2019-06-13 15:12:07 +01:00
|
|
|
)
|
|
|
|
|
2019-06-19 21:22:14 +01:00
|
|
|
// Route is network route
|
|
|
|
type Route struct {
|
2021-03-06 19:45:13 +03:00
|
|
|
// Metadata for the route
|
|
|
|
Metadata metadata.Metadata
|
2019-07-09 15:45:42 +01:00
|
|
|
// Service is destination service name
|
|
|
|
Service string
|
2019-06-26 16:03:19 +01:00
|
|
|
// Gateway is route gateway
|
|
|
|
Gateway string
|
2019-07-08 16:16:50 +01:00
|
|
|
// Network is network address
|
2019-06-10 19:50:54 +01:00
|
|
|
Network string
|
2019-08-27 23:08:35 +01:00
|
|
|
// Router is router id
|
|
|
|
Router string
|
2019-07-09 15:45:42 +01:00
|
|
|
// Link is network link
|
|
|
|
Link string
|
2021-03-06 19:45:13 +03:00
|
|
|
// Address is service node address
|
|
|
|
Address string
|
2019-06-19 21:22:14 +01:00
|
|
|
// Metric is the route cost metric
|
2019-10-23 12:53:36 +01:00
|
|
|
Metric int64
|
2019-06-09 23:09:38 +01:00
|
|
|
}
|
2019-06-18 18:33:05 +01:00
|
|
|
|
2019-07-05 19:15:32 +01:00
|
|
|
// Hash returns route hash sum.
|
|
|
|
func (r *Route) Hash() uint64 {
|
|
|
|
h := fnv.New64()
|
2021-02-13 01:46:16 +03:00
|
|
|
//nolint:errcheck
|
|
|
|
h.Write([]byte(r.Service))
|
|
|
|
//nolint:errcheck
|
|
|
|
h.Write([]byte(r.Address))
|
|
|
|
//nolint:errcheck
|
|
|
|
h.Write([]byte(r.Gateway))
|
|
|
|
//nolint:errcheck
|
|
|
|
h.Write([]byte(r.Network))
|
|
|
|
//nolint:errcheck
|
|
|
|
h.Write([]byte(r.Router))
|
|
|
|
//nolint:errcheck
|
|
|
|
h.Write([]byte(r.Link))
|
2019-07-05 19:15:32 +01:00
|
|
|
return h.Sum64()
|
|
|
|
}
|