udp

package
v0.0.0-...-60b8695 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: Apache-2.0 Imports: 19 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,
	ConnectionErrorExpires: 5 * time.Minute,
	ScheduleLateTime:       800 * time.Millisecond,
	AddrChangeBlock:        0,
	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 acknowledgment 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
	// acknowledgment is received.
	ConnectionExpires time.Duration `name:"connection-expires" description:"Time after which a connection of a gateway expires"`
	// ConnectionErrorExpires defines for how long an existing connection is cached by the Gateway Server when there is a connection error
	// before initiating a new connection. This ensures that packet handlers are not being stalled by gateways which cannot connect but
	// still attempt to do so.
	ConnectionErrorExpires time.Duration `name:"connection-error-expires" description:"Time after which a connection error 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