reliable

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package reliable implements the SCION ReliableSocket protocol

Servers should first call Listen on a UNIX socket address, and then call Accept on the received Listener.

Clients should either call:

Dial, if they do not want to register a receiving address with the remote end
  (e.g., when connecting to SCIOND);
Register, to register the address argument with the remote end
  (e.g., when connecting to a dispatcher).

ReliableSocket common header message format:

8-bytes: COOKIE (0xde00ad01be02ef03)
1-byte: ADDR TYPE (NONE=0, IPv4=1, IPv6=2, SVC=3)
4-byte: data length
var-byte: Destination address (0 bytes for SCIOND API)
  +2-byte: If destination address not NONE, destination port
var-byte: Payload

ReliableSocket registration message format:

13-bytes: [Common header with address type NONE]
 1-byte: Command (bit mask with 0x04=Bind address, 0x02=SCMP enable, 0x01 always set)
 1-byte: L4 Proto (IANA number)
 8-bytes: ISD-AS
 2-bytes: L4 port
 1-byte: Address type
 var-byte: Address
+2-bytes: L4 bind port  \
+1-byte: Address type    ) (optional bind address)
+var-byte: Bind Address /
+2-bytes: SVC (optional SVC type)

To communicate with SCIOND, clients must first connect to SCIOND's UNIX socket. Messages for SCIOND must set the ADDR TYPE field in the common header to NONE. The payload contains the query for SCIOND (e.g., a request for paths to a SCION destination). The reply header contains the same fields, and the reply payload contains the query answer.

To receive messages from remote SCION hosts, hosts can register their address and port with the SCION dispatcher. The common header of a registration message uses an address of type NONE. The payload contains the address type of the registered address, the address itself and the layer 4 port.

To send messages to remote SCION hosts, hosts fill in the common header with the address type, the address and the layer 4 port of the remote host.

Reads and writes to the connection are thread safe.

Index

Constants

View Source
const (
	// DefaultDispPath contains the system default for a dispatcher socket.
	DefaultDispPath = "/run/shm/dispatcher/default.sock"

	// DefaultDispSocketFileMode allows read/write to the user and group only.
	DefaultDispSocketFileMode = 0770
)

Variables

View Source
var (
	ErrNoAddress             common.ErrMsg = "no address found"
	ErrNoPort                common.ErrMsg = "missing port"
	ErrPayloadTooLong        common.ErrMsg = "payload too long"
	ErrIncompleteFrameHeader common.ErrMsg = "incomplete frame header"
	ErrBadFrameLength        common.ErrMsg = "bad frame length"
	ErrBadCookie             common.ErrMsg = "bad cookie"
	ErrBadAddressType        common.ErrMsg = "bad address type"
	ErrIncompleteAddress     common.ErrMsg = "incomplete IP address"
	ErrIncompletePort        common.ErrMsg = "incomplete UDP port"
	ErrIncompleteMessage     common.ErrMsg = "incomplete message"
	ErrBadLength             common.ErrMsg = "bad length"
	ErrBufferTooSmall        common.ErrMsg = "buffer too small"
)

Possible errors

Functions

func IsDispatcherError added in v0.4.0

func IsDispatcherError(err error) bool

func IsSpecificSysError added in v0.4.0

func IsSpecificSysError(err error, errno syscall.Errno) bool

func IsSysError added in v0.4.0

func IsSysError(err error) bool

Types

type CommandBitField added in v0.4.0

type CommandBitField uint8
const (
	CmdBindAddress CommandBitField = 0x04
	CmdEnableSCMP  CommandBitField = 0x02
	CmdAlwaysOn    CommandBitField = 0x01
)

type Confirmation added in v0.4.0

type Confirmation struct {
	Port uint16
}

func (*Confirmation) DecodeFromBytes added in v0.4.0

func (c *Confirmation) DecodeFromBytes(b []byte) error

func (*Confirmation) SerializeTo added in v0.4.0

func (c *Confirmation) SerializeTo(b []byte) (int, error)

type Conn

type Conn struct {
	*net.UnixConn
	// contains filtered or unexported fields
}

Conn implements the ReliableSocket framing protocol over UNIX sockets.

func Dial

func Dial(ctx context.Context, address string) (*Conn, error)

Dial connects to the UNIX socket specified by address.

The provided context must be non-nil. If the context expires before the connection is complete, an error is returned. Once successfully connected, any expiration of the context will not affect the connection.

func (*Conn) Read

func (conn *Conn) Read(buf []byte) (int, error)

Read blocks until it reads the next framed message payload from conn and stores it in buf. The first return value contains the number of payload bytes read. buf must be large enough to fit the entire message. No addressing data is returned, only the payload. On error, the number of bytes returned is meaningless.

func (*Conn) ReadFrom

func (conn *Conn) ReadFrom(buf []byte) (int, net.Addr, error)

ReadFrom works similarly to Read. In addition to Read, it also returns the last hop (usually, the border router) which sent the message.

func (*Conn) WriteTo

func (conn *Conn) WriteTo(buf []byte, dst net.Addr) (int, error)

WriteTo blocks until it sends buf as a single framed message through conn. The ReliableSocket message header will contain the address and port information in dst. On error, the number of bytes returned is meaningless. On success, the number of bytes is always len(buf).

type Dispatcher added in v0.5.0

type Dispatcher interface {
	// Register connects to a SCION Dispatcher's UNIX socket. Future messages for the address in AS
	// ia which arrive at the dispatcher can be read by calling Read on the returned connection.
	Register(ctx context.Context, ia addr.IA, address *net.UDPAddr,
		svc addr.HostSVC) (net.PacketConn, uint16, error)
}

Dispatcher controls how SCION applications open sockets in the SCION world.

func NewDispatcher added in v0.5.0

func NewDispatcher(name string) Dispatcher

NewDispatcher creates a new dispatcher API endpoint on top of a UNIX STREAM reliable socket. If name is empty, the default dispatcher path is chosen.

type Listener

type Listener struct {
	*net.UnixListener
}

Listener listens on Unix sockets and returns Conn sockets on Accept().

func Listen

func Listen(laddr string) (*Listener, error)

Listen listens on UNIX socket laddr.

func (*Listener) Accept

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

Accept returns sockets which implement the SCION ReliableSocket protocol for reading and writing.

func (*Listener) String

func (listener *Listener) String() string

type ReadPacketizer added in v0.4.0

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

ReadPacketizer splits a stream of reliable socket frames into packets.

FIXME(scrye): This will be deleted when we move to SEQPACKET.

func NewReadPacketizer added in v0.4.0

func NewReadPacketizer(conn net.Conn) *ReadPacketizer

func (*ReadPacketizer) Read added in v0.4.0

func (r *ReadPacketizer) Read(b []byte) (int, error)

type Registration added in v0.4.0

type Registration struct {
	IA            addr.IA
	PublicAddress *net.UDPAddr
	BindAddress   *net.UDPAddr
	SVCAddress    addr.HostSVC
}

Registration contains metadata for a SCION Dispatcher registration message.

func (*Registration) DecodeFromBytes added in v0.4.0

func (r *Registration) DecodeFromBytes(b []byte) error

func (*Registration) SerializeTo added in v0.4.0

func (r *Registration) SerializeTo(b []byte) (int, error)

type UnderlayPacket added in v0.6.0

type UnderlayPacket struct {
	Address *net.UDPAddr
	Payload []byte
}

UnderlayPacket contains metadata about a SCION packet going through the reliable socket framing protocol.

func (*UnderlayPacket) DecodeFromBytes added in v0.6.0

func (p *UnderlayPacket) DecodeFromBytes(b []byte) error

func (*UnderlayPacket) SerializeTo added in v0.6.0

func (p *UnderlayPacket) SerializeTo(b []byte) (int, error)

type WriteStreamer added in v0.4.0

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

WriteStreamer sends a packet via a stream. It is guaranteed to block until the whole packet has been sent (or an error occurred).

FIXME(scrye): This will be delete when we move to SEQPACKET.

func NewWriteStreamer added in v0.4.0

func NewWriteStreamer(conn net.Conn) *WriteStreamer

func (*WriteStreamer) Write added in v0.4.0

func (writer *WriteStreamer) Write(b []byte) error

Directories

Path Synopsis
internal
Package mock_reliable is a generated GoMock package.
Package mock_reliable is a generated GoMock package.
Package reconnect implements transparent logic for reconnecting to the dispatcher.
Package reconnect implements transparent logic for reconnecting to the dispatcher.
mock_reconnect
Package mock_reconnect is a generated GoMock package.
Package mock_reconnect is a generated GoMock package.

Jump to

Keyboard shortcuts

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