node

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyConnected = errors.New("already connected")
)

Functions

This section is empty.

Types

type DiscoverOptions added in v1.1.1

type DiscoverOptions struct {
	Enable   bool
	Delay    time.Duration
	MaxPeers int
}

type Node

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

func New

func New(
	clipboard clipboard.Manager,
	peers *Storage,
	localClipboard data.Channel,
	opt *Options,
) *Node

New creates a new instance of Node with the specified settings.

func (*Node) Broadcast

func (n *Node) Broadcast(msg *data.Message, ignore data.UniqueID)

Broadcast sends a message to all connected nodes except those specified in the 'ignore' list. It first checks if the message is a duplicate of the last sent message by comparing their IDs and hashes. If the message is a duplicate, it is not sent. For each connection in the storage, it writes the message to the connection's writer. The method logs the sent messages and their hashes for debugging purposes. The 'msg' parameter is the message to be broadcast. The 'ignore' parameter is a variadic list of AddrPort to exclude from the broadcast.

func (*Node) ConnectTo

func (n *Node) ConnectTo(addr string) error

ConnectTo establishes a TCP connection to a remote clipboard at the specified address. It adds the connection to the node's storage and starts handling the connection using 'handleConnection'. The 'addr' parameter should be in the format "host:port" to specify the remote clipboard's address. If the connection is successfully established, it returns nil; otherwise, it returns an error.

func (*Node) Metadata

func (n *Node) Metadata() *data.MetaData

func (*Node) MonitorBuffer

func (n *Node) MonitorBuffer()

MonitorBuffer starts monitoring the clipboard and subsequently sending data to other nodes

func (*Node) Notify added in v1.1.0

func (n *Node) Notify(message string, v ...any)

func (*Node) Start

func (n *Node) Start() error

Start starts the node by listening for incoming connections on the specified public port. It also starts a clipboard monitor to periodically scan and update the local clipboard. When a new connection is accepted, it invokes the 'handleConnection' method to handle the connection. The 'scanDelay' parameter determines the interval at which the clipboard is scanned and updated. The method returns an error if it fails to start listening.

type Options added in v1.0.3

type Options struct {
	PublicPort         int
	BitSize            int
	KeepAlive          time.Duration
	ClipboardScanDelay time.Duration
	WriteTimeout       time.Duration
	// represents the current device
	Metadata *data.MetaData

	Notifier notification.Notifier

	Discovering DiscoverOptions
}

type Peer

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

func AcquirePeer

func AcquirePeer(
	conn net.Conn,
	addr netip.AddrPort,
	meta *data.MetaData,
	updates data.Channel,
	cipher *encrypter.Cipher,
) *Peer

func (*Peer) Addr

func (p *Peer) Addr() netip.AddrPort

func (*Peer) Close

func (p *Peer) Close() error

func (*Peer) Conn

func (p *Peer) Conn() net.Conn

func (*Peer) MetaData added in v1.0.3

func (p *Peer) MetaData() *data.MetaData

func (*Peer) Receive

func (p *Peer) Receive(last *data.LastMessage)

func (*Peer) Release

func (p *Peer) Release()

func (*Peer) Signer added in v1.0.3

func (p *Peer) Signer() crypto.Signer

func (*Peer) String

func (p *Peer) String() string

func (*Peer) Updates

func (p *Peer) Updates() data.Channel

type Storage

type Storage = storage.SyncMap[data.UniqueID, *Peer]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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