diameter

package module
v0.0.0-...-c6cbb2e Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

README

golang Diameter

Creating and using a Dictionary

A dictionary defines AVP code and type information, as well as message types and their corresponding codes. A set of standard dictionaries are available in the dictionaries/ directory.

AvpTypes:
    - Name: "Auth-Application-Id"
      Code: 258
      Type: "Unsigned32"
    - Name: "Auth-Request-Type"
      Code: 274
      Type: "Enumerated"
      Enumeration:
        - Name: "AUTHENTICATE_ONLY"
          Value: 1
        - Name: "AUTHORIZE_ONLY"
          Value: 2
        - Name: "AUTHORIZE_AUTHENTICATE"
          Value: 3
    - Name: "Acct-Session-Id"
      Code: 44
      Type: "OctetString"
    - Name: "Accounting-Sub-Session-Id"
      Code: 287
      Type: "Unsigned64"
    - Name: "Error-Message"
      Code: 281
      Type: "UTF8String"
    - Name: "Error-Reporting-Host"
      Code: 294
      Type: "DiamIdent"
    - Name: "Experimental-Result"
      Code: 297
      Type: "Grouped"
    - Name: "Host-IP-AddressInband-Security"
      Code: 257
      Type: "Address"
    - Name: "Redirect-Host"
      Code: 292
      Type: "DiamURI"
MessageTypes:
    - Basename: "Accouting"
      Abbreviations:
          Request: "ACR"
          Answer: "ACA"
      Code: 271
    - Basename: "Capabilities-Exchange"
      Abbreviations:
          Request: "CER"
          Answer: "CEA"
      Code: 257
    - Basename: "Device-Watchdog"
      Abbreviations:
          Request: "DWR"
          Answer: "DWA"
      Code: 280
    - Basename: "Disconnect-Peer"
      Abbreviations:
          Request: "DPR"
          Answer: "DPA"
      Code: 282
    - Basename: "Provide-Location"
      Abbreviations:
        Request: "PLR"
        Answer: "PLA"
      Code: 8388620
      Application-Id: 16777255

To load and use a dictionary:

    d := diameter.dictionary.FromYamlFile( yaml_dictionary_file_path )
    avp := AVP("Auth-Application-Id", uint32(0))

To use a dictionary:


Base Application Server

    server := NewBaseApplicationServer(BaseCapabilities{OriginHost: "host", OriginRealm: "realm", ...}).
        SetAuthApplicationIDs(uint32[]{1, 2, 3}).
        SetIncomingTransportFilter(transportFilterFunction).
        SetIncomingCapabilitiesExchangeFilter(cerFilterFunction)
    serverEventChan := make(chan *BaseNodeEventMessage)
    server.Start(serverEventChan)

    for {
        switch event := <-serverEventChan; event.Type {
        case IncomingTransportAttemptBlocked:
            // ...

        case IncomingPeerBlockedOnCapbilitiesExchange:
            // ...

        case CapabilitiesExchangeSuccessfullyCompleted:
            // ...

        // ... etc ...
        }
    }

Base Application Client

    client := NewBaseApplicationClient(BaseCapabilities{OriginHost: "host", OriginRealm: "realm", ...}).
        SetAuthApplicationIDs(uint32[]{1, 2, 3}).
        SetIncomingTransportFilter(transportFilterFunction).
        SetIncomingCapabilitiesExchangeFilter(cerFilterFunction)
    clientEventChan := make(chan *BaseNodeEventMessage)
    client.Start(clientEventChan)

    for {
        select {
            case event := <-clientEventChan:
                switch event.Type {
                    // ...
                }

            default:
                if someConditionIsTrue {
                    client.ConnectToServer(...)
                }
        }
    }

Documentation

Index

Constants

View Source
const (
	MsgFlagRequest             = 0x80
	MsgFlagProxiable           = 0x40
	MsgFlagError               = 0x20
	MsgFlagPotentialRetransmit = 0x10
	MsgHeaderSize              = Uint24(20)
)

Possible flag values for a Diameter message

Variables

This section is empty.

Functions

func ConvertAVPDataToTypedData

func ConvertAVPDataToTypedData(avpData []byte, dataType AVPDataType) (interface{}, error)

ConvertAVPDataToTypedData attempts to convert the provided AVP data into a typed value, according to the data type provided.

Types

type AVP

type AVP struct {
	Code               uint32
	VendorSpecific     bool
	Mandatory          bool
	Protected          bool
	VendorID           uint32
	Data               []byte
	Length             int
	PaddedLength       int
	ExtendedAttributes *AVPExtendedAttributes
}

AVP represents a Diameter Message AVP

func DecodeAVP

func DecodeAVP(input []byte) (*AVP, error)

DecodeAVP accepts a byte stream in network byte order and produces an AVP object from it.

func NewAVP

func NewAVP(code uint32, VendorID uint32, mandatory bool, data []byte) *AVP

NewAVP is an AVP constructor

func NewTypedAVP

func NewTypedAVP(code uint32, vendorID uint32, mandatory bool, avpType AVPDataType, value interface{}) *AVP

NewTypedAVP is the same as NewTypedAVPErrorable, except that it raises panic() on an error

func NewTypedAVPErrorable

func NewTypedAVPErrorable(code uint32, vendorID uint32, mandatory bool, avpType AVPDataType, value interface{}) (*AVP, error)

NewTypedAVPErrorable is an AVP constructor provided typed data rather than the raw data. Returns an error if the value is not convertible from the avpType. The ExtendedAttributes will be set, but the Name will be the empty string

func (*AVP) Clone

func (avp *AVP) Clone() *AVP

Clone makes a copy of this AVP and returns it. No effort is made to make the copy thread-safe.

func (*AVP) ConvertDataToTypedData

func (avp *AVP) ConvertDataToTypedData(dataType AVPDataType) (interface{}, error)

ConvertDataToTypedData overrides any internally stored typed data representation for the AVP and attempts to convert the raw data into the named type.

func (*AVP) Encode

func (avp *AVP) Encode() []byte

Encode produces an octet stream in network byte order from this AVP

func (*AVP) Equal

func (avp *AVP) Equal(a *AVP) bool

Equal compares the current AVP to another AVP to determine if they are byte-wise identical (that is, if they would map identically as a byte stream using Encode)

func (*AVP) MakeProtected

func (avp *AVP) MakeProtected() *AVP

MakeProtected sets avp.Protected to true and returns the AVP reference. It is so rare for this flag to be set, this provides a convenient method to set the value inline after AVP creation

type AVPDataType

type AVPDataType int

AVPDataType is an enumeration of Diameter AVP types

const (
	// Unsigned32 indicates AVP type for unsigned 32-bit integer
	Unsigned32 AVPDataType = 1 + iota
	// Unsigned64 indicates AVP type for unsigned 64-bit integer
	Unsigned64
	// Integer32 indicates AVP type for signed 32-bit integer
	Integer32
	// Integer64 indicates AVP type for signed 64-bit integer
	Integer64
	// Float32 indicates AVP type for signed 32-bit floating point
	Float32
	// Float64 indicates AVP type for signed 64-bit floating point
	Float64
	// Enumerated indicates AVP type for enumerated (integer)
	Enumerated
	// UTF8String indicates AVP type for UTF8String (a UTF8 encoded octet stream)
	UTF8String
	// OctetString indicates AVP type for octet string (an arbitrary octet stream)
	OctetString
	// Time indicates AVP type for time (unix epoch time as unsigned 32)
	Time
	// Address indicates AVP type for address (an IPv4 or IPv6 address with leading type qualifier)
	Address
	// DiamIdent indicates AVP type for diameter identity (an octet stream)
	DiamIdent
	// DiamURI indicates AVP type for a diameter URI (an octet stream)
	DiamURI
	// Grouped indicates AVP type for grouped (a set of AVPs)
	Grouped
	// IPFilterRule indicates AVP type for IP Filter Rule
	IPFilterRule
	// TypeOrAvpUnknown is used when a query is made for an unknown AVP or the dictionary
	// contains an unknown type
	TypeOrAvpUnknown
)

type AVPExtendedAttributes

type AVPExtendedAttributes struct {
	Name       string
	DataType   AVPDataType
	TypedValue interface{}
}

AVPExtendedAttributes includes extended AVP attributes that can be provided by, for example, a dictionary. It includes a human-friendly name and a typed value (e.g., a uint32 for AVPs of Unsigned32 type)

type CapabiltiesExchangeInformation

type CapabiltiesExchangeInformation struct {
	OriginHost                 string
	OriginRealm                string
	HostIPAddresses            []*net.IPAddr
	VendorID                   uint32
	ProductName                string
	AdditionalAVPsToSendToPeer []*AVP
}

CapabiltiesExchangeInformation contains information sent to peer nodes during the capabilities exchange, or received from peer nodes during the capabilities exchange

func (*CapabiltiesExchangeInformation) MakeCEA

func (info *CapabiltiesExchangeInformation) MakeCEA() *Message

MakeCEA is shorthand for MakeCeaUsingResultCode(2002).

func (*CapabiltiesExchangeInformation) MakeCEAUsingResultCode

func (info *CapabiltiesExchangeInformation) MakeCEAUsingResultCode(resultCode uint32) *Message

MakeCEAUsingResultCode makes a CEA using the exchange information values, with a Result-Code set to the provided value.

func (*CapabiltiesExchangeInformation) MakeCER

func (info *CapabiltiesExchangeInformation) MakeCER() *Message

MakeCER creates a CER using the exchange information values.

type Dictionary

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

Dictionary is a Diameter dictionary, mapping AVP and message type data to names

func DictionaryFromYamlFile

func DictionaryFromYamlFile(filepath string) (*Dictionary, error)

DictionaryFromYamlFile processes a file that should be a YAML formatted Diameter dictionary

func DictionaryFromYamlString

func DictionaryFromYamlString(yamlString string) (*Dictionary, error)

DictionaryFromYamlString reads a string containing a Diameter dictionary in YAML format

func (*Dictionary) AVP

func (dictionary *Dictionary) AVP(name string, value interface{}) *AVP

AVP is the same as AVPErrorable, except that, if an error occurs, panic() is invoked with the error string

func (*Dictionary) AVPErrorable

func (dictionary *Dictionary) AVPErrorable(name string, value interface{}) (*AVP, error)

AVPErrorable returns an AVP based on the dictionary definition. If the name is not in the dictionary, or the value type is incorrect based on the dictionary definition, return an error. This is Errorable because it may throw an error. It is assumed that this will be the uncommon case, because ordinarily, the value will be known in advance by the application creating it.

func (*Dictionary) DataTypeForAVPNamed

func (dictionary *Dictionary) DataTypeForAVPNamed(name string) (AVPDataType, error)

DataTypeForAVPNamed looks up the data type for the specific AVP

func (*Dictionary) Message

func (dictionary *Dictionary) Message(name string, flags MessageFlags, mandatoryAVPs []*AVP, additionalAVPs []*AVP) *Message

Message is the same as MessageErrorable, except that, if an error occurs, panic() is invoked with the error string

func (*Dictionary) MessageErrorable

func (dictionary *Dictionary) MessageErrorable(name string, flags MessageFlags, mandatoryAVPs []*AVP, additionalAVPs []*AVP) (*Message, error)

MessageErrorable returns a Message based on the dictionary definition. If the name is not present in the dictionary, an error is returned. The AVP set will be re-arranged to match the AVP order presented in the dictionary for the message type, and the mandatory flag will be changed to match the definition for the message type. An error, however, is not raised if a mandatory flag is not present.

type DictionaryYaml

type DictionaryYaml struct {
	AvpTypes     []DictionaryYamlAvpType     `yaml:"AvpTypes"`
	MessageTypes []DictionaryYamlMessageType `yaml:"MessageTypes"`
}

DictionaryYaml represents a YAML dictionary containing Diameter message type and AVP definitions

type DictionaryYamlAvpEnumerationType

type DictionaryYamlAvpEnumerationType struct {
	Name  string `yaml:"Name"`
	Value uint32 `yaml:"Value"`
}

DictionaryYamlAvpEnumerationType is the type for Avp Enumerations

type DictionaryYamlAvpType

type DictionaryYamlAvpType struct {
	Name        string                             `yaml:"Name"`
	Code        uint32                             `yaml:"Code"`
	Type        string                             `yaml:"Type"`
	VendorID    uint32                             `yaml:"Vendor-Id"`
	Enumeration []DictionaryYamlAvpEnumerationType `yaml:"Enumeration"`
}

DictionaryYamlAvpType is the type for AvpTypes in a Diameter YAML Dictionary

type DictionaryYamlMessageAbbreviation

type DictionaryYamlMessageAbbreviation struct {
	Request string `yaml:"Request"`
	Answer  string `yaml:"Answer"`
}

DictionaryYamlMessageAbbreviation is the type for MessageTypes.Abbreviations in a Diameter YAML Dictionary

type DictionaryYamlMessageType

type DictionaryYamlMessageType struct {
	Basename      string                            `yaml:"Basename"`
	Code          uint32                            `yaml:"Code"`
	ApplicationID uint32                            `yaml:"Application-Id"`
	Abbreviations DictionaryYamlMessageAbbreviation `yaml:"Abbreviations"`
}

DictionaryYamlMessageType is the type for MessageTypes in a Diameter YAML Dictionary

type DictionaryYamlMetadataSpecificationType

type DictionaryYamlMetadataSpecificationType struct {
	Type       string `yaml:"Type"`
	Identifier string `yaml:"Identifier"`
	URL        string `yaml:"URL"`
}

DictionaryYamlMetadataSpecificationType is the type for a dictionary yaml field Metadata section

type DictionaryYamlMetadataType

type DictionaryYamlMetadataType struct {
	Name           string                                    `yaml:"Name"`
	Specifications []DictionaryYamlMetadataSpecificationType `yaml:"Specifications"`
}

DictionaryYamlMetadataType is the type for a dictionary yaml Metadata section Specification subsection

type IncomingPeerListener

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

func NewIncomingPeerListener

func NewIncomingPeerListener(usingUnderlyingListener net.Listener, usingCapabilitiesInformation CapabiltiesExchangeInformation) *IncomingPeerListener

func (*IncomingPeerListener) StartListening

func (peerListener *IncomingPeerListener) StartListening(eventChannel chan<- *NodeEvent)

func (*IncomingPeerListener) StopListening

func (peerListener *IncomingPeerListener) StopListening() error

type Message

type Message struct {
	Version    uint8
	Length     Uint24
	Flags      uint8
	Code       Uint24
	AppID      uint32
	HopByHopID uint32
	EndToEndID uint32
	Avps       []*AVP
}

Message represents a single Diameter message

func DecodeMessage

func DecodeMessage(input []byte) (*Message, error)

DecodeMessage accepts an octet stream and attempts to interpret it as a Diameter message. The stream must contain at least a single Diameter message. To decode incoming streams, use a MessageStreamReader. If the input stream is at least one Diameter message, or an error occurs in the reading of the stream or creation of the message, return nil and an error; otherwise return a Message object and nil for the error.

func NewMessage

func NewMessage(flags uint8, code Uint24, appID uint32, hopByHopID uint32, endToEndID uint32, mandatoryAvps []*AVP, additionalAvps []*AVP) (m *Message)

NewMessage creates a new diameter.Message instance. 'mandatoryAvps' will all have their Mandatory flag set to true. The Mandatory flag for 'additionalAvps' will be left untouched.

func (*Message) BecomeAnAnswerBasedOnTheRequestMessage

func (m *Message) BecomeAnAnswerBasedOnTheRequestMessage(request *Message) *Message

BecomeAnAnswerBasedOnTheRequestMessage extracts the end-to-end-id and hop-by-hop-id from the request message and applies them to this message. It also clears the request flag if it is set and sets this message's code to the request message's code. Return this message, so that this call may be chained, if desired.

func (*Message) Clone

func (m *Message) Clone() *Message

Clone makes a copy of the current message. No effort is made to be thread-safe against changes to the message being cloned. All AVPs in this message are also cloned.

func (*Message) Encode

func (m *Message) Encode() []byte

Encode transforms the current message into an octet stream appropriate for network transmission

func (*Message) Equals

func (m *Message) Equals(c *Message) bool

Equals compares the current Message object to a different message object. If they have equivalent values for all fields and AVPs, return true; otherwise return false. AVPs are compared exactly in order.

func (*Message) FindFirstAVPByCode

func (m *Message) FindFirstAVPByCode(code Uint24) *AVP

FindFirstAVPByCode returns the first instance of the identified AVP associated with the current Message, or nil if the Message has no instances of the AVP

func (*Message) IsError

func (m *Message) IsError() bool

IsError returns true if the message is a Diameter erro9r message (that is, the error flag in the Diameter message header is set)

func (*Message) IsPotentiallyRetransmitted

func (m *Message) IsPotentiallyRetransmitted() bool

IsPotentiallyRetransmitted returns true if the potentially retransmit flag in the Diameter message header is set

func (*Message) IsProxiable

func (m *Message) IsProxiable() bool

IsProxiable returns true if the proxiable flag in the Diameter message header is set

func (*Message) IsRequest

func (m *Message) IsRequest() bool

IsRequest returns true if the message is a Diameter Request message (that is, the request flag in the Diameter message header is set)

type MessageByteReader

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

MessageByteReader simplifies the reading of an octet stream which must be converted to one or more diameter.Message objects. Generally, a new MessageByteReader is created, then ReceiveBytes() is repeatedly called on an input stream (which must be in network byte order) as bytes arrive. This method will return diameter.Message objects as they can be extracted, and store any bytes that are left over after message conversion

func NewMessageByteReader

func NewMessageByteReader() *MessageByteReader

NewMessageByteReader creates a new MessageStreamReader object

func (*MessageByteReader) ReceiveBytes

func (reader *MessageByteReader) ReceiveBytes(incoming []byte) ([]*Message, error)

ReceiveBytes returns one or more diameter.Message objects read from the incoming byte stream. Return nil if no Message is yet found. Return error on malformed byte stream. If an error is returned, subsequent calls are no longer reliable.

func (*MessageByteReader) ReceiveBytesButReturnAtMostOneMessage

func (reader *MessageByteReader) ReceiveBytesButReturnAtMostOneMessage(incoming []byte) (*Message, error)

ReceiveBytesButReturnAtMostOneMessage is the same as ReceiveBytes(), but it will return no more than one message. If more than one message is available in the internal buffer plus the incoming bytes, all messages after the first are saved in the internal buffer, which means they'll be returned on the next call to ReceiveBytes().

type MessageFlags

type MessageFlags struct {
	Proxiable           bool
	Error               bool
	PotentialRetransmit bool
}

MessageFlags provides the Diameter Message flag types

type MessageStreamReader

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

MessageStreamReader is the same as MessageByteReader, but instead of being passed bytes repeatedly, it is supplied an io.Reader, and reads from that, blocking until messages are found on each call to ReadNextMessage().

func NewMessageStreamReader

func NewMessageStreamReader(usingReader io.Reader) *MessageStreamReader

NewMessageStreamReader creates an empty reader which will use the provided io.Reader for each call to ReadNextMessage().

func (*MessageStreamReader) ReadNextMessage

func (reader *MessageStreamReader) ReadNextMessage() (*Message, error)

ReadNextMessage will repeatedly perform a Read() on the underlying Reader until a message is found. It will then queue any additional bytes after the returned message. If that internal byte buffer contains a complete message, a subsequent call will return that message and buffer again any left over bytes. This will continue until the internal buffer no longer contains a complete message, at which point, another Read() will occur. The returned error may be io.EOF. In this case, the returned message will still be nil.

func (*MessageStreamReader) ReadOnce

func (reader *MessageStreamReader) ReadOnce() (*Message, error)

ReadOnce does the same as ReadNextMessage(), but it will perform no more than a single Read() on the underlying Reader. If the Read() (plus any internal buffer) does not yield a complete message, this will return. In that case, the returned Message and error will both be nil.

type Node

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

Node is an entity that implements the Diameter base protocol state machine for Peer node flows. It can both listen for incoming flows and initiate outbound flows.

func NewNode

func NewNode(defaultCapabilitiesExchangeAssertion CapabiltiesExchangeInformation) *Node

NewNode creates a new Diameter node. The provided default capabilities exchange assertion will be used in any capabilities exchange request if it is not overridden when the request for the outbound connection to a peer is made.

func (*Node) AddListener

func (node *Node) AddListener(listener *NodeListener) *Node

AddListener adds a listener and the capabilities exchange assertion that should be used when a new incoming flow is initiated to the listener and a CER is received on that flow. Returns the node on which the operation is being applied so that it can be chained with other calls, if desired.

func (*Node) AddListeners

func (node *Node) AddListeners(listeners []*NodeListener) *Node

AddListeners is the same as AddListener() but adds multiple listeners at the same time.

func (*Node) AutomaticallyDisconnectAnyPeerThatSendsDisconnectRequest

func (node *Node) AutomaticallyDisconnectAnyPeerThatSendsDisconnectRequest() *Node

AutomaticallyDisconnectAnyPeerThatSendsDisconnectRequest signals that when a DPR is received on a previously accepted flow for any peer, a DPA should be automatically sent. Normally, this is done manually when the PeerSentDisconnectRequest is received.

func (*Node) AutomaticallyDisconnectPeerWhenPeerSendsDisconnectRequest

func (node *Node) AutomaticallyDisconnectPeerWhenPeerSendsDisconnectRequest(peer *Peer) error

AutomaticallyDisconnectPeerWhenPeerSendsDisconnectRequest signals that when a DPR is received on a previously accepted flow for the identified peer, a DPA should be automatically sent. Normally, this is done manually when the PeerSentDisconnectRequest is received.

func (*Node) ChangeDefaultOutboundCapabilitiesInformationTo

func (node *Node) ChangeDefaultOutboundCapabilitiesInformationTo(defaultInformation CapabiltiesExchangeInformation) *Node

ChangeDefaultOutboundCapabilitiesInformationTo changes the default information asserted in the capabilities exchange request sent by this node when it initiates an outbound flow.

func (*Node) ConnectToPeer

func (node *Node) ConnectToPeer(usingConnection net.Conn) (*Peer, error)

ConnectToPeer synchronously attempts to complete a capabilities exchange over the provided connection. Returns a Peer object on success, or an error on failure.

func (*Node) ConnectToPeerAsynchronously

func (node *Node) ConnectToPeerAsynchronously(usingConnection net.Conn)

ConnectToPeerAsynchronously is the same as ConnectToPeer(), but does so asynchronously. It launches a goroutine then immediately returns. The attempt will generate generate events.

func (*Node) ConnectToPeerUsingCapabilities

func (node *Node) ConnectToPeerUsingCapabilities(usingConnection net.Conn, information CapabiltiesExchangeInformation) (*Peer, error)

ConnectToPeerUsingCapabilities is the same as ConnectToPeer(), but instead of using the default outgoing capabilities assertion, it uses the provided information.

func (*Node) ConnectToPeerUsingCapabilitiesAsynchronously

func (node *Node) ConnectToPeerUsingCapabilitiesAsynchronously(usingConnection net.Conn, information CapabiltiesExchangeInformation)

ConnectToPeerUsingCapabilitiesAsynchronously is the same as ConnectToPeerAsynchronously(), but rather than using the default outgoing capabilities assertion, it uses the provided information.

func (*Node) DisconnectAllPeerFlowsAsynchronously

func (node *Node) DisconnectAllPeerFlowsAsynchronously()

DisconnectAllPeerFlowsAsynchronously does the same as DisconnectFromAllPeerFlows(), but does so asynchronously. It launches a goroutine then immediately returns. The attempt will generate events.

func (*Node) DisconnectAllPeerFlowsWithCustomInformation

func (node *Node) DisconnectAllPeerFlowsWithCustomInformation(disconnectCauseValue uint32, additionalAVPs []*AVP) []PeerSpecificError

DisconnectAllPeerFlowsWithCustomInformation does the same as DisconnectFromAllPeerFlows(), but sends the provided Disconnect-Cause value (the caller is responsible for ensuring that the value is valid for the Disconnect-Cause enumeration) and any desired additional AVPs in the DPR.

func (*Node) DisconnectAllPeerFlowsWithCustomInformationAsynchronously

func (node *Node) DisconnectAllPeerFlowsWithCustomInformationAsynchronously(disconnectCauseValue uint32, additionalAVPs []*AVP)

DisconnectAllPeerFlowsWithCustomInformationAsynchronously does the same as DisconnectFromAllPeerFlowsWithCustomInformation but does so asynchronously. It launches a goroutine then immediately returns. The attempt will generate events.

func (*Node) DisconnectFromAllPeerFlows

func (node *Node) DisconnectFromAllPeerFlows() []PeerSpecificError

DisconnectFromAllPeerFlows attempts to disconnect all peer flows by sending a DPR to each. It will send DO_NOT_WANT_TO_TALK_TO_YOU as the Disconnect-Reason. It also attempts to close the underlying connection. If an error occurs for a flow, it still attempts to continue. Returns the accumulated set of errors, as well as Peer connected to flow on which the error occurred. Returns nil if no error occurred.

func (*Node) DisconnectFromPeer

func (node *Node) DisconnectFromPeer(peer *Peer) error

DisconnectFromPeer sends a DPR toward the named Peer. There are two cases where this is valid: 1. to initiate a disconnect (i.e., signaling that the node should send a DPR); and 2. after a DPR is received by a Peer (and thus, this would be called after receiving the event PeerSentDisconnectRequest). If this is for case 1 (node sends DPR), then the node will set the Disconnect-Cause to DO_NOT_WANT_TO_TALK_TO_YOU. If this is case 1 (nodes sends DPR), then on the receipt of a DPA, the node will attempt to close the underlying connection. If this is for case 2 (responding to DPR with a DPA), the ndoe will send the DPA then attempt to close the underlying connection.

func (*Node) DisconnectFromPeerAsynchronously

func (node *Node) DisconnectFromPeerAsynchronously(peer *Peer)

DisconnectFromPeerAsynchronously does the same as DisconnectFromPeer(), but does so asynchronously. It launches a goroutine then immediately returns. The attempt will generate events.

func (*Node) DisconnectFromPeerWithCustomInformation

func (node *Node) DisconnectFromPeerWithCustomInformation(peer *Peer, disconnectCauseValue uint32, additionalAVPs []*AVP) error

DisconnectFromPeerWithCustomInformation is the same as DisconnectFromPeer() but it sends for the Disconnect-Cause the provided value (it is up to the caller to ensure that it is a valid value for the Disconnect-Cause enumeration type), and sends any provided additional AVPs.

func (*Node) DisconnectFromPeerWithCustomInformationAsynchronously

func (node *Node) DisconnectFromPeerWithCustomInformationAsynchronously(peer *Peer, disconnectCauseValue uint32, additionalAVPs []*AVP)

DisconnectFromPeerWithCustomInformationAsynchronously does the same as DisconnectFromPeerWithCustomInformation(), but does so asynchronously. It launches a goroutine then immediately returns. The attempt will generate events.

func (*Node) FilterOutStateMessages

func (node *Node) FilterOutStateMessages() *Node

FilterOutStateMessages signals that Capabilities-Exchange, Diameter-Watchdog and Disconnect-Peer messages should not be included in the event stream. This is the default behavior.

func (*Node) Start

func (node *Node) Start() chan<- *NodeEvent

Start starts the node. It returns a channel of events that are produced by this node.

func (*Node) StopAllListeners

func (node *Node) StopAllListeners() error

StopAllListeners stops all listener from listening. It does not close any flows initiated through the listeners. This is a synchronous action.

func (*Node) StopListener

func (node *Node) StopListener(listener *NodeListener) error

StopListener stops a listener from listening. It does not close any flows initiated through the listener. This is a synchronous action.

func (*Node) UnfilterStateMessages

func (node *Node) UnfilterStateMessages() *Node

UnfilterStateMessages signals that Capabilities-Exchange, Diameter-Watchdog and Disconnect-Peer messages that are received should be included in the event stream. By default, messages of this type are supressed.

type NodeEvent

type NodeEvent struct {
	Type       NodeEventType
	Peer       *Peer
	Connection net.Conn
	Message    *Message
	Error      error
}

NodeEvent is an event related to the node's operation.

type NodeEventType

type NodeEventType int

NodeEventType describes the types of events that are raised in relationship to a node's operation.

const (
	FatalTransportError                        NodeEventType = -1
	RecoverableTransportError                  NodeEventType = -2
	MessageDeliveryError                       NodeEventType = -3
	CapabilitiesExchangeFailed                 NodeEventType = -4
	WatchdogTimeoutExceeded                    NodeEventType = -5
	IncomingTransportAttemptBlocked            NodeEventType = -6
	IncomingPeerBlockedOnCapbilitiesExchange   NodeEventType = -7
	TimedOutConnectingToPeer                   NodeEventType = -8
	ListenerFailed                             NodeEventType = -9
	DuplicationPeerFlowRejected                NodeEventType = -10
	UnableToParseIncomingMessageStream         NodeEventType = -11
	InternalFailure                            NodeEventType = -12
	CapabilitiesExchangeSuccessfullyCompleted  NodeEventType = 1
	CapabilitiesRequestReceivedFromPeer        NodeEventType = 2
	ReceivedDiameterMessageFromPeer            NodeEventType = 3
	SuccessfullyDeliveredDiameterMessageToPeer NodeEventType = 4
	PeerSentDisconnectRequest                  NodeEventType = 5
	PeerFullyDisconnected                      NodeEventType = 6
	ReceivedCapabilitiesExchangeRequest        NodeEventType = 7
	ReceivedWatchdogRequest                    NodeEventType = 8
	WatchdogSuccessful                         NodeEventType = 9
	TransportClosed                            NodeEventType = 10
)

type NodeListener

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

NodeListener contains information describing a listener for incoming peer flows

func NewNodeListener

func NewNodeListener(listener net.Listener, informationAssertedInCapabilitiesAnswer *CapabiltiesExchangeInformation) *NodeListener

NewNodeListener creates attaches a listener to the node, and provides information that should be asserted to any incoming peer when the peer initiates a flow against the listener.

type Peer

type Peer struct {
	TypeOfPeer                  PeerType
	PeerCapabilitiesInformation *CapabiltiesExchangeInformation
	ConnectionInformation       PeerConnectionInformation
}

type PeerConnectionInformation

type PeerConnectionInformation struct {
	RemoteAddress     *net.IP
	RemotePort        uint16
	TransportProtocol string
	LocalAddress      *net.IP
	LocalPort         uint16
}

type PeerFlowInformation

type PeerFlowInformation struct {
	PeerAddress       *net.IPAddr
	PeerPort          uint16
	MyAddress         *net.IPAddr
	MyPort            uint16
	TransportProtocol string // "tcp" or "sctp"
}

PeerFlowInformation contains information for an active connection flow with a peer node.

type PeerHandler

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

func NewHandlerForInitiatorPeer

func NewHandlerForInitiatorPeer(flowConnection net.Conn, eventChannel chan<- *NodeEvent) *PeerHandler

func NewHandlerForResponderPeer

func NewHandlerForResponderPeer(flowConnection net.Conn, eventChannel chan<- *NodeEvent) *PeerHandler

func (*PeerHandler) CloseDiameterFlow

func (handler *PeerHandler) CloseDiameterFlow() error

func (*PeerHandler) SeedIdentifiers

func (handler *PeerHandler) SeedIdentifiers() (*PeerHandler, error)

func (*PeerHandler) SendMessageToPeer

func (handler *PeerHandler) SendMessageToPeer(message *Message) error

func (*PeerHandler) StartHandling

func (handler *PeerHandler) StartHandling()

func (*PeerHandler) Terminate

func (handler *PeerHandler) Terminate() error

func (*PeerHandler) WithCapabilities

func (handler *PeerHandler) WithCapabilities(capabilities *CapabiltiesExchangeInformation) *PeerHandler

func (*PeerHandler) WithSeededIdentifiers

func (handler *PeerHandler) WithSeededIdentifiers() (*PeerHandler, error)

type PeerSpecificError

type PeerSpecificError struct {
	Peer  *Peer
	Error error
}

PeerSpecificError connects an error to a specific peer.

type PeerType

type PeerType int
const (
	Initator  PeerType = iota
	Responder PeerType = iota
)

type Uint24

type Uint24 uint32

Uint24 is a documentation reference type. There is no enforcement of boundaries; it is simply a visual reminder of the type

Jump to

Keyboard shortcuts

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