Documentation
¶
Overview ¶
Package gamelink carries a game's UDP traffic between two PCs over a peer stream. The guest's game connects to a loopback endpoint; the host forwards each admitted guest to its game server with a socket of its own, so the server sees every guest as a separate client. Each stream opens with a handshake that names the server process the guest expects, and game packets flow only once the host accepts it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrGameLeft = errors.New("Left the game")
ErrGameLeft reports that the game stopped sending after the server answered it: the player left the server or quit Deadlock.
var ErrUnanswered = errors.New("The host's game did not answer. Choose Join again.")
ErrUnanswered reports that the game stopped sending before the server ever answered it: the game gave up connecting to a server that never replied.
Functions ¶
func AcceptGeneration ¶
func AcceptGeneration(ctx context.Context, stream io.ReadWriteCloser) error
AcceptGeneration tells the guest that its forwarding socket is in place, so game packets may flow.
func Forward ¶
func Forward(ctx context.Context, target *net.UDPAddr, peer stream.MessageStream, accept func() error) error
Forward forwards an admitted guest's stream to the game server at target until ctx ends or either side stops. It binds the guest a socket of its own, so the server sees it as a separate client and replies cannot cross guests, and calls accept, such as AcceptGeneration, once that socket is bound. It owns peer even when it fails.
func ReadGeneration ¶
ReadGeneration reads the server generation a guest asks for, before any game packets. The caller compares it with the server it runs.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client owns one loopback endpoint until the peer disconnects, the game leaves, or Close returns. It serves one server process and is not reused.
func Dial ¶
func Dial(ctx context.Context, b bus.Bus, protocol protocol.ID, local, host peer.ID, generation uint64) (*Client, error)
Dial opens a game stream of protocol to the host peer and keeps its link until forwarding stops. ctx owns both the dial and the endpoint's lifetime. It returns the endpoint only once the host accepts generation and has reserved the guest's socket.
func Open ¶
Open takes ownership of an admitted game stream and binds the loopback endpoint for it. The caller then points the game at Address; no process is launched.
func (*Client) Arrived ¶
func (c *Client) Arrived() <-chan struct{}
Arrived closes when the server's first packet reaches the game, so the game's own connect attempts alone never count as arrival.
func (*Client) Close ¶
func (c *Client) Close()
Close cancels forwarding and waits for sockets and pumps to close.