ships

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2020 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

type Builder

type Builder struct {
	LaunchShip    func(ctx context.Context, transport *hub.Transport, ip net.IP) (Ship, error)
	EstablishPier func(ctx context.Context, transport *hub.Transport, dockingRequests chan *DockingRequest) (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 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

	// Docking is the blocking (!) procedure that docks new ships and sends docking requests. This should be run as a worker by the caller.
	Docking(ctx context.Context) error

	// Addr returns the underlying network address used by the listener.
	Addr() net.Addr

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

Pier represents a network connection listener.

func EstablishPier

func EstablishPier(ctx context.Context, transport *hub.Transport, dockingRequests chan *DockingRequest) (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) Addr

func (pier *PierBase) Addr() net.Addr

Addr returns the underlying network address used by the listener.

func (*PierBase) Docking

func (pier *PierBase) Docking(ctx context.Context) error

Docking is the blocking (!) procedure that docks new ships and sends docking requests. This should be run as a worker by the caller.

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

	// Load loads data into the ship - ie. sends the data via the connection. It returns the amount of data written, a boolean if everything is ok and an optional error if something is not okay and needs to be reported. If ok is false, stop using the ship.
	Load(data []byte) (ok bool, 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, a boolean if everything is ok and an optional error if something is not okay and needs to be reported. If ok is false, stop using the ship.
	UnloadTo(buf []byte) (n int, ok bool, 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()
}

Ship represents a network layer connection.

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) Load

func (ship *ShipBase) Load(data []byte) (ok bool, err error)

Load loads data into the ship - ie. sends the data via the connection. It returns the amount of data written, a boolean if everything is ok and an optional error if something is not okay and needs to be reported. If ok is false, stop using the ship.

func (*ShipBase) LocalAddr

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

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

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, ok bool, 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, a boolean if everything is ok and an optional error if something is not okay and needs to be reported. If ok is false, stop using the ship.

type TCPPier

type TCPPier struct {
	PierBase
}

TCPPier is a pier that uses TCP.

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() *TestShip

NewTestShip returns a new TestShip for simulation.

func (*TestShip) IsMine

func (d *TestShip) IsMine() bool

IsMine returns whether the ship was launched from here.

func (*TestShip) Load

func (d *TestShip) Load(data []byte) (ok bool, err error)

Load loads data into the ship - ie. sends the data via the connection. It returns the amount of data written, a boolean if everything is ok and an optional error if something is not okay and needs to be reported. If ok is false, stop using the ship.

func (*TestShip) LocalAddr

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

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

func (*TestShip) RemoteAddr

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

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

func (*TestShip) Reverse

func (d *TestShip) Reverse() *TestShip

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

func (*TestShip) Sink

func (d *TestShip) Sink()

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

func (*TestShip) String

func (d *TestShip) String() string

String returns a human readable informational summary about the ship.

func (*TestShip) Transport

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

Transport returns the transport used for this ship.

func (*TestShip) UnloadTo

func (d *TestShip) UnloadTo(buf []byte) (n int, ok bool, 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, a boolean if everything is ok and an optional error if something is not okay and needs to be reported. If ok is false, stop using the ship.

Jump to

Keyboard shortcuts

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