loudp2p

package
v0.0.0-...-baa52f3 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2017 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SayHello      EventType = 1
	HelloPeerAddr           = 2
	HelloRPCPort            = 3
)
View Source
const (
	DefaultSettingsFilename = "settings.json"
	DefaultRPCPort          = 5555
)

Variables

This section is empty.

Functions

func HandleExchange

func HandleExchange()

Types

type Client

type Client struct {
	Peers    []Peer
	Settings *Settings
	Events   *EventHandler
}

Client represents a standard data structure for clients.

func NewClient

func NewClient(settings *Settings, events *EventHandler) (client Client, err error)

NewClient initializes a new client, using the data from settings.

func (*Client) AnnounceTo

func (c *Client) AnnounceTo(peer Peer)

AnnounceTo is used to announce a client to another peer.

func (*Client) HandleEvents

func (c *Client) HandleEvents()

HandleEvents listens for events:

func (*Client) Start

func (c *Client) Start()

Start starts the peer discovery process.

type Event

type Event struct {
	Type     EventType
	Metadata interface{}
}

Event is a data structure for events.

type EventHandler

type EventHandler struct {
	Listeners []*chan (*Event)
}

EventHandler is the event handler base data structure.

func NewEventHandler

func NewEventHandler() (eventHandler EventHandler)

NewEventHandler returns a brand new EventHandler{}.

func (*EventHandler) AddListener

func (e *EventHandler) AddListener() *chan (*Event)

AddListener initializes a listener channel and returns a pointer to it.

func (*EventHandler) Emit

func (e *EventHandler) Emit(event Event)

Emit broadcasts the emitted event to available listeners.

type EventType

type EventType int

EventType is an event identifier for the enum-like thing.

type Peer

type Peer struct {
	Address string
	Conn    *grpc.ClientConn
	Client  loud.LoudClient
}

Peer represents the standard data structure for peers.

type Server

type Server struct {
	Settings *Settings
	Events   *EventHandler
}

Server represents the standard data structure for servers.

func NewServer

func NewServer(settings *Settings, events *EventHandler) (server Server, err error)

NewServer initializes a new server using the data from settings.

func (*Server) Dispatch

func (s *Server) Dispatch(stream pb.Loud_DispatchServer) (err error)

func (*Server) HandleEvents

func (s *Server) HandleEvents()

Event handler:

func (*Server) Hello

func (s *Server) Hello(ctx context.Context, helloMessage *pb.HelloMessage) (message *pb.DummyMessage, err error)

Service implementation:

func (*Server) Start

func (s *Server) Start()

Start starts the server.

type Settings

type Settings struct {
	PrivateKey *ecdsa.PrivateKey `json:"-"`
	PublicKey  *ecdsa.PublicKey  `json:"-"`

	PrivKeyBytes []byte
	PubKeyBytes  []byte
	PeerID       string

	IgnoreInitialPeers bool `json:"-"`
	RPCPort            int64
}

Settings holds the key pair & peer ID.

func LoadSettings

func LoadSettings() (settings *Settings)

LoadSettings will load the settings from disk.

func (*Settings) LoadKeys

func (s *Settings) LoadKeys() (err error)

LoadKeys will call crypto.ParseKeys.

func (*Settings) Persist

func (s *Settings) Persist() (err error)

Persist will persist the settings to disk.

func (*Settings) Validate

func (s *Settings) Validate() (err error)

Validate will validate the settings fields.

Jump to

Keyboard shortcuts

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