rdtp

package module
v0.0.0-...-70695b7 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2021 License: MPL-2.0 Imports: 8 Imported by: 0

README

rdtp - Reliable Data Transport Protocol

Go Report Card Documentation license

[IPPROTO_RDTP = 0x9D]

Specification of a reliable transport layer protocol to be used over IP networks, along a simplistic and modular implementation in Go.

To-Dos:

  • Reliability
    • Polish socket dialer
    • Implement socket listener
    • Implement selective acknowledgements
  • Flow Control
    • Receiver window in header

Based on:

  • UDP - User Datagram Protocol [RFC]
  • TCP - Transmission Control Protocol [RFC]

Header Format

 0      7 8     15 16    23 24    31
+--------+--------+--------+--------+
|     Src. Port   |    Dst. Port    |
+--------+--------+--------+--------+
|      Length     |    Checksum     |
+--------+--------+--------+--------+
|          Sequence Number          |
+--------+-----------------+--------+
|       Acknowledgement Number      |
+--------+-----------------+--------+
|  Flags |                          |
+--------+                          |
|             ( Data )              |
+               ....                +

Important Notes:

The value for the underlying IP header's "Protocol" field must be set to 0x9D (157 -- currently Unassigned)

Over the Wire

Here's a Wireshark capture of an RDTP packet over the wire:

(The highlighted bytes are the RDTP header + payload)

Documentation

Index

Constants

View Source
const (
	// ClientMessageTypeAccept is the message type sent from clients
	// to rdtp-service to acknowledge a notification and receive a full duplex
	// communication channel between the dialing caller and the rdtp port
	// being listened on by a client
	// Note: RemoteAddress **must** be defined
	ClientMessageTypeAccept = ClientMessageType("ACCEPT")

	// ClientMessageTypeDial is the message type sent from clients
	// to rdtp-service to "dial" a remote rdtp address
	// Note: RemoteAddr **must** be defined
	ClientMessageTypeDial = ClientMessageType("DIAL")

	// ClientMessageTypeListen is the message type sent from clients
	// to rdtp-service to "listen" for inbound connections on a local rdtp port
	// Note: LocalAddr **must** be defined
	ClientMessageTypeListen = ClientMessageType("LISTEN")

	// ServiceMessageTypeOK is the message type sent from rdtp-service to clients
	// to acknowledge their request and indicate that it was served successfully
	ServiceMessageTypeOK = ServiceMessageType("OK")

	// ServiceMessageTypeNotify is the message type sent from rdtp-service to
	// clients to notify them that there is a new remote client for
	// the client's listener
	ServiceMessageTypeNotify = ServiceMessageType("NOTIFY")

	// ServiceMessageTypeError is the message type sent from rdtp-service to
	// clients to acklowledge their request and indicate that there was an error
	ServiceMessageTypeError = ServiceMessageType("ERROR")

	// ServiceErrorTypeConnClosedByClient is the error type for errors caused by
	// the rdtp client closing the client -> rdtp-service connection
	ServiceErrorTypeConnClosedByClient = ServiceErrorType("CONN_CLOSED_BY_CLIENT")

	// ServiceErrorTypeMalformedMessage is the error type for errors
	// caused by the rdtp client sending a bad/malformed request
	ServiceErrorTypeMalformedMessage = ServiceErrorType("MALFORMED_MESSAGE")

	// ServiceErrorTypeInvalidMessageType is the error type for errors
	// caused by the rdtp client sending a message with an invalid type
	ServiceErrorTypeInvalidMessageType = ServiceErrorType("INVALID_MESSAGE_TYPE")

	// ServiceErrorTypeFailedToCreateSocket is the error type for errors caused
	// by the rdtp service failing to create a new socket
	ServiceErrorTypeFailedToCreateSocket = ServiceErrorType("CREATE_SOCKET_FAIL")

	// ServiceErrorTypeFailedToAttachSocket is the error type for errors caused
	// by the rdtp service failing to attach a created socket to the socket mgr
	ServiceErrorTypeFailedToAttachSocket = ServiceErrorType("ATTACH_SOCKET_FAIL")

	// ServiceErrorTypeFailedToAttachListener is the error type for errors caused
	// by the rdtp service failing to attach a created listener to the socket mgr
	ServiceErrorTypeFailedToAttachListener = ServiceErrorType("ATTACH_LISTENER_FAIL")

	// ServiceErrorTypeFailedHandshake is the error type for errors caused
	// by the rdtp service failing the rdtp handshake with a remote address
	ServiceErrorTypeFailedHandshake = ServiceErrorType("HANDSHAKE_FAILED")

	// ServiceErrorTypeFailedCommunication is the error type for errors caused
	// by the rdtp service failing to communicate with the rdtp client
	ServiceErrorTypeFailedCommunication = ServiceErrorType("COMMUNICATION_FAILED")
)
View Source
const (
	// IPProtoRDTP is the protocol number for RDTP packets over IP
	// The value 157 (0x9D) is unassigned as per:
	// https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers
	IPProtoRDTP = 0x9D

	// DiscoveryPort is the port that receives new RDTP connections
	DiscoveryPort = uint16(0)

	// MaxPort is the highest possible RDTP port number
	MaxPort = uint16(65535)

	// DefaultRDTPServiceAddr is the default rdtp service socket
	DefaultRDTPServiceAddr = "/var/run/rdtp.sock"
)
View Source
const Network = "rdtp"

Network is the name of the RDTP network

Variables

This section is empty.

Functions

func Listen

func Listen(address string) (net.Listener, error)

Listen announces on the local network address

func NewClientMessage

func NewClientMessage(clientMessageType ClientMessageType,
	laddr, raddr *Addr) ([]byte, error)

NewClientMessage returns a serialized client message

func NewServiceMessage

func NewServiceMessage(serviceMessageType ServiceMessageType,
	laddr, raddr *Addr, errorType *ServiceErrorType) ([]byte, error)

NewServiceMessage returns a serialized service message

Types

type Addr

type Addr struct {
	Host string `json:"host"`
	Port uint16 `json:"port"`
}

Addr implements the net.Addr interface https://golang.org/pkg/net/#Addr

func (*Addr) Network

func (a *Addr) Network() string

Network returns the name of the network

func (*Addr) String

func (a *Addr) String() string

String returns the string form of the address

type ClientMessage

type ClientMessage struct {
	Type       ClientMessageType `json:"type"`
	LocalAddr  Addr              `json:"local_addr"`
	RemoteAddr Addr              `json:"remote_addr"`
}

ClientMessage is the json model of a request for the rdtp service

type ClientMessageType

type ClientMessageType string

ClientMessageType is the go type for client -> rdtp-service messages (requests)

type Conn

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

Conn is a logical communication channel between the local and remote hosts. Implements the net.Conn interface (https://golang.org/pkg/net/#Conn)

func Dial

func Dial(address string) (*Conn, error)

Dial returns a connection to a remote address where the remote address has a format: ${host}:${port}

func (Conn) Close

func (c Conn) Close() error

Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.

func (Conn) LocalAddr

func (c Conn) LocalAddr() net.Addr

LocalAddr returns the local address for this conn

func (Conn) Read

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

Read reads data from the connection.

func (Conn) RemoteAddr

func (c Conn) RemoteAddr() net.Addr

RemoteAddr returns the remote address for this conn

func (Conn) SetDeadline

func (c Conn) SetDeadline(t time.Time) error

SetDeadline sets the deadline on the connection

func (Conn) SetReadDeadline

func (c Conn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the read deadline on the connection

func (Conn) SetWriteDeadline

func (c Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the write deadline on the connection

func (Conn) Write

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

Write writes data to the connection.

type Listener

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

Listener listens for new inbound rdtp connections on a local rdtp port Implements the net.Listener interface https://golang.org/pkg/net/#Listener

func (*Listener) Accept

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

Accept waits for and returns the next connection to the listener.

func (*Listener) Addr

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

Addr returns the listener's network address.

func (*Listener) Close

func (l *Listener) Close() error

Close closes the listener.

type ServiceErrorType

type ServiceErrorType string

ServiceErrorType is the go type included within a ServiceMessageType to provide more detail on failures

type ServiceMessage

type ServiceMessage struct {
	Type       ServiceMessageType `json:"type"`
	LocalAddr  Addr               `json:"local_addr"`
	RemoteAddr Addr               `json:"remote_addr"`
	Error      ServiceErrorType   `json:"error,omitempty"`
}

ServiceMessage is the json model of a message/response from the rdtp service

type ServiceMessageType

type ServiceMessageType string

ServiceMessageType is the go type for rdtp-service -> client messages (responses/notifications)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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