sm

package
v3.0.2+incompatible Latest Latest
Warning

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

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

Documentation

Overview

Package sm provides diameter state machines for clients and servers.

It currently handles CER/CEA handshakes, and automatic DWR/DWA. Peers that pass the handshake get metadata associated to their connection. See the peer sub-package for details on the metadata.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingStateMachine is returned by Dial or DialTLS when
	// the Client does not have a valid StateMachine set.
	ErrMissingStateMachine = errors.New("client state machine is nil")

	// ErrHandshakeTimeout is returned by Dial or DialTLS when the
	// client does not receive a handshake answer from the server.
	//
	// If the client is configured to retransmit messages, the
	// handshake timeout only occurs after all retransmits are
	// attempted and none has an aswer.
	ErrHandshakeTimeout = errors.New("handshake timeout (no response)")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Dict                        *dict.Parser  // Dictionary parser (uses dict.Default if unset)
	Handler                     *StateMachine // Message handler
	MaxRetransmits              uint          // Max number of retransmissions before aborting
	RetransmitInterval          time.Duration // Interval between retransmissions (default 1s)
	EnableWatchdog              bool          // Enable automatic DWR
	WatchdogInterval            time.Duration // Interval between DWRs (default 5s)
	SupportedVendorID           []*diam.AVP   // Supported vendor ID
	AcctApplicationID           []*diam.AVP   // Acct applications
	AuthApplicationID           []*diam.AVP   // Auth applications
	VendorSpecificApplicationID []*diam.AVP   // Vendor specific applications
}

A Client is a diameter client that automatically performs a handshake with the server after the connection is established.

It sends a Capabilities-Exchange-Request with the AVPs defined in it, and expects a Capabilities-Exchange-Answer with a success (2001) result code. If enabled, the client will send Device-Watchdog-Request messages in background until the connection is terminated.

By default, retransmission and watchdog are disabled. Retransmission is enabled by setting MaxRetransmits to a number greater than zero, and watchdog is enabled by setting EnableWatchdog to true.

A custom message handler for Device-Watchdog-Answer (DWA) can be registered. However, that will be overwritten if watchdog is enabled.

func (*Client) Dial

func (cli *Client) Dial(addr string) (diam.Conn, error)

Dial calls the address set as ip:port, performs a handshake and optionally start a watchdog goroutine in background.

func (*Client) DialNetwork

func (cli *Client) DialNetwork(network, addr string) (diam.Conn, error)

DialNetwork calls the network address set as ip:port, performs a handshake and optionally start a watchdog goroutine in background.

func (*Client) DialNetworkTLS

func (cli *Client) DialNetworkTLS(network, addr, certFile, keyFile string) (diam.Conn, error)

DialNetworkTLS calls the network address set as ip:port, performs a handshake and optionally start a watchdog goroutine in background.

func (*Client) DialTLS

func (cli *Client) DialTLS(addr, certFile, keyFile string) (diam.Conn, error)

DialTLS is like Dial, but using TLS.

func (*Client) DialTLSTimeout

func (cli *Client) DialTLSTimeout(addr, certFile, keyFile string, timeout time.Duration) (diam.Conn, error)

DialTLSTimeout is like DialTimeout, but using TLS.

func (*Client) DialTimeout

func (cli *Client) DialTimeout(addr string, timeout time.Duration) (diam.Conn, error)

DialTimeout is like Dial, but with timeout

func (*Client) NewConn

func (cli *Client) NewConn(rw net.Conn, addr string) (diam.Conn, error)

NewConn is like Dial, but using an already open net.Conn.

type HandshakeNotifier

type HandshakeNotifier interface {
	// HandshakeNotify returns a channel that receives
	// a peer's diam.Conn after it passes the handshake.
	HandshakeNotify() <-chan diam.Conn
}

The HandshakeNotifier interface is implemented by Handlers that allow detecting peers that have passed the CER/CEA handshake.

type Settings

type Settings struct {
	OriginHost  datatype.DiameterIdentity
	OriginRealm datatype.DiameterIdentity
	VendorID    datatype.Unsigned32
	ProductName datatype.UTF8String

	// OriginStateID is optional for clients, and not added if unset.
	//
	// On servers it has no effect because CEA will contain the
	// same value from CER, if present.
	//
	// May be set to datatype.Unsigned32(time.Now().Unix()).
	OriginStateID datatype.Unsigned32

	// FirmwareRevision is optional, and not added if unset.
	FirmwareRevision datatype.Unsigned32

	// HostIPAddress is optional for both clients and servers, when not set local
	// host IP address is used.
	//
	// This property may be set when the IP address of the host sending/receiving
	// the request is different from the configured allowed IPs in the other end,
	// for example when using a VPN or a gateway.
	HostIPAddresses []datatype.Address
}

Settings used to configure the state machine with AVPs to be added to CER on clients or CEA on servers.

type StateMachine

type StateMachine struct {
	// contains filtered or unexported fields
}

StateMachine is a specialized type of diam.ServeMux that handles the CER/CEA handshake and DWR/DWA messages for clients or servers.

Other handlers registered in the state machine are only executed after the peer has passed the initial CER/CEA handshake.

func New

func New(settings *Settings) *StateMachine

New creates and initializes a new StateMachine for clients or servers.

func (*StateMachine) Error

func (sm *StateMachine) Error(err *diam.ErrorReport)

Error implements the diam.ErrorReporter interface.

func (*StateMachine) ErrorReports

func (sm *StateMachine) ErrorReports() <-chan *diam.ErrorReport

ErrorReports implement the diam.ErrorReporter interface.

func (*StateMachine) Handle

func (sm *StateMachine) Handle(cmd string, handler diam.Handler)

Handle implements the diam.Handler interface.

func (*StateMachine) HandleFunc

func (sm *StateMachine) HandleFunc(cmd string, handler diam.HandlerFunc)

HandleFunc implements the diam.Handler interface.

func (*StateMachine) HandleIdx

func (sm *StateMachine) HandleIdx(cmd diam.CommandIndex, handler diam.Handler)

func (*StateMachine) HandshakeNotify

func (sm *StateMachine) HandshakeNotify() <-chan diam.Conn

HandshakeNotify implements the HandshakeNotifier interface.

func (*StateMachine) ServeDIAM

func (sm *StateMachine) ServeDIAM(c diam.Conn, m *diam.Message)

ServeDIAM implements the diam.Handler interface.

func (*StateMachine) Settings

func (sm *StateMachine) Settings() *Settings

Settings return the Settings object used by this StateMachine.

type SupportedApp

type SupportedApp struct {
	ID      uint32
	AppType string
	Vendor  uint32
}

SupportedApp holds properties of each locally supported App

func PrepareSupportedApps

func PrepareSupportedApps(d *dict.Parser) []*SupportedApp

PrepareSupportedApps prepares a list of locally supported apps

Directories

Path Synopsis
Package smparser provides message parsers for the state machine.
Package smparser provides message parsers for the state machine.
Package smpeer provides functions for extracting information from a CER or CEA, and associating with a Context.
Package smpeer provides functions for extracting information from a CER or CEA, and associating with a Context.

Jump to

Keyboard shortcuts

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