ships

package
v1.6.14 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseMTU           = 1460 // 1500 with 40 bytes extra space for special cases.
	IPv4HeaderMTUSize = 20   // Without options, as not common.
	IPv6HeaderMTUSize = 40   // Without options, as not common.
	TCPHeaderMTUSize  = 60   // Maximum size with options.
	UDPHeaderMTUSize  = 8    // Has no options.
)

MTU Calculation Configuration.

Variables

View Source
var (

	// DisplayHubID holds the Hub ID for displaying it on the info page.
	DisplayHubID string
)
View Source
var ErrSunk = errors.New("ship sunk")

ErrSunk is returned when a ship sunk, ie. the connection was lost.

Functions

func EnableMasking

func EnableMasking(salt []byte)

EnableMasking enables masking with the given salt.

func GetVirtualNetworkAddress

func GetVirtualNetworkAddress(dstHubID string) net.IP

GetVirtualNetworkAddress returns the virtual network IP for the given Hub.

func GetVirtualNetworkConfig

func GetVirtualNetworkConfig() *hub.VirtualNetworkConfig

GetVirtualNetworkConfig returns the virtual networking config.

func Protocols

func Protocols() []string

Protocols returns a slice with all registered protocol names. The return slice must not be edited.

func Register

func Register(protocol string, builder *Builder)

Register registers a new builder for a protocol.

func ServeInfoPage

func ServeInfoPage(w http.ResponseWriter, r *http.Request)

ServeInfoPage serves the info page for the given request.

func SetVirtualNetworkConfig

func SetVirtualNetworkConfig(config *hub.VirtualNetworkConfig)

SetVirtualNetworkConfig sets the virtual networking config.

Types

type Builder

type Builder struct {
	LaunchShip    func(ctx context.Context, transport *hub.Transport, ip net.IP) (Ship, error)
	EstablishPier func(transport *hub.Transport, dockingRequests chan Ship) (Pier, error)
}

Builder is a factory that can build ships and piers of it's protocol.

func GetBuilder

func GetBuilder(protocol string) *Builder

GetBuilder returns the builder for the given protocol, or nil if it does not exist.

type DockingRequest

type DockingRequest struct {
	Pier Pier
	Ship Ship
	Err  error
}

DockingRequest is a uniform request that Piers emit when a new ship arrives.

type HTTPPier

type HTTPPier struct {
	PierBase
	// contains filtered or unexported fields
}

HTTPPier is a pier that uses HTTP.

func (*HTTPPier) Abolish

func (pier *HTTPPier) Abolish()

Abolish closes the underlying listener and cleans up any related resources.

func (*HTTPPier) ServeHTTP

func (pier *HTTPPier) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HTTPShip

type HTTPShip struct {
	ShipBase
}

HTTPShip is a ship that uses HTTP.

type KCPPier

type KCPPier struct {
	PierBase
}

KCPPier is a pier that uses KCP.

type KCPShip

type KCPShip struct {
	ShipBase
}

KCPShip is a ship that uses KCP.

type Pier

type Pier interface {
	// String returns a human readable informational summary about the ship.
	String() string

	// Transport returns the transport used for this ship.
	Transport() *hub.Transport

	// Abolish closes the underlying listener and cleans up any related resources.
	Abolish()
}

Pier represents a network connection listener.

func EstablishPier

func EstablishPier(transport *hub.Transport, dockingRequests chan Ship) (Pier, error)

EstablishPier is shorthand function to get the transport's builder and establish a pier.

type PierBase

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

PierBase implements common functions to comply with the Pier interface.

func (*PierBase) Abolish

func (pier *PierBase) Abolish()

Abolish closes the underlying listener and cleans up any related resources.

func (*PierBase) String

func (pier *PierBase) String() string

String returns a human readable informational summary about the ship.

func (*PierBase) Transport

func (pier *PierBase) Transport() *hub.Transport

Transport returns the transport used for this ship.

type Ship

type Ship interface {
	// String returns a human readable informational summary about the ship.
	String() string

	// Transport returns the transport used for this ship.
	Transport() *hub.Transport

	// IsMine returns whether the ship was launched from here.
	IsMine() bool

	// IsSecure returns whether the ship provides transport security.
	IsSecure() bool

	// Public returns whether the ship is marked as public.
	Public() bool

	// MarkPublic marks the ship as public.
	MarkPublic()

	// LoadSize returns the recommended data size that should be handed to Load().
	// This value will be most likely somehow related to the connection's MTU.
	// Alternatively, using a multiple of LoadSize is also recommended.
	LoadSize() int

	// Load loads data into the ship - ie. sends the data via the connection.
	// Returns ErrSunk if the ship has already sunk earlier.
	Load(data []byte) error

	// UnloadTo unloads data from the ship - ie. receives data from the
	// connection - puts it into the buf. It returns the amount of data
	// written and an optional error.
	// Returns ErrSunk if the ship has already sunk earlier.
	UnloadTo(buf []byte) (n int, err error)

	// LocalAddr returns the underlying local net.Addr of the connection.
	LocalAddr() net.Addr

	// RemoteAddr returns the underlying remote net.Addr of the connection.
	RemoteAddr() net.Addr

	// Sink closes the underlying connection and cleans up any related resources.
	Sink()

	// MaskAddress masks the address, if enabled.
	MaskAddress(addr net.Addr) string
	// MaskIP masks an IP, if enabled.
	MaskIP(ip net.IP) string
	// Mask masks a value.
	Mask(value []byte) string
}

Ship represents a network layer connection.

func Launch

func Launch(ctx context.Context, h *hub.Hub, transport *hub.Transport, ip net.IP) (Ship, error)

Launch launches a new ship to the given Hub.

type ShipBase

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

ShipBase implements common functions to comply with the Ship interface.

func (*ShipBase) IsMine

func (ship *ShipBase) IsMine() bool

IsMine returns whether the ship was launched from here.

func (*ShipBase) IsSecure

func (ship *ShipBase) IsSecure() bool

IsSecure returns whether the ship provides transport security.

func (*ShipBase) Load

func (ship *ShipBase) Load(data []byte) error

Load loads data into the ship - ie. sends the data via the connection. Returns ErrSunk if the ship has already sunk earlier.

func (*ShipBase) LoadSize

func (ship *ShipBase) LoadSize() int

LoadSize returns the recommended data size that should be handed to Load(). This value will be most likely somehow related to the connection's MTU. Alternatively, using a multiple of LoadSize is also recommended.

func (*ShipBase) LocalAddr

func (ship *ShipBase) LocalAddr() net.Addr

LocalAddr returns the underlying local net.Addr of the connection.

func (*ShipBase) MarkPublic

func (ship *ShipBase) MarkPublic()

MarkPublic marks the ship as public.

func (*ShipBase) Mask

func (ship *ShipBase) Mask(value []byte) string

Mask masks the given value.

func (*ShipBase) MaskAddress

func (ship *ShipBase) MaskAddress(addr net.Addr) string

MaskAddress masks the given address if masking is enabled and the ship is not public.

func (*ShipBase) MaskIP

func (ship *ShipBase) MaskIP(ip net.IP) string

MaskIP masks the given IP if masking is enabled and the ship is not public.

func (*ShipBase) Public

func (ship *ShipBase) Public() bool

Public returns whether the ship is marked as public.

func (*ShipBase) RemoteAddr

func (ship *ShipBase) RemoteAddr() net.Addr

RemoteAddr returns the underlying remote net.Addr of the connection.

func (*ShipBase) Sink

func (ship *ShipBase) Sink()

Sink closes the underlying connection and cleans up any related resources.

func (*ShipBase) String

func (ship *ShipBase) String() string

String returns a human readable informational summary about the ship.

func (*ShipBase) Transport

func (ship *ShipBase) Transport() *hub.Transport

Transport returns the transport used for this ship.

func (*ShipBase) UnloadTo

func (ship *ShipBase) UnloadTo(buf []byte) (n int, err error)

UnloadTo unloads data from the ship - ie. receives data from the connection - puts it into the buf. It returns the amount of data written and an optional error. Returns ErrSunk if the ship has already sunk earlier.

type TCPPier

type TCPPier struct {
	PierBase
	// contains filtered or unexported fields
}

TCPPier is a pier that uses TCP.

func (*TCPPier) Abolish

func (pier *TCPPier) Abolish()

Abolish closes the underlying listener and cleans up any related resources.

type TCPShip

type TCPShip struct {
	ShipBase
}

TCPShip is a ship that uses TCP.

type TestShip

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

TestShip is a simulated ship that is used for testing higher level components.

func NewTestShip

func NewTestShip(secure bool, loadSize int) *TestShip

NewTestShip returns a new TestShip for simulation.

func (*TestShip) IsMine

func (ship *TestShip) IsMine() bool

IsMine returns whether the ship was launched from here.

func (*TestShip) IsSecure

func (ship *TestShip) IsSecure() bool

IsSecure returns whether the ship provides transport security.

func (*TestShip) Load

func (ship *TestShip) Load(data []byte) error

Load loads data into the ship - ie. sends the data via the connection. Returns ErrSunk if the ship has already sunk earlier.

func (*TestShip) LoadSize

func (ship *TestShip) LoadSize() int

LoadSize returns the recommended data size that should be handed to Load(). This value will be most likely somehow related to the connection's MTU. Alternatively, using a multiple of LoadSize is also recommended.

func (*TestShip) LocalAddr

func (ship *TestShip) LocalAddr() net.Addr

func (*TestShip) MarkPublic

func (ship *TestShip) MarkPublic()

func (*TestShip) Mask

func (ship *TestShip) Mask(value []byte) string

func (*TestShip) MaskAddress

func (ship *TestShip) MaskAddress(addr net.Addr) string

func (*TestShip) MaskIP

func (ship *TestShip) MaskIP(ip net.IP) string

func (*TestShip) Public

func (ship *TestShip) Public() bool

func (*TestShip) RemoteAddr

func (ship *TestShip) RemoteAddr() net.Addr

func (*TestShip) Reverse

func (ship *TestShip) Reverse() *TestShip

Reverse creates a connected TestShip. This is used to simulate a connection instead of using a Pier.

func (*TestShip) Sink

func (ship *TestShip) Sink()

Sink closes the underlying connection and cleans up any related resources.

func (*TestShip) String

func (ship *TestShip) String() string

String returns a human readable informational summary about the ship.

func (*TestShip) Transport

func (ship *TestShip) Transport() *hub.Transport

Transport returns the transport used for this ship.

func (*TestShip) UnloadTo

func (ship *TestShip) UnloadTo(buf []byte) (n int, err error)

UnloadTo unloads data from the ship - ie. receives data from the connection - puts it into the buf. It returns the amount of data written and an optional error. Returns ErrSunk if the ship has already sunk earlier.

Jump to

Keyboard shortcuts

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