Documentation ¶
Index ¶
- Constants
- Variables
- func EnableMasking(salt []byte)
- func Protocols() []string
- func Register(protocol string, builder *Builder)
- type Builder
- type DockingRequest
- type KCPPier
- type KCPShip
- type Pier
- type PierBase
- type Ship
- type ShipBase
- func (ship *ShipBase) IsMine() bool
- func (ship *ShipBase) IsSecure() bool
- func (ship *ShipBase) Load(data []byte) error
- func (ship *ShipBase) LoadSize() int
- func (ship *ShipBase) LocalAddr() net.Addr
- func (ship *ShipBase) MarkPublic()
- func (ship *ShipBase) Mask(value []byte) string
- func (ship *ShipBase) MaskAddress(addr net.Addr) string
- func (ship *ShipBase) MaskIP(ip net.IP) string
- func (ship *ShipBase) Public() bool
- func (ship *ShipBase) RemoteAddr() net.Addr
- func (ship *ShipBase) Sink()
- func (ship *ShipBase) String() string
- func (ship *ShipBase) Transport() hub.Transport
- func (ship *ShipBase) UnloadTo(buf []byte) (n int, err error)
- type TCPPier
- type TCPShip
- type TestShip
- func (d *TestShip) IsMine() bool
- func (d *TestShip) IsSecure() bool
- func (ship *TestShip) Load(data []byte) error
- func (d *TestShip) LoadSize() int
- func (d *TestShip) LocalAddr() net.Addr
- func (d *TestShip) MarkPublic()
- func (d *TestShip) Mask(value []byte) string
- func (d *TestShip) MaskAddress(addr net.Addr) string
- func (d *TestShip) MaskIP(ip net.IP) string
- func (d *TestShip) Public() bool
- func (d *TestShip) RemoteAddr() net.Addr
- func (d *TestShip) Reverse() *TestShip
- func (d *TestShip) Sink()
- func (d *TestShip) String() string
- func (d *TestShip) Transport() hub.Transport
- func (ship *TestShip) UnloadTo(buf []byte) (n int, err error)
Constants ¶
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. )
Variables ¶
var (
ErrSunk = errors.New("ship sunk")
)
Functions ¶
func EnableMasking ¶ added in v0.3.0
func EnableMasking(salt []byte)
EnableMasking enables masking with the given salt.
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 *DockingRequest) (Pier, error) }
Builder is a factory that can build ships and piers of it's protocol.
func GetBuilder ¶
GetBuilder returns the builder for the given protocol, or nil if it does not exist.
type DockingRequest ¶
DockingRequest is a uniform request that Piers emit when a new ship arrives.
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(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) Docking ¶
Docking is the blocking (!) procedure that docks new ships and sends docking requests. This should be run as a worker by the caller.
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(addr net.Addr) string MaskIP(ip net.IP) string Mask(value []byte) string }
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) IsSecure ¶ added in v0.3.0
IsSecure returns whether the ship provides transport security.
func (*ShipBase) Load ¶
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 ¶ added in v0.3.0
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) MarkPublic ¶ added in v0.3.0
func (ship *ShipBase) MarkPublic()
MarkPublic marks the ship as public.
func (*ShipBase) MaskAddress ¶ added in v0.3.0
MaskAddress masks the given address if masking is enabled and the ship is not public.
func (*ShipBase) MaskIP ¶ added in v0.3.0
MaskIP masks the given IP if masking is enabled and the ship is not public.
func (*ShipBase) RemoteAddr ¶
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.
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 ¶
NewTestShip returns a new TestShip for simulation.
func (*TestShip) IsSecure ¶ added in v0.3.0
IsSecure returns whether the ship provides transport security.
func (*TestShip) Load ¶
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 ¶ added in v0.3.0
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) MarkPublic ¶ added in v0.3.0
func (d *TestShip) MarkPublic()
func (*TestShip) RemoteAddr ¶
func (*TestShip) Reverse ¶
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.