Documentation
¶
Index ¶
- Constants
- func JsonFromEEBUSJson(data []byte) []byte
- func JsonIntoEEBUSJson(data []byte) (string, error)
- type ShipConnection
- func (c *ShipConnection) AbortIfPending() bool
- func (c *ShipConnection) AbortPendingHandshake()
- func (c *ShipConnection) ApproveIfPending() bool
- func (c *ShipConnection) ApprovePendingHandshake()
- func (c *ShipConnection) CloseConnection(safe bool, code int, reason string)
- func (c *ShipConnection) DataHandler() api.WebsocketDataWriterInterface
- func (c *ShipConnection) HandleIncomingWebsocketMessage(message []byte)
- func (c *ShipConnection) RemoteSKI() string
- func (c *ShipConnection) ReportConnectionError(err error)
- func (c *ShipConnection) Run()
- func (c *ShipConnection) ShipHandshakeState() (model.ShipMessageExchangeState, error)
- func (c *ShipConnection) WriteShipMessageWithPayload(message []byte)
- type ShipRole
Constants ¶
const ( ShipRoleServer shipRole = "server" ShipRoleClient shipRole = "client" )
Variables ¶
This section is empty.
Functions ¶
func JsonFromEEBUSJson ¶
convert incoming EEBUS json format into standard json format
func JsonIntoEEBUSJson ¶
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 ¶
func (c *ShipConnection) DataHandler() api.WebsocketDataWriterInterface
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) 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