Documentation ¶
Index ¶
Constants ¶
const ( SayHello EventType = 1 HelloPeerAddr = 2 HelloRPCPort = 3 )
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 ¶
AnnounceTo is used to announce a client to another peer.
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 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) Hello ¶
func (s *Server) Hello(ctx context.Context, helloMessage *pb.HelloMessage) (message *pb.DummyMessage, err error)
Service implementation:
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.