websocket

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigID = ControllerID

ConfigID is the string used to identify this config object.

View Source
const ControllerID = "bifrost/websocket"

ControllerID is the WebSocket controller ID.

View Source
const PeerPathSuffix = "/peer"

PeerPathSuffix is the path suffix to use for the peer id.

View Source
const TransportType = "ws"

TransportType is the transport type identifier for this transport.

Variables

View Source
var Version = semver.MustParse("0.0.1")

Version is the version of the implementation.

Functions

This section is empty.

Types

type Config

type Config struct {

	// TransportPeerID sets the peer ID to attach the transport to.
	// If unset, attaches to any running peer with a private key.
	TransportPeerId string `protobuf:"bytes,1,opt,name=transport_peer_id,json=transportPeerId,proto3" json:"transportPeerId,omitempty"`
	// ListenAddr contains the address to listen on.
	// Has no effect in the browser.
	ListenAddr string `protobuf:"bytes,2,opt,name=listen_addr,json=listenAddr,proto3" json:"listenAddr,omitempty"`
	// Quic contains the quic protocol options.
	//
	// The WebSocket transport always disables FEC and several other UDP-centric
	// features which are unnecessary due to the "reliable" nature of WebSockets.
	Quic *quic.Opts `protobuf:"bytes,3,opt,name=quic,proto3" json:"quic,omitempty"`
	// Dialers maps peer IDs to dialers.
	Dialers map[string]*dialer.DialerOpts `` /* 155-byte string literal not displayed */
	// HttpPath is the http path to expose the websocket.
	// If unset, ignores the incoming request path.
	HttpPath string `protobuf:"bytes,5,opt,name=http_path,json=httpPath,proto3" json:"httpPath,omitempty"`
	// DisableServePeerId disables serving the peer id.
	// If this is unset the peer ID is available at http_path+"/peer"
	// If http_path is unset the peer ID is available at /peer
	DisableServePeerId bool `protobuf:"varint,6,opt,name=disable_serve_peer_id,json=disableServePeerId,proto3" json:"disableServePeerId,omitempty"`
	// contains filtered or unexported fields
}

Config is the configuration for the Websocket transport.

Bifrost speaks Quic over the websocket. While this is not always necessary, especially when using wss transports, we still need to ensure end-to-end encryption to the peer that we handshake with on the other end, and to manage stream congestion control, multiplexing,

func (*Config) CloneMessageVT added in v0.15.6

func (m *Config) CloneMessageVT() protobuf_go_lite.CloneMessage

func (*Config) CloneVT added in v0.8.3

func (m *Config) CloneVT() *Config

func (*Config) EqualMessageVT added in v0.15.6

func (this *Config) EqualMessageVT(thatMsg any) bool

func (*Config) EqualVT added in v0.3.0

func (this *Config) EqualVT(that *Config) bool

func (*Config) EqualsConfig

func (c *Config) EqualsConfig(c2 config.Config) bool

EqualsConfig checks if the other config is equal.

func (*Config) GetConfigID

func (c *Config) GetConfigID() string

GetConfigID returns the unique string for this configuration type. This string is stored with the encoded config.

func (*Config) GetDebugVals

func (c *Config) GetDebugVals() config.DebugValues

GetDebugVals returns the directive arguments as key/value pairs. This should be something like param1="test", param2="test". This is not necessarily unique, and is primarily intended for display.

func (*Config) GetDialers

func (x *Config) GetDialers() map[string]*dialer.DialerOpts

func (*Config) GetDisableServePeerId added in v0.27.0

func (x *Config) GetDisableServePeerId() bool

func (*Config) GetHttpPath added in v0.23.9

func (x *Config) GetHttpPath() string

func (*Config) GetListenAddr

func (x *Config) GetListenAddr() string

func (*Config) GetQuic

func (x *Config) GetQuic() *quic.Opts

func (*Config) GetTransportPeerId

func (x *Config) GetTransportPeerId() string

func (*Config) MarshalJSON added in v0.29.0

func (x *Config) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Config to JSON.

func (*Config) MarshalProtoJSON added in v0.29.0

func (x *Config) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the Config message to JSON.

func (*Config) MarshalProtoText added in v0.29.2

func (x *Config) MarshalProtoText() string

func (*Config) MarshalToSizedBufferVT added in v0.2.0

func (m *Config) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*Config) MarshalToVT added in v0.2.0

func (m *Config) MarshalToVT(dAtA []byte) (int, error)

func (*Config) MarshalVT added in v0.2.0

func (m *Config) MarshalVT() (dAtA []byte, err error)

func (*Config) ParseTransportPeerID added in v0.20.0

func (c *Config) ParseTransportPeerID() (peer.ID, error)

ParseTransportPeerID parses the node peer ID if it is not empty.

func (*Config) ProtoMessage

func (*Config) ProtoMessage()

func (*Config) Reset

func (x *Config) Reset()

func (*Config) SetTransportPeerId

func (c *Config) SetTransportPeerId(peerID string)

SetTransportPeerId sets the node peer ID field.

func (*Config) SizeVT added in v0.2.0

func (m *Config) SizeVT() (n int)

func (*Config) String

func (x *Config) String() string

func (*Config) UnmarshalJSON added in v0.29.0

func (x *Config) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the Config from JSON.

func (*Config) UnmarshalProtoJSON added in v0.29.0

func (x *Config) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the Config message from JSON.

func (*Config) UnmarshalVT added in v0.2.0

func (m *Config) UnmarshalVT(dAtA []byte) error

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration. This is a cursory validation to see if the values "look correct."

type Config_DialersEntry added in v0.29.0

type Config_DialersEntry struct {
	Key   string             `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Value *dialer.DialerOpts `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

func (*Config_DialersEntry) GetKey added in v0.29.0

func (x *Config_DialersEntry) GetKey() string

func (*Config_DialersEntry) GetValue added in v0.29.0

func (x *Config_DialersEntry) GetValue() *dialer.DialerOpts

func (*Config_DialersEntry) MarshalJSON added in v0.29.0

func (x *Config_DialersEntry) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Config_DialersEntry to JSON.

func (*Config_DialersEntry) MarshalProtoJSON added in v0.29.0

func (x *Config_DialersEntry) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the Config_DialersEntry message to JSON.

func (*Config_DialersEntry) MarshalProtoText added in v0.29.2

func (x *Config_DialersEntry) MarshalProtoText() string

func (*Config_DialersEntry) ProtoMessage added in v0.29.0

func (*Config_DialersEntry) ProtoMessage()

func (*Config_DialersEntry) Reset added in v0.29.0

func (x *Config_DialersEntry) Reset()

func (*Config_DialersEntry) String added in v0.29.2

func (x *Config_DialersEntry) String() string

func (*Config_DialersEntry) UnmarshalJSON added in v0.29.0

func (x *Config_DialersEntry) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the Config_DialersEntry from JSON.

func (*Config_DialersEntry) UnmarshalProtoJSON added in v0.29.0

func (x *Config_DialersEntry) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the Config_DialersEntry message from JSON.

type Factory

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

Factory constructs a WebSocket transport.

func NewFactory

func NewFactory(bus bus.Bus) *Factory

NewFactory builds a transport factory.

func (*Factory) Construct

func (t *Factory) Construct(
	ctx context.Context,
	conf config.Config,
	opts controller.ConstructOpts,
) (controller.Controller, error)

Construct constructs the associated controller given configuration.

func (*Factory) ConstructConfig

func (t *Factory) ConstructConfig() config.Config

ConstructConfig constructs an instance of the controller configuration.

func (*Factory) GetConfigID

func (t *Factory) GetConfigID() string

GetConfigID returns the configuration ID for the controller.

func (*Factory) GetControllerID

func (t *Factory) GetControllerID() string

GetControllerID returns the unique ID for the controller.

func (*Factory) GetVersion

func (t *Factory) GetVersion() semver.Version

GetVersion returns the version of this controller.

type Link = conn.Link

Link represents a WebSocket-based connection/link.

type PacketConn

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

PacketConn implements the PacketConn interface with a websocket.

func NewPacketConn

func NewPacketConn(ctx context.Context, ws *websocket.Conn, laddr, raddr net.Addr) *PacketConn

NewPacketConn constructs a new packet conn from a WebSocket conn.

func (*PacketConn) Close

func (c *PacketConn) Close() error

Close closes the connection.

func (*PacketConn) LocalAddr

func (c *PacketConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*PacketConn) ReadFrom

func (c *PacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)

ReadFrom reads a packet from the connection.

func (*PacketConn) ReadMessage

func (c *PacketConn) ReadMessage() ([]byte, error)

ReadMessage reads a single message from the connection.

func (*PacketConn) SetDeadline

func (c *PacketConn) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.

A deadline is an absolute time after which I/O operations fail instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to Read or Write. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future.

If the deadline is exceeded a call to Read or Write or to other I/O methods will return an error that wraps os.ErrDeadlineExceeded. This can be tested using errors.Is(err, os.ErrDeadlineExceeded). The error's Timeout method will return true, but note that there are other possible errors for which the Timeout method will return true even if the deadline has not been exceeded.

An idle timeout can be implemented by repeatedly extending the deadline after successful ReadFrom or WriteTo calls.

A zero value for t means I/O operations will not time out.

func (*PacketConn) SetReadDeadline

func (c *PacketConn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future ReadFrom calls and any currently-blocked ReadFrom call. A zero value for t means ReadFrom will not time out.

func (*PacketConn) SetWriteDeadline

func (c *PacketConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future WriteTo calls and any currently-blocked WriteTo call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means WriteTo will not time out.

func (*PacketConn) WriteMessage

func (c *PacketConn) WriteMessage(msg []byte) error

WriteMessage writes a single message to the connection.

func (*PacketConn) WriteTo

func (c *PacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error)

WriteTo writes a packet with payload p to addr. WriteTo can be made to time out and return an Error after a fixed time limit; see SetDeadline and SetWriteDeadline. On packet-oriented connections, write timeouts are rare.

type WebSocket

type WebSocket struct {
	// Transport implements the quic-backed transport type
	*transport_quic.Transport
	// contains filtered or unexported fields
}

WebSocket implements a WebSocket transport.

func NewWebSocket

func NewWebSocket(
	ctx context.Context,
	le *logrus.Entry,
	conf *Config,
	pKey crypto.PrivKey,
	c transport.TransportHandler,
) (*WebSocket, error)

NewWebSocket builds a new WebSocket transport.

ServeHTTP is implemented and can be used with a standard HTTP mux. Optionally listens on an address.

func (*WebSocket) Execute

func (w *WebSocket) Execute(ctx context.Context) error

Execute executes the transport as configured, returning any fatal error.

func (*WebSocket) GetPeerDialer added in v0.21.0

func (w *WebSocket) GetPeerDialer(ctx context.Context, peerID peer.ID) (*dialer.DialerOpts, error)

GetPeerDialer returns the dialing information for a peer. Called when resolving EstablishLink. Return nil, nil to indicate not found or unavailable.

func (*WebSocket) ListenHTTP

func (w *WebSocket) ListenHTTP(ctx context.Context, addr string) error

ListenHTTP listens for incoming HTTP connections on an address.

func (*WebSocket) MatchTransportType added in v0.14.1

func (w *WebSocket) MatchTransportType(transportType string) bool

MatchTransportType checks if the given transport type ID matches this transport. If returns true, the transport controller will call DialPeer with that tptaddr. E.x.: "udp-quic" or "ws"

func (*WebSocket) ServeHTTP

func (w *WebSocket) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP serves the websocket upgraded HTTP endpoint.

Jump to

Keyboard shortcuts

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