Documentation
¶
Overview ¶
Diameter Base Protocol for the Go programming language. See RFC 6733.
Index ¶
- Variables
- func ErrorReports() chan ErrorReport
- func Handle(cmd string, handler Handler)
- func HandleFunc(cmd string, handler func(Conn, *Message))
- func ListenAndServe(addr string, handler Handler, dict *dict.Parser) error
- func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Handler, ...) error
- func Serve(l net.Listener, handler Handler) error
- type AVP
- type CloseNotifier
- type Codec
- type Conn
- type ErrorReport
- type Grouped
- func (gr *Grouped) Add(avp *AVP)
- func (gr *Grouped) Bytes() []byte
- func (gr *Grouped) Data() avpdata.Generic
- func (gr *Grouped) Length() uint32
- func (gr *Grouped) NewAVP(code interface{}, flags uint8, vendor uint32, data avpdata.Generic) (*AVP, error)
- func (gr *Grouped) Put(d []byte)
- func (gr *Grouped) String() string
- type Handler
- type HandlerFunc
- type Header
- type Message
- func (m *Message) Add(avp *AVP)
- func (m *Message) Answer(resultCode uint32) *Message
- func (m *Message) FindAVP(code interface{}) (*AVP, error)
- func (m *Message) NewAVP(code interface{}, flags uint8, vendor uint32, data avpdata.Generic) (*AVP, error)
- func (m *Message) Pack() []byte
- func (m *Message) PrettyPrint()
- func (m *Message) String() string
- type ServeMux
- type Server
Constants ¶
This section is empty.
Variables ¶
var DefaultServeMux = NewServeMux()
DefaultServeMux is the default ServeMux used by Serve.
var ErrHandlerTimeout = errors.New("diam: Handler timeout")
ErrHandlerTimeout is returned on MessageWriter Write calls in handlers which have timed out.
var ErrInvalidAvpHdr = errors.New("Invalid AVP header size: probably a bad dict")
var ErrNoParentMessage = errors.New("This AVP has no parent message")
Functions ¶
func ErrorReports ¶
func ErrorReports() chan ErrorReport
ErrorReport returns the ErrorReport channel of the DefaultServeMux.
func HandleFunc ¶
HandleFunc registers the handler function for the given command in the DefaultServeMux.
func ListenAndServe ¶
ListenAndServe listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections.
If handler is nil, diam.DefaultServeMux is used.
If dict is nil, dict.Default is used.
func ListenAndServeTLS ¶
func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Handler, dict *dict.Parser) error
ListenAndServeTLS acts identically to ListenAndServe, except that it expects SSL connections. Additionally, files containing a certificate and matching private key for the server must be provided. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate followed by the CA's certificate.
One can use generate_cert.go in crypto/tls to generate cert.pem and key.pem.
Types ¶
type AVP ¶
type AVP struct { Code uint32 Flags uint8 Length uint32 VendorId uint32 // contains filtered or unexported fields }
AVP represents an AVP header and data.
func ReadAVP ¶
ReadAVP reads an AVP from the connection and returns the total number of padding bytes read and the parsed AVP, or an error.
Total AVP bytes is avp.Length + padding.
For details on AVP length and padding see http://tools.ietf.org/html/rfc6733#section-4
A pointer to the parent Message is required, otherwise it panics.
func (*AVP) Pack ¶
Pack returns an AVP in binary form so it can be attached to a Message before sent to a connection.
func (*AVP) String ¶
String returns the AVP in human readable format.
The AVP name is "guessed" by scanning the list of available AVPs in the dictionary that was used to build this AVP. It might return the wrong AVP name if the same code is used by different dictionaries in different applications, with a different name - yet, very unlikely.
type CloseNotifier ¶
type CloseNotifier interface { // CloseNotify returns a channel that receives a single value // when the client connection has gone away. CloseNotify() <-chan bool }
The CloseNotifier interface is implemented by Conns which allow detecting when the underlying connection has gone away.
This mechanism can be used to detect if the client has disconnected.
type Codec ¶
type Codec interface { // Decode binary data from the network and store as internal AVP data. Put([]byte) // Encode internal AVP data to binary and return it. Bytes() []byte // Returns internal AVP data. Data() avpdata.Generic // Length of the internal data without padding. // Might be diffent from len(Bytes()). Length() uint32 // String returns the internal AVP data in human readable format. String() string }
Codec provides an interface for converting data from network bytes to Go native and vice-versa.
This interface is used to encode and decode AVP data such as OctetString, and is implemented by all data types in the avpdata sub package.
type Conn ¶
type Conn interface { Write(*Message) (int, error) // Writes a msg to the connection Close() // Close the connection LocalAddr() net.Addr // Local IP RemoteAddr() net.Addr // Remote IP TLS() *tls.ConnectionState // or nil when not using TLS }
A Conn interface is used by a handler to send diameter messages.
type ErrorReport ¶
ErrorReport is sent out of the server in case it fails to read messages because of a bad dictionary or network errors.
type Grouped ¶
type Grouped struct { Message *Message // Parent Message of this group. AVP []*AVP // Group AVPs Buffer []byte // len(Buffer) might be bigger than length below due to padding. // contains filtered or unexported fields }
Grouped Diameter Type
func (*Grouped) Bytes ¶
Bytes implement the Codec interface. Bytes are always returned from internal Buffer cache.
func (*Grouped) NewAVP ¶
func (gr *Grouped) NewAVP(code interface{}, flags uint8, vendor uint32, data avpdata.Generic) (*AVP, error)
NewAVP allocates an AVP and appends to the group. @code can be either the AVP code (int, uint32) or name (string).
type Handler ¶
type Handler interface { ServeDiam(Conn, *Message) ErrorReports() chan ErrorReport }
Objects implementing the Handler interface can be registered to serve particular messages like CER, DWR.
ServeDiam should write messages to the Conn and then return. Returning signals that the request is finished and that the server can move on to the next request on the connection.
func TimeoutHandler ¶
TimeoutHandler returns a Handler that runs h with the given time limit.
The new Handler calls h.ServeDiam to handle each request, but if a call runs for longer than its time limit, the connection is closed. After such a timeout its MessageWriter will return ErrHandlerTimeout.
type HandlerFunc ¶
The HandlerFunc type is an adapter to allow the use of ordinary functions as diameter handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.
func (HandlerFunc) ErrorReports ¶
func (f HandlerFunc) ErrorReports() chan ErrorReport
ErrorReports calls f.ErrorReports()
func (HandlerFunc) ServeDiam ¶
func (f HandlerFunc) ServeDiam(c Conn, m *Message)
ServeDiam calls f(c, m).
type Header ¶
type Header struct { Version uint8 RawMessageLength [3]uint8 CommandFlags uint8 RawCommandCode [3]uint8 ApplicationId uint32 HopByHopId uint32 EndToEndId uint32 }
func (*Header) CommandCode ¶
CommandCode returns RawCommandCode as int.
func (*Header) MessageLength ¶
MessageLength helper function returns RawMessageLength as int.
func (*Header) SetMessageLength ¶
UpdateLength updates RawMessageLength from an int.
type Message ¶
type Message struct { Header *Header AVP []*AVP Dict *dict.Parser // Dictionary associated with this Message }
Message represents a diameter message.
func NewMessage ¶
NewMessage allocates a new Message object. Used for building messages that will be sent to a connection later.
Arguments hopbyhop and endtoend are optional. If set to 0, random values are used.
Dictionary d is used for encoding the AVPs added to the message. If set to nil, static dict.Default is used.
TODO: Support command short names like CER, CEA.
func ReadMessage ¶
ReadMessage reads a diameter message from the connection.
Dictionary d is used to parse message's AVPs. If set to nil, the static dict.Default is used.
Using the wrong dictionary might result in errors.
func (*Message) Answer ¶
Answer creates an answer for the current Message with an embedded Result-Code AVP.
func (*Message) FindAVP ¶
FindAVP looks for an AVP in the message body, and return it. code can be either the AVP code (int, uint32) or name (string).
Example:
avp, err := m.FindAVP(264) avp, err := m.FindAVP("Origin-Host")
func (*Message) NewAVP ¶
func (m *Message) NewAVP(code interface{}, flags uint8, vendor uint32, data avpdata.Generic) (*AVP, error)
NewAVP allocates and returns a new AVP. @code can be either the AVP code (int, uint32) or name (string).
func (*Message) PrettyPrint ¶
func (m *Message) PrettyPrint()
PrettyPrint prints the message in a human readable format.
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
ServeMux is a diameter message multiplexer. It matches the command from the incoming message against a list of registered commands and calls the handler.
func (*ServeMux) ErrorReports ¶
func (mux *ServeMux) ErrorReports() chan ErrorReport
ErrorReports returns the ErrorReport channel of the handler.
func (*ServeMux) Handle ¶
Handle registers the handler for the given code. If a handler already exists for code, Handle panics.
func (*ServeMux) HandleFunc ¶
HandleFunc registers the handler function for the given command. Special cmd "ALL" may be used as a catch all.
type Server ¶
type Server struct { Addr string // TCP address to listen on, ":3868" if empty Handler Handler // handler to invoke, diam.DefaultServeMux if nil Dict *dict.Parser // diameter dictionaries for this server ReadTimeout time.Duration // maximum duration before timing out read of the request WriteTimeout time.Duration // maximum duration before timing out write of the response TLSConfig *tls.Config // optional TLS config, used by ListenAndServeTLS }
A Server defines parameters for running a diameter server.
func (*Server) ListenAndServe ¶
ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections. If srv.Addr is blank, ":3868" is used.
func (*Server) ListenAndServeTLS ¶
ListenAndServeTLS listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming TLS connections.
Filenames containing a certificate and matching private key for the server must be provided. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate followed by the CA's certificate.
If srv.Addr is blank, ":3868" is used.