peers

package
v0.0.0-...-512bbbe Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExternalIP

func GetExternalIP() string

Get external IP address

Types

type MessagePayload

type MessagePayload struct {
	Recipient string `json"recipient"`
	Data      string `json:"data"`
}

Expected JSON payload of an incoming message

type Peer

type Peer struct {
	// Exposed information
	Ip       string `json:"ip"`      // IP of our local node
	Version  string `json:"version"` // Protocol version
	Services struct {
		Messenger struct {
			Total     int    `json:"total"`
			Broadhash string `json:"broadhash"`
		} `json:"messenger"`
	} `json:"services"`
	Os string `json:"os"` // Operating system the local node is running
	// contains filtered or unexported fields
}

A representation of a Peer

func NewPeer

func NewPeer(address string, version string) *Peer

Return a new instance of a Peer for local use

func (*Peer) ConnectToPeer

func (p *Peer) ConnectToPeer(ip string) error

Connect to a peer based on its IP address

func (*Peer) HandleIncoming

func (p *Peer) HandleIncoming(w http.ResponseWriter, r *http.Request)

Incoming messages

func (*Peer) RetrieveMessages

func (p *Peer) RetrieveMessages(w http.ResponseWriter, r *http.Request)

Retrieve messages querying via a public key with a GET request Return a list of all the messages we have for this public key. It will be up to the client to filter them.

func (*Peer) SendMessage

func (p *Peer) SendMessage(ip string, msg msg.Message)

Send messages to other peers

func (*Peer) StoreMessage

func (p *Peer) StoreMessage(w http.ResponseWriter, r *http.Request)

Submit a message to other peers on the network through the HTTP API. This endpoint will take a JSON payload, convert it to a P2P friendly message and then broadcast to the other connected nodes.

Jump to

Keyboard shortcuts

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