Adds network id. Skips processing routes when router is the origin.
This commit is contained in:
@@ -34,8 +34,8 @@ type network struct {
|
||||
proxy.Proxy
|
||||
// tun is network tunnel
|
||||
tunnel.Tunnel
|
||||
// srv is network server
|
||||
srv server.Server
|
||||
// server is network server
|
||||
server server.Server
|
||||
// client is network client
|
||||
client client.Client
|
||||
|
||||
@@ -59,13 +59,19 @@ func newNetwork(opts ...Option) Network {
|
||||
tunnel.Address(options.Address),
|
||||
)
|
||||
|
||||
// init router Id to the network id
|
||||
options.Router.Init(
|
||||
router.Id(options.Id),
|
||||
)
|
||||
|
||||
// create tunnel client with tunnel transport
|
||||
tunTransport := trn.NewTransport(
|
||||
trn.WithTunnel(options.Tunnel),
|
||||
)
|
||||
|
||||
// srv is network server
|
||||
srv := server.NewServer(
|
||||
// server is network server
|
||||
server := server.NewServer(
|
||||
server.Id(options.Id),
|
||||
server.Address(options.Address),
|
||||
server.Name(options.Name),
|
||||
server.Transport(tunTransport),
|
||||
@@ -86,7 +92,7 @@ func newNetwork(opts ...Option) Network {
|
||||
Router: options.Router,
|
||||
Proxy: options.Proxy,
|
||||
Tunnel: options.Tunnel,
|
||||
srv: srv,
|
||||
server: server,
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
@@ -333,7 +339,7 @@ func (n *network) Connect() error {
|
||||
go n.process(listener)
|
||||
|
||||
// start the server
|
||||
if err := n.srv.Start(); err != nil {
|
||||
if err := n.server.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -345,7 +351,7 @@ func (n *network) Connect() error {
|
||||
|
||||
func (n *network) close() error {
|
||||
// stop the server
|
||||
if err := n.srv.Stop(); err != nil {
|
||||
if err := n.server.Stop(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -390,5 +396,5 @@ func (n *network) Client() client.Client {
|
||||
|
||||
// Server returns network server
|
||||
func (n *network) Server() server.Server {
|
||||
return n.srv
|
||||
return n.server
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/go-micro/network/resolver"
|
||||
"github.com/micro/go-micro/network/resolver/registry"
|
||||
"github.com/micro/go-micro/proxy"
|
||||
@@ -13,6 +14,8 @@ type Option func(*Options)
|
||||
|
||||
// Options configure network
|
||||
type Options struct {
|
||||
// Id of the node
|
||||
Id string
|
||||
// Name of the network
|
||||
Name string
|
||||
// Address to bind to
|
||||
@@ -27,14 +30,21 @@ type Options struct {
|
||||
Resolver resolver.Resolver
|
||||
}
|
||||
|
||||
// Name is the network name
|
||||
// Id sets the id of the network node
|
||||
func Id(id string) Option {
|
||||
return func(o *Options) {
|
||||
o.Id = id
|
||||
}
|
||||
}
|
||||
|
||||
// Name sets the network name
|
||||
func Name(n string) Option {
|
||||
return func(o *Options) {
|
||||
o.Name = n
|
||||
}
|
||||
}
|
||||
|
||||
// Address is the network address
|
||||
// Address sets the network address
|
||||
func Address(a string) Option {
|
||||
return func(o *Options) {
|
||||
o.Address = a
|
||||
@@ -72,6 +82,7 @@ func Resolver(r resolver.Resolver) Option {
|
||||
// DefaultOptions returns network default options
|
||||
func DefaultOptions() Options {
|
||||
return Options{
|
||||
Id: uuid.New().String(),
|
||||
Name: DefaultName,
|
||||
Address: DefaultAddress,
|
||||
Tunnel: tunnel.NewTunnel(),
|
||||
|
Reference in New Issue
Block a user