From be5093798b8f1043e7268fe80185eb7c654c5d49 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 15 Oct 2019 16:08:38 +0100 Subject: [PATCH] Use DialMode/ListenMode --- network/default.go | 8 ++++---- tunnel/broker/broker.go | 4 ++-- tunnel/options.go | 8 ++++---- tunnel/tunnel.go | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/network/default.go b/network/default.go index e12ab8c9..1494d348 100644 --- a/network/default.go +++ b/network/default.go @@ -822,7 +822,7 @@ func (n *network) Connect() error { } // dial into ControlChannel to send route adverts - ctrlClient, err := n.tunnel.Dial(ControlChannel, tunnel.DialMulticast()) + ctrlClient, err := n.tunnel.Dial(ControlChannel, tunnel.DialMode(tunnel.Multicast)) if err != nil { n.Unlock() return err @@ -831,14 +831,14 @@ func (n *network) Connect() error { n.tunClient[ControlChannel] = ctrlClient // listen on ControlChannel - ctrlListener, err := n.tunnel.Listen(ControlChannel, tunnel.ListenMulticast()) + ctrlListener, err := n.tunnel.Listen(ControlChannel, tunnel.ListenMode(tunnel.Multicast)) if err != nil { n.Unlock() return err } // dial into NetworkChannel to send network messages - netClient, err := n.tunnel.Dial(NetworkChannel, tunnel.DialMulticast()) + netClient, err := n.tunnel.Dial(NetworkChannel, tunnel.DialMode(tunnel.Multicast)) if err != nil { n.Unlock() return err @@ -847,7 +847,7 @@ func (n *network) Connect() error { n.tunClient[NetworkChannel] = netClient // listen on NetworkChannel - netListener, err := n.tunnel.Listen(NetworkChannel, tunnel.ListenMulticast()) + netListener, err := n.tunnel.Listen(NetworkChannel, tunnel.ListenMode(tunnel.Multicast)) if err != nil { n.Unlock() return err diff --git a/tunnel/broker/broker.go b/tunnel/broker/broker.go index 75779698..d11e160c 100644 --- a/tunnel/broker/broker.go +++ b/tunnel/broker/broker.go @@ -58,7 +58,7 @@ func (t *tunBroker) Disconnect() error { func (t *tunBroker) Publish(topic string, m *broker.Message, opts ...broker.PublishOption) error { // TODO: this is probably inefficient, we might want to just maintain an open connection // it may be easier to add broadcast to the tunnel - c, err := t.tunnel.Dial(topic, tunnel.DialMulticast()) + c, err := t.tunnel.Dial(topic, tunnel.DialMode(tunnel.Multicast)) if err != nil { return err } @@ -71,7 +71,7 @@ func (t *tunBroker) Publish(topic string, m *broker.Message, opts ...broker.Publ } func (t *tunBroker) Subscribe(topic string, h broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) { - l, err := t.tunnel.Listen(topic, tunnel.ListenMulticast()) + l, err := t.tunnel.Listen(topic, tunnel.ListenMode(tunnel.Multicast)) if err != nil { return nil, err } diff --git a/tunnel/options.go b/tunnel/options.go index 54e740e2..7d6360ab 100644 --- a/tunnel/options.go +++ b/tunnel/options.go @@ -95,18 +95,18 @@ func DefaultOptions() Options { } // Listen options -func ListenMulticast() ListenOption { +func ListenMode(m Mode) ListenOption { return func(o *ListenOptions) { - o.Mode = Multicast + o.Mode = m } } // Dial options // Dial multicast sets the multicast option to send only to those mapped -func DialMulticast() DialOption { +func DialMode(m Mode) DialOption { return func(o *DialOptions) { - o.Mode = Multicast + o.Mode = m } } diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index f46c90b8..a2671f62 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -13,7 +13,7 @@ const ( Unicast Mode = iota // send to all channel listeners Multicast - // send to all listeners + // send to all links Broadcast )