tcpcl

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2020 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package tcpcl provides a library for the Delay-Tolerant Networking TCP Convergence Layer Protocol Version 4, draft-ietf-dtn-tcpclv4-14.

A new TCPCL server can be started by the Listener, which provides multiple connection to its Clients. To reach a remote server, a new Client connection can be dialed.

Index

Constants

View Source
const KEEPALIVE uint8 = 0x04

KEEPALIVE is the Message Header code for a Keepalive Message.

View Source
const MSG_REJECT uint8 = 0x06

MSG_REJECT is the Message Header code for a Message Rejection Message.

View Source
const SESS_INIT uint8 = 0x07

SESS_INIT is the Message Header code for a Session Initialization Message.

View Source
const SESS_TERM uint8 = 0x05

SESS_TERM is the Message Header code for a Session Termination Message.

View Source
const XFER_ACK uint8 = 0x02

XFER_ACK is the Message Header code for a Data Acknowledgement Message.

View Source
const XFER_REFUSE uint8 = 0x03

XFER_REFUSE is the Message Header code for a Transfer Refusal Message.

View Source
const XFER_SEGMENT uint8 = 0x01

XFER_SEGMENT is the Message Header code for a Data Transmission Message.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a TCPCL client for a bidirectional Bundle exchange. Thus, the Client type implements both cla.ConvergenceReceiver and cla.ConvergenceSender. A Client can be created by the Listener for incoming connections or dialed for outbounding connections.

func DialClient

func DialClient(address string, endpointID bundle.EndpointID, permanent bool) *Client

DialClient tries to establish a new TCPCL Client to a remote server.

func NewClient

func NewClient(conn net.Conn, endpointID bundle.EndpointID) *Client

NewClient creates a new Client on an existing connection. This function is used from the Listener.

func (*Client) Address

func (client *Client) Address() string

func (*Client) Channel

func (client *Client) Channel() chan cla.ConvergenceStatus

func (*Client) Close

func (client *Client) Close()

func (*Client) GetEndpointID

func (client *Client) GetEndpointID() bundle.EndpointID

func (*Client) GetPeerEndpointID

func (client *Client) GetPeerEndpointID() bundle.EndpointID

func (*Client) IsPermanent

func (client *Client) IsPermanent() bool

func (*Client) Send

func (client *Client) Send(bndl *bundle.Bundle) error

func (*Client) Start

func (client *Client) Start() (err error, retry bool)

func (*Client) String

func (client *Client) String() string

type ClientState

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

ClientState describes the state of a TCPCL Client. Each Client can always upgrade its state to a later one, but cannot go back to a previous state. A transition can be made into the following or the termination state.

func (*ClientState) IsContact

func (cs *ClientState) IsContact() bool

IsContact checks if the ClientState is in the contact state.

func (*ClientState) IsEstablished

func (cs *ClientState) IsEstablished() bool

IsEstablished checks if the ClientState is in the established state.

func (*ClientState) IsInit

func (cs *ClientState) IsInit() bool

IsInit checks if the ClientState is in the initialization state.

func (*ClientState) IsTerminated

func (cs *ClientState) IsTerminated() bool

IsTerminated checks if the ClientState is in the terminated state.

func (*ClientState) Next

func (cs *ClientState) Next()

Next enters the following ClientState.

func (*ClientState) String

func (cs *ClientState) String() string

func (*ClientState) Terminate

func (cs *ClientState) Terminate()

Terminate sets the ClientState into the termination state.

type ContactFlags

type ContactFlags uint8

ContactFlags are single-bit flags used in the ContactHeader.

const (
	// ContactCanTls indicates that the sending peer is capable of TLS security.
	ContactCanTls ContactFlags = 0x01
)

func (ContactFlags) String

func (cf ContactFlags) String() string

type ContactHeader

type ContactHeader struct {
	Flags ContactFlags
}

ContactHeader will be exchanged at first after a TCP connection was established. Both entities are sending a ContactHeader and are validating the peer's one.

func NewContactHeader

func NewContactHeader(flags ContactFlags) ContactHeader

NewContactHeader creates a new ContactHeader with given ContactFlags.

func (ContactHeader) Marshal

func (ch ContactHeader) Marshal(w io.Writer) error

func (ContactHeader) String

func (ch ContactHeader) String() string

func (*ContactHeader) Unmarshal

func (ch *ContactHeader) Unmarshal(r io.Reader) error

type DataAcknowledgementMessage

type DataAcknowledgementMessage struct {
	Flags      SegmentFlags
	TransferId uint64
	AckLen     uint64
}

DataAcknowledgementMessage is the XFER_ACK message for data acknowledgements.

func NewDataAcknowledgementMessage

func NewDataAcknowledgementMessage(flags SegmentFlags, tid, acklen uint64) DataAcknowledgementMessage

NewDataAcknowledgementMessage creates a new DataAcknowledgementMessage with given fields.

func (DataAcknowledgementMessage) Marshal

func (dam DataAcknowledgementMessage) Marshal(w io.Writer) error

func (DataAcknowledgementMessage) String

func (dam DataAcknowledgementMessage) String() string

func (*DataAcknowledgementMessage) Unmarshal

func (dam *DataAcknowledgementMessage) Unmarshal(r io.Reader) error

type DataTransmissionMessage

type DataTransmissionMessage struct {
	Flags      SegmentFlags
	TransferId uint64
	Data       []byte
}

DataTransmissionMessage is the XFER_SEGMENT message for data transmission.

func NewDataTransmissionMessage

func NewDataTransmissionMessage(flags SegmentFlags, tid uint64, data []byte) DataTransmissionMessage

NewDataTransmissionMessage creates a new DataTransmissionMessage with given fields.

func (DataTransmissionMessage) Marshal

func (dtm DataTransmissionMessage) Marshal(w io.Writer) error

func (DataTransmissionMessage) String

func (dtm DataTransmissionMessage) String() string

func (*DataTransmissionMessage) Unmarshal

func (dtm *DataTransmissionMessage) Unmarshal(r io.Reader) error

type IncomingTransfer

type IncomingTransfer struct {
	Id uint64
	// contains filtered or unexported fields
}

IncomingTransfer represents an incoming Bundle Transfer for the TCPCL.

func NewIncomingTransfer

func NewIncomingTransfer(id uint64) *IncomingTransfer

NewIncomingTransfer creates a new IncomingTransfer for the given Transfer ID.

func (IncomingTransfer) IsFinished

func (t IncomingTransfer) IsFinished() bool

IsFinished indicates if this Transfer is finished.

func (*IncomingTransfer) NextSegment

NextSegment reads data from a XFER_SEGMENT and retruns a XFER_ACK or an error.

func (IncomingTransfer) String

func (t IncomingTransfer) String() string

func (*IncomingTransfer) ToBundle

func (t *IncomingTransfer) ToBundle() (bndl bundle.Bundle, err error)

ToBundle returns the Bundle for a finished Transfer.

type KeepaliveMessage

type KeepaliveMessage struct{}

KeepaliveMessage is the KEEPALIVE message for session upkeep.

func NewKeepaliveMessage

func NewKeepaliveMessage() KeepaliveMessage

NewKeepaliveMessage creates a new KeepaliveMessage.

func (KeepaliveMessage) Marshal

func (km KeepaliveMessage) Marshal(w io.Writer) error

func (KeepaliveMessage) String

func (_ KeepaliveMessage) String() string

func (*KeepaliveMessage) Unmarshal

func (km *KeepaliveMessage) Unmarshal(r io.Reader) error

type Listener

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

Listener is a TCPCL server bound to a TCP port to accept incoming TCPCL connections. This type implements the cla.ConvergenceProvider and should be supervised by a cla.Manager.

func NewListener

func NewListener(listenAddress string, endpointID bundle.EndpointID) *Listener

NewListener creates a new Listener which should be bound to the given address and advertises the endpoint ID as its own node identifier.

func (*Listener) Close

func (listener *Listener) Close()

func (*Listener) RegisterManager

func (listener *Listener) RegisterManager(manager *cla.Manager)

func (*Listener) Start

func (listener *Listener) Start() error

func (Listener) String

func (listener Listener) String() string

type Message

type Message interface {
	Marshal(w io.Writer) error
	Unmarshal(r io.Reader) error
}

Message describes all kind of TCPCL messages, which have their serialization and deserialization in common.

func NewMessage

func NewMessage(typeCode uint8) (msg Message, err error)

NewMessage creates a new Message type for a given type code.

func ReadMessage

func ReadMessage(r io.Reader) (msg Message, err error)

ReadMessage parses the next TCPCL message from the Reader.

type MessageRejectionMessage

type MessageRejectionMessage struct {
	ReasonCode    MessageRejectionReason
	MessageHeader uint8
}

MessageRejectionMessage is the MSG_REJECT message for message rejection.

func NewMessageRejectionMessage

func NewMessageRejectionMessage(reasonCode MessageRejectionReason, messageHeader uint8) MessageRejectionMessage

NewMessageRejectionMessage creates a new MessageRejectionMessage with given fields.

func (MessageRejectionMessage) Marshal

func (mrm MessageRejectionMessage) Marshal(w io.Writer) error

func (MessageRejectionMessage) String

func (mrm MessageRejectionMessage) String() string

func (*MessageRejectionMessage) Unmarshal

func (mrm *MessageRejectionMessage) Unmarshal(r io.Reader) error

type MessageRejectionReason

type MessageRejectionReason uint8

MessageRejectionReason is the one-octet refusal code from a MessageRejectionMessage.

const (
	// RejectionTypeUnknown indicates an unknown Message Type Code.
	RejectionTypeUnknown MessageRejectionReason = 0x01

	// RejectionUnsupported indicates that this TCPCL node cannot comply with
	// the message content.
	RejectionUnsupported MessageRejectionReason = 0x02

	// RejectionUnexptected indicates that this TCPCL node received a message
	// while the session is in a state in which the message is not expected.
	RejectionUnexptected MessageRejectionReason = 0x03
)

func (MessageRejectionReason) IsValid

func (mrr MessageRejectionReason) IsValid() bool

IsValid checks if this MessageRejectionReason represents a valid value.

func (MessageRejectionReason) String

func (mrr MessageRejectionReason) String() string

type OutgoingTransfer

type OutgoingTransfer struct {
	Id uint64
	// contains filtered or unexported fields
}

OutgoingTransfer represents an outgoing Bundle Transfer for the TCPCL.

func NewBundleOutgoingTransfer

func NewBundleOutgoingTransfer(id uint64, b bundle.Bundle) *OutgoingTransfer

NewBundleOutgoingTransfer creates a new OutgoingTransfer for a Bundle.

func NewOutgoingTransfer

func NewOutgoingTransfer(id uint64) (t *OutgoingTransfer, w io.Writer)

NewOutgoingTransfer creates a new OutgoingTransfer for data written into the returned Writer.

func (*OutgoingTransfer) NextSegment

func (t *OutgoingTransfer) NextSegment(mru uint64) (dtm DataTransmissionMessage, err error)

NextSegment creates the next XFER_SEGMENT for the given MRU or an EOF in case of a finished Writer.

func (OutgoingTransfer) String

func (t OutgoingTransfer) String() string

type SegmentFlags

type SegmentFlags uint8

SegmentFlags are an one-octet field of single-bit flags for a XFER_SEGMENT.

const (
	// SegmentEnd indicates that this segment is the last of the transfer.
	SegmentEnd SegmentFlags = 0x01

	// SegmentStart indicates that this segment is the first of the transfer.
	SegmentStart SegmentFlags = 0x02
)

func (SegmentFlags) String

func (sf SegmentFlags) String() string

type SessionInitMessage

type SessionInitMessage struct {
	KeepaliveInterval uint16
	SegmentMru        uint64
	TransferMru       uint64
	Eid               string
}

SessionInitMessage is the SESS_INIT message to negotiate session parameters.

func NewSessionInitMessage

func NewSessionInitMessage(keepaliveInterval uint16, segmentMru, transferMru uint64, eid string) SessionInitMessage

NewSessionInitMessage creates a new SessionInitMessage with given fields.

func (SessionInitMessage) Marshal

func (si SessionInitMessage) Marshal(w io.Writer) error

func (SessionInitMessage) String

func (si SessionInitMessage) String() string

func (*SessionInitMessage) Unmarshal

func (si *SessionInitMessage) Unmarshal(r io.Reader) error

type SessionTerminationCode

type SessionTerminationCode uint8

SessionTerminationCode is the one-octet refusal reason code for a SESS_TERM message.

const (
	// TerminationUnknown indicates an unknown or not specified reason.
	TerminationUnknown SessionTerminationCode = 0x00

	// TerminationIdleTimeout indicates a session being closed due to idleness.
	TerminationIdleTimeout SessionTerminationCode = 0x01

	// TerminationVersionMismatch indicates that the node cannot conform to the
	// specified TCPCL protocol version number.
	TerminationVersionMismatch SessionTerminationCode = 0x02

	// TerminationBusy indicates a too busy node.
	TerminationBusy SessionTerminationCode = 0x03

	// TerminationContactFailure indicates that the node cannot interpret or
	// negotiate contact header options.
	TerminationContactFailure SessionTerminationCode = 0x04

	// TerminationResourceExhaustion indicates that the node has run into some
	// resource limit.
	TerminationResourceExhaustion SessionTerminationCode = 0x05
)

func (SessionTerminationCode) IsValid

func (stc SessionTerminationCode) IsValid() bool

IsValid checks if this SessionTerminationCode represents a valid value.

func (SessionTerminationCode) String

func (stc SessionTerminationCode) String() string

type SessionTerminationFlags

type SessionTerminationFlags uint8

SessionTerminationFlags are single-bit flags used in the SessionTerminationMessage.

const (
	// TerminationReply indicates that this message is an acknowledgement of an
	// earlier SESS_TERM message.
	TerminationReply SessionTerminationFlags = 0x01
)

func (SessionTerminationFlags) String

func (stf SessionTerminationFlags) String() string

type SessionTerminationMessage

type SessionTerminationMessage struct {
	Flags      SessionTerminationFlags
	ReasonCode SessionTerminationCode
}

SessionTerminationMessage is the SESS_TERM message for session termination.

func NewSessionTerminationMessage

func NewSessionTerminationMessage(flags SessionTerminationFlags, reason SessionTerminationCode) SessionTerminationMessage

NewSessionTerminationMessage creates a new SessionTerminationMessage with given fields.

func (SessionTerminationMessage) Marshal

func (stm SessionTerminationMessage) Marshal(w io.Writer) error

func (SessionTerminationMessage) String

func (stm SessionTerminationMessage) String() string

func (*SessionTerminationMessage) Unmarshal

func (stm *SessionTerminationMessage) Unmarshal(r io.Reader) error

type TransferRefusalCode

type TransferRefusalCode uint8

TransferRefusalCode is the one-octet refusal reason code for a XFER_REFUSE message.

const (
	// RefusalUnknown indicates an unknown or not specified reason.
	RefusalUnknown TransferRefusalCode = 0x00

	// RefusalExtensionFailure indicates a failure processing the Transfer Extension Items.
	RefusalExtensionFailure TransferRefusalCode = 0x01

	// RefusalCompleted indicates that the receiver already has the complete bundle.
	RefusalCompleted TransferRefusalCode = 0x02

	// RefusalNoResources indicate that the receiver's resources are exhausted.
	RefusalNoResources TransferRefusalCode = 0x03

	// RefusalRetransmit indicates a problem on the receiver's side. This requires
	// the complete bundle to be retransmitted.
	RefusalRetransmit TransferRefusalCode = 0x04
)

func (TransferRefusalCode) IsValid

func (trc TransferRefusalCode) IsValid() bool

IsValid checks if this TransferRefusalCode represents a valid value.

func (TransferRefusalCode) String

func (trc TransferRefusalCode) String() string

type TransferRefusalMessage

type TransferRefusalMessage struct {
	ReasonCode TransferRefusalCode
	TransferId uint64
}

TransferRefusalMessage is the XFER_REFUSE message for transfer refusals.

func NewTransferRefusalMessage

func NewTransferRefusalMessage(reason TransferRefusalCode, tid uint64) TransferRefusalMessage

NewTransferRefusalMessage creates a new TransferRefusalMessage with given fields.

func (TransferRefusalMessage) Marshal

func (trm TransferRefusalMessage) Marshal(w io.Writer) error

func (TransferRefusalMessage) String

func (trm TransferRefusalMessage) String() string

func (*TransferRefusalMessage) Unmarshal

func (trm *TransferRefusalMessage) Unmarshal(r io.Reader) error

Jump to

Keyboard shortcuts

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