Skip to content

Commit

Permalink
simplify GetChannelMediumOptions func signature
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed May 20, 2024
1 parent d53083e commit bbe5bb1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions channel_medium.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bbe5bb1

Please sign in to comment.