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 ¶
- Variables
- func InstallKey(token string) []byte
- type Client
- func (c *Client) Close() error
- func (c *Client) LastCloseStatus() (websocket.StatusCode, bool)
- func (c *Client) Receive(timeout time.Duration) (protocol.Envelope, error)
- func (c *Client) ReceiveBytes(timeout time.Duration) ([]byte, error)
- func (c *Client) Send(env protocol.Envelope) error
- func (c *Client) SendBytes(data []byte) error
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
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 ¶
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 ¶
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
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.