From bbe5bb130f4f8acbd69a37c6250d05a68551a9a5 Mon Sep 17 00:00:00 2001 From: FZambia Date: Mon, 20 May 2024 17:29:31 +0300 Subject: [PATCH] simplify GetChannelMediumOptions func signature --- channel_medium.go | 4 ++++ config.go | 5 ++--- node.go | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/channel_medium.go b/channel_medium.go index 8773861c..4adb5dc4 100644 --- a/channel_medium.go +++ b/channel_medium.go @@ -47,6 +47,10 @@ type ChannelMediumOptions struct { broadcastDelay time.Duration } +func (o ChannelMediumOptions) isMediumEnabled() bool { + return o.SharedPositionSync || o.KeepLatestPublication || o.enableQueue || o.broadcastDelay > 0 +} + // Keep global to save 8 byte per-channel. Must be only changed by tests. var channelMediumTimeNow = time.Now diff --git a/config.go b/config.go index 5c7f63c9..3bf7d2e2 100644 --- a/config.go +++ b/config.go @@ -114,10 +114,9 @@ type Config struct { ChannelNamespaceLabelForTransportMessagesReceived bool // GetChannelMediumOptions is a way to provide ChannelMediumOptions for specific channel. - // This function is called each time new channel appears on the Node. If it returns false - // then no medium layer will be used for the channel. + // This function is called each time new channel appears on the Node. // See the doc comment for ChannelMediumOptions for more details about channel medium concept. - GetChannelMediumOptions func(channel string) (ChannelMediumOptions, bool) + GetChannelMediumOptions func(channel string) ChannelMediumOptions } const ( diff --git a/node.go b/node.go index 12a7652f..c610539c 100644 --- a/node.go +++ b/node.go @@ -985,8 +985,8 @@ func (n *Node) addSubscription(ch string, sub subInfo) error { } if first { if n.config.GetChannelMediumOptions != nil { - mediumOptions, ok := n.config.GetChannelMediumOptions(ch) - if ok { + mediumOptions := n.config.GetChannelMediumOptions(ch) + if mediumOptions.isMediumEnabled() { medium, err := newChannelMedium(ch, n, mediumOptions) if err != nil { return err