Help us shape the future of Go! Take the 2026 Go Developer Survey

peernet

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Overview

Package peernet runs a modlock peer: a PC's key on Spacewave's peer network, which links to other PCs directly when it can and through a relay when it cannot. A signaling service, hyperline.gg by default, introduces two peers that cannot reach each other on their own network. It admits a peer while that peer holds a socket signed by its key and carrying the creator's sign-in, and issues relay credentials to the same sign-in.

Index

Constants

View Source
const AdmitPath = "/api/signal/peer"

AdmitPath is where the service admits a signed-in peer to signaling for as long as its socket stays open.

View Source
const GameProtocolID = protocol.ID("modlock/game/1")

GameProtocolID identifies game streams between modlock peers, which gamelink forwards. The handshake's generation is the hosted session, so only a guest holding the join code reaches the server.

View Source
const ProbeProtocolID = protocol.ID("modlock/probe/1")

ProbeProtocolID identifies probe streams between modlock peers. The stream is an unreliable message stream, like a game's, and the answering peer returns each probe packet to its sender.

View Source
const RelayPath = "/api/turn-credentials"

RelayPath is where the service issues relay credentials to a signed-in creator.

View Source
const SRPCPeerNetServiceID = "modlock.peernet.PeerNet"
View Source
const SigningEnv = "hyperline"

SigningEnv separates the signatures a peer sends hyperline.gg from requests to any other service its key could sign for.

Variables

View Source
var (
	AdmissionState_name = map[int32]string{
		0: "ADMISSION_STATE_SIGNED_OUT",
		1: "ADMISSION_STATE_CONNECTING",
		2: "ADMISSION_STATE_ADMITTED",
		3: "ADMISSION_STATE_REFUSED",
	}
	AdmissionState_value = map[string]int32{
		"ADMISSION_STATE_SIGNED_OUT": 0,
		"ADMISSION_STATE_CONNECTING": 1,
		"ADMISSION_STATE_ADMITTED":   2,
		"ADMISSION_STATE_REFUSED":    3,
	}
)

Enum value maps for AdmissionState.

Functions

func LoadKey

func LoadKey(path string) (crypto.PrivKey, error)

LoadKey reads the peer key at path, creating it on first use. Only one process may call it for a path at a time, such as the daemon that holds its state directory.

func NewSRPCPeerNetHandler

func NewSRPCPeerNetHandler(impl SRPCPeerNetServer, serviceID string) srpc.Handler

NewSRPCPeerNetHandler constructs a new RPC handler. serviceID: if empty, uses default: modlock.peernet.PeerNet

func Run

func Run(
	ctx context.Context,
	le *logrus.Entry,
	parent bus.Bus,
	key crypto.PrivKey,
	origin string,
	serve func(ctx context.Context, node *Node) error,
) error

Run starts a peer for key that signals through the service at origin and runs serve with it until serve returns or the peer stops. The node's bus resolves directives it does not own, such as relay credentials, on parent. A peer the service does not admit yet retries signaling without delaying serve; links that need no signaling keep working meanwhile.

func SRPCRegisterPeerNet

func SRPCRegisterPeerNet(mux srpc.Mux, impl SRPCPeerNetServer) error

SRPCRegisterPeerNet registers the implementation with the mux. Uses the default serviceID: modlock.peernet.PeerNet

Types

type Admission

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

Admission holds a peer's admission to signaling at a service. It reads the sign-in again before each attempt, retries a dropped socket, and waits for Wake while signed out or refused, since only a new sign-in can change that.

func NewAdmission

func NewAdmission(origin string, key crypto.PrivKey, signIn func() SignIn) *Admission

NewAdmission constructs the admission of key at origin.

func (*Admission) Run

func (a *Admission) Run(ctx context.Context)

Run holds the admission until ctx ends.

func (*Admission) Snapshot

func (a *Admission) Snapshot() (AdmissionState, string, string)

Snapshot returns the admission's state, signed-in name and last failure.

func (*Admission) Wake

func (a *Admission) Wake()

Wake asks Run to read the sign-in again, such as after a client signed in.

type AdmissionState

type AdmissionState int32

AdmissionState is where a peer stands with the signaling service, which introduces it to peers it cannot reach on its own network.

const (
	// ADMISSION_STATE_SIGNED_OUT means no sign-in is saved, so the service
	// does not know the peer.
	AdmissionState_ADMISSION_STATE_SIGNED_OUT AdmissionState = 0
	// ADMISSION_STATE_CONNECTING means the peer is opening its admission
	// socket, or waits to retry after it dropped.
	AdmissionState_ADMISSION_STATE_CONNECTING AdmissionState = 1
	// ADMISSION_STATE_ADMITTED means the service signals for the peer.
	AdmissionState_ADMISSION_STATE_ADMITTED AdmissionState = 2
	// ADMISSION_STATE_REFUSED means the service refused the saved sign-in,
	// which has expired or was signed out.
	AdmissionState_ADMISSION_STATE_REFUSED AdmissionState = 3
)

func (AdmissionState) Enum

func (x AdmissionState) Enum() *AdmissionState

func (AdmissionState) MarshalJSON

func (x AdmissionState) MarshalJSON() ([]byte, error)

MarshalJSON marshals the AdmissionState to JSON.

func (AdmissionState) MarshalProtoJSON

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

MarshalProtoJSON marshals the AdmissionState to JSON.

func (AdmissionState) MarshalProtoText

func (x AdmissionState) MarshalProtoText() string

func (AdmissionState) MarshalText

func (x AdmissionState) MarshalText() ([]byte, error)

MarshalText marshals the AdmissionState to text.

func (AdmissionState) String

func (x AdmissionState) String() string

func (*AdmissionState) UnmarshalJSON

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

UnmarshalJSON unmarshals the AdmissionState from JSON.

func (*AdmissionState) UnmarshalProtoJSON

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

UnmarshalProtoJSON unmarshals the AdmissionState from JSON.

func (*AdmissionState) UnmarshalText

func (x *AdmissionState) UnmarshalText(b []byte) error

UnmarshalText unmarshals the AdmissionState from text.

type Echo

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

Echo answers probe streams from any peer to the local peer for as long as its controller runs on the bus.

func NewEcho

func NewEcho(local peer.ID) *Echo

NewEcho constructs the echo for the local peer.

func (*Echo) Close

func (e *Echo) Close() error

Close does nothing; each stream ends with its own context.

func (*Echo) Execute

func (e *Echo) Execute(context.Context) error

Execute does nothing; the echo answers streams as they arrive.

func (*Echo) GetControllerInfo

func (e *Echo) GetControllerInfo() *controller.Info

GetControllerInfo identifies the echo.

func (*Echo) HandleDirective

func (e *Echo) HandleDirective(_ context.Context, inst directive.Instance) ([]directive.Resolver, error)

HandleDirective accepts probe streams to the local peer.

func (*Echo) HandleMountedStream

func (e *Echo) HandleMountedStream(ctx context.Context, mounted link.MountedStream) error

HandleMountedStream returns each probe packet to its sender until the stream closes or the limit passes.

type GetPeerRequest

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

GetPeerRequest asks for the daemon's peer.

func (*GetPeerRequest) CloneMessageVT

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

func (*GetPeerRequest) CloneVT

func (m *GetPeerRequest) CloneVT() *GetPeerRequest

func (*GetPeerRequest) EqualMessageVT

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

func (*GetPeerRequest) EqualVT

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

func (*GetPeerRequest) MarshalJSON

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

MarshalJSON marshals the GetPeerRequest to JSON.

func (*GetPeerRequest) MarshalProtoJSON

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

MarshalProtoJSON marshals the GetPeerRequest message to JSON.

func (*GetPeerRequest) MarshalProtoText

func (x *GetPeerRequest) MarshalProtoText() string

func (*GetPeerRequest) MarshalToSizedBufferVT

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

func (*GetPeerRequest) MarshalToVT

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

func (*GetPeerRequest) MarshalVT

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

func (*GetPeerRequest) ProtoMessage

func (*GetPeerRequest) ProtoMessage()

func (*GetPeerRequest) Reset

func (x *GetPeerRequest) Reset()

func (*GetPeerRequest) SizeVT

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

func (*GetPeerRequest) String

func (x *GetPeerRequest) String() string

func (*GetPeerRequest) UnmarshalJSON

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

UnmarshalJSON unmarshals the GetPeerRequest from JSON.

func (*GetPeerRequest) UnmarshalProtoJSON

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

UnmarshalProtoJSON unmarshals the GetPeerRequest message from JSON.

func (*GetPeerRequest) UnmarshalVT

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

type GetPeerResponse

type GetPeerResponse struct {

	// peer_id is the PC's peer on the network.
	PeerId string `protobuf:"bytes,1,opt,name=peer_id,json=peerId,proto3" json:"peerId,omitempty"`
	// origin is the signaling service, such as https://hyperline.gg.
	Origin string `protobuf:"bytes,2,opt,name=origin,proto3" json:"origin,omitempty"`
	// admission is the peer's standing with that service.
	Admission AdmissionState `protobuf:"varint,3,opt,name=admission,proto3" json:"admission,omitempty"`
	// account is the signed-in name, when a sign-in is saved.
	Account string `protobuf:"bytes,4,opt,name=account,proto3" json:"account,omitempty"`
	// error says why the last admission attempt failed while connecting.
	Error string `protobuf:"bytes,5,opt,name=error,proto3" json:"error,omitempty"`
	// contains filtered or unexported fields
}

GetPeerResponse describes the daemon's peer.

func (*GetPeerResponse) CloneMessageVT

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

func (*GetPeerResponse) CloneVT

func (m *GetPeerResponse) CloneVT() *GetPeerResponse

func (*GetPeerResponse) EqualMessageVT

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

func (*GetPeerResponse) EqualVT

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

func (*GetPeerResponse) GetAccount

func (x *GetPeerResponse) GetAccount() string

func (*GetPeerResponse) GetAdmission

func (x *GetPeerResponse) GetAdmission() AdmissionState

func (*GetPeerResponse) GetError

func (x *GetPeerResponse) GetError() string

func (*GetPeerResponse) GetOrigin

func (x *GetPeerResponse) GetOrigin() string

func (*GetPeerResponse) GetPeerId

func (x *GetPeerResponse) GetPeerId() string

func (*GetPeerResponse) MarshalJSON

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

MarshalJSON marshals the GetPeerResponse to JSON.

func (*GetPeerResponse) MarshalProtoJSON

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

MarshalProtoJSON marshals the GetPeerResponse message to JSON.

func (*GetPeerResponse) MarshalProtoText

func (x *GetPeerResponse) MarshalProtoText() string

func (*GetPeerResponse) MarshalToSizedBufferVT

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

func (*GetPeerResponse) MarshalToVT

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

func (*GetPeerResponse) MarshalVT

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

func (*GetPeerResponse) ProtoMessage

func (*GetPeerResponse) ProtoMessage()

func (*GetPeerResponse) Reset

func (x *GetPeerResponse) Reset()

func (*GetPeerResponse) SizeVT

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

func (*GetPeerResponse) String

func (x *GetPeerResponse) String() string

func (*GetPeerResponse) UnmarshalJSON

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

UnmarshalJSON unmarshals the GetPeerResponse from JSON.

func (*GetPeerResponse) UnmarshalProtoJSON

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

UnmarshalProtoJSON unmarshals the GetPeerResponse message from JSON.

func (*GetPeerResponse) UnmarshalVT

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

type HostEvent

type HostEvent struct {

	// Types that are assignable to Body:
	//	*HostEvent_JoinCode
	//	*HostEvent_Joined
	//	*HostEvent_Left
	Body isHostEvent_Body `protobuf_oneof:"body"`
	// contains filtered or unexported fields
}

HostEvent is one change to a hosted session.

func (*HostEvent) CloneMessageVT

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

func (*HostEvent) CloneVT

func (m *HostEvent) CloneVT() *HostEvent

func (*HostEvent) EqualMessageVT

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

func (*HostEvent) EqualVT

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

func (*HostEvent) GetBody

func (m *HostEvent) GetBody() isHostEvent_Body

func (*HostEvent) GetJoinCode

func (x *HostEvent) GetJoinCode() string

func (*HostEvent) GetJoined

func (x *HostEvent) GetJoined() string

func (*HostEvent) GetLeft

func (x *HostEvent) GetLeft() string

func (*HostEvent) MarshalJSON

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

MarshalJSON marshals the HostEvent to JSON.

func (*HostEvent) MarshalProtoJSON

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

MarshalProtoJSON marshals the HostEvent message to JSON.

func (*HostEvent) MarshalProtoText

func (x *HostEvent) MarshalProtoText() string

func (*HostEvent) MarshalToSizedBufferVT

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

func (*HostEvent) MarshalToVT

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

func (*HostEvent) MarshalVT

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

func (*HostEvent) ProtoMessage

func (*HostEvent) ProtoMessage()

func (*HostEvent) Reset

func (x *HostEvent) Reset()

func (*HostEvent) SizeVT

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

func (*HostEvent) String

func (x *HostEvent) String() string

func (*HostEvent) UnmarshalJSON

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

UnmarshalJSON unmarshals the HostEvent from JSON.

func (*HostEvent) UnmarshalProtoJSON

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

UnmarshalProtoJSON unmarshals the HostEvent message from JSON.

func (*HostEvent) UnmarshalVT

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

type HostEvent_JoinCode

type HostEvent_JoinCode struct {
	// join_code is the code a guest passes to modlock join. It names the
	// host's peer and the session, and comes first.
	JoinCode string `protobuf:"bytes,1,opt,name=join_code,json=joinCode,proto3,oneof"`
}

func (*HostEvent_JoinCode) CloneOneofVT

func (m *HostEvent_JoinCode) CloneOneofVT() isHostEvent_Body

func (*HostEvent_JoinCode) CloneVT

func (m *HostEvent_JoinCode) CloneVT() *HostEvent_JoinCode

func (*HostEvent_JoinCode) EqualVT

func (this *HostEvent_JoinCode) EqualVT(thatIface isHostEvent_Body) bool

func (*HostEvent_JoinCode) MarshalToSizedBufferVT

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

func (*HostEvent_JoinCode) MarshalToVT

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

func (*HostEvent_JoinCode) SizeVT

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

type HostEvent_Joined

type HostEvent_Joined struct {
	// joined is the peer of a guest whose game stream the host accepted.
	Joined string `protobuf:"bytes,2,opt,name=joined,proto3,oneof"`
}

func (*HostEvent_Joined) CloneOneofVT

func (m *HostEvent_Joined) CloneOneofVT() isHostEvent_Body

func (*HostEvent_Joined) CloneVT

func (m *HostEvent_Joined) CloneVT() *HostEvent_Joined

func (*HostEvent_Joined) EqualVT

func (this *HostEvent_Joined) EqualVT(thatIface isHostEvent_Body) bool

func (*HostEvent_Joined) MarshalToSizedBufferVT

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

func (*HostEvent_Joined) MarshalToVT

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

func (*HostEvent_Joined) SizeVT

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

type HostEvent_Left

type HostEvent_Left struct {
	// left is the peer of a guest whose game stream ended.
	Left string `protobuf:"bytes,3,opt,name=left,proto3,oneof"`
}

func (*HostEvent_Left) CloneOneofVT

func (m *HostEvent_Left) CloneOneofVT() isHostEvent_Body

func (*HostEvent_Left) CloneVT

func (m *HostEvent_Left) CloneVT() *HostEvent_Left

func (*HostEvent_Left) EqualVT

func (this *HostEvent_Left) EqualVT(thatIface isHostEvent_Body) bool

func (*HostEvent_Left) MarshalToSizedBufferVT

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

func (*HostEvent_Left) MarshalToVT

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

func (*HostEvent_Left) SizeVT

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

type HostRequest

type HostRequest struct {

	// port is the server's UDP game port on loopback.
	Port uint32 `protobuf:"varint,1,opt,name=port,proto3" json:"port,omitempty"`
	// contains filtered or unexported fields
}

HostRequest names the game server to serve.

func (*HostRequest) CloneMessageVT

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

func (*HostRequest) CloneVT

func (m *HostRequest) CloneVT() *HostRequest

func (*HostRequest) EqualMessageVT

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

func (*HostRequest) EqualVT

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

func (*HostRequest) GetPort

func (x *HostRequest) GetPort() uint32

func (*HostRequest) MarshalJSON

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

MarshalJSON marshals the HostRequest to JSON.

func (*HostRequest) MarshalProtoJSON

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

MarshalProtoJSON marshals the HostRequest message to JSON.

func (*HostRequest) MarshalProtoText

func (x *HostRequest) MarshalProtoText() string

func (*HostRequest) MarshalToSizedBufferVT

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

func (*HostRequest) MarshalToVT

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

func (*HostRequest) MarshalVT

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

func (*HostRequest) ProtoMessage

func (*HostRequest) ProtoMessage()

func (*HostRequest) Reset

func (x *HostRequest) Reset()

func (*HostRequest) SizeVT

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

func (*HostRequest) String

func (x *HostRequest) String() string

func (*HostRequest) UnmarshalJSON

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

UnmarshalJSON unmarshals the HostRequest from JSON.

func (*HostRequest) UnmarshalProtoJSON

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

UnmarshalProtoJSON unmarshals the HostRequest message from JSON.

func (*HostRequest) UnmarshalVT

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

type JoinCode

type JoinCode struct {
	// Host is the hosting PC's peer.
	Host peer.ID
	// Session is the session's nonzero secret.
	Session uint64
}

JoinCode names a hosted session: the host's peer and the session's secret.

func ParseJoinCode

func ParseJoinCode(code string) (JoinCode, error)

ParseJoinCode reads a code that JoinCode.String formatted.

func (JoinCode) String

func (c JoinCode) String() string

String formats the code as the peer, a dash and the session in hex. Peer IDs are base58, which has no dash.

type JoinEvent

type JoinEvent struct {

	// Types that are assignable to Body:
	//	*JoinEvent_Address
	//	*JoinEvent_Arrived
	Body isJoinEvent_Body `protobuf_oneof:"body"`
	// contains filtered or unexported fields
}

JoinEvent is one step of joining a hosted session.

func (*JoinEvent) CloneMessageVT

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

func (*JoinEvent) CloneVT

func (m *JoinEvent) CloneVT() *JoinEvent

func (*JoinEvent) EqualMessageVT

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

func (*JoinEvent) EqualVT

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

func (*JoinEvent) GetAddress

func (x *JoinEvent) GetAddress() string

func (*JoinEvent) GetArrived

func (x *JoinEvent) GetArrived() bool

func (*JoinEvent) GetBody

func (m *JoinEvent) GetBody() isJoinEvent_Body

func (*JoinEvent) MarshalJSON

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

MarshalJSON marshals the JoinEvent to JSON.

func (*JoinEvent) MarshalProtoJSON

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

MarshalProtoJSON marshals the JoinEvent message to JSON.

func (*JoinEvent) MarshalProtoText

func (x *JoinEvent) MarshalProtoText() string

func (*JoinEvent) MarshalToSizedBufferVT

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

func (*JoinEvent) MarshalToVT

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

func (*JoinEvent) MarshalVT

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

func (*JoinEvent) ProtoMessage

func (*JoinEvent) ProtoMessage()

func (*JoinEvent) Reset

func (x *JoinEvent) Reset()

func (*JoinEvent) SizeVT

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

func (*JoinEvent) String

func (x *JoinEvent) String() string

func (*JoinEvent) UnmarshalJSON

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

UnmarshalJSON unmarshals the JoinEvent from JSON.

func (*JoinEvent) UnmarshalProtoJSON

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

UnmarshalProtoJSON unmarshals the JoinEvent message from JSON.

func (*JoinEvent) UnmarshalVT

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

type JoinEvent_Address

type JoinEvent_Address struct {
	// address is the loopback endpoint the local game connects to, sent once
	// the host accepted the guest.
	Address string `protobuf:"bytes,1,opt,name=address,proto3,oneof"`
}

func (*JoinEvent_Address) CloneOneofVT

func (m *JoinEvent_Address) CloneOneofVT() isJoinEvent_Body

func (*JoinEvent_Address) CloneVT

func (m *JoinEvent_Address) CloneVT() *JoinEvent_Address

func (*JoinEvent_Address) EqualVT

func (this *JoinEvent_Address) EqualVT(thatIface isJoinEvent_Body) bool

func (*JoinEvent_Address) MarshalToSizedBufferVT

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

func (*JoinEvent_Address) MarshalToVT

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

func (*JoinEvent_Address) SizeVT

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

type JoinEvent_Arrived

type JoinEvent_Arrived struct {
	// arrived reports the game's first packet through address.
	Arrived bool `protobuf:"varint,2,opt,name=arrived,proto3,oneof"`
}

func (*JoinEvent_Arrived) CloneOneofVT

func (m *JoinEvent_Arrived) CloneOneofVT() isJoinEvent_Body

func (*JoinEvent_Arrived) CloneVT

func (m *JoinEvent_Arrived) CloneVT() *JoinEvent_Arrived

func (*JoinEvent_Arrived) EqualVT

func (this *JoinEvent_Arrived) EqualVT(thatIface isJoinEvent_Body) bool

func (*JoinEvent_Arrived) MarshalToSizedBufferVT

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

func (*JoinEvent_Arrived) MarshalToVT

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

func (*JoinEvent_Arrived) SizeVT

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

type JoinRequest

type JoinRequest struct {

	// code is the host's join code.
	Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"`
	// contains filtered or unexported fields
}

JoinRequest names the session to join.

func (*JoinRequest) CloneMessageVT

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

func (*JoinRequest) CloneVT

func (m *JoinRequest) CloneVT() *JoinRequest

func (*JoinRequest) EqualMessageVT

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

func (*JoinRequest) EqualVT

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

func (*JoinRequest) GetCode

func (x *JoinRequest) GetCode() string

func (*JoinRequest) MarshalJSON

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

MarshalJSON marshals the JoinRequest to JSON.

func (*JoinRequest) MarshalProtoJSON

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

MarshalProtoJSON marshals the JoinRequest message to JSON.

func (*JoinRequest) MarshalProtoText

func (x *JoinRequest) MarshalProtoText() string

func (*JoinRequest) MarshalToSizedBufferVT

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

func (*JoinRequest) MarshalToVT

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

func (*JoinRequest) MarshalVT

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

func (*JoinRequest) ProtoMessage

func (*JoinRequest) ProtoMessage()

func (*JoinRequest) Reset

func (x *JoinRequest) Reset()

func (*JoinRequest) SizeVT

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

func (*JoinRequest) String

func (x *JoinRequest) String() string

func (*JoinRequest) UnmarshalJSON

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

UnmarshalJSON unmarshals the JoinRequest from JSON.

func (*JoinRequest) UnmarshalProtoJSON

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

UnmarshalProtoJSON unmarshals the JoinRequest message from JSON.

func (*JoinRequest) UnmarshalVT

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

type Node

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

Node is a running peer: the bus that dials and serves peer streams under the node's peer ID.

func (*Node) GetBus

func (n *Node) GetBus() bus.Bus

GetBus returns the bus that dials and serves peer streams.

func (*Node) GetPeerId

func (n *Node) GetPeerId() peer.ID

GetPeerId returns the node's peer ID, derived from its key.

type ProbeRequest

type ProbeRequest struct {

	// peer_id is the other PC's peer.
	PeerId string `protobuf:"bytes,1,opt,name=peer_id,json=peerId,proto3" json:"peerId,omitempty"`
	// contains filtered or unexported fields
}

ProbeRequest names the peer to measure.

func (*ProbeRequest) CloneMessageVT

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

func (*ProbeRequest) CloneVT

func (m *ProbeRequest) CloneVT() *ProbeRequest

func (*ProbeRequest) EqualMessageVT

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

func (*ProbeRequest) EqualVT

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

func (*ProbeRequest) GetPeerId

func (x *ProbeRequest) GetPeerId() string

func (*ProbeRequest) MarshalJSON

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

MarshalJSON marshals the ProbeRequest to JSON.

func (*ProbeRequest) MarshalProtoJSON

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

MarshalProtoJSON marshals the ProbeRequest message to JSON.

func (*ProbeRequest) MarshalProtoText

func (x *ProbeRequest) MarshalProtoText() string

func (*ProbeRequest) MarshalToSizedBufferVT

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

func (*ProbeRequest) MarshalToVT

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

func (*ProbeRequest) MarshalVT

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

func (*ProbeRequest) ProtoMessage

func (*ProbeRequest) ProtoMessage()

func (*ProbeRequest) Reset

func (x *ProbeRequest) Reset()

func (*ProbeRequest) SizeVT

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

func (*ProbeRequest) String

func (x *ProbeRequest) String() string

func (*ProbeRequest) UnmarshalJSON

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

UnmarshalJSON unmarshals the ProbeRequest from JSON.

func (*ProbeRequest) UnmarshalProtoJSON

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

UnmarshalProtoJSON unmarshals the ProbeRequest message from JSON.

func (*ProbeRequest) UnmarshalVT

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

type ProbeResponse

type ProbeResponse struct {

	// rtt_us is the shortest round trip of the probe's packets, in
	// microseconds.
	RttUs uint32 `protobuf:"varint,1,opt,name=rtt_us,json=rttUs,proto3" json:"rttUs,omitempty"`
	// relayed reports that the link runs through the service's relay rather
	// than directly between the PCs.
	Relayed bool `protobuf:"varint,2,opt,name=relayed,proto3" json:"relayed,omitempty"`
	// contains filtered or unexported fields
}

ProbeResponse reports one measured link.

func Probe

func Probe(ctx context.Context, b bus.Bus, local, remote peer.ID) (*ProbeResponse, error)

Probe opens a probe stream from local to remote on b and returns the shortest round trip of its packets and whether the link is relayed.

func (*ProbeResponse) CloneMessageVT

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

func (*ProbeResponse) CloneVT

func (m *ProbeResponse) CloneVT() *ProbeResponse

func (*ProbeResponse) EqualMessageVT

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

func (*ProbeResponse) EqualVT

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

func (*ProbeResponse) GetRelayed

func (x *ProbeResponse) GetRelayed() bool

func (*ProbeResponse) GetRttUs

func (x *ProbeResponse) GetRttUs() uint32

func (*ProbeResponse) MarshalJSON

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

MarshalJSON marshals the ProbeResponse to JSON.

func (*ProbeResponse) MarshalProtoJSON

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

MarshalProtoJSON marshals the ProbeResponse message to JSON.

func (*ProbeResponse) MarshalProtoText

func (x *ProbeResponse) MarshalProtoText() string

func (*ProbeResponse) MarshalToSizedBufferVT

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

func (*ProbeResponse) MarshalToVT

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

func (*ProbeResponse) MarshalVT

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

func (*ProbeResponse) ProtoMessage

func (*ProbeResponse) ProtoMessage()

func (*ProbeResponse) Reset

func (x *ProbeResponse) Reset()

func (*ProbeResponse) SizeVT

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

func (*ProbeResponse) String

func (x *ProbeResponse) String() string

func (*ProbeResponse) UnmarshalJSON

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

UnmarshalJSON unmarshals the ProbeResponse from JSON.

func (*ProbeResponse) UnmarshalProtoJSON

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

UnmarshalProtoJSON unmarshals the ProbeResponse message from JSON.

func (*ProbeResponse) UnmarshalVT

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

type Relay

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

Relay supplies relay credentials from the creator's sign-in to one local peer's links, for the PCs that cannot link directly. Without them a link still tries the direct path.

func NewRelay

func NewRelay(le *logrus.Entry, local peer.ID, origin string, signIn func() SignIn) *Relay

NewRelay constructs the relay credentials for local's links.

func (*Relay) Close

func (r *Relay) Close() error

Close does nothing.

func (*Relay) Execute

func (r *Relay) Execute(context.Context) error

Execute does nothing; credentials are fetched for each connection attempt.

func (*Relay) GetControllerInfo

func (r *Relay) GetControllerInfo() *controller.Info

GetControllerInfo identifies the relay credentials.

func (*Relay) HandleDirective

func (r *Relay) HandleDirective(_ context.Context, inst directive.Instance) ([]directive.Resolver, error)

HandleDirective supplies the credentials to the local peer only.

func (*Relay) ICEConfig

func (r *Relay) ICEConfig(ctx context.Context) (*webrtc.WebRtcConfig, error)

ICEConfig returns the direct path and fresh relay credentials. When the credentials are unavailable, such as while signed out, the link tries the direct path alone.

type RelayCredentials

type RelayCredentials struct {

	// servers are the relay servers the peer may use.
	Servers []*RelayServer `protobuf:"bytes,1,rep,name=servers,proto3" json:"servers,omitempty"`
	// expires_at is when the credentials stop working, in Unix milliseconds.
	ExpiresAt int64 `protobuf:"varint,2,opt,name=expires_at,json=expiresAt,proto3" json:"expiresAt,omitempty"`
	// contains filtered or unexported fields
}

RelayCredentials answers GET /api/turn-credentials, which issues short-lived relay credentials to a signed-in creator.

func (*RelayCredentials) CloneMessageVT

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

func (*RelayCredentials) CloneVT

func (m *RelayCredentials) CloneVT() *RelayCredentials

func (*RelayCredentials) EqualMessageVT

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

func (*RelayCredentials) EqualVT

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

func (*RelayCredentials) GetExpiresAt

func (x *RelayCredentials) GetExpiresAt() int64

func (*RelayCredentials) GetServers

func (x *RelayCredentials) GetServers() []*RelayServer

func (*RelayCredentials) MarshalJSON

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

MarshalJSON marshals the RelayCredentials to JSON.

func (*RelayCredentials) MarshalProtoJSON

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

MarshalProtoJSON marshals the RelayCredentials message to JSON.

func (*RelayCredentials) MarshalProtoText

func (x *RelayCredentials) MarshalProtoText() string

func (*RelayCredentials) MarshalToSizedBufferVT

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

func (*RelayCredentials) MarshalToVT

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

func (*RelayCredentials) MarshalVT

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

func (*RelayCredentials) ProtoMessage

func (*RelayCredentials) ProtoMessage()

func (*RelayCredentials) Reset

func (x *RelayCredentials) Reset()

func (*RelayCredentials) SizeVT

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

func (*RelayCredentials) String

func (x *RelayCredentials) String() string

func (*RelayCredentials) UnmarshalJSON

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

UnmarshalJSON unmarshals the RelayCredentials from JSON.

func (*RelayCredentials) UnmarshalProtoJSON

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

UnmarshalProtoJSON unmarshals the RelayCredentials message from JSON.

func (*RelayCredentials) UnmarshalVT

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

type RelayServer

type RelayServer struct {

	// urls are the server's STUN and TURN addresses.
	Urls []string `protobuf:"bytes,1,rep,name=urls,proto3" json:"urls,omitempty"`
	// username is the credential's identifier.
	Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
	// credential is the credential's secret.
	Credential string `protobuf:"bytes,3,opt,name=credential,proto3" json:"credential,omitempty"`
	// contains filtered or unexported fields
}

RelayServer is one relay and its credential.

func (*RelayServer) CloneMessageVT

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

func (*RelayServer) CloneVT

func (m *RelayServer) CloneVT() *RelayServer

func (*RelayServer) EqualMessageVT

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

func (*RelayServer) EqualVT

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

func (*RelayServer) GetCredential

func (x *RelayServer) GetCredential() string

func (*RelayServer) GetUrls

func (x *RelayServer) GetUrls() []string

func (*RelayServer) GetUsername

func (x *RelayServer) GetUsername() string

func (*RelayServer) MarshalJSON

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

MarshalJSON marshals the RelayServer to JSON.

func (*RelayServer) MarshalProtoJSON

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

MarshalProtoJSON marshals the RelayServer message to JSON.

func (*RelayServer) MarshalProtoText

func (x *RelayServer) MarshalProtoText() string

func (*RelayServer) MarshalToSizedBufferVT

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

func (*RelayServer) MarshalToVT

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

func (*RelayServer) MarshalVT

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

func (*RelayServer) ProtoMessage

func (*RelayServer) ProtoMessage()

func (*RelayServer) Reset

func (x *RelayServer) Reset()

func (*RelayServer) SizeVT

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

func (*RelayServer) String

func (x *RelayServer) String() string

func (*RelayServer) UnmarshalJSON

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

UnmarshalJSON unmarshals the RelayServer from JSON.

func (*RelayServer) UnmarshalProtoJSON

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

UnmarshalProtoJSON unmarshals the RelayServer message from JSON.

func (*RelayServer) UnmarshalVT

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

type SRPCPeerNetClient

type SRPCPeerNetClient interface {
	// SRPCClient returns the underlying SRPC client.
	SRPCClient() srpc.Client

	// GetPeer returns the daemon's peer and its admission to signaling.
	GetPeer(ctx context.Context, in *GetPeerRequest) (*GetPeerResponse, error)
	// Probe opens a stream to another peer and measures its round trip.
	Probe(ctx context.Context, in *ProbeRequest) (*ProbeResponse, error)
	// Host serves the local game server to guests holding the join code it
	// sends first, for as long as the call stays open.
	Host(ctx context.Context, in *HostRequest) (SRPCPeerNet_HostClient, error)
	// Join links to a hosted game server and serves it to the local game on a
	// loopback port until the game leaves or the call ends.
	Join(ctx context.Context, in *JoinRequest) (SRPCPeerNet_JoinClient, error)
}

func NewSRPCPeerNetClient

func NewSRPCPeerNetClient(cc srpc.Client) SRPCPeerNetClient

func NewSRPCPeerNetClientWithServiceID

func NewSRPCPeerNetClientWithServiceID(cc srpc.Client, serviceID string) SRPCPeerNetClient

type SRPCPeerNetHandler

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

func (SRPCPeerNetHandler) GetMethodIDs

func (SRPCPeerNetHandler) GetMethodIDs() []string

func (*SRPCPeerNetHandler) GetServiceID

func (d *SRPCPeerNetHandler) GetServiceID() string

func (*SRPCPeerNetHandler) InvokeMethod

func (d *SRPCPeerNetHandler) InvokeMethod(
	serviceID, methodID string,
	strm srpc.Stream,
) (bool, error)

func (SRPCPeerNetHandler) InvokeMethod_GetPeer

func (SRPCPeerNetHandler) InvokeMethod_GetPeer(impl SRPCPeerNetServer, strm srpc.Stream) error

func (SRPCPeerNetHandler) InvokeMethod_Host

func (SRPCPeerNetHandler) InvokeMethod_Host(impl SRPCPeerNetServer, strm srpc.Stream) error

func (SRPCPeerNetHandler) InvokeMethod_Join

func (SRPCPeerNetHandler) InvokeMethod_Join(impl SRPCPeerNetServer, strm srpc.Stream) error

func (SRPCPeerNetHandler) InvokeMethod_Probe

func (SRPCPeerNetHandler) InvokeMethod_Probe(impl SRPCPeerNetServer, strm srpc.Stream) error

type SRPCPeerNetServer

type SRPCPeerNetServer interface {
	// GetPeer returns the daemon's peer and its admission to signaling.
	GetPeer(context.Context, *GetPeerRequest) (*GetPeerResponse, error)
	// Probe opens a stream to another peer and measures its round trip.
	Probe(context.Context, *ProbeRequest) (*ProbeResponse, error)
	// Host serves the local game server to guests holding the join code it
	// sends first, for as long as the call stays open.
	Host(*HostRequest, SRPCPeerNet_HostStream) error
	// Join links to a hosted game server and serves it to the local game on a
	// loopback port until the game leaves or the call ends.
	Join(*JoinRequest, SRPCPeerNet_JoinStream) error
}

type SRPCPeerNet_GetPeerStream

type SRPCPeerNet_GetPeerStream interface {
	srpc.Stream
}

type SRPCPeerNet_HostClient

type SRPCPeerNet_HostClient interface {
	srpc.Stream
	Recv() (*HostEvent, error)
	RecvTo(*HostEvent) error
}

type SRPCPeerNet_HostStream

type SRPCPeerNet_HostStream interface {
	srpc.Stream
	Send(*HostEvent) error
	SendAndClose(*HostEvent) error
}

type SRPCPeerNet_JoinClient

type SRPCPeerNet_JoinClient interface {
	srpc.Stream
	Recv() (*JoinEvent, error)
	RecvTo(*JoinEvent) error
}

type SRPCPeerNet_JoinStream

type SRPCPeerNet_JoinStream interface {
	srpc.Stream
	Send(*JoinEvent) error
	SendAndClose(*JoinEvent) error
}

type SRPCPeerNet_ProbeStream

type SRPCPeerNet_ProbeStream interface {
	srpc.Stream
}

type Service

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

Service runs a PC's peer with its admission and relay credentials, and serves the PeerNet service for it. Its calls wait for Run to load the key, so a daemon can register the service before it holds its state directory.

func NewService

func NewService(origin, keyPath string, signIn func() SignIn) *Service

NewService constructs the peer whose key lives at keyPath, signaling at origin.

func (*Service) GetPeer

func (s *Service) GetPeer(ctx context.Context, _ *GetPeerRequest) (*GetPeerResponse, error)

GetPeer returns the peer and its admission. A call also asks the admission to read the sign-in again, since a client may have just signed in.

func (*Service) Host

func (s *Service) Host(req *HostRequest, strm SRPCPeerNet_HostStream) error

Host serves the local game server to guests holding the join code it sends first, until the call ends.

func (*Service) Join

func (s *Service) Join(req *JoinRequest, strm SRPCPeerNet_JoinStream) error

Join links to the session the code names and serves it to the local game on a loopback port until the game leaves or the call ends.

func (*Service) Probe

func (s *Service) Probe(ctx context.Context, req *ProbeRequest) (*ProbeResponse, error)

Probe measures the link to another peer once the local peer is ready.

func (*Service) Register

func (s *Service) Register(mux srpc.Mux) error

Register serves the PeerNet service on mux.

func (*Service) Run

func (s *Service) Run(ctx context.Context, le *logrus.Entry) error

Run loads the key, creating it on first use, and runs the peer, its admission and its probe echo until ctx ends. Only one process may run a service for a key file at a time.

type SignIn

type SignIn struct {
	// Token is the bearer credential.
	Token string
	// Account is the signed-in name.
	Account string
}

SignIn is the creator's saved sign-in with the service. An empty Token means signed out.

Jump to

Keyboard shortcuts

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