Documentation ¶
Index ¶
- Variables
- type Channel
- type DiscoverOptions
- type LastMessage
- type Node
- type Option
- func WithBitSize(size int) Option
- func WithClipboardScanDelay(delay time.Duration) Option
- func WithDiscovering(opt DiscoverOptions) Option
- func WithKeepAlive(duration time.Duration) Option
- func WithNotifier(notifier notification.Notifier) Option
- func WithPublicPort(port int) Option
- func WithWriteTimeout(timeout time.Duration) Option
- type Options
- type Peer
- type PeerOption
- type Storage
Constants ¶
This section is empty.
Variables ¶
var (
ErrAlreadyConnected = errors.New("already connected")
)
Functions ¶
This section is empty.
Types ¶
type DiscoverOptions ¶ added in v1.1.1
type LastMessage ¶ added in v1.2.0
type LastMessage struct { *domain.Message Update chan *domain.Message // contains filtered or unexported fields }
LastMessage which is stored in Node and serves to identify duplicate messages
func NewLastMessage ¶ added in v1.2.0
func NewLastMessage() *LastMessage
func (*LastMessage) Get ¶ added in v1.2.0
func (m *LastMessage) Get() *domain.Message
func (*LastMessage) ListenUpdates ¶ added in v1.2.0
func (m *LastMessage) ListenUpdates()
ListenUpdates updates the lastMessage with the latest message received
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func New ¶
func New( clipboard clipboard.Manager, peers *Storage, localClipboard Channel, opts ...Option, ) *Node
New creates a new instance of Node with the specified settings.
func (*Node) Broadcast ¶
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 ¶
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) MonitorBuffer ¶
func (n *Node) MonitorBuffer()
MonitorBuffer starts monitoring the clipboard and subsequently sending data to other nodes
func (*Node) Start ¶
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 Option ¶ added in v1.2.0
type Option func(*Options)
Option defines the method to configure Options
func WithBitSize ¶ added in v1.2.0
func WithClipboardScanDelay ¶ added in v1.2.0
func WithDiscovering ¶ added in v1.2.0
func WithDiscovering(opt DiscoverOptions) Option
func WithKeepAlive ¶ added in v1.2.0
func WithNotifier ¶ added in v1.2.0
func WithNotifier(notifier notification.Notifier) Option
func WithPublicPort ¶ added in v1.2.0
func WithWriteTimeout ¶ added in v1.2.0
type Options ¶ added in v1.0.3
type Options struct { PublicPort int BitSize int KeepAlive time.Duration ClipboardScanDelay time.Duration WriteTimeout time.Duration Notifier notification.Notifier Discovering DiscoverOptions }
func NewOptions ¶ added in v1.2.0
NewOptions creates Options with provided options
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
func AcquirePeer ¶
func AcquirePeer(opts ...PeerOption) *Peer
func (*Peer) Receive ¶
func (p *Peer) Receive(last *LastMessage)
type PeerOption ¶ added in v1.2.0
type PeerOption func(*Peer)
func WithCipher ¶ added in v1.2.0
func WithCipher(cipher *encrypter.Cipher) PeerOption
func WithConn ¶ added in v1.2.0
func WithConn(conn net.Conn) PeerOption
func WithLocalClipboard ¶ added in v1.2.0
func WithLocalClipboard(updates Channel) PeerOption
func WithMetaData ¶ added in v1.2.0
func WithMetaData(meta domain.MetaData) PeerOption