ship

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ShipRoleServer shipRole = "server"
	ShipRoleClient shipRole = "client"
)

Variables

This section is empty.

Functions

func JsonFromEEBUSJson

func JsonFromEEBUSJson(data []byte) []byte

convert incoming EEBUS json format into standard json format

func JsonIntoEEBUSJson

func JsonIntoEEBUSJson(data []byte) (string, error)

convert json into the EEBUS json format

Types

type ShipConnection

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

A ShipConnection handles the data connection and coordinates SHIP and SPINE messages i/o

func NewConnectionHandler

func NewConnectionHandler(
	dataProvider api.ShipConnectionInfoProviderInterface,
	dataHandler api.WebsocketDataWriterInterface,
	role shipRole,
	localShipID,
	remoteSki,
	remoteShipId string) *ShipConnection

NewConnectionHandler creates a new SHIP connection handler

func (*ShipConnection) AbortIfPending added in v0.7.0

func (c *ShipConnection) AbortIfPending() bool

AbortIfPending atomically aborts the handshake if in pending or ready state Returns true if the abort was successful, false otherwise

This method accepts both SmeHelloStatePendingListen and SmeHelloStateReadyListen states because the handshake can be aborted at any point before reaching SmeHelloStateOk. The ReadyListen state is included to handle the case where an approve operation transitions the state from PendingListen through ReadyInit to ReadyListen, but the handshake should still be abortable until fully complete.

Similar to ApproveIfPending, this method prevents race conditions during concurrent handshake operations by atomically checking and updating the state.

func (*ShipConnection) AbortPendingHandshake

func (c *ShipConnection) AbortPendingHandshake()

AbortPendingHandshake invoked when pairing for a pending request is denied

func (*ShipConnection) ApproveIfPending added in v0.7.0

func (c *ShipConnection) ApproveIfPending() bool

ApproveIfPending atomically approves the handshake if in pending state Returns true if the approval was successful, false otherwise

This method addresses a race condition where concurrent approve/abort operations could result in inconsistent state. The previous implementation had a time-of-check-time-of-use (TOCTOU) bug where the state was read without holding the lock, then actions were taken based on that potentially stale state.

The atomic implementation ensures that the state check and update happen together while holding the lock, preventing race conditions.

func (*ShipConnection) ApprovePendingHandshake

func (c *ShipConnection) ApprovePendingHandshake()

ApprovePendingHandshake invoked when pairing for a pending request is approved

func (*ShipConnection) CloseConnection

func (c *ShipConnection) CloseConnection(safe bool, code int, reason string)

CloseConnection closes this ship connection

func (*ShipConnection) DataHandler

DataHandler returns the WebSocket data writer

func (*ShipConnection) HandleIncomingWebsocketMessage

func (c *ShipConnection) HandleIncomingWebsocketMessage(message []byte)

HandleIncomingWebsocketMessage routes the incoming message to either SHIP or SPINE message handlers

func (*ShipConnection) RemoteSKI

func (c *ShipConnection) RemoteSKI() string

RemoteSKI returns the remote SKI

func (*ShipConnection) ReportConnectionError

func (c *ShipConnection) ReportConnectionError(err error)

ReportConnectionError handles WebSocket connection errors from remote

func (*ShipConnection) Run

func (c *ShipConnection) Run()

Run starts SHIP communication

func (*ShipConnection) ShipHandshakeState

func (c *ShipConnection) ShipHandshakeState() (model.ShipMessageExchangeState, error)

ShipHandshakeState provides the current ship state and error value if the state is in error

func (*ShipConnection) WriteShipMessageWithPayload

func (c *ShipConnection) WriteShipMessageWithPayload(message []byte)

WriteShipMessageWithPayload sends a SPINE message via SHIP protocol

type ShipRole added in v0.7.0

type ShipRole = shipRole

ShipRole is the exported name of the connection role type, so callers can hold a role in a variable (e.g. to defer starting a connection) instead of only passing the constants through directly.

Jump to

Keyboard shortcuts

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