poll

package
v0.2.97 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var POLL_BUCKET = []byte("poll-list")

Functions

func NewStore

func NewStore(db *bbolt.DB) (*pollStore, error)

Types

type MessageReceiver

type MessageReceiver interface {
	AddMessageHandler(func(peerId string, msgType string, payload []byte) error)
}

type MessageSender

type MessageSender interface {
	SendMessage(peerId string, message []byte, messageType int) error
}

type Messenger

type Messenger interface {
	MessageSender
	MessageReceiver
}

type PeerGetter

type PeerGetter interface {
	GetPeers() []string
}

type Policy

type Policy interface {
	IsPeerAllowed(peerId string) bool
}

type PollInfo

type PollInfo struct {
	ProtocolVersion uint64   `json:"version"`
	Assets          []string `json:"assets"`
	PeerAllowed     bool
	LastSeen        time.Time
}

type PollMessage

type PollMessage struct {
	Version     uint64   `json:"version"`
	Assets      []string `json:"assets"`
	PeerAllowed bool     `json:"peer_allowed"`
}

func (PollMessage) MessageType

func (PollMessage) MessageType() messages.MessageType

type PollNotFoundErr

type PollNotFoundErr string

func (PollNotFoundErr) Error

func (p PollNotFoundErr) Error() string

type RequestPollMessage

type RequestPollMessage struct {
	Version     uint64   `json:"version"`
	Assets      []string `json:"assets"`
	PeerAllowed bool     `json:"peer_allowed"`
}

func (RequestPollMessage) MessageType

func (RequestPollMessage) MessageType() messages.MessageType

type Service

type Service struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewService

func NewService(tickDuration time.Duration, removeDuration time.Duration, store Store, messenger Messenger, policy Policy, peers PeerGetter, allowedAssets []string) *Service

func (*Service) GetCompatiblePolls

func (s *Service) GetCompatiblePolls() (map[string]PollInfo, error)

GetCompatiblePolls returns all polls from peers that are running the same protocol version.

func (*Service) GetPollFrom

func (s *Service) GetPollFrom(peerId string) (*PollInfo, error)

GetPollFrom returns the PollInfo for a single peer with peerId. Returns a PollNotFoundErr if no PollInfo for the peer is present.

func (*Service) GetPolls

func (s *Service) GetPolls() (map[string]PollInfo, error)

func (*Service) MessageHandler

func (s *Service) MessageHandler(peerId string, msgType string, payload []byte) error

MessageHandler checks for the incomming messages type and takes the incomming payload to update the store.

func (*Service) Poll

func (s *Service) Poll(peer string)

Poll sends the POLL message to a single peer.

func (*Service) PollAllPeers

func (s *Service) PollAllPeers()

func (*Service) RequestAllPeerPolls

func (s *Service) RequestAllPeerPolls()

RequestAllPeerPolls requests the poll message from every peer.

func (*Service) RequestPoll

func (s *Service) RequestPoll(peer string)

RequestPoll sends the REUQEST_POLL message to a single peer.

func (*Service) Start

func (s *Service) Start()

Start the poll message loop and send the poll messages on every tick.

func (*Service) Stop

func (s *Service) Stop()

type Store

type Store interface {
	Update(peerId string, info PollInfo) error
	GetAll() (map[string]PollInfo, error)
	RemoveUnseen(olderThan time.Duration) error
}

Jump to

Keyboard shortcuts

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