Documentation
¶
Overview ¶
Package skynet pkg/skynet/client.go c2-app-skynet
Package skynet pkg/skynet/common.go c2-app-skynet
Package skynet pkg/skynet/hosted.go
Index ¶
Constants ¶
const MaxRequestSize = 10 * 1024 * 1024 // 10 MB
MaxRequestSize limits incoming request bodies to prevent memory exhaustion.
Variables ¶
This section is empty.
Functions ¶
func SignHosted ¶
func SignHosted(service cipher.PubKey, serviceSK cipher.SecKey, host cipher.PubKey) (cipher.Sig, error)
SignHosted signs, with the service's key, that host runs the service. A host returns it when it hands a stream to the service, so a caller knows the visor it reached may speak for that key.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client connects to a remote skynet server and forwards traffic to a local port. Pre-2026-05-21 this was single-shot: one Connect + one Serve = one local accept + forward + exit. That tore down the cli skynet start app after every curl, leaked the local listener for ~minutes, and made the port-forward operationally useless for any multi-connection workload. The current shape accepts in a loop and dials a fresh remote per accept so sequential local clients each get a clean independent forward.
func NewClient ¶
func NewClient(log logrus.FieldLogger, remotePK cipher.PubKey, remotePort, localPort int, dialRemote DialRemoteFunc) *Client
NewClient creates a new skynet client. dialRemote is called once per accepted local connection to produce a fresh remote conn.
func (*Client) Close ¶
Close stops the client. Subsequent Accept calls return ErrClosed. Active per-conn forwards drain via the closeCh in forwardOnce.
func (*Client) Connect ¶
Connect runs the skynet handshake against a freshly-dialed remote conn: read ready-signal, send port-request, read reply. Returns nil on success — the conn is then ready for raw byte forwarding. Errors close the conn and propagate; caller should drop the local conn that triggered the dial.
type ClientMsg ¶
type ClientMsg struct {
Port int `json:"port"`
// PK names a service the visor hosts under its own key. Empty means the
// visor itself.
PK string `json:"pk,omitempty"`
}
ClientMsg is the initial JSON request from client to server. Exported so in-process consumers (e.g. pkg/skynetweb) can speak the same protocol without redefining the wire format.
type DialRemoteFunc ¶
DialRemoteFunc returns a fresh authenticated net.Conn to the remote skynet server. The Client calls it per-accept so each local TCP connection gets its own independent remote tunnel — necessary because the skynet wire is a raw byte stream with no per-connection framing, so concurrent or even tightly-sequenced local conns sharing a single remoteConn would interleave bytes and corrupt payloads.
The handshake (ready-signal read + port-request write + reply read) lives inside Client.Connect, which the caller invokes against the returned conn before forwarding. Implementations typically wrap the host visor's appCl.Dial to the SkyForwardingServerPort.
type ServerReply ¶
type ServerReply struct {
Error *string `json:"error,omitempty"`
// PK echoes ClientMsg.PK once the stream is handed to that service.
PK string `json:"pk,omitempty"`
// Sig is the service key's signature naming this visor as its host, see
// SignHosted. A caller checks it against the key its stream reached.
Sig string `json:"sig,omitempty"`
}
ServerReply is the server's JSON response to ClientMsg.