fakephone

package
v0.40.4 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 10 Imported by: 0 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

Overview

Package fakephone is an in-process WebSocket client that speaks the phone half of the mobile↔relay protocol (docs/protocol-mobile.md § Authentication, § Message envelope). It exists so daemon-side e2e tests can script the appendix flow as if a phone were connected, without depending on a real device or platform stack.

The package lives under internal/e2e/internal/ to visibility-fence it from non-e2e callers. It is the sibling of fakerelay: the relay owns the routing-envelope wrap/unwrap, so this client speaks raw protocol.Envelope JSON.

Surface

One Client type, four methods (Dial, Send, Receive, Close) and two sentinel errors (ErrReceiveTimeout, ErrClosed). The harness is synchronous: each method blocks on its own I/O. No reconnect, no ping pump, no hello/hello_ack handling — those are envelope-sequencing concerns owned by the consumer test.

Concurrency

  • One goroutine may call Send and one (possibly the same) may call Receive; coder/websocket permits one concurrent reader plus one concurrent writer.
  • Close is safe to call from any goroutine and unblocks an in-flight Receive with ErrClosed.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrReceiveTimeout = errors.New("fakephone: receive timeout")
	ErrClosed         = errors.New("fakephone: client closed")
)

Sentinel errors. Both are matchable via errors.Is.

Functions

func InstallKey added in v0.31.0

func InstallKey(token string) []byte

InstallKey returns the Noise static private key of the one app install that holds token. Since #2734 the daemon binds a pairing to the static key of its first accepted connection and refuses the same token from any other key, so a test that reconnects, or opens a second connection with one token, must present the same key each time — as a real phone does, keeping one keypair per paired daemon. Deriving it from the token gives every helper in every package that key without threading it through. Any 32 bytes are a valid X25519 scalar.

Types

type Client

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

Client is a WS client wired to the fake-relay's /v1/client endpoint. Construct with Dial; tear down with Close.

func Dial

func Dial(ctx context.Context, baseURL, serverID, token, deviceName string) (*Client, error)

Dial opens /v1/client at baseURL with the three required headers set verbatim from the arguments. baseURL is the bare ws://host:port form (e.g. as returned by fakerelay.Server.URL()); Dial appends the path.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the WS connection cleanly. Idempotent. After Close, every Send and Receive returns ErrClosed.

func (*Client) LastCloseStatus

func (c *Client) LastCloseStatus() (websocket.StatusCode, bool)

LastCloseStatus returns the WS close status code observed by the most recent Receive call that failed with a CloseError. ok is false when no such close has been observed yet (e.g. the conn is still open, or was closed locally via Close()).

func (*Client) Receive

func (c *Client) Receive(timeout time.Duration) (protocol.Envelope, error)

Receive reads one WS text frame and unmarshals it into a protocol.Envelope. On deadline expiry returns ErrReceiveTimeout; note that coder/websocket closes the underlying connection when the Read context is canceled, so a timed-out Client cannot be reused. After Close, returns ErrClosed.

func (*Client) ReceiveBytes added in v0.14.0

func (c *Client) ReceiveBytes(timeout time.Duration) ([]byte, error)

ReceiveBytes reads one WS text frame and returns the raw payload. Same timeout / close semantics as Receive. Used by v2 e2e tests where the wire shape inside RoutingEnvelope.Frame is an InnerFrameV2 rather than a protocol.Envelope.

func (*Client) Send

func (c *Client) Send(env protocol.Envelope) error

Send marshals env and writes it as a single WS text frame.

func (*Client) SendBytes added in v0.14.0

func (c *Client) SendBytes(data []byte) error

SendBytes writes data as a single WS text frame without any marshalling. Used by v2 e2e tests where the wire shape inside RoutingEnvelope.Frame is an InnerFrameV2 rather than a protocol.Envelope.

Jump to

Keyboard shortcuts

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