snet

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2018 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package snet implements interfaces net.Conn and net.PacketConn for SCION connections.

The default (package-wide) SCION network must first be initialized by calling Init. All future package scoped DialSCION and ListenSCION calls will use this initial context to get the local ISD-AS, dispatcher or sciond.

A connection can be created by calling DialSCION or ListenSCION; both functions register an address-port pair with the local dispatcher. For Dial, the remote address is fixed, meaning only Read and Write can be used. Attempting to ReadFrom or WriteTo a connection created by Dial is an invalid operation. For Listen, the remote address cannot be fixed. ReadFrom, ReadFromSCION can be used to read from the connection and find out the sender's address; WriteTo and WriteToSCION can be used to send a message to a chosen destination.

For applications that need to run in multiple ASes, new networking contexts can be created using NewNetwork. Calling the DialSCION or ListenSCION methods on the networking context yields connections that run in that context.

Multiple networking contexts can share the same SCIOND and/or dispatcher.

Write calls never return SCMP errors directly. If a write call caused an SCMP message to be received by the Conn, it can be inspected by calling Read. In this case, the error value is non-nil and can be type asserted to *OpError. Method SCMP() can be called on the error to extract the SCMP header.

Important: not draining SCMP errors via Read calls can cause the dispatcher to shutdown the socket (see https://github.com/scionproto/scion/pull/1356). To prevent this on a Conn object with only Write calls, run a separate goroutine that continuously calls Read on the Conn.

Index

Constants

View Source
const (
	// Receive and send buffer sizes
	BufSize = 1<<16 - 1
)

Variables

This section is empty.

Functions

func IA

func IA() addr.IA

IA returns the default ISD-AS

func Init

func Init(ia addr.IA, sciondPath string, dispatcherPath string) error

Init initializes the default SCION networking context.

func InitWithNetwork

func InitWithNetwork(network *SCIONNetwork) error

InitWithNetwork initializes snet with the provided SCION networking context.

Types

type Addr

type Addr struct {
	IA      addr.IA
	Host    *addr.AppAddr
	Path    *spath.Path
	NextHop *overlay.OverlayAddr
}

func AddrFromString

func AddrFromString(s string) (*Addr, error)

AddrFromString converts an address string of format isd-as,[ipaddr]:port (e.g., 1-ff00:0:300,[192.168.1.1]:80) to a SCION address.

func (*Addr) Copy

func (a *Addr) Copy() *Addr

func (*Addr) Desc

func (a *Addr) Desc() string

func (*Addr) EqAddr

func (a *Addr) EqAddr(o *Addr) bool

EqAddr compares the IA/Host/L4port values with the supplied Addr

func (*Addr) IsZero

func (a *Addr) IsZero() bool

func (*Addr) Network

func (a *Addr) Network() string

func (*Addr) Set

func (a *Addr) Set(s string) error

This method implements flag.Value interface

func (*Addr) String

func (a *Addr) String() string

func (*Addr) UnmarshalText

func (a *Addr) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type Conn

type Conn interface {
	Read(b []byte) (int, error)
	ReadFrom(b []byte) (int, net.Addr, error)
	ReadFromSCION(b []byte) (int, *Addr, error)
	Write(b []byte) (int, error)
	WriteTo(b []byte, address net.Addr) (int, error)
	WriteToSCION(b []byte, address *Addr) (int, error)
	Close() error
	LocalAddr() net.Addr
	BindAddr() net.Addr
	SVC() addr.HostSVC
	RemoteAddr() net.Addr
	SetDeadline(deadline time.Time) error
	SetReadDeadline(deadline time.Time) error
	SetWriteDeadline(deadline time.Time) error
}

func DialSCION

func DialSCION(network string, laddr, raddr *Addr) (Conn, error)

DialSCION calls DialSCION with infinite timeout on the default networking context.

func DialSCIONWithBindSVC

func DialSCIONWithBindSVC(network string, laddr, raddr, baddr *Addr,
	svc addr.HostSVC) (Conn, error)

DialSCIONWithBindSVC calls DialSCIONWithBindSVC with infinite timeout on the default networking context.

func ListenSCION

func ListenSCION(network string, laddr *Addr) (Conn, error)

ListenSCION calls ListenSCION with infinite timeout on the default networking context.

func ListenSCIONWithBindSVC

func ListenSCIONWithBindSVC(network string, laddr, baddr *Addr, svc addr.HostSVC) (Conn, error)

ListenSCIONWithBindSVC calls ListenSCIONWithBindSVC with infinite timeout on the default networking context.

type Error

type Error interface {
	error
	SCMP() *scmp.Hdr
}

type Network

type Network interface {
	ListenSCIONWithBindSVC(network string,
		laddr, baddr *Addr, svc addr.HostSVC, timeout time.Duration) (Conn, error)
	DialSCIONWithBindSVC(network string,
		laddr, raddr, baddr *Addr, svc addr.HostSVC, timeout time.Duration) (Conn, error)
}

type OpError

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

func (*OpError) Error

func (e *OpError) Error() string

func (*OpError) SCMP

func (e *OpError) SCMP() *scmp.Hdr

type SCIONConn added in v0.3.0

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

func (*SCIONConn) BindAddr added in v0.3.0

func (c *SCIONConn) BindAddr() net.Addr

func (*SCIONConn) BindSnetAddr added in v0.3.0

func (c *SCIONConn) BindSnetAddr() *Addr

func (*SCIONConn) Close added in v0.3.0

func (c *SCIONConn) Close() error

func (*SCIONConn) LocalAddr added in v0.3.0

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

func (*SCIONConn) LocalSnetAddr added in v0.3.0

func (c *SCIONConn) LocalSnetAddr() *Addr

func (*SCIONConn) Read added in v0.3.0

func (c *SCIONConn) Read(b []byte) (int, error)

Read reads data into b from a connection with a fixed remote address. If the remote address for the connection is unknown, Read returns an error.

func (*SCIONConn) ReadFrom added in v0.3.0

func (c *SCIONConn) ReadFrom(b []byte) (int, net.Addr, error)

func (*SCIONConn) ReadFromSCION added in v0.3.0

func (c *SCIONConn) ReadFromSCION(b []byte) (int, *Addr, error)

ReadFromSCION reads data into b, returning the length of copied data and the address of the sender. If the remote address for the connection is already known, ReadFromSCION returns an error.

func (*SCIONConn) RemoteAddr added in v0.3.0

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

func (*SCIONConn) RemoteSnetAddr added in v0.3.0

func (c *SCIONConn) RemoteSnetAddr() *Addr

func (*SCIONConn) SVC added in v0.3.0

func (c *SCIONConn) SVC() addr.HostSVC

func (*SCIONConn) SetDeadline added in v0.3.0

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

func (*SCIONConn) SetReadDeadline added in v0.3.0

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

func (*SCIONConn) SetWriteDeadline added in v0.3.0

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

func (*SCIONConn) Write added in v0.3.0

func (c *SCIONConn) Write(b []byte) (int, error)

Write sends b through a connection with fixed remote address. If the remote address for the conenction is unknown, Write returns an error.

func (*SCIONConn) WriteTo added in v0.3.0

func (c *SCIONConn) WriteTo(b []byte, raddr net.Addr) (int, error)

func (*SCIONConn) WriteToSCION added in v0.3.0

func (c *SCIONConn) WriteToSCION(b []byte, raddr *Addr) (int, error)

WriteToSCION sends b to raddr.

type SCIONNetwork added in v0.3.0

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

SCION networking context, containing local ISD-AS, SCIOND, Dispatcher and Path resolver.

var (
	// Default SCION networking context for package-level Dial and Listen
	DefNetwork *SCIONNetwork
)

func NewNetwork

func NewNetwork(ia addr.IA, sciondPath string, dispatcherPath string) (*SCIONNetwork, error)

NewNetwork creates a new networking context, on which future Dial or Listen calls can be made. The new connections use the SCIOND server at sciondPath, the dispatcher at dispatcherPath, and ia for the local ISD-AS.

If sciondPath is the empty string, the network will run without SCIOND. In this mode of operation, the app is fully responsible with supplying paths for sent traffic.

func NewNetworkWithPR

func NewNetworkWithPR(ia addr.IA, dispatcherPath string, pr *pathmgr.PR) *SCIONNetwork

NewNetworkWithPR creates a new networking context with path resolver pr. A nil path resolver means the Network will run without SCIOND.

func (*SCIONNetwork) DialSCION added in v0.3.0

func (n *SCIONNetwork) DialSCION(network string, laddr, raddr *Addr,
	timeout time.Duration) (Conn, error)

DialSCION returns a SCION connection to raddr. Nil values for laddr are not supported yet. Parameter network must be "udp4". The returned connection's Read and Write methods can be used to receive and send SCION packets.

A timeout of 0 means infinite timeout.

func (*SCIONNetwork) DialSCIONWithBindSVC added in v0.3.0

func (n *SCIONNetwork) DialSCIONWithBindSVC(network string, laddr, raddr, baddr *Addr,
	svc addr.HostSVC, timeout time.Duration) (Conn, error)

DialSCIONWithBindSVC returns a SCION connection to raddr. Nil values for laddr are not supported yet. Parameter network must be "udp4". The returned connection's Read and Write methods can be used to receive and send SCION packets.

A timeout of 0 means infinite timeout.

func (*SCIONNetwork) IA added in v0.3.0

func (n *SCIONNetwork) IA() addr.IA

IA returns the ISD-AS assigned to n

func (*SCIONNetwork) ListenSCION added in v0.3.0

func (n *SCIONNetwork) ListenSCION(network string, laddr *Addr,
	timeout time.Duration) (Conn, error)

ListenSCION registers laddr with the dispatcher. Nil values for laddr are not supported yet. The returned connection's ReadFrom and WriteTo methods can be used to receive and send SCION packets with per-packet addressing. Parameter network must be "udp4".

A timeout of 0 means infinite timeout.

func (*SCIONNetwork) ListenSCIONWithBindSVC added in v0.3.0

func (n *SCIONNetwork) ListenSCIONWithBindSVC(network string, laddr, baddr *Addr,
	svc addr.HostSVC, timeout time.Duration) (Conn, error)

ListenSCIONWithBindSVC registers laddr with the dispatcher. Nil values for laddr are not supported yet. The returned connection's ReadFrom and WriteTo methods can be used to receive and send SCION packets with per-packet addressing. Parameter network must be "udp4".

A timeout of 0 means infinite timeout.

func (*SCIONNetwork) PathResolver added in v0.3.0

func (n *SCIONNetwork) PathResolver() *pathmgr.PR

PathResolver returns the pathmgr.PR that the network is using.

func (*SCIONNetwork) Sciond added in v0.3.0

func (n *SCIONNetwork) Sciond() sciond.Service

Sciond returns the sciond.Service that the network is using.

Directories

Path Synopsis
package rpt (Reliable Packet Transport) implements a simple packet-oriented protocol with ACKs on top of net.PacketConn.
package rpt (Reliable Packet Transport) implements a simple packet-oriented protocol with ACKs on top of net.PacketConn.
Package snetproxy implements transparent logic for reconnecting to the dispatcher.
Package snetproxy implements transparent logic for reconnecting to the dispatcher.
QUIC/SCION implementation.
QUIC/SCION implementation.

Jump to

Keyboard shortcuts

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