host

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Host *RedisHost
	// contains filtered or unexported fields
}

Client represents a host on the network who wishes to do something with a specific server, whether this is a file-transfer operation, an interactive session, or a series of pings.

func NewClient

func NewClient(username string, hostname string, uri string, logger *zap.SugaredLogger) (*Client, error)

NewClient creates a new client and its underlying connection to Redis. It is not actively receiving, sending, or processing messages at this point; that is only enabled upon start.

func (*Client) Close

func (clnt *Client) Close()

Close is called to destroy the client's Redis connection and perform cleanup.

func (*Client) DownloadFile

func (clnt *Client) DownloadFile(remoteFilename string, localFilename string) error

Downloads a file from the remote server.

func (*Client) LoginInteractively

func (clnt *Client) LoginInteractively() error

Creates an interactive session with its server.

func (*Client) Ping

func (clnt *Client) Ping()

Sends an infinite series of pings to the server until it receives an interrupt from the user.

func (*Client) Start

func (clnt *Client) Start()

Start is a non-blocking function that enables client message processing.

func (*Client) UploadFile

func (clnt *Client) UploadFile(localFilename string, remoteFilename string) error

Uploads a file to the remote server.

type RedisHost

type RedisHost struct {
	Hostname   string                    // The name of this host (e.g. what channel this host is listening on)
	Logger     *zap.SugaredLogger        // The logger attached to this host
	Encryption *drshsec.EncryptionModule // Responsible for performing key exchange, symmetric encryption, etc.
	// contains filtered or unexported fields
}

A wrapper around Redis that only uses Redis as a message broker. It tries to hide the full functionality of Redis by only exposing functions related to sending and receiving drsh messages.

func NewChildRedisHost

func NewChildRedisHost(hostname string, parent *RedisHost) (*RedisHost, error)

A niche method that is used by a server session to create a host using the parent server's existing connection. This host shares the parent's connection resources, but doesn't own them. This is mainly used by the server for spawning new sessions.

func NewRedisHost

func NewRedisHost(hostname string, uri string, logger *zap.SugaredLogger) (*RedisHost, error)

Creates a new Redis host. The host will connect as `hostname` to the Redis node at `uri` and will subscribe to the channel "drsh:`hostname`". Although the host is connected, it is not actively processing messages at this point.

func (*RedisHost) Close

func (host *RedisHost) Close()

Closes the host. The connection to Redis is dropped and the host can no longer send messages. If the host was created using NewInheritedRedisHost (e.g. a server spawns a session), then the underlying connection is left intact.

func (*RedisHost) IsListening

func (host *RedisHost) IsListening(hostname string) bool

Returns whether or not a host with this name is listening on the network. A listening host means that the host is subscribed to its channel. It is a necessary but not sufficient condition for host communication, as the other host must be responsive too.

func (*RedisHost) IsOpen

func (host *RedisHost) IsOpen() bool

Returns whether or not the host is listening on the network. The host is considered open from creation until Close() is called on it.

func (*RedisHost) SendPublicMessage

func (host *RedisHost) SendPublicMessage(recipient string, msg drshproto.PublicMessage)

A thread-safe way to send public messages to another host on the network.

func (*RedisHost) SendSessionMessage

func (host *RedisHost) SendSessionMessage(recipient string, msg drshproto.SessionMessage)

A thread-safe way to send session messages to another host on the network. The session messages will be encrypted with a mutually derived key.

func (*RedisHost) Start

func (host *RedisHost) Start()

Starts the host. Upon completion of this function, the host can both send and receive messages through its Redis node. It is actively listening for incoming messages from counterparties and sending outgoing messages from its own queue.

type Server

type Server struct {
	Host     *RedisHost
	Sessions sync.Map
}

Represents a host on the network that accepts connections & pings from any clients that wish to communicate with it. On a successful handshake with a client, a server will spawn a separate "session" through which all communication is encrypted. Because the session handles most of the connection legwork, the actual server class is fairly light.

func NewServer

func NewServer(hostname string, uri string, logger *zap.SugaredLogger) (*Server, error)

NewServer creates a new server and its underlying connection to Redis. It is not actively receiving, sending, or processing messages at this point; that is only enabled upon start.

func (*Server) Close

func (serv *Server) Close()

Destroys the server's Redis connection and perform cleanup.

func (*Server) NewSession

func (serv *Server) NewSession(clientHostname string, keyPart []byte) (*Session, error)

Creates a session given that the server has received necessary information like a client's public key and target username. It sets up the Redis host, subscribes to the proper channel, assigns a name to the session, sets up encryption, and initializes the client's interactive pseudoterminal and/or transfer file.

func (*Server) Start

func (serv *Server) Start()

Non-blocking function that enables server message processing.

type Session

type Session struct {
	Host *RedisHost
	// contains filtered or unexported fields
}

Represents the server's view of the connection between it and the client. Every session between a server and a client is considered unique. The session piggybacks off of the server's own Redis connection so that not as much TCP state has to be maintained. In many ways, a session is analogous to an encrypted tunnel in SSH, as the session can only be created after a successful key exchange occurring in a handshake. Every session also maintains its own pseudoterminal that is controlled by the client.

func (*Session) Close

func (session *Session) Close()

Performs session cleanup but does not destroy the Redis connection.

func (*Session) Start

func (session *Session) Start()

Non-blocking function that enables session message processing.

Jump to

Keyboard shortcuts

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