filter

package
v0.9.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2018 License: BSD-3-Clause Imports: 3 Imported by: 0

README

autobahnkreuz - filtering

autobahnkreuz provides a super advanced filtering since version 0.9 which is intended to solve real problems.

Imagine all your clients have subscribed to a single topic, but you want to publish sensible information to just a few clients. On the other hand, you want system callers to keep track of all information, so how do you solve this?

In most WAMP routers, you would either send multiple publications with the same content but different filters, or you create multiple topics. Both variants are not good to maintain, so we created an advanced filtering framework that lets you combine filters.

Warning

This feature is intended for advanced users, allows users to create "arbitrarily" complex filters which may slow down the router!

Altough our focus is on performance, reliability and security, until now this feature is considered BETA.

Writing good filters

To ensure your filters perform as good as possible, write the sub-filters that likely match (for match any) or likely mismatch (for match all) first. This way, we have not to check ALL sub filters, so we can return early.

Reference

Filtering is done via publish_options, which can be specified in all conformant WAMP clients. You can specify a 'standard' WAMP publish filter to have eligible_authrole and so on, but you can also make use of the advanced filtering.

To use advanced filtering, set another key within the options dictionary: filter_type. Currently, filter_type can take 3 values:

  • not - match if the specified filter does not match.
  • all - all specified filters have to match
  • any - one of the specified filters has to match
Example - not - excluding a specific session

If you are having a simple filter, you can just specify it inline:

const options = {
  "filter_type": "not",
  "eligible": session_id
}

For more complex filters, the filter property is used:

const options = {
  "filter_type": "not",
  "filter": {
    "filter_type": "any",
    "filters": [
      {
        "eligible": session_id
      },
      {
        "blacklist_authrole": "admin"
      }
    ]
  }
}
Example - any - matching different authroles and authids

A filters (plural!) property is introduced to allow multiple sub-filters to be specified:

const options = {
  "filter_type": "any",
  "filters": [ // note the plural
    {
      "eligible": session_id
    },
    {
      "eligible_authrole": "admin"
    }
  ]
}
Example - all - excluding a session when it has no specific authrole
const options = {
  "filter_type": "all",
  "filters": [ // note the plural
    {
      "blacklist_authrole": "anonymous"
    },
    {
      "eligible": session_id
    }
  ]
}

Documentation

Index

Constants

View Source
const (
	KeyType    = "filter_type"
	KeyFilter  = "filter"
	KeyFilters = "filters"
	TypeNeg    = "not"
	TypeAny    = "any"
	TypeAll    = "all"
)

Variables

This section is empty.

Functions

func IsValidFilter

func IsValidFilter(ftype string) bool

func NewComplexFilter

func NewComplexFilter(msg *wamp.Publish) router.PublishFilter

func NewSimplePublishFilter

func NewSimplePublishFilter(opts wamp.Dict) router.PublishFilter

NewSimplePublishFilter gets any blacklists and whitelists included in a PUBLISH message. If there are no filters defined by the PUBLISH message, then nil is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL