tosi

package module
v0.0.0-...-3c938a4 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: GPL-3.0 Imports: 6 Imported by: 0

README

tosi
======

tosi provides an implementation of RFC 1006, as defined at 

 http://tools.ietf.org/html/rfc1006.

The implementation puts ISO/IEC 8072/8073 transport class 0 (with some minor modifications) on top of a TCP/IP connection, on port 102 by default, even if another port can be chosen.
ISO/IEC 8072/8073 are identical to ITU standards X.214 and X.224, defined at 

 http://www.itu.int/ITU-T/recommendations/rec.aspx?id=3262 

and 

 http://www.itu.int/ITU-T/recommendations/rec.aspx?id=3264. 

Documentation
-------------

The tosi API reference is available on GoDoc: 

 http://godoc.org/github.com/danielePala/tosi.

License
-------

See the COPYING file.

Author
-------

Daniele Pala <pala.daniele@gmail.com>

Known bugs/limitations
-------

None.

Documentation

Overview

Package tosi provides an implementation of RFC 1006.

The protocol is defined at http://tools.ietf.org/html/rfc1006. The implementation puts ISO/IEC 8072/8073 transport class 0 (with some minor modifications) on top of a TCP/IP connection, on port 102 by default, even if another port can be chosen. ISO/IEC 8072/8073 are identical to ITU standards X.214 and X.224, defined at http://www.itu.int/ITU-T/recommendations/rec.aspx?id=3262 and http://www.itu.int/ITU-T/recommendations/rec.aspx?id=3264.

The external interface is based on the constructs defined in the 'net' package, and in particular the basic interface provided by the Dial, Listen, and Accept functions and the associated Conn and Listener interfaces. Please refer to that package's documentation for general informations on their usage and philosophy, it can be found here: http://golang.org/pkg/net/.

The DialTOSI function connects to a server:

tosiAddr, err := tosi.ResolveTOSIAddr("tosi", "192.168.1.1:80:100")
if err != nil {
        // handle error
}
conn, err := tosi.DialTOSI("tosi", nil, tosiAddr)
if err != nil {
        // handle error
}
fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n")
status, err := bufio.NewReader(conn).ReadString('\n')
// ...

A tosi address is composed by a TCP address and an optional "transport selector (TSEL)" which can be an arbitrary sequence of bytes. Thus "10.20.30.40:80:hello" is a valid address, and 'hello' is the TSEL. The TCP port can be omitted, and in this case the default value (102) will be used, as in "10.20.30.40::hello". The TSEL can also be omitted, as in "10.20.30.40::".

The ListenTOSI function creates servers:

tosiAddr, err := tosi.ResolveTOSIAddr("tosi", "192.168.1.1:80:100")
if err != nil {
        // handle error
}
ln, err := tosi.ListenTOSI("tosi", tosiAddr)
if err != nil {
        // handle error
}
for {
        conn, err := ln.Accept()
        if err != nil {
                // handle error
                continue
        }
        go handleConnection(conn)
}

Index

Constants

View Source
const (
	RFC1006port     = "102" // Default TCP port used by TOSI servers
	ErrBadAddress   = "invalid address"
	ErrBadNetwork   = "unknown network"
	ErrUnknownReply = "unknown reply from server"
	ErrBadTPKT      = "received an invalid TPKT"
	ErrBadCC        = "received an invalid CC"
	ErrBadED        = "received an invalid ED"
	ErrBadDT        = "received an invalid DT"
	ErrBadTPDU      = "received an invalid TPDU"
	ErrBadCR        = "received an invalid CR"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DialOpt

type DialOpt struct {
	Expedited   bool   // use of expedited data transfer
	Data        []byte // initial user data
	MaxTPDUSize int    // maximum TPDU size
}

DialOpt contains options to be used by the DialOptTOSI function during connection establishment: use of expedited data transfer, maximum TPDU size and initial user data (up to 32 bytes). The maximum TPDU size should be a multiple of 128, and be smaller than 65531 bytes.

type ProtocolError

type ProtocolError struct {
	Info []byte // additional information about the error
	// contains filtered or unexported fields
}

ProtocolError represents TOSI protocol errors.

func (*ProtocolError) Error

func (err *ProtocolError) Error() string

type ReadInfo

type ReadInfo struct {
	N         int  // number of bytes read
	Expedited bool // is this data from an expedited TPDU?
	EndOfTSDU bool // is this data the last part of a TSDU?
}

ReadInfo contains information returned by ReadTOSI regarding the data passed to the caller: the number of bytes read, if the data comes from an expedited TPDU, and if it is the end of a TSDU.

type TOSIAddr

type TOSIAddr struct {
	net.TCPAddr        // TCP address
	TSel        []byte // Transport selector (optional)
}

TOSIAddr represents the address of a TOSI end point.

func ResolveTOSIAddr

func ResolveTOSIAddr(tnet, addr string) (tosiAddr *TOSIAddr, err error)

ResolveTOSIAddr parses addr as a TOSI address of the form tcp:tsel and resolves domain names to numeric addresses on the network tnet, which must be "tosi", "tosi4" or "tosi6". The tcp part must be a valid TCP address of the form host:port, as in "127.0.0.1:80", or just an IP address followed by ':', as in "127.0.0.1:". A literal IPv6 host address must be enclosed in square brackets, as in "[::]:80". tsel is the "transport selector", which can be an arbitrary sequence of bytes. Thus "10.20.30.40:80:hello" is a valid address. If no TCP port is specified, as in "10.20.30.40::hello", it defaults to 102. The tsel parameter is optional, thus "10.20.30.40:80:" is a valid address.

func (*TOSIAddr) Network

func (a *TOSIAddr) Network() string

Network returns the address's network name, "tosi".

func (*TOSIAddr) String

func (a *TOSIAddr) String() string

type TOSIConn

type TOSIConn struct {
	MaxTpduSize  int  // max TPDU size
	UseExpedited bool // use of expedited TPDUs enabled
	// contains filtered or unexported fields
}

TOSIConn is an implementation of the net.Conn interface for TOSI network connections.

func DialOptTOSI

func DialOptTOSI(net string, loc, rem *TOSIAddr, op DialOpt) (*TOSIConn, error)

DialOptTOSI is the same as DialTOSI, but it takes an additional 'options' parameter which can be used to negotiate the use of expedited TPDUs and to send initial data during connection establishment. The result of the expedited data negotiation is returned in a TOSIConn field. The maximum size of initial data is 32 bytes, if the input is bigger than this size, it is trimmed.

func DialTOSI

func DialTOSI(net string, loc, rem *TOSIAddr) (*TOSIConn, error)

DialTOSI connects to the remote address raddr on the network net, which must be "tosi", "tosi4", or "tosi6". If loc is not nil, it is used as the local address for the connection.

func (*TOSIConn) Close

func (c *TOSIConn) Close() error

Close closes the TOSI connection. This is the 'implicit' variant defined in ISO 8073, i.e. all it does is closing the underlying TCP connection.

func (*TOSIConn) LocalAddr

func (c *TOSIConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*TOSIConn) Read

func (c *TOSIConn) Read(b []byte) (n int, err error)

Read implements the net.Conn Read method. If b is not large enough for the TPDU data, it fills b and next Read will read the rest of the TPDU data.

func (*TOSIConn) ReadTOSI

func (c *TOSIConn) ReadTOSI(b []byte) (read ReadInfo, err error)

ReadTOSI is the same as Read, but it also indicates if the data comes from an expedited TPDU, and if it is the end of a TSDU.

func (*TOSIConn) ReadTSDU

func (c *TOSIConn) ReadTSDU() (tsdu []byte, r ReadInfo, err error)

ReadTSDU reads from a TOSI connection until end-of-TSDU is indicated, or an error occurs. In case of error tsdu contains all data read before the error occurrence.

func (*TOSIConn) RemoteAddr

func (c *TOSIConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*TOSIConn) SetDeadline

func (c *TOSIConn) SetDeadline(t time.Time) error

SetDeadline implements the net.Conn SetDeadline method.

func (*TOSIConn) SetReadDeadline

func (c *TOSIConn) SetReadDeadline(t time.Time) error

SetReadDeadline implements the net.Conn SetReadDeadline method.

func (*TOSIConn) SetWriteDeadline

func (c *TOSIConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the Conn SetWriteDeadline method.

func (*TOSIConn) Write

func (c *TOSIConn) Write(b []byte) (n int, err error)

Write implements the net.Conn Write method.

func (*TOSIConn) WriteTOSI

func (c *TOSIConn) WriteTOSI(b []byte, expedited bool) (n int, err error)

WriteTOSI is the same as Write, but it also allows to send expedited TPDUs. If the use of expedited TPDUs was not negotiated during connection establishment, the expedited parameter is ignored.

type TOSIListener

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

TOSIListener is a TOSI network listener. Clients should typically use variables of type net.Listener instead of assuming TOSI.

func ListenTOSI

func ListenTOSI(tnet string, loc *TOSIAddr) (*TOSIListener, error)

ListenTOSI announces on the TOSI address loc and returns a TOSI listener. tnet must be "tosi", "tosi4", or "tosi6".

func (*TOSIListener) Accept

func (l *TOSIListener) Accept() (net.Conn, error)

Accept implements the Accept method in the net.Listener interface; it waits for the next call and returns a generic net.Conn.

func (*TOSIListener) AcceptTOSI

func (l *TOSIListener) AcceptTOSI(data func([]byte) []byte) (*TOSIConn, error)

AcceptTOSI is the same as Accept, but it also takes a user function which should produce initial data to be sent during connection establishment, taking as input the data received from the caller (if present). In fact, RFC 1006 allows for the exchange of user data during connection establishment.

func (*TOSIListener) Addr

func (l *TOSIListener) Addr() net.Addr

Addr returns the listener's network address.

func (*TOSIListener) Close

func (l *TOSIListener) Close() error

Close stops listening on the TOSI address. Already Accepted connections are not closed.

Jump to

Keyboard shortcuts

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