data

package
v0.0.0-...-a6db137 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

The cache implementation is mostly a verbatim copy of the following: https://www.alexedwards.net/blog/implementing-an-in-memory-cache-in-go

Index

Constants

View Source
const (
	SIPSeparator = "@"

	AREDNDomain    = "local.mesh"
	AREDNLocalNode = "localnode.local.mesh" // AREDN default for local node
)
View Source
const (
	DefaultSIPVersion  = "SIP/2.0"
	DefaultMaxForwards = "30"

	SIPNewline = "\r\n"
)

Variables

This section is empty.

Functions

func GenerateCallID

func GenerateCallID(host string) string

func GenerateFromTag

func GenerateFromTag() string

Types

type ByCallsign

type ByCallsign []*Entry

func (ByCallsign) Len

func (e ByCallsign) Len() int

func (ByCallsign) Less

func (e ByCallsign) Less(i, j int) bool

func (ByCallsign) Swap

func (e ByCallsign) Swap(i, j int)

type ByName

type ByName []*Entry

func (ByName) Len

func (e ByName) Len() int

func (ByName) Less

func (e ByName) Less(i, j int) bool

func (ByName) Swap

func (e ByName) Swap(i, j int)

type Entry

type Entry struct {
	FirstName   string
	LastName    string
	Callsign    string
	PhoneNumber string

	// Metadata
	OLSR *OLSR // if present, the participant seems to be active
}

func NewEntryFromOLSR

func NewEntryFromOLSR(o *OLSR) *Entry

func (*Entry) DirectCallAddress

func (e *Entry) DirectCallAddress() string

func (*Entry) DisplayName

func (e *Entry) DisplayName(pfx string) string

func (*Entry) PhoneFQDN

func (e *Entry) PhoneFQDN() string

type GenericEntry

type GenericEntry struct {
	Name      string   `xml:"Name"`
	Telephone []string `xml:"Telephone"`
}

type GenericPhoneBook

type GenericPhoneBook struct {
	Entry []*GenericEntry `xml:"DirectoryEntry"`
}

type Host

type Host struct {
	Name string `json:"name"`
	IP   string `json:"ip"`
}

type NodeDetails

type NodeDetails struct {
	Model           string `json:"model"`
	MeshGateway     string `json:"mesh_gateway"`
	BoardID         string `json:"board_id"`
	FirmwareMfg     string `json:"firmware_mfg"`
	FirmwareVersion string `json:"firmware_version"`
}

type OLSR

type OLSR struct {
	IP       string
	Hostname string
}

type RecordStats

type RecordStats struct {
	Count   int       `json:"count"`
	Updated time.Time `json:"updated"`
}

type Records

type Records struct {
	Mu      *sync.RWMutex
	Updated time.Time
	Entries []*Entry
}

type Runtime

type Runtime struct {
	Node    string      `json:"node,omitempty"`
	Uptime  string      `json:"uptime,omitempty"`
	Details NodeDetails `json:"details,omitempty"`
	Updated time.Time   `json:"updated"`
}

type RuntimeInfo

type RuntimeInfo struct {
	Mu      *sync.RWMutex
	Updated time.Time

	SysInfo *SysInfo
}

type SIPAddress

type SIPAddress struct {
	DisplayName string
	URI         *SIPURI
	Params      map[string]string
}

func (*SIPAddress) Clone

func (a *SIPAddress) Clone() *SIPAddress

func (*SIPAddress) Parse

func (a *SIPAddress) Parse(line string) error

func (*SIPAddress) String

func (a *SIPAddress) String() string

type SIPClient

type SIPClient struct {
	Address *SIPAddress
	UA      string
}

func NewSIPClientFromRegister

func NewSIPClientFromRegister(req *SIPRequest) *SIPClient

func (*SIPClient) Key

func (c *SIPClient) Key() string

type SIPHeader

type SIPHeader struct {
	Name  string
	Value string

	// Optionally set when header has an address.
	// Note: This is parsed but not used during serialization!
	Address *SIPAddress
}

func (*SIPHeader) Clone

func (h *SIPHeader) Clone() SIPHeader

type SIPMessage

type SIPMessage struct {
	SIPVersion string // Set to 2.0 version by default
	Headers    []*SIPHeader
	Body       []byte
}

func (*SIPMessage) AddHeader

func (m *SIPMessage) AddHeader(name, value string)

func (*SIPMessage) Contact

func (m *SIPMessage) Contact() *SIPAddress

func (*SIPMessage) ContentLength

func (m *SIPMessage) ContentLength(update bool) (int, error)

func (*SIPMessage) FindHeaders

func (m *SIPMessage) FindHeaders(name string) []*SIPHeader

func (*SIPMessage) From

func (m *SIPMessage) From() *SIPAddress

func (*SIPMessage) RemoveHeaders

func (m *SIPMessage) RemoveHeaders(name string)

func (*SIPMessage) To

func (m *SIPMessage) To() *SIPAddress

type SIPRequest

type SIPRequest struct {
	SIPMessage
	Method string
	URI    string
}

func NewSIPRequest

func NewSIPRequest(method string, from, to *SIPAddress, seq int, hdrs []*SIPHeader, body []byte) *SIPRequest

func (*SIPRequest) Parse

func (r *SIPRequest) Parse(data []byte) error

func (*SIPRequest) Serialize

func (r *SIPRequest) Serialize(withBody bool) []byte

func (*SIPRequest) Write

func (r *SIPRequest) Write(w io.Writer, dbg bool) (int, error)

type SIPResponse

type SIPResponse struct {
	SIPMessage
	StatusCode    int
	StatusMessage string
}

func NewSIPResponseFromRequest

func NewSIPResponseFromRequest(req *SIPRequest, statusCode int, statusMsg string) *SIPResponse

func (*SIPResponse) Parse

func (r *SIPResponse) Parse(data []byte) error

func (*SIPResponse) Serialize

func (r *SIPResponse) Serialize(withBody bool) []byte

func (*SIPResponse) Write

func (r *SIPResponse) Write(w io.Writer, dbg bool) (int, error)

type SIPURI

type SIPURI struct {
	User   string // The user part of the URI. The 'joe' in sip:joe@example.com
	Host   string // The host part of the URI. This can be a domain, or a string representation of an IP address.
	Port   int    // The port part of the URI. This is optional, and can be empty.
	Params map[string]string
}

func (*SIPURI) Clone

func (u *SIPURI) Clone() *SIPURI

func (*SIPURI) String

func (u *SIPURI) String() string

type SysInfo

type SysInfo struct {
	APIVersion string `json:"api_version"`

	Node        string       `json:"node"`
	NodeDetails *NodeDetails `json:"node_details"`
	System      *System      `json:"sysinfo"`

	Longitude  string `json:"lon"`
	Latitude   string `json:"lat"`
	Gridsquare string `json:"grid_square"`

	Hosts []*Host `json:"hosts"`
}

type System

type System struct {
	Uptime string `json:"uptime"`
}

type TTLCache

type TTLCache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

TTLCache is a generic cache implementation with support for time-to-live (TTL) expiration.

func NewTTL

func NewTTL[K comparable, V any]() *TTLCache[K, V]

NewTTL creates a new TTLCache instance and starts a goroutine to periodically remove expired items every 5 seconds.

func (*TTLCache[K, V]) Get

func (c *TTLCache[K, V]) Get(key K) (V, bool)

Get retrieves the value associated with the given key from the cache.

func (*TTLCache[K, V]) Keys

func (c *TTLCache[K, V]) Keys() []K

func (*TTLCache[K, V]) Len

func (c *TTLCache[K, V]) Len() int

func (*TTLCache[K, V]) Pop

func (c *TTLCache[K, V]) Pop(key K) (V, bool)

Pop removes and returns the item with the specified key from the cache.

func (*TTLCache[K, V]) Remove

func (c *TTLCache[K, V]) Remove(key K)

Remove removes the item with the specified key from the cache.

func (*TTLCache[K, V]) Set

func (c *TTLCache[K, V]) Set(key K, value V, ttl time.Duration)

Set adds a new item to the cache with the specified key, value, and time-to-live (TTL).

type Update

type Update struct {
	// Type defines what color the message is rendered in. Supported are:
	// - "info": Light background.
	// - "warn": Yellow background.
	// - "danger": Red background.
	// - "success": Green background.
	// - every other value will be rendered with a grey background.
	// For more details, see https://getbootstrap.com/docs/5.3/components/alerts/
	Type string `json:"info_type"`

	Message string `json:"message"`
}

type Updates

type Updates struct {
	Updated time.Time     `json:"-"`
	Mu      *sync.RWMutex `json:"-"`

	Updates []*Update `json:"updates"`
}

type Version

type Version struct {
	Version   string `json:"version"`
	CommitSHA string `json:"commit_sha"`
}

type WebDefault

type WebDefault struct {
	Title   string
	Version *Version `json:"version"`
	Updated string
	Updates []*Update
}

type WebIndex

type WebIndex struct {
	WebDefault

	Registered map[string]string
	Records    map[string]string
	UpdateURLs string
	Sources    string
	Exporters  []string
}

type WebInfo

type WebInfo struct {
	WebDefault
	Registered  map[string]string `json:"registered_phones,omitempty"`
	RecordStats RecordStats       `json:"records_stats,omitempty"`
	Runtime     Runtime           `json:"runtime,omitempty"`
}

type WebMessage

type WebMessage struct {
	WebDefault

	Success bool
	From    string
	To      string
	Message string
}

type WebReload

type WebReload struct {
	WebDefault

	Source  string
	Success bool
}

type WebShowConfig

type WebShowConfig struct {
	WebDefault

	Messages []string
	Content  string
	Diff     bool
	Success  bool
}

type WebUpdateConfig

type WebUpdateConfig struct {
	WebDefault

	Messages []string
	Success  bool
}

Jump to

Keyboard shortcuts

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