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

skynet

package
v1.3.104 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

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

View Source
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.

func VerifyHosted

func VerifyHosted(service, host cipher.PubKey, sig cipher.Sig) error

VerifyHosted checks a SignHosted signature.

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

func (c *Client) Close() error

Close stops the client. Subsequent Accept calls return ErrClosed. Active per-conn forwards drain via the closeCh in forwardOnce.

func (*Client) Connect

func (c *Client) Connect(remoteConn net.Conn) error

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.

func (*Client) LocalPort

func (c *Client) LocalPort() int

LocalPort returns the local port

func (*Client) RemotePK

func (c *Client) RemotePK() cipher.PubKey

RemotePK returns the remote public key

func (*Client) RemotePort

func (c *Client) RemotePort() int

RemotePort returns the remote port

func (*Client) Serve

func (c *Client) Serve() error

Serve binds the local listener and runs the accept loop. Each accepted local conn gets its own goroutine + fresh remote dial. Returns when the listener closes (Client.Close) or Accept errors non-recoverably.

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

type DialRemoteFunc func() (net.Conn, error)

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.

Jump to

Keyboard shortcuts

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