autonomous_peer

package
v0.0.0-...-ac027a7 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	API           = "/exchange"
	MAX_MESSAGE   = 1000000 //1M
	MESSAGE_PEERS = "Peers"
	MESSAGE_END   = "End"
)

Variables

This section is empty.

Functions

func CreateAddress

func CreateAddress(addr, id string) string

Types

type Data

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

func (*Data) GetData

func (d *Data) GetData(dataType string) []byte

GetData for a given dataType Protected by data Mutex

func (*Data) RegisterDataUpdate

func (d *Data) RegisterDataUpdate(dataType string, update func([]byte))

RegisterDataUpdate for a given dataType Protected by data Mutex

func (*Data) SetData

func (d *Data) SetData(dataType string, data []byte)

SetData for a given dataType Protected by data Mutex

type IdRec

type IdRec struct {
	Id      string    `json:"id"`
	Version time.Time `json:"ver"`
}

type P2pHost

type P2pHost struct {
	Data Data
	// contains filtered or unexported fields
}

func NewHost

func NewHost(myAddr string, psk []byte) *P2pHost

func (*P2pHost) AddPeers

func (h *P2pHost) AddPeers(peerHosts map[string]*IdRec)

AddPeers using a map of peers. Protected with host mutex.

func (*P2pHost) Close

func (h *P2pHost) Close()

func (*P2pHost) GetAddress

func (h *P2pHost) GetAddress() string

func (*P2pHost) GetHostAddress

func (h *P2pHost) GetHostAddress() string

func (*P2pHost) GetID

func (h *P2pHost) GetID() string

func (*P2pHost) PurgePeer

func (h *P2pHost) PurgePeer(hostAddr string)

PurgePeer of a given hostAddr. Protected with host mutex.

func (*P2pHost) SetDataVersion

func (h *P2pHost) SetDataVersion(dataType string, version *time.Time)

SetDataVersion for a given dataType. Protected with host mutex.

Jump to

Keyboard shortcuts

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