peer

package
v0.0.0-...-c98d9f8 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2021 License: EPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Done

type Done chan<- interface{}

Done is channel used to singal the termination of the service.

type OnPeerStoreChange

type OnPeerStoreChange func(i int)

OnPeerStoreChange is a function that is executed everytime a peer is added to the store.

type Peer

type Peer struct {
	Name      string   // Name is the peers name.
	IPAddress net.IP   // IPAddress is the net.IP address of the peer.
	Port      int      // Port is the network port where the peer will receive connections.
	Address   net.Addr // Address is the resolved TCP Address of the peer IP+Port.
	Me        bool     // Me identify the peer as the local peer.
}

Peer defines a network peer that can send and receive files.

type PeerList

type PeerList struct {
	widget.List
	TransferRequest

	Parent fyne.Window
	// contains filtered or unexported fields
}

PeerList is an extended version of widget.List where is uses a store to hold the list items, has a callback to the ouside and has is own layout.

func NewView

func NewView(store *PeerStore) *PeerList

NewView creates a new PeerList which is just an extended version of widget.List.

Everytime the store content changes the view is refreshed.

type PeerServer

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

PeerServer defines the server that registers the peer and discover other peers. It wrappes the logic for zeroconf.

func NewServer

func NewServer(name string, port int, store *PeerStore) *PeerServer

NewServer will create a new peer server instace.

The name to be added to the instance name, the port is the port number used for the TCP connections from where the files will be transferred.

func (*PeerServer) Run

func (s *PeerServer) Run(ctx context.Context, done Done) error

Run will start the Server that will register the peer and start looking for peers on the local network with zeroconf.

Each peer that is discovered will be added to the peer store.

If there is an error, it can be because the server couldn't make the registrations, the server listener couldn't start or fail to start the discovery process.

type PeerStore

type PeerStore struct {
	OnPeerStoreChange
	// contains filtered or unexported fields
}

PeerStore is a thread-safe store that allows to store and retrieve peers and also get notification when the content of the store changes.

func NewStore

func NewStore() *PeerStore

NewStore create a new instance of PeerStore.

func (*PeerStore) Add

func (s *PeerStore) Add(p *Peer) int

Add will append a peer to the existing list of peers.

It returns the index where the peer whas stored.

After the peer gets added the function OnPeerStoreChanged is executed.

func (*PeerStore) Get

func (s *PeerStore) Get(i int) *Peer

Get return a peer from the specified index.

If the index doesn't exists returns nil.

func (*PeerStore) GetMe

func (s *PeerStore) GetMe() *Peer

func (*PeerStore) Size

func (s *PeerStore) Size() int

type TransferRequest

type TransferRequest func(filePath, fileName, checksum, peerNames string, size int64, addr net.Addr)

TransferRequest represents the callback that is executed when a new transfer is added to the queue to be transferred or waiting for confirmation.

Jump to

Keyboard shortcuts

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