udp

package
v0.0.0-...-5352646 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	PacketHandlers:      1 << 4,
	PacketBuffer:        50,
	DownlinkPathExpires: 15 * time.Second,
	ConnectionExpires:   1 * time.Minute,
	ScheduleLateTime:    800 * time.Millisecond,
	AddrChangeBlock:     1 * time.Minute,
	RateLimiting: RateLimitingConfig{
		Enable:    true,
		Messages:  10,
		Threshold: 10 * time.Millisecond,
	},
}

DefaultConfig contains the default configuration.

Functions

func Serve

func Serve(ctx context.Context, server io.Server, conn *net.UDPConn, config Config) error

Serve serves the UDP frontend.

Types

type Config

type Config struct {
	// PacketHandlers defines the number of concurrent packet handlers.
	PacketHandlers int `name:"packet-handlers" description:"Number of concurrent packet handlers"`
	// PacketBuffer defines how many packets are buffered to handlers before it overflows.
	PacketBuffer int `name:"packet-buffer" description:"Buffer size of unhandled packets"`
	// DownlinkPathExpires defines for how long a downlink path is valid. A downlink path is renewed on each pull data and
	// TX acknowledgement packet.
	// Gateways typically pull data every 5 seconds.
	DownlinkPathExpires time.Duration `name:"downlink-path-expires" description:"Time after which a downlink path to a gateway expires"`
	// ConnectionExpires defines for how long a connection remains valid while no pull data, push data or TX
	// acknowledgement is received.
	ConnectionExpires time.Duration `name:"connection-expires" description:"Time after which a connection of a gateway expires"`
	// ScheduleLateTime defines the time in advance to the actual transmission the downlink message should be scheduled to
	// the gateway.
	ScheduleLateTime time.Duration `name:"schedule-late-time" description:"Time in advance to send downlink to the gateway when scheduling late"`
	// AddrChangeBlock defines the time to block traffic when the address changes.
	AddrChangeBlock time.Duration `name:"addr-change-block" description:"Time to block traffic when a gateway's address changes"`
	// RateLimitingConfig is the configuration for the rate limiting firewall capabilities.
	RateLimiting RateLimitingConfig `name:"rate-limiting"`
}

Config contains configuration settings for the UDP gateway frontend. Use DefaultConfig for recommended settings.

type Firewall

type Firewall interface {
	Filter(packet encoding.Packet) error
}

Firewall filters packets by tracking addresses and time.

func NewMemoryFirewall

func NewMemoryFirewall(ctx context.Context, addrChangeBlock time.Duration) Firewall

NewMemoryFirewall returns an in-memory Firewall.

func NewRateLimitingFirewall

func NewRateLimitingFirewall(firewall Firewall, messages int, threshold time.Duration) Firewall

NewRateLimitingFirewall returns a Firewall with rate limiting capabilities.

type RateLimitingConfig

type RateLimitingConfig struct {
	Enable    bool          `name:"enable" description:"Enable rate limiting for gateways"`
	Messages  int           `name:"messages" description:"Number of past messages to check timestamp for"`
	Threshold time.Duration `` /* 139-byte string literal not displayed */
}

RateLimitingConfig contains configuration settings for the rate limiting capabilities of the UDP gateway frontend firewall.

Jump to

Keyboard shortcuts

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